Mercurial > audlegacy-plugins
annotate src/cdaudio-ng/cdaudio-ng.c @ 1706:bec872f5809e
Fixed cdaudio-ng.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Sep 2007 17:50:10 +0300 |
parents | f6f5603a0954 |
children | b98f403b829f |
rev | line source |
---|---|
1508
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
1 /* |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
2 * Audacious CD Digital Audio plugin |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
3 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
4 * Copyright (c) 2007 Calin Crisan <ccrisan@gmail.com> |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
5 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
8 * the Free Software Foundation; under version 3 of the License. |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
9 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
13 * GNU General Public License for more details. |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
14 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
16 * along with this program. If not, see <http://www.gnu.org/licenses>. |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
17 */ |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
18 |
1048 | 19 |
20 #include <string.h> | |
21 #include <stdlib.h> | |
22 #include <unistd.h> | |
23 #include <errno.h> | |
24 #include <libgen.h> | |
25 | |
26 #include <cdio/cdio.h> | |
27 #include <cdio/cdtext.h> | |
28 #include <cdio/track.h> | |
29 #include <cdio/cdda.h> | |
30 #include <cdio/audio.h> | |
31 #include <cdio/sector.h> | |
32 #include <cdio/cd_types.h> | |
1282 | 33 #include <cddb/cddb.h> |
1048 | 34 |
35 #include <glib.h> | |
36 | |
1529 | 37 #include <audacious/configdb.h> |
1048 | 38 #include <audacious/i18n.h> |
1529 | 39 #include <audacious/output.h> |
40 #include <audacious/playlist.h> | |
1123 | 41 #include <audacious/plugin.h> |
1529 | 42 #include <audacious/ui_plugin_menu.h> |
1048 | 43 #include <audacious/util.h> |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
44 #include "config.h" |
1048 | 45 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
46 #include "cdaudio-ng.h" |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
47 #include "configure.h" |
1123 | 48 |
1048 | 49 |
50 static int firsttrackno = -1; | |
51 static int lasttrackno = -1; | |
1123 | 52 static CdIo_t *pcdio = NULL; |
1048 | 53 static trackinfo_t *trackinfo = NULL; |
1282 | 54 |
1123 | 55 static gboolean use_dae = TRUE; |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
56 static gboolean use_cdtext = TRUE; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
57 static gboolean use_cddb = TRUE; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
58 static char device[DEF_STRING_LEN]; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
59 static int limitspeed = 1; |
1048 | 60 static gboolean is_paused = FALSE; |
61 static int playing_track = -1; | |
1123 | 62 static dae_params_t *pdae_params = NULL; |
1193 | 63 static gboolean debug = FALSE; |
1303 | 64 static char cddb_server[DEF_STRING_LEN]; |
65 static int cddb_port; | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
66 static InputPlayback *pglobalinputplayback = NULL; |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
67 static GtkWidget *main_menu_item, *playlist_menu_item; |
1048 | 68 |
69 static void cdaudio_init(); | |
70 static void cdaudio_about(); | |
71 static void cdaudio_configure(); | |
72 static gint cdaudio_is_our_file(gchar *filename); | |
73 static GList *cdaudio_scan_dir(gchar *dirname); | |
74 static void cdaudio_play_file(InputPlayback *pinputplayback); | |
75 static void cdaudio_stop(InputPlayback *pinputplayback); | |
76 static void cdaudio_pause(InputPlayback *pinputplayback, gshort paused); | |
77 static void cdaudio_seek(InputPlayback *pinputplayback, gint time); | |
78 static gint cdaudio_get_time(InputPlayback *pinputplayback); | |
79 static gint cdaudio_get_volume(gint *l, gint *r); | |
80 static gint cdaudio_set_volume(gint l, gint r); | |
81 static void cdaudio_cleanup(); | |
82 static void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length); | |
1466 | 83 static Tuple *cdaudio_get_song_tuple(gchar *filename); |
1048 | 84 |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
85 static void menu_click(); |
1466 | 86 static Tuple *create_tuple_from_trackinfo(char *filename); |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
87 static void dae_play_loop(dae_params_t *pdae_params); |
1048 | 88 static int calculate_track_length(int startlsn, int endlsn); |
89 static int find_trackno_from_filename(char *filename); | |
1123 | 90 static void cleanup_on_error(); |
1048 | 91 |
92 | |
93 static InputPlugin inputplugin = { | |
1624
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
94 .description = "CD Audio Plugin NG", |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
95 .init = cdaudio_init, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
96 .about = cdaudio_about, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
97 .configure = cdaudio_configure, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
98 .is_our_file = cdaudio_is_our_file, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
99 .scan_dir = cdaudio_scan_dir, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
100 .play_file = cdaudio_play_file, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
101 .stop = cdaudio_stop, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
102 .pause = cdaudio_pause, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
103 .seek = cdaudio_seek, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
104 .get_time = cdaudio_get_time, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
105 .get_volume = cdaudio_get_volume, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
106 .set_volume = cdaudio_set_volume, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
107 .cleanup = cdaudio_cleanup, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
108 .get_song_info = cdaudio_get_song_info, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
109 .get_song_tuple = cdaudio_get_song_tuple |
1048 | 110 }; |
111 | |
1098
334afe46961c
[svn] - cdaudio-ng (aka Zither's CD Audio Plugin): convert to plugin API v2
nenolod
parents:
1048
diff
changeset
|
112 InputPlugin *cdaudio_iplist[] = { &inputplugin, NULL }; |
1048 | 113 |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1389
diff
changeset
|
114 DECLARE_PLUGIN(cdaudio, NULL, NULL, cdaudio_iplist, NULL, NULL, NULL, NULL, NULL); |
1048 | 115 |
1123 | 116 |
1048 | 117 void cdaudio_init() |
118 { | |
1193 | 119 if (debug) |
120 printf("cdaudio-ng: cdaudio_init()\n"); | |
1125 | 121 |
1123 | 122 if (!cdio_init()) { |
123 fprintf(stderr, "cdaudio-ng: failed to initialize cdio subsystem\n"); | |
124 cleanup_on_error(); | |
125 return; | |
126 } | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
127 |
1282 | 128 libcddb_init(); |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
129 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
130 ConfigDb *db = bmp_cfg_db_open(); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
131 gchar *string = NULL; |
1529 | 132 gchar *menu_item_text = _("Add CD"); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
133 |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
134 /* |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
135 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_dae", &use_dae)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
136 use_dae = TRUE; |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
137 */ |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
138 if (!bmp_cfg_db_get_int(db, "CDDA", "limitspeed", &limitspeed)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
139 limitspeed = 1; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
140 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cdtext", &use_cdtext)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
141 use_cdtext = TRUE; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
142 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cddb", &use_cddb)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
143 use_cddb = TRUE; |
1303 | 144 if (!bmp_cfg_db_get_string(db, "CDDA", "cddbserver", &string)) |
1340
7bb2692b3be9
Setting a sane default configuration for the plugin
Calin Crisan ccrisan@gmail.com
parents:
1339
diff
changeset
|
145 strcpy(cddb_server, CDDA_DEFAULT_CDDB_SERVER); |
1303 | 146 else |
147 strcpy(cddb_server, string); | |
148 if (!bmp_cfg_db_get_int(db, "CDDA", "cddbport", &cddb_port)) | |
1340
7bb2692b3be9
Setting a sane default configuration for the plugin
Calin Crisan ccrisan@gmail.com
parents:
1339
diff
changeset
|
149 cddb_port = CDDA_DEFAULT_CDDB_PORT; |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
150 if (!bmp_cfg_db_get_string(db, "CDDA", "device", &string)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
151 strcpy(device, ""); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
152 else |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
153 strcpy(device, string); |
1193 | 154 if (!bmp_cfg_db_get_bool(db, "CDDA", "debug", &debug)) |
155 debug = FALSE; | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
156 |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
157 bmp_cfg_db_close(db); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
158 |
1193 | 159 if (debug) |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
160 printf("cdaudio-ng: configuration: "/*use_dae = %d, */"limitspeed = %d, use_cdtext = %d, use_cddb = %d, cddbserver = \"%s\", cddbport = %d, device = \"%s\", debug = %d\n", /*use_dae, */limitspeed, use_cdtext, use_cddb, cddb_server, cddb_port, device, debug); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
161 |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
162 configure_set_variables(/*&use_dae, */&limitspeed, &use_cdtext, &use_cddb, device, &debug, cddb_server, &cddb_port); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
163 configure_create_gui(); |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
164 |
1529 | 165 main_menu_item = gtk_image_menu_item_new_with_label(menu_item_text); |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
166 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(main_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
167 gtk_widget_show(main_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
168 audacious_menu_plugin_item_add(AUDACIOUS_MENU_MAIN, main_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
169 g_signal_connect(G_OBJECT(main_menu_item), "button_press_event", G_CALLBACK(menu_click), NULL); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
170 |
1529 | 171 playlist_menu_item = gtk_image_menu_item_new_with_label(menu_item_text); |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
172 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(playlist_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
173 gtk_widget_show(playlist_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
174 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST, playlist_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
175 g_signal_connect(G_OBJECT(playlist_menu_item), "button_press_event", G_CALLBACK(menu_click), NULL); |
1482
3b2a302fe43f
Register cdda:// with uri_set_plugin
Christian Birchinger <joker@netswarm.net>
parents:
1473
diff
changeset
|
176 |
3b2a302fe43f
Register cdda:// with uri_set_plugin
Christian Birchinger <joker@netswarm.net>
parents:
1473
diff
changeset
|
177 uri_set_plugin("cdda://", &inputplugin); |
1048 | 178 } |
179 | |
180 void cdaudio_about() | |
181 { | |
1193 | 182 if (debug) |
183 printf("cdaudio-ng: cdaudio_about()\n"); | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
184 |
1377
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
185 static GtkWidget* about_window = NULL; |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
186 |
1377
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
187 if (about_window) { |
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
188 gdk_window_raise(about_window->window); |
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
189 } |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
190 |
1377
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
191 char about_text[1000]; |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
192 sprintf(about_text, _("Copyright (c) 2007, by Calin Crisan <ccrisan@gmail.com> and The Audacious Team.\n\n" |
1377
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
193 "Many thanks to libcdio developers <http://www.gnu.org/software/libcdio/>\n\tand to libcddb developers <http://libcddb.sourceforge.net/>.\n\n" |
1378
7a7f446bc87c
Some changes to the about box
Calin Crisan ccrisan@gmail.com
parents:
1377
diff
changeset
|
194 "Also thank you Tony Vroon for mentoring & guiding me.\n\n" |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
195 "This was a Google Summer of Code 2007 project.")); |
1377
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
196 |
1677
f6f5603a0954
xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents:
1624
diff
changeset
|
197 about_window = audacious_info_dialog(_("About CD Audio Plugin NG"), about_text, _("OK"), FALSE, NULL, NULL); |
1377
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
198 |
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
199 g_signal_connect(G_OBJECT(about_window), "destroy", |
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
200 G_CALLBACK(gtk_widget_destroyed), &about_window); |
1048 | 201 } |
202 | |
203 void cdaudio_configure() | |
204 { | |
1193 | 205 if (debug) |
206 printf("cdaudio-ng: cdaudio_configure()\n"); | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
207 |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
208 /* |
1303 | 209 if (playing_track != -1) |
210 playback_stop(); | |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
211 */ |
1303 | 212 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
213 configure_show_gui(); |
1048 | 214 } |
215 | |
216 gint cdaudio_is_our_file(gchar *filename) | |
217 { | |
1193 | 218 if (debug) |
219 printf("cdaudio-ng: cdaudio_is_our_file(\"%s\")\n", filename); | |
1125 | 220 |
1048 | 221 if ((filename != NULL) && strlen(filename) > 4 && (!strcasecmp(filename + strlen(filename) - 4, ".cda"))) { |
1123 | 222 /* no CD information yet */ |
223 if (pcdio == NULL) { | |
1193 | 224 if (debug) |
225 printf("cdaudio-ng: no cd information, scanning\n"); | |
1125 | 226 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 227 } |
1123 | 228 |
229 /* reload the cd information if the media has changed */ | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
230 if (cdio_get_media_changed(pcdio) && pcdio != NULL) { |
1193 | 231 if (debug) |
232 printf("cdaudio-ng: cd changed, rescanning\n"); | |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
233 if (cdaudio_scan_dir(CDDA_DEFAULT) == NULL) |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
234 pcdio = NULL; |
1048 | 235 } |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
236 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
237 if (pcdio == NULL) { |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
238 if (debug) |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
239 printf("cdaudio-ng: \"%s\" is not our file\n", filename); |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
240 return FALSE; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
241 } |
1123 | 242 |
243 /* check if the requested track actually exists on the current audio cd */ | |
244 int trackno = find_trackno_from_filename(filename); | |
1125 | 245 if (trackno < firsttrackno || trackno > lasttrackno) { |
1193 | 246 if (debug) |
247 printf("cdaudio-ng: \"%s\" is not our file\n", filename); | |
1123 | 248 return FALSE; |
1125 | 249 } |
1123 | 250 |
1193 | 251 if (debug) |
252 printf("cdaudio-ng: \"%s\" is our file\n", filename); | |
1123 | 253 return TRUE; |
1048 | 254 } |
1125 | 255 else { |
1193 | 256 if (debug) |
257 printf("cdaudio-ng: \"%s\" is not our file\n", filename); | |
1123 | 258 return FALSE; |
1125 | 259 } |
1048 | 260 } |
261 | |
262 GList *cdaudio_scan_dir(gchar *dirname) | |
263 { | |
1193 | 264 if (debug) |
265 printf("cdaudio-ng: cdaudio_scan_dir(\"%s\")\n", dirname); | |
1125 | 266 |
1123 | 267 /* if the given dirname does not belong to us, we return NULL */ |
1125 | 268 if (strstr(dirname, CDDA_DEFAULT) == NULL) { |
1193 | 269 if (debug) |
270 printf("cdaudio-ng: \"%s\" directory does not belong to us\n", dirname); | |
1048 | 271 return NULL; |
1125 | 272 } |
1123 | 273 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
274 /* find an available, audio capable, cd drive */ |
1282 | 275 if (device != NULL && strlen(device) > 0) { |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
276 pcdio = cdio_open(device, DRIVER_UNKNOWN); |
1282 | 277 if (pcdio == NULL) { |
278 fprintf(stderr, "cdaudio-ng: failed to open cd device \"%s\"\n", device); | |
279 return NULL; | |
280 } | |
281 } | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
282 else { |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
283 char **ppcd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false); |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
284 pcdio = NULL; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
285 if (ppcd_drives != NULL && *ppcd_drives != NULL) { /* we have at least one audio capable cd drive */ |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
286 pcdio = cdio_open(*ppcd_drives, DRIVER_UNKNOWN); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
287 if (pcdio == NULL) { |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
288 fprintf(stderr, "cdaudio-ng: failed to open cd\n"); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
289 cleanup_on_error(); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
290 return NULL; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
291 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
292 if (debug) |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
293 printf("cdaudio-ng: found cd drive \"%s\" with audio capable media\n", *ppcd_drives); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
294 } |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
295 else { |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
296 fprintf(stderr, "cdaudio-ng: unable find or access a cdda capable drive\n"); |
1123 | 297 cleanup_on_error(); |
298 return NULL; | |
299 } | |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
300 if (ppcd_drives != NULL && *ppcd_drives != NULL) |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
301 cdio_free_device_list(ppcd_drives); |
1048 | 302 } |
303 | |
1193 | 304 /* limit read speed */ |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
305 if (limitspeed > 0 && use_dae) { |
1193 | 306 if (debug) |
307 printf("cdaudio-ng: setting drive speed limit to %dx\n", limitspeed); | |
1194 | 308 if (cdio_set_speed(pcdio, limitspeed) != DRIVER_OP_SUCCESS) |
1193 | 309 fprintf(stderr, "cdaudio-ng: failed to set drive speed to %dx\n", limitspeed); |
310 } | |
1282 | 311 |
312 /* get general track initialization */ | |
1194 | 313 cdrom_drive_t *pcdrom_drive = cdio_cddap_identify_cdio(pcdio, 1, NULL); // todo : check return / NULL |
1048 | 314 firsttrackno = cdio_get_first_track_num(pcdrom_drive->p_cdio); |
315 lasttrackno = cdio_get_last_track_num(pcdrom_drive->p_cdio); | |
1123 | 316 if (firsttrackno == CDIO_INVALID_TRACK || lasttrackno == CDIO_INVALID_TRACK) { |
1282 | 317 fprintf(stderr, "cdaudio-ng: failed to retrieve first/last track number\n"); |
1123 | 318 cleanup_on_error(); |
319 return NULL; | |
320 } | |
1193 | 321 if (debug) |
322 printf("cdaudio-ng: first track is %d and last track is %d\n", firsttrackno, lasttrackno); | |
1048 | 323 |
1123 | 324 if (trackinfo != NULL) /* if a previously allocated track information exists, we free it */ |
1048 | 325 free(trackinfo); |
326 trackinfo = (trackinfo_t *) malloc(sizeof(trackinfo_t) * (lasttrackno + 1)); | |
327 int trackno; | |
1282 | 328 |
1340
7bb2692b3be9
Setting a sane default configuration for the plugin
Calin Crisan ccrisan@gmail.com
parents:
1339
diff
changeset
|
329 trackinfo[0].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, 0); |
1303 | 330 trackinfo[0].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, CDIO_CDROM_LEADOUT_TRACK); |
331 strcpy(trackinfo[0].performer, ""); | |
332 strcpy(trackinfo[0].name, ""); | |
333 strcpy(trackinfo[0].genre, ""); | |
1282 | 334 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { |
335 trackinfo[trackno].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, trackno); | |
336 trackinfo[trackno].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, trackno); | |
1303 | 337 strcpy(trackinfo[trackno].performer, ""); |
338 strcpy(trackinfo[trackno].name, ""); | |
339 strcpy(trackinfo[trackno].genre, ""); | |
1282 | 340 |
341 if (trackinfo[trackno].startlsn == CDIO_INVALID_LSN || trackinfo[trackno].endlsn == CDIO_INVALID_LSN) { | |
342 fprintf(stderr, "cdaudio-ng: failed to retrieve stard/end lsn for track %d\n", trackno); | |
343 cleanup_on_error(); | |
344 return NULL; | |
345 } | |
346 } | |
347 | |
348 /* initialize de cddb subsystem */ | |
349 cddb_conn_t *pcddb_conn = NULL; | |
350 cddb_disc_t *pcddb_disc = NULL; | |
351 cddb_track_t *pcddb_track = NULL; | |
352 | |
353 if (use_cddb) { | |
354 pcddb_conn = cddb_new(); | |
355 if (pcddb_conn == NULL) | |
356 fprintf(stderr, "cdaudio-ng: failed to create the cddb connection\n"); | |
357 else { | |
358 if (debug) | |
359 printf("cdaudio-ng: getting cddb info\n"); | |
360 | |
1303 | 361 cddb_set_server_name(pcddb_conn, cddb_server); |
362 cddb_set_server_port(pcddb_conn, cddb_port); | |
1282 | 363 |
364 pcddb_disc = cddb_disc_new(); | |
365 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { | |
366 pcddb_track = cddb_track_new(); | |
367 cddb_track_set_frame_offset(pcddb_track, trackinfo[trackno].startlsn); | |
368 cddb_disc_add_track(pcddb_disc, pcddb_track); | |
369 } | |
370 | |
371 msf_t startmsf, endmsf; | |
372 cdio_get_track_msf(pcdio, 1, &startmsf); | |
373 cdio_get_track_msf(pcdio, CDIO_CDROM_LEADOUT_TRACK, &endmsf); | |
374 cddb_disc_set_length(pcddb_disc, cdio_audio_get_msf_seconds(&endmsf) - cdio_audio_get_msf_seconds(&startmsf)); | |
375 | |
376 int matches; | |
377 if ((matches = cddb_query(pcddb_conn, pcddb_disc)) == -1) { | |
378 fprintf(stderr, "cdaudio-ng: failed to query the cddb server: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); | |
379 cddb_disc_destroy(pcddb_disc); | |
380 pcddb_disc = NULL; | |
381 } | |
382 else { | |
383 if (debug) | |
384 printf("cdaudio-ng: discid = %X, category = \"%s\"\n", cddb_disc_get_discid(pcddb_disc), cddb_disc_get_category_str(pcddb_disc)); | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
385 |
1282 | 386 cddb_read(pcddb_conn, pcddb_disc); |
387 if (cddb_errno(pcddb_conn) != CDDB_ERR_OK) { | |
388 fprintf(stderr, "cdaudio-ng: failed to read the cddb info: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); | |
389 cddb_disc_destroy(pcddb_disc); | |
390 pcddb_disc = NULL; | |
391 } | |
392 else { | |
393 if (debug) | |
394 printf("cdaudio-ng: we have got the cddb info\n"); | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
395 |
1282 | 396 strcpy(trackinfo[0].performer, cddb_disc_get_artist(pcddb_disc)); |
397 strcpy(trackinfo[0].name, cddb_disc_get_title(pcddb_disc)); | |
398 strcpy(trackinfo[0].genre, cddb_disc_get_genre(pcddb_disc)); | |
399 } | |
400 } | |
401 } | |
402 } | |
403 | |
404 /* adding trackinfo[0] information (the disc) */ | |
405 if (use_cdtext) { | |
406 if (debug) | |
407 printf("cdaudio-ng: getting cd-text information for disc\n"); | |
408 cdtext_t *pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, 0); | |
409 if (pcdtext == NULL || pcdtext->field[CDTEXT_TITLE] == NULL) { | |
410 if (debug) | |
411 printf("cdaudio-ng: no cd-text available for disc\n"); | |
412 } | |
413 else { | |
414 strcpy(trackinfo[0].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : ""); | |
415 strcpy(trackinfo[0].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : ""); | |
416 strcpy(trackinfo[0].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : ""); | |
417 } | |
418 } | |
419 | |
420 /* add track "file" names to the list */ | |
421 GList *list = NULL; | |
1048 | 422 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
423 list = g_list_append(list, g_strdup_printf("track%02u.cda", trackno)); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
424 cdtext_t *pcdtext = NULL; |
1282 | 425 if (use_cdtext) { |
426 if (debug) | |
427 printf("cdaudio-ng: getting cd-text information for track %d\n", trackno); | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
428 pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, trackno); |
1282 | 429 if (pcdtext == NULL || pcdtext->field[CDTEXT_PERFORMER] == NULL) { |
430 if (debug) | |
431 printf("cdaudio-ng: no cd-text available for track %d\n", trackno); | |
432 pcdtext = NULL; | |
433 } | |
434 } | |
1048 | 435 |
436 if (pcdtext != NULL) { | |
437 strcpy(trackinfo[trackno].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : ""); | |
438 strcpy(trackinfo[trackno].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : ""); | |
439 strcpy(trackinfo[trackno].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : ""); | |
440 } | |
1282 | 441 else |
442 if (pcddb_disc != NULL) { | |
443 cddb_track_t *pcddb_track = cddb_disc_get_track(pcddb_disc, trackno - 1); | |
444 strcpy(trackinfo[trackno].performer, cddb_track_get_artist(pcddb_track)); | |
445 strcpy(trackinfo[trackno].name, cddb_track_get_title(pcddb_track)); | |
446 strcpy(trackinfo[trackno].genre, cddb_disc_get_genre(pcddb_disc)); | |
447 } | |
448 else { | |
449 strcpy(trackinfo[trackno].performer, ""); | |
450 strcpy(trackinfo[trackno].name, ""); | |
451 strcpy(trackinfo[trackno].genre, ""); | |
452 } | |
453 | |
1048 | 454 if (strlen(trackinfo[trackno].name) == 0) |
455 sprintf(trackinfo[trackno].name, "CD Audio Track %02u", trackno); | |
456 | |
1282 | 457 } |
458 | |
459 if (debug) { | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
460 printf("cdaudio-ng: disc has : performer = \"%s\", name = \"%s\", genre = \"%s\"\n", |
1282 | 461 trackinfo[0].performer, trackinfo[0].name, trackinfo[0].genre); |
462 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
463 printf("cdaudio-ng: track %d has : performer = \"%s\", name = \"%s\", genre = \"%s\", startlsn = %d, endlsn = %d\n", |
1282 | 464 trackno, trackinfo[trackno].performer, trackinfo[trackno].name, trackinfo[trackno].genre, trackinfo[trackno].startlsn, trackinfo[trackno].endlsn); |
1123 | 465 } |
1282 | 466 } |
1125 | 467 |
1282 | 468 if (pcddb_disc != NULL) |
469 cddb_disc_destroy(pcddb_disc); | |
470 if (pcddb_conn != NULL) | |
471 cddb_destroy(pcddb_conn); | |
1048 | 472 |
473 return list; | |
474 } | |
475 | |
476 void cdaudio_play_file(InputPlayback *pinputplayback) | |
1125 | 477 { |
1466 | 478 Tuple *tuple; |
479 char *title; | |
480 | |
1193 | 481 if (debug) |
482 printf("cdaudio-ng: cdaudio_play_file(\"%s\")\n", pinputplayback->filename); | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
483 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
484 pglobalinputplayback = pinputplayback; |
1125 | 485 |
1048 | 486 if (trackinfo == NULL) { |
1193 | 487 if (debug) |
488 printf("cdaudio-ng: no cd information, scanning\n"); | |
1125 | 489 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 490 } |
491 | |
1123 | 492 if (cdio_get_media_changed(pcdio)) { |
1193 | 493 if (debug) |
494 printf("cdaudio-ng: cd changed, rescanning\n"); | |
1125 | 495 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 496 } |
1123 | 497 |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
498 if (trackinfo == NULL) { |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
499 if (debug) |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
500 printf("cdaudio-ng: no cd information can be retrieved, aborting\n"); |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
501 pinputplayback->playing = FALSE; |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
502 return; |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
503 } |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
504 |
1048 | 505 int trackno = find_trackno_from_filename(pinputplayback->filename); |
1123 | 506 if (trackno < firsttrackno || trackno > lasttrackno) { |
1125 | 507 fprintf(stderr, "cdaudio-ng: trackno %d is out of range [%d..%d]\n", trackno, firsttrackno, lasttrackno); |
1123 | 508 cleanup_on_error(); |
1048 | 509 return; |
1123 | 510 } |
1048 | 511 |
512 pinputplayback->playing = TRUE; | |
513 playing_track = trackno; | |
1123 | 514 is_paused = FALSE; |
515 | |
1466 | 516 tuple = create_tuple_from_trackinfo(pinputplayback->filename); |
1510
3a252050736c
replace tuple_formatter_process_string() with tuple_formatter_make_title_string() except that for streamings.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1508
diff
changeset
|
517 title = tuple_formatter_make_title_string(tuple, get_gentitle_format()); |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
518 |
1388
eb6c11de9f33
Changed the cdda bitrate to 1411kbit/s in respect to the Red Book specifications
Calin Crisan ccrisan@gmail.com
parents:
1387
diff
changeset
|
519 inputplugin.set_info(title, calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn), 1411200, 44100, 2); |
1466 | 520 free(title); title = NULL; |
521 tuple_free(tuple); tuple = NULL; | |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
522 |
1123 | 523 if (use_dae) { |
1193 | 524 if (debug) |
525 printf("cdaudio-ng: using digital audio extraction\n"); | |
1125 | 526 |
1123 | 527 if (pdae_params != NULL) { |
528 fprintf(stderr, "cdaudio-ng: dae playback seems to be already started\n"); | |
529 return; | |
530 } | |
531 | |
532 if (pinputplayback->output->open_audio(FMT_S16_LE, 44100, 2) == 0) { | |
533 fprintf(stderr, "cdaudio-ng: failed open audio output\n"); | |
534 cleanup_on_error(); | |
535 return; | |
536 } | |
537 | |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
538 /* |
1193 | 539 if (debug) |
540 printf("cdaudio-ng: starting dae thread...\n"); | |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
541 */ |
1123 | 542 pdae_params = (dae_params_t *) malloc(sizeof(dae_params_t)); |
543 pdae_params->startlsn = trackinfo[trackno].startlsn; | |
544 pdae_params->endlsn = trackinfo[trackno].endlsn; | |
545 pdae_params->pplayback = pinputplayback; | |
546 pdae_params->seektime = -1; | |
547 pdae_params->currlsn = trackinfo[trackno].startlsn; | |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
548 pdae_params->thread = g_thread_self(); |
1447
195b5657303e
updated input plugins to use set_pb_ready to signal to the core that they're ready for playback
Giacomo Lozito <james@develia.org>
parents:
1395
diff
changeset
|
549 pinputplayback->set_pb_ready(pinputplayback); |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
550 dae_play_loop(pdae_params); |
1123 | 551 } |
552 else { | |
1193 | 553 if (debug) |
554 printf("cdaudio-ng: not using digital audio extraction\n"); | |
1125 | 555 |
1123 | 556 msf_t startmsf, endmsf; |
557 cdio_lsn_to_msf(trackinfo[trackno].startlsn, &startmsf); | |
558 cdio_lsn_to_msf(trackinfo[trackno].endlsn, &endmsf); | |
559 if (cdio_audio_play_msf(pcdio, &startmsf, &endmsf) != DRIVER_OP_SUCCESS) { | |
560 fprintf(stderr, "cdaudio-ng: failed to play analog audio cd\n"); | |
561 cleanup_on_error(); | |
562 return; | |
563 } | |
564 } | |
1048 | 565 } |
566 | |
567 void cdaudio_stop(InputPlayback *pinputplayback) | |
1125 | 568 { |
1193 | 569 if (debug) |
1303 | 570 printf("cdaudio-ng: cdaudio_stop(\"%s\")\n", pinputplayback != NULL ? pinputplayback->filename : "N/A"); |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
571 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
572 pglobalinputplayback = NULL; |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
573 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
574 if (playing_track == -1) |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
575 return; |
1125 | 576 |
1303 | 577 if (pinputplayback != NULL) |
578 pinputplayback->playing = FALSE; | |
1048 | 579 playing_track = -1; |
1123 | 580 is_paused = FALSE; |
581 | |
582 if (use_dae) { | |
583 if (pdae_params != NULL) { | |
584 g_thread_join(pdae_params->thread); | |
585 free(pdae_params); | |
586 pdae_params = NULL; | |
587 } | |
588 } | |
589 else { | |
590 if (cdio_audio_stop(pcdio) != DRIVER_OP_SUCCESS) { | |
591 fprintf(stderr, "cdaudio-ng: failed to stop analog cd\n"); | |
592 return; | |
593 } | |
594 } | |
1048 | 595 } |
596 | |
597 void cdaudio_pause(InputPlayback *pinputplayback, gshort paused) | |
598 { | |
1193 | 599 if (debug) |
600 printf("cdaudio-ng: cdaudio_pause(\"%s\", %d)\n", pinputplayback->filename, paused); | |
1125 | 601 |
1048 | 602 if (!is_paused) { |
603 is_paused = TRUE; | |
1123 | 604 if (!use_dae) |
605 if (cdio_audio_pause(pcdio) != DRIVER_OP_SUCCESS) { | |
606 fprintf(stderr, "cdaudio-ng: failed to pause analog cd\n"); | |
607 cleanup_on_error(); | |
608 return; | |
609 } | |
1048 | 610 } |
611 else { | |
612 is_paused = FALSE; | |
1123 | 613 if (!use_dae) |
614 if (cdio_audio_resume(pcdio) != DRIVER_OP_SUCCESS) { | |
615 fprintf(stderr, "cdaudio-ng: failed to resume analog cd\n"); | |
616 cleanup_on_error(); | |
617 return; | |
618 } | |
1048 | 619 } |
620 } | |
621 | |
622 void cdaudio_seek(InputPlayback *pinputplayback, gint time) | |
623 { | |
1193 | 624 if (debug) |
625 printf("cdaudio-ng: cdaudio_seek(\"%s\", %d)\n", pinputplayback->filename, time); | |
1125 | 626 |
1048 | 627 if (playing_track == -1) |
628 return; | |
629 | |
1123 | 630 if (use_dae) { |
631 if (pdae_params != NULL) { | |
632 pdae_params->seektime = time * 1000; | |
633 } | |
634 } | |
635 else { | |
636 int newstartlsn = trackinfo[playing_track].startlsn + time * 75; | |
637 msf_t startmsf, endmsf; | |
638 cdio_lsn_to_msf(newstartlsn, &startmsf); | |
639 cdio_lsn_to_msf(trackinfo[playing_track].endlsn, &endmsf); | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
640 |
1123 | 641 if (cdio_audio_play_msf(pcdio, &startmsf, &endmsf) != DRIVER_OP_SUCCESS) { |
642 fprintf(stderr, "cdaudio-ng: failed to play analog cd\n"); | |
643 cleanup_on_error(); | |
644 return; | |
645 } | |
646 } | |
1048 | 647 } |
648 | |
649 gint cdaudio_get_time(InputPlayback *pinputplayback) | |
650 { | |
1125 | 651 //printf("cdaudio-ng: cdaudio_get_time(\"%s\")\n", pinputplayback->filename); // annoying! |
652 | |
1048 | 653 if (playing_track == -1) |
654 return -1; | |
655 | |
1123 | 656 if (!use_dae) { |
657 cdio_subchannel_t subchannel; | |
658 if (cdio_audio_read_subchannel(pcdio, &subchannel) != DRIVER_OP_SUCCESS) { | |
659 fprintf(stderr, "cdaudio-ng: failed to read analog cd subchannel\n"); | |
660 cleanup_on_error(); | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
661 return 0; |
1123 | 662 } |
663 int currlsn = cdio_msf_to_lsn(&subchannel.abs_addr); | |
1048 | 664 |
1123 | 665 /* check to see if we have reached the end of the song */ |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
666 if (currlsn == trackinfo[playing_track].endlsn) |
1123 | 667 return -1; |
668 | |
669 return calculate_track_length(trackinfo[playing_track].startlsn, currlsn); | |
1048 | 670 } |
1123 | 671 else { |
672 if (pdae_params != NULL) | |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
673 if (pdae_params->pplayback->playing) |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
674 return pinputplayback->output->output_time(); |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
675 else |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
676 return -1; |
1123 | 677 else |
678 return -1; | |
679 } | |
1048 | 680 } |
681 | |
682 gint cdaudio_get_volume(gint *l, gint *r) | |
683 { | |
1125 | 684 //printf("cdaudio-ng: cdaudio_get_volume()\n"); // annoying! |
685 | |
1123 | 686 if (use_dae) { |
687 *l = *r = 0; | |
688 return FALSE; | |
689 } | |
690 else { | |
691 cdio_audio_volume_t volume; | |
692 if (cdio_audio_get_volume(pcdio, &volume) != DRIVER_OP_SUCCESS) { | |
693 fprintf(stderr, "cdaudio-ng: failed to retrieve analog cd volume\n"); | |
694 cleanup_on_error(); | |
695 *l = *r = 0; | |
696 return FALSE; | |
697 } | |
698 *l = volume.level[0]; | |
699 *r = volume.level[1]; | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
700 |
1123 | 701 return TRUE; |
702 } | |
1048 | 703 } |
704 | |
705 gint cdaudio_set_volume(gint l, gint r) | |
706 { | |
1193 | 707 if (debug) |
708 printf("cdaudio-ng: cdaudio_set_volume(%d, %d)\n", l, r); | |
1125 | 709 |
1123 | 710 if (use_dae) { |
711 return FALSE; | |
712 } | |
713 else { | |
714 cdio_audio_volume_t volume = {{l, r, 0, 0}}; | |
715 if (cdio_audio_set_volume(pcdio, &volume) != DRIVER_OP_SUCCESS) { | |
716 fprintf(stderr, "cdaudio-ng: failed to set analog cd volume\n"); | |
717 cleanup_on_error(); | |
718 return FALSE; | |
719 } | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
720 |
1123 | 721 return TRUE; |
722 } | |
1048 | 723 } |
724 | |
725 void cdaudio_cleanup() | |
726 { | |
1193 | 727 if (debug) |
728 printf("cdaudio-ng: cdaudio_cleanup()\n"); | |
1125 | 729 |
1282 | 730 libcddb_shutdown(); |
731 | |
1123 | 732 if (pcdio!= NULL) { |
733 if (playing_track != -1 && !use_dae) | |
734 cdio_audio_stop(pcdio); | |
735 cdio_destroy(pcdio); | |
736 pcdio = NULL; | |
737 } | |
738 if (trackinfo != NULL) { | |
739 free(trackinfo); | |
740 trackinfo = NULL; | |
741 } | |
742 playing_track = -1; | |
1282 | 743 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
744 // todo: destroy the gui |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
745 |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
746 ConfigDb *db = bmp_cfg_db_open(); |
1339
83cbc6968a0b
Set DAE the default and non-optional play method; Configuring the plugin no longer stops the playback;
Calin Crisan ccrisan@gmail.com
parents:
1314
diff
changeset
|
747 /*bmp_cfg_db_set_bool(db, "CDDA", "use_dae", use_dae);*/ |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
748 bmp_cfg_db_set_int(db, "CDDA", "limitspeed", limitspeed); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
749 bmp_cfg_db_set_bool(db, "CDDA", "use_cdtext", use_cdtext); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
750 bmp_cfg_db_set_bool(db, "CDDA", "use_cddb", use_cddb); |
1303 | 751 bmp_cfg_db_set_string(db, "CDDA", "cddbserver", cddb_server); |
752 bmp_cfg_db_set_int(db, "CDDA", "cddbport", cddb_port); | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
753 bmp_cfg_db_set_string(db, "CDDA", "device", device); |
1193 | 754 bmp_cfg_db_set_bool(db, "CDDA", "debug", debug); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
755 bmp_cfg_db_close(db); |
1048 | 756 } |
757 | |
758 void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length) | |
759 { | |
1193 | 760 if (debug) |
761 printf("cdaudio-ng: cdaudio_get_song_info(\"%s\")\n", filename); | |
1125 | 762 |
763 int trackno = find_trackno_from_filename(filename); | |
1466 | 764 Tuple *tuple = create_tuple_from_trackinfo(filename); |
1125 | 765 |
1466 | 766 if(tuple) { |
1473
eb0913bf54c3
use get_gentitle_format() to get format string so that presets and custom string can coexist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1466
diff
changeset
|
767 *title = tuple_formatter_process_string(tuple, get_gentitle_format()); |
1466 | 768 tuple_free(tuple); |
769 tuple = NULL; | |
770 } | |
1125 | 771 *length = calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn); |
1048 | 772 } |
773 | |
1466 | 774 Tuple *cdaudio_get_song_tuple(gchar *filename) |
1048 | 775 { |
1193 | 776 if (debug) |
777 printf("cdaudio-ng: cdaudio_get_song_tuple(\"%s\")\n", filename); | |
1125 | 778 |
1341
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
779 return create_tuple_from_trackinfo(filename); |
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
780 } |
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
781 |
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
782 |
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
783 /* auxiliar functions */ |
1048 | 784 |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
785 void menu_click() |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
786 { |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
787 GList *list, *node; |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
788 gchar *filename; |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
789 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
790 if (!(list = cdaudio_scan_dir(CDDA_DEFAULT))) { |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
791 const gchar *markup = |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
792 N_("<b><big>No playable CD found.</big></b>\n\n" |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
793 "No CD inserted, or inserted CD is not an audio CD.\n"); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
794 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
795 GtkWidget *dialog = |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
796 gtk_message_dialog_new_with_markup(NULL, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
797 GTK_DIALOG_DESTROY_WITH_PARENT, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
798 GTK_MESSAGE_ERROR, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
799 GTK_BUTTONS_OK, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
800 _(markup)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
801 gtk_dialog_run(GTK_DIALOG(dialog)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
802 gtk_widget_destroy(dialog); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
803 return; |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
804 } |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
805 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
806 for (node = list; node; node = g_list_next(node)) { |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
807 filename = g_build_filename(CDDA_DEFAULT, node->data, NULL); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
808 playlist_add(playlist_get_active(), filename); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
809 g_free(filename); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
810 g_free(node->data); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
811 } |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
812 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
813 g_list_free(list); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
814 } |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
815 |
1466 | 816 Tuple *create_tuple_from_trackinfo(char *filename) |
1341
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
817 { |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
818 if (trackinfo == NULL) |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
819 return NULL; |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
820 |
1466 | 821 Tuple *tuple = tuple_new_from_filename(filename); |
1048 | 822 int trackno = find_trackno_from_filename(filename); |
1341
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
823 |
1048 | 824 if (trackno < firsttrackno || trackno > lasttrackno) |
825 return NULL; | |
826 | |
1466 | 827 if(strlen(trackinfo[trackno].performer)) { |
1706 | 828 tuple_associate_string(tuple, FIELD_ARTIST, NULL, trackinfo[trackno].performer); |
1466 | 829 } |
830 if(strlen(trackinfo[0].name)) { | |
1706 | 831 tuple_associate_string(tuple, FIELD_ALBUM, NULL trackinfo[0].name); |
1466 | 832 } |
833 if(strlen(trackinfo[trackno].name)) { | |
1706 | 834 tuple_associate_string(tuple, FIELD_TITLE, NULL, trackinfo[trackno].name); |
1466 | 835 } |
1706 | 836 tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, trackno); |
837 tuple_associate_string(tuple, -1, "ext", "cda"); //XXX should do? --yaz | |
1466 | 838 |
1706 | 839 tuple_associate_int(tuple, FIELD_LENGTH, NULL, calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn)); |
1466 | 840 if(strlen(trackinfo[trackno].genre)) { |
1706 | 841 tuple_associate_string(tuple, FIELD_GENRE, NULL, trackinfo[trackno].genre); |
1466 | 842 } |
1048 | 843 //tuple->year = 0; todo: set the year |
844 | |
845 return tuple; | |
846 } | |
847 | |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
848 void dae_play_loop(dae_params_t *pdae_params) |
1123 | 849 { |
850 unsigned char *buffer = (unsigned char *) malloc(CDDA_DAE_FRAMES * CDIO_CD_FRAMESIZE_RAW); | |
851 | |
1193 | 852 if (debug) |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
853 printf("cdaudio-ng: dae started\n"); |
1123 | 854 cdio_lseek(pcdio, pdae_params->startlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET); |
855 | |
856 gboolean output_paused = FALSE; | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
857 int read_error_counter = 0; |
1125 | 858 |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
859 //pdae_params->endlsn += 75 * 3; |
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
860 |
1123 | 861 while (pdae_params->pplayback->playing) { |
862 /* handle pause status */ | |
863 if (is_paused) { | |
864 if (!output_paused) { | |
1193 | 865 if (debug) |
866 printf("cdaudio-ng: playback was not paused, pausing\n"); | |
1123 | 867 pdae_params->pplayback->output->pause(TRUE); |
868 output_paused = TRUE; | |
869 } | |
870 usleep(1000); | |
871 continue; | |
872 } | |
1125 | 873 else { |
1123 | 874 if (output_paused) { |
1193 | 875 if (debug) |
876 printf("cdaudio-ng: playback was paused, resuming\n"); | |
1123 | 877 pdae_params->pplayback->output->pause(FALSE); |
878 output_paused = FALSE; | |
879 } | |
1125 | 880 } |
1123 | 881 |
882 /* check if we have to seek */ | |
883 if (pdae_params->seektime != -1) { | |
1193 | 884 if (debug) |
885 printf("cdaudio-ng: requested seek to %d ms\n", pdae_params->seektime); | |
1123 | 886 int newlsn = pdae_params->startlsn + pdae_params->seektime * 75 / 1000; |
887 cdio_lseek(pcdio, newlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET); | |
888 pdae_params->pplayback->output->flush(pdae_params->seektime); | |
889 pdae_params->currlsn = newlsn; | |
890 pdae_params->seektime = -1; | |
891 } | |
892 | |
893 /* compute the actual number of sectors to read */ | |
894 int lsncount = CDDA_DAE_FRAMES <= (pdae_params->endlsn - pdae_params->currlsn + 1) ? CDDA_DAE_FRAMES : (pdae_params->endlsn - pdae_params->currlsn + 1); | |
895 /* check too see if we have reached the end of the song */ | |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
896 if (lsncount <= 0) { |
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
897 sleep(3); |
1123 | 898 break; |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
899 } |
1123 | 900 |
901 if (cdio_read_audio_sectors(pcdio, buffer, pdae_params->currlsn, lsncount) != DRIVER_OP_SUCCESS) { | |
902 fprintf(stderr, "cdaudio-ng: failed to read audio sector\n"); | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
903 read_error_counter++; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
904 if (read_error_counter >= 2) { |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
905 read_error_counter = 0; |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
906 fprintf(stderr, "cdaudio-ng: this cd can no longer be played, stopping\n"); |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
907 break; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
908 } |
1123 | 909 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
910 else |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
911 read_error_counter = 0; |
1123 | 912 |
913 int remainingbytes = lsncount * CDIO_CD_FRAMESIZE_RAW; | |
914 unsigned char *bytebuff = buffer; | |
915 while (pdae_params->pplayback->playing && remainingbytes > 0 && pdae_params->seektime == -1) { | |
916 /* compute the actual number of bytes to play */ | |
917 int bytecount = CDIO_CD_FRAMESIZE_RAW <= remainingbytes ? CDIO_CD_FRAMESIZE_RAW : remainingbytes; | |
918 /* wait until the output buffer has enough room */ | |
919 while (pdae_params->pplayback->playing && pdae_params->pplayback->output->buffer_free() < bytecount && pdae_params->seektime == -1) | |
920 usleep(1000); | |
921 /* play the sound :) */ | |
922 if (pdae_params->pplayback->playing && pdae_params->seektime == -1) | |
923 produce_audio(pdae_params->pplayback->output->written_time(), FMT_S16_LE, 2, bytecount, bytebuff, &pdae_params->pplayback->playing); | |
924 remainingbytes -= bytecount; | |
925 bytebuff += bytecount; | |
926 } | |
927 pdae_params->currlsn += lsncount; | |
928 } | |
1193 | 929 if (debug) |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
930 printf("cdaudio-ng: dae ended\n"); |
1123 | 931 |
932 pdae_params->pplayback->playing = FALSE; | |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
933 pdae_params->pplayback->output->close_audio(); |
1123 | 934 is_paused = FALSE; |
935 | |
936 pdae_params->pplayback->output->close_audio(); | |
937 free(buffer); | |
938 } | |
939 | |
1048 | 940 int calculate_track_length(int startlsn, int endlsn) |
941 { | |
942 return ((endlsn - startlsn + 1) * 1000) / 75; | |
943 } | |
944 | |
945 int find_trackno_from_filename(char *filename) | |
946 { | |
947 if ((filename == NULL) || strlen(filename) <= 6) | |
948 return -1; | |
949 | |
950 char tracknostr[3]; | |
951 strncpy(tracknostr, filename + strlen(filename) - 6, 2); | |
952 tracknostr[2] = '\0'; | |
953 return strtol(tracknostr, NULL, 10); | |
954 } | |
1123 | 955 |
956 void cleanup_on_error() | |
957 { | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
958 if (playing_track != -1) { |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
959 playing_track = -1; |
1123 | 960 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
961 |
1123 | 962 if (trackinfo != NULL) { |
963 free(trackinfo); | |
964 trackinfo = NULL; | |
965 } | |
966 } | |
1193 | 967 |