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