Mercurial > audlegacy
annotate Plugins/Input/adplug/adplug-xmms.cc @ 619:fc1788e1ab04 trunk
[svn] Start building adplug.
author | chainsaw |
---|---|
date | Sun, 05 Feb 2006 13:58:33 -0800 |
parents | 7fa1738514d5 |
children | 61bc556b71f0 |
rev | line source |
---|---|
359 | 1 /* |
2 AdPlug/XMMS - AdPlug XMMS Plugin | |
3 Copyright (C) 2002, 2003 Simon Peter <dn.tlp@gmx.net> | |
4 | |
5 AdPlug/XMMS is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This plugin is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this plugin; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 #include <algorithm> | |
21 #include <sstream> | |
22 #include <stdlib.h> | |
23 #include <stdio.h> | |
24 #include <sys/types.h> | |
25 #include <gtk/gtk.h> | |
26 #include "adplug.h" | |
27 #include "emuopl.h" | |
28 #include "silentopl.h" | |
29 #include "players.h" | |
30 #include "audacious/plugin.h" | |
31 #include "libaudacious/util.h" | |
32 #include "libaudacious/configdb.h" | |
414
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
33 extern "C" { |
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
34 #include "audacious/output.h" |
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
35 } |
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
36 |
359 | 37 |
38 /***** Defines *****/ | |
39 | |
40 // Version string | |
41 #define ADPLUG_NAME "AdPlug" | |
42 | |
43 // Sound buffer size in samples | |
44 #define SNDBUFSIZE 512 | |
45 | |
46 // AdPlug's 8 and 16 bit audio formats | |
47 #define FORMAT_8 FMT_U8 | |
48 #define FORMAT_16 FMT_S16_NE | |
49 | |
50 // Default file name of AdPlug's database file | |
51 #define ADPLUGDB_FILE "adplug.db" | |
52 | |
53 // Default AdPlug user's configuration subdirectory | |
54 #define ADPLUG_CONFDIR ".adplug" | |
55 | |
56 /***** Global variables *****/ | |
57 | |
58 extern "C" InputPlugin adplug_ip; | |
59 static gboolean audio_error = FALSE; | |
60 | |
61 // Configuration (and defaults) | |
62 static struct { | |
63 gint freq; | |
361
db298f2d3dd9
[svn] Detect files by content; remove quick detect.
chainsaw
parents:
359
diff
changeset
|
64 gboolean bit16, stereo, endless; |
359 | 65 CPlayers players; |
361
db298f2d3dd9
[svn] Detect files by content; remove quick detect.
chainsaw
parents:
359
diff
changeset
|
66 } cfg = { 44100l, true, false, false, CAdPlug::players }; |
359 | 67 |
68 // Player variables | |
69 static struct { | |
70 CPlayer *p; | |
71 CAdPlugDatabase *db; | |
72 unsigned int subsong, songlength; | |
73 int seek; | |
74 char filename[PATH_MAX]; | |
75 char *songtitle; | |
76 float time_ms; | |
77 bool playing; | |
78 GThread *play_thread; | |
79 GtkLabel *infobox; | |
80 GtkDialog *infodlg; | |
81 } plr = { 0, 0, 0, 0, -1, "", NULL, 0.0f, false, 0, NULL, NULL }; | |
82 | |
83 /***** Debugging *****/ | |
84 | |
85 #ifdef DEBUG | |
86 | |
87 #include <stdarg.h> | |
88 | |
89 static void dbg_printf(const char *fmt, ...) | |
90 { | |
91 va_list argptr; | |
92 | |
93 va_start(argptr, fmt); | |
94 vfprintf(stderr, fmt, argptr); | |
95 va_end(argptr); | |
96 } | |
97 | |
98 #else | |
99 | |
100 static void dbg_printf(const char *fmt, ...) | |
101 { } | |
102 | |
103 #endif | |
104 | |
105 /***** [Dialog]: Utility functions *****/ | |
106 | |
107 static GtkWidget *make_framed(GtkWidget *what, const gchar *label) | |
108 { | |
109 GtkWidget *framebox = gtk_frame_new(label); | |
110 | |
111 gtk_container_add(GTK_CONTAINER(framebox), what); | |
112 return framebox; | |
113 } | |
114 | |
115 static GtkWidget *print_left(const gchar *text) | |
116 { | |
117 GtkLabel *label = GTK_LABEL(gtk_label_new(text)); | |
118 | |
119 gtk_label_set_justify(label, GTK_JUSTIFY_LEFT); | |
120 gtk_misc_set_padding(GTK_MISC(label), 2, 2); | |
121 return GTK_WIDGET(label); | |
122 } | |
123 | |
124 static void MessageBox(const char *title, const char *text, const char *button) | |
125 { | |
126 char *tmptitle = (char *)malloc(strlen(title) + 1), | |
127 *tmptxt = (char *)malloc(strlen(text) + 1), | |
128 *tmpbutton = (char *)malloc(strlen(button) + 1); | |
129 | |
130 strcpy(tmptitle, title); strcpy(tmptxt, text); strcpy(tmpbutton, button); | |
131 | |
132 GtkWidget *msgbox = xmms_show_message(tmptitle, tmptxt, tmpbutton, FALSE, | |
133 GTK_SIGNAL_FUNC(gtk_widget_destroyed), &msgbox); | |
134 | |
135 free(tmptitle); free(tmptxt); free(tmpbutton); | |
136 } | |
137 | |
138 /***** Dialog boxes *****/ | |
139 | |
140 static void adplug_about(void) | |
141 { | |
142 std::ostringstream text; | |
143 | |
144 text << ADPLUG_NAME "\n" | |
145 "Copyright (C) 2002, 2003 Simon Peter <dn.tlp@gmx.net>\n\n" | |
146 "This plugin is released under the terms and conditions of the GNU LGPL.\n" | |
147 "See http://www.gnu.org/licenses/lgpl.html for details." | |
148 "\n\nThis plugin uses the AdPlug library, which is copyright (C) Simon Peter, et al.\n" | |
149 "Linked AdPlug library version: " << CAdPlug::get_version() << std::ends; | |
150 | |
151 MessageBox("About " ADPLUG_NAME, text.str().c_str(), "Ugh!"); | |
152 } | |
153 | |
154 static void close_config_box_ok(GtkButton *button, GPtrArray *rblist) | |
155 { | |
156 // Apply configuration settings | |
157 cfg.bit16 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_ptr_array_index(rblist, 0))); | |
158 cfg.stereo = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_ptr_array_index(rblist, 1))); | |
159 | |
160 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_ptr_array_index(rblist, 2)))) cfg.freq = 11025; | |
161 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_ptr_array_index(rblist, 3)))) cfg.freq = 22050; | |
162 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_ptr_array_index(rblist, 4)))) cfg.freq = 44100; | |
163 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_ptr_array_index(rblist, 5)))) cfg.freq = 48000; | |
164 | |
165 cfg.endless = !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_ptr_array_index(rblist, 6))); | |
166 | |
361
db298f2d3dd9
[svn] Detect files by content; remove quick detect.
chainsaw
parents:
359
diff
changeset
|
167 cfg.players = *(CPlayers *)g_ptr_array_index(rblist, 7); |
db298f2d3dd9
[svn] Detect files by content; remove quick detect.
chainsaw
parents:
359
diff
changeset
|
168 delete (CPlayers *)g_ptr_array_index(rblist, 7); |
359 | 169 |
170 g_ptr_array_free(rblist, FALSE); | |
171 } | |
172 | |
173 static void close_config_box_cancel(GtkButton *button, GPtrArray *rblist) | |
174 { | |
361
db298f2d3dd9
[svn] Detect files by content; remove quick detect.
chainsaw
parents:
359
diff
changeset
|
175 delete (CPlayers *)g_ptr_array_index(rblist, 7); |
359 | 176 g_ptr_array_free(rblist, FALSE); |
177 } | |
178 | |
179 static void config_fl_row_select(GtkCList *fl, gint row, gint col, | |
180 GdkEventButton *event, CPlayers *pl) | |
181 { | |
182 pl->push_back((CPlayerDesc *)gtk_clist_get_row_data(fl, row)); | |
183 pl->unique(); | |
184 } | |
185 | |
186 static void config_fl_row_unselect(GtkCList *fl, gint row, gint col, | |
187 GdkEventButton *event, CPlayers *pl) | |
188 { | |
189 pl->remove((CPlayerDesc *)gtk_clist_get_row_data(fl, row)); | |
190 } | |
191 | |
192 static void adplug_config(void) | |
193 { | |
194 GtkDialog *config_dlg = GTK_DIALOG(gtk_dialog_new()); | |
195 GtkNotebook *notebook = GTK_NOTEBOOK(gtk_notebook_new()); | |
196 GtkTable *table; | |
197 GtkTooltips *tooltips = gtk_tooltips_new(); | |
198 GPtrArray *rblist = g_ptr_array_new(); | |
199 | |
200 gtk_window_set_title(GTK_WINDOW(config_dlg), "AdPlug :: Configuration"); | |
201 gtk_window_set_policy(GTK_WINDOW(config_dlg), FALSE, FALSE, TRUE); // Window is auto sized | |
202 gtk_window_set_modal(GTK_WINDOW(config_dlg), TRUE); | |
203 gtk_container_add(GTK_CONTAINER(config_dlg->vbox), GTK_WIDGET(notebook)); | |
204 | |
205 // Add Ok & Cancel buttons | |
206 { | |
207 GtkWidget *button; | |
208 | |
209 button = gtk_button_new_with_label("Ok"); | |
210 gtk_signal_connect(GTK_OBJECT(button), "clicked", | |
211 GTK_SIGNAL_FUNC(close_config_box_ok), | |
212 (gpointer)rblist); | |
213 gtk_signal_connect_object_after(GTK_OBJECT(button), "clicked", | |
214 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
215 GTK_OBJECT(config_dlg)); | |
216 gtk_container_add(GTK_CONTAINER(config_dlg->action_area), button); | |
217 | |
218 button = gtk_button_new_with_label("Cancel"); | |
219 gtk_signal_connect(GTK_OBJECT(button), "clicked", | |
220 GTK_SIGNAL_FUNC(close_config_box_cancel), | |
221 (gpointer)rblist); | |
222 gtk_signal_connect_object(GTK_OBJECT(button), "clicked", | |
223 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
224 GTK_OBJECT(config_dlg)); | |
225 gtk_container_add(GTK_CONTAINER(config_dlg->action_area), button); | |
226 } | |
227 | |
228 /***** Page 1: General *****/ | |
229 | |
230 table = GTK_TABLE(gtk_table_new(1, 2, TRUE)); | |
231 gtk_table_set_row_spacings(table, 5); gtk_table_set_col_spacings(table, 5); | |
232 gtk_notebook_append_page(notebook, GTK_WIDGET(table), print_left("General")); | |
233 | |
234 // Add "Sound quality" section | |
235 { | |
236 GtkTable *sqt = GTK_TABLE(gtk_table_new(2, 2, FALSE)); | |
237 GtkVBox *fvb; | |
238 GtkRadioButton *rb; | |
239 | |
240 gtk_table_set_row_spacings(sqt, 5); | |
241 gtk_table_set_col_spacings(sqt, 5); | |
242 gtk_table_attach_defaults(table, make_framed(GTK_WIDGET(sqt), "Sound quality"), | |
243 0, 1, 0, 1); | |
244 | |
245 // Add "Resolution" section | |
246 fvb = GTK_VBOX(gtk_vbox_new(TRUE, 0)); | |
247 gtk_table_attach_defaults(sqt, make_framed(GTK_WIDGET(fvb), "Resolution"), | |
248 0, 1, 0, 1); | |
249 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label(NULL, "8bit")); | |
250 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), !cfg.bit16); | |
251 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
252 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label_from_widget(rb, "16bit")); | |
253 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), cfg.bit16); | |
254 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
255 g_ptr_array_add(rblist, (gpointer)rb); | |
256 | |
257 // Add "Channels" section | |
258 fvb = GTK_VBOX(gtk_vbox_new(TRUE, 0)); | |
259 gtk_table_attach_defaults(sqt, make_framed(GTK_WIDGET(fvb), "Channels"), | |
260 0, 1, 1, 2); | |
261 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label(NULL, "Mono")); | |
262 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), !cfg.stereo); | |
263 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
264 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label_from_widget(rb, "Stereo")); | |
265 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), cfg.stereo); | |
266 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
267 gtk_tooltips_set_tip(tooltips, GTK_WIDGET(rb), | |
268 "Setting stereo is not recommended, unless you need to. " | |
269 "This won't add any stereo effects to the sound - OPL2 " | |
270 "is just mono - but eats up more CPU power!", NULL); | |
271 g_ptr_array_add(rblist, (gpointer)rb); | |
272 | |
273 // Add "Frequency" section | |
274 fvb = GTK_VBOX(gtk_vbox_new(TRUE, 0)); | |
275 gtk_table_attach_defaults(sqt, make_framed(GTK_WIDGET(fvb), "Frequency"), | |
276 1, 2, 0, 2); | |
277 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label(NULL, "11025")); | |
278 if(cfg.freq == 11025) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), TRUE); | |
279 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
280 g_ptr_array_add(rblist, (gpointer)rb); | |
281 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label_from_widget(rb, "22050")); | |
282 if(cfg.freq == 22050) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), TRUE); | |
283 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
284 g_ptr_array_add(rblist, (gpointer)rb); | |
285 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label_from_widget(rb, "44100")); | |
286 if(cfg.freq == 44100) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), TRUE); | |
287 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
288 g_ptr_array_add(rblist, (gpointer)rb); | |
289 rb = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label_from_widget(rb, "48000")); | |
290 if(cfg.freq == 48000) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rb), TRUE); | |
291 gtk_container_add(GTK_CONTAINER(fvb), GTK_WIDGET(rb)); | |
292 g_ptr_array_add(rblist, (gpointer)rb); | |
293 } | |
294 | |
295 // Add "Playback" section | |
296 { | |
297 GtkVBox *vb = GTK_VBOX(gtk_vbox_new(FALSE, 0)); | |
298 GtkCheckButton *cb; | |
299 | |
300 gtk_table_attach_defaults(table, make_framed(GTK_WIDGET(vb), "Playback"), | |
301 1, 2, 0, 1); | |
302 | |
303 cb = GTK_CHECK_BUTTON(gtk_check_button_new_with_label("Detect songend")); | |
304 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), !cfg.endless); | |
305 gtk_container_add(GTK_CONTAINER(vb), GTK_WIDGET(cb)); | |
306 gtk_tooltips_set_tip(tooltips, GTK_WIDGET(cb), | |
307 "If enabled, XMMS will detect a song's ending, stop " | |
308 "it and advance in the playlist. If disabled, XMMS " | |
309 "won't take notice of a song's ending and loop it all " | |
310 "over again and again.", NULL); | |
311 g_ptr_array_add(rblist, (gpointer)cb); | |
312 } | |
313 | |
314 /***** Page 2: Formats *****/ | |
315 | |
316 table = GTK_TABLE(gtk_table_new(1, 1, TRUE)); | |
317 gtk_notebook_append_page(notebook, GTK_WIDGET(table), print_left("Formats")); | |
318 | |
319 // Add "Format selection" section | |
320 { | |
321 GtkHBox *vb = GTK_HBOX(gtk_hbox_new(FALSE, 0)); | |
322 gtk_table_attach_defaults(table, make_framed(GTK_WIDGET(vb), "Format selection"), | |
323 0, 1, 0, 1); | |
324 // Add scrollable list | |
325 { | |
326 gchar *rowstr[] = {"Format", "Extension"}; | |
327 GtkEventBox *eventbox = GTK_EVENT_BOX(gtk_event_box_new()); | |
328 GtkScrolledWindow *formatswnd = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); | |
329 GtkCList *fl = GTK_CLIST(gtk_clist_new_with_titles(2, rowstr)); | |
330 CPlayers::const_iterator i; | |
331 unsigned int j; | |
332 gtk_clist_set_selection_mode(fl, GTK_SELECTION_MULTIPLE); | |
333 | |
334 // Build list | |
335 for(i = CAdPlug::players.begin(); i != CAdPlug::players.end(); i++) { | |
336 gint rownum; | |
337 | |
338 gchar *rws[2]; | |
339 rws[0] = g_strdup((*i)->filetype.c_str()); | |
340 rws[1] = g_strdup((*i)->get_extension(0)); | |
341 for(j = 1; (*i)->get_extension(j); j++) | |
342 rws[1] = g_strjoin(", ", rws[1], (*i)->get_extension(j), NULL); | |
343 rownum = gtk_clist_append(fl, rws); | |
344 g_free(rws[0]); g_free(rws[1]); | |
345 gtk_clist_set_row_data(fl, rownum, (gpointer)(*i)); | |
346 if(find(cfg.players.begin(), cfg.players.end(), *i) != cfg.players.end()) | |
347 gtk_clist_select_row(fl, rownum, 0); | |
348 } | |
349 | |
350 gtk_clist_columns_autosize(fl); | |
351 gtk_scrolled_window_set_policy(formatswnd, GTK_POLICY_AUTOMATIC, | |
352 GTK_POLICY_AUTOMATIC); | |
353 gpointer pl = (gpointer)new CPlayers(cfg.players); | |
354 gtk_signal_connect(GTK_OBJECT(fl), "select-row", | |
355 GTK_SIGNAL_FUNC(config_fl_row_select), pl); | |
356 gtk_signal_connect(GTK_OBJECT(fl), "unselect-row", | |
357 GTK_SIGNAL_FUNC(config_fl_row_unselect), pl); | |
358 gtk_container_add(GTK_CONTAINER(formatswnd), GTK_WIDGET(fl)); | |
359 gtk_container_add(GTK_CONTAINER(eventbox), GTK_WIDGET(formatswnd)); | |
360 gtk_container_add(GTK_CONTAINER(vb), GTK_WIDGET(eventbox)); | |
361 gtk_tooltips_set_tip(tooltips, GTK_WIDGET(eventbox), | |
362 "Selected file types will be recognized and played " | |
363 "back by this plugin. Deselected types will be " | |
364 "ignored to make room for other plugins to play " | |
365 "these files.", NULL); | |
366 g_ptr_array_add(rblist, pl); | |
367 } | |
368 } | |
369 | |
370 // Show window | |
371 gtk_widget_show_all(GTK_WIDGET(config_dlg)); | |
372 } | |
373 | |
374 static void add_instlist(GtkCList *instlist, const char *t1, const char *t2) | |
375 { | |
376 gchar *rowstr[2]; | |
377 | |
378 rowstr[0] = g_strdup(t1); rowstr[1] = g_strdup(t2); | |
379 gtk_clist_append(instlist, rowstr); | |
380 g_free(rowstr[0]); g_free(rowstr[1]); | |
381 } | |
382 | |
383 static CPlayer *factory(const std::string &filename, Copl *newopl) | |
384 { | |
385 CPlayer *p; | |
386 CPlayers::const_iterator i; | |
387 unsigned int j; | |
388 | |
389 dbg_printf("factory(\"%s\",opl): ", filename.c_str()); | |
361
db298f2d3dd9
[svn] Detect files by content; remove quick detect.
chainsaw
parents:
359
diff
changeset
|
390 return CAdPlug::factory(filename, newopl, cfg.players); |
359 | 391 } |
392 | |
393 static void adplug_stop(void); | |
394 static void adplug_play(char *filename); | |
395 | |
619 | 396 #if 0 |
359 | 397 static void subsong_slider(GtkAdjustment *adj) |
398 { | |
399 adplug_stop(); | |
400 plr.subsong = (unsigned int)adj->value - 1; | |
401 adplug_play(plr.filename); | |
402 } | |
403 | |
404 static void close_infobox(GtkDialog *infodlg) | |
405 { | |
406 // Forget our references to the instance of the "currently playing song" info | |
407 // box. But only if we're really destroying that one... ;) | |
408 if(infodlg == plr.infodlg) { | |
409 plr.infobox = NULL; | |
410 plr.infodlg = NULL; | |
411 } | |
412 } | |
413 | |
414 static void adplug_info_box(char *filename) | |
415 { | |
416 CSilentopl tmpopl; | |
417 CPlayer *p = (strcmp(filename, plr.filename) || !plr.p) ? | |
418 factory(filename, &tmpopl) : plr.p; | |
419 | |
420 if(!p) return; // bail out if no player could be created | |
421 if(p == plr.p && plr.infodlg) return; // only one info box for active song | |
422 | |
423 std::ostringstream infotext; | |
424 unsigned int i; | |
425 GtkDialog *infobox = GTK_DIALOG(gtk_dialog_new()); | |
426 GtkButton *okay_button = GTK_BUTTON(gtk_button_new_with_label("Ok")); | |
427 GtkPacker *packer = GTK_PACKER(gtk_packer_new()); | |
428 GtkHBox *hbox = GTK_HBOX(gtk_hbox_new(TRUE, 2)); | |
429 | |
430 // Build file info box | |
431 gtk_window_set_title(GTK_WINDOW(infobox), "AdPlug :: File Info"); | |
432 gtk_window_set_policy(GTK_WINDOW(infobox), FALSE, FALSE, TRUE); // Window is auto sized | |
433 gtk_container_add(GTK_CONTAINER(infobox->vbox), GTK_WIDGET(packer)); | |
434 gtk_packer_set_default_border_width(packer, 2); | |
435 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE); | |
436 gtk_signal_connect_object(GTK_OBJECT(okay_button), "clicked", | |
437 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
438 GTK_OBJECT(infobox)); | |
439 gtk_signal_connect(GTK_OBJECT(infobox), "destroy", | |
440 GTK_SIGNAL_FUNC(close_infobox), 0); | |
441 gtk_container_add(GTK_CONTAINER(infobox->action_area), GTK_WIDGET(okay_button)); | |
442 | |
443 // Add filename section | |
444 gtk_packer_add_defaults(packer, make_framed(print_left(filename), "Filename"), | |
445 GTK_SIDE_TOP, GTK_ANCHOR_CENTER, GTK_FILL_X); | |
446 | |
447 // Add "Song info" section | |
448 infotext << "Title: " << p->gettitle() << std::endl << | |
449 "Author: " << p->getauthor() << std::endl << | |
450 "File Type: " << p->gettype() << std::endl << | |
451 "Subsongs: " << p->getsubsongs() << std::endl << | |
452 "Instruments: " << p->getinstruments(); | |
453 if(plr.p == p) | |
454 infotext << std::ends; | |
455 else { | |
456 infotext << std::endl << "Orders: " << p->getorders() << std::endl << | |
457 "Patterns: " << p->getpatterns() << std::ends; | |
458 } | |
459 gtk_container_add(GTK_CONTAINER(hbox), | |
460 make_framed(print_left(infotext.str().c_str()), "Song")); | |
461 | |
462 // Add "Playback info" section if currently playing | |
463 if(plr.p == p) { | |
464 plr.infobox = GTK_LABEL(gtk_label_new("")); | |
465 gtk_label_set_justify(plr.infobox, GTK_JUSTIFY_LEFT); | |
466 gtk_misc_set_padding(GTK_MISC(plr.infobox), 2, 2); | |
467 gtk_container_add(GTK_CONTAINER(hbox), | |
468 make_framed(GTK_WIDGET(plr.infobox), "Playback")); | |
469 } | |
470 gtk_packer_add_defaults(packer, GTK_WIDGET(hbox), GTK_SIDE_TOP, | |
471 GTK_ANCHOR_CENTER, GTK_FILL_X); | |
472 | |
473 // Add instrument names section | |
474 if(p->getinstruments()) { | |
475 GtkScrolledWindow *instwnd = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); | |
476 GtkCList *instnames; | |
477 gchar tmpstr[10]; | |
478 | |
479 { | |
480 gchar *rowstr[] = {"#","Instrument name"}; | |
481 instnames = GTK_CLIST(gtk_clist_new_with_titles(2, rowstr)); | |
482 } | |
483 gtk_clist_set_column_justification(instnames, 0, GTK_JUSTIFY_RIGHT); | |
484 | |
485 for(i=0;i<p->getinstruments();i++) { | |
486 sprintf(tmpstr, "%d", i + 1); | |
487 add_instlist(instnames, tmpstr, p->getinstrument(i).c_str()); | |
488 } | |
489 | |
490 gtk_clist_columns_autosize(instnames); | |
491 gtk_scrolled_window_set_policy(instwnd, GTK_POLICY_AUTOMATIC, | |
492 GTK_POLICY_AUTOMATIC); | |
493 gtk_container_add(GTK_CONTAINER(instwnd), GTK_WIDGET(instnames)); | |
494 gtk_packer_add(packer, GTK_WIDGET(instwnd), GTK_SIDE_TOP, | |
495 GTK_ANCHOR_CENTER, GTK_FILL_X, 0, 0, 0, 0, 50); | |
496 } | |
497 | |
498 // Add "Song message" section | |
499 if(!p->getdesc().empty()) { | |
500 GtkScrolledWindow *msgwnd = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); | |
501 GtkText *msg = GTK_TEXT(gtk_text_new(NULL, NULL)); | |
502 gint pos = 0; | |
503 | |
504 gtk_scrolled_window_set_policy(msgwnd, GTK_POLICY_AUTOMATIC, | |
505 GTK_POLICY_AUTOMATIC); | |
506 gtk_text_set_editable(msg, FALSE); | |
507 gtk_text_set_word_wrap(msg, TRUE); | |
508 // gtk_text_set_line_wrap(msg, TRUE); | |
509 gtk_editable_insert_text(GTK_EDITABLE(msg), p->getdesc().c_str(), | |
510 p->getdesc().length(), &pos); | |
511 | |
512 gtk_container_add(GTK_CONTAINER(msgwnd), GTK_WIDGET(msg)); | |
513 gtk_packer_add(packer, make_framed(GTK_WIDGET(msgwnd), "Song message"), | |
514 GTK_SIDE_TOP, GTK_ANCHOR_CENTER, GTK_FILL_X, 2, 0, 0, 200, 50); | |
515 } | |
516 | |
517 // Add subsong slider section | |
518 if(p == plr.p && p->getsubsongs() > 1) { | |
519 GtkAdjustment *adj = GTK_ADJUSTMENT(gtk_adjustment_new(plr.subsong + 1, 1, | |
520 p->getsubsongs() + 1, | |
521 1, 5, 1)); | |
522 GtkHScale *slider = GTK_HSCALE(gtk_hscale_new(adj)); | |
523 | |
524 gtk_signal_connect(GTK_OBJECT(adj), "value_changed", | |
525 GTK_SIGNAL_FUNC(subsong_slider), NULL); | |
526 gtk_range_set_update_policy(GTK_RANGE(slider), GTK_UPDATE_DISCONTINUOUS); | |
527 gtk_scale_set_digits(GTK_SCALE(slider), 0); | |
528 gtk_packer_add_defaults(packer, make_framed(GTK_WIDGET(slider), "Subsong selection"), | |
529 GTK_SIDE_TOP, GTK_ANCHOR_CENTER, GTK_FILL_X); | |
530 } | |
531 | |
532 // Show dialog box | |
533 gtk_widget_show_all(GTK_WIDGET(infobox)); | |
534 if(p == plr.p) { // Remember widget, so we could destroy it later | |
535 plr.infodlg = infobox; | |
536 } else // Delete temporary player | |
537 delete p; | |
538 } | |
539 | |
540 /***** Main player (!! threaded !!) *****/ | |
541 | |
542 static void update_infobox(void) | |
543 { | |
544 std::ostringstream infotext; | |
545 | |
546 // Recreate info string | |
547 infotext << "Order: " << plr.p->getorder() << " / " << plr.p->getorders() << | |
548 std::endl << "Pattern: " << plr.p->getpattern() << " / " << | |
549 plr.p->getpatterns() << std::endl << "Row: " << plr.p->getrow() << | |
550 std::endl << "Speed: " << plr.p->getspeed() << std::endl << "Timer: " << | |
551 plr.p->getrefresh() << "Hz" << std::ends; | |
552 | |
553 GDK_THREADS_ENTER(); | |
554 gtk_label_set_text(plr.infobox, infotext.str().c_str()); | |
555 GDK_THREADS_LEAVE(); | |
556 } | |
557 #endif | |
558 | |
559 // Define sampsize macro (only usable inside play_loop()!) | |
560 #define sampsize ((bit16 ? 2 : 1) * (stereo ? 2 : 1)) | |
561 | |
562 static void *play_loop(void *filename) | |
563 /* Main playback thread. Takes the filename to play as argument. */ | |
564 { | |
565 dbg_printf("play_loop(\"%s\"): ", (char *)filename); | |
566 CEmuopl opl(cfg.freq, cfg.bit16, cfg.stereo); | |
567 long toadd = 0, i, towrite; | |
568 char *sndbuf, *sndbufpos; | |
569 bool playing = true, // Song self-end indicator. | |
570 bit16 = cfg.bit16, // Duplicate config, so it doesn't affect us if | |
571 stereo = cfg.stereo; // the user changes it while we're playing. | |
572 unsigned long freq = cfg.freq; | |
573 | |
574 // Try to load module | |
575 dbg_printf("factory, "); | |
576 if(!(plr.p = factory((char *)filename, &opl))) { | |
577 dbg_printf("error!\n"); | |
578 MessageBox("AdPlug :: Error", "File could not be opened!", "Ok"); | |
579 plr.playing = false; | |
580 g_thread_exit(NULL); | |
581 } | |
582 | |
583 // Cache song length | |
584 dbg_printf("length, "); | |
585 plr.songlength = plr.p->songlength(plr.subsong); | |
586 | |
587 // cache song title | |
588 dbg_printf("title, "); | |
589 if(!plr.p->gettitle().empty()) { | |
590 plr.songtitle = (char *)malloc(plr.p->gettitle().length() + 1); | |
591 strcpy(plr.songtitle, plr.p->gettitle().c_str()); | |
592 } | |
593 | |
594 // reset to first subsong on new file | |
595 dbg_printf("subsong, "); | |
596 if(strcmp((char *)filename, plr.filename)) { | |
597 strcpy(plr.filename, (char *)filename); | |
598 plr.subsong = 0; | |
599 } | |
600 | |
601 // Allocate audio buffer | |
602 dbg_printf("buffer, "); | |
603 sndbuf = (char *)malloc(SNDBUFSIZE * sampsize); | |
604 | |
605 // Set XMMS main window information | |
606 dbg_printf("xmms, "); | |
607 adplug_ip.set_info(plr.songtitle, plr.songlength, freq * sampsize * 8, | |
608 freq, stereo ? 2 : 1); | |
609 | |
610 // Rewind player to right subsong | |
611 dbg_printf("rewind, "); | |
612 plr.p->rewind(plr.subsong); | |
613 | |
614 // main playback loop | |
615 dbg_printf("loop.\n"); | |
616 while((playing || cfg.endless) && plr.playing) { | |
617 // seek requested ? | |
618 if(plr.seek != -1) { | |
619 // backward seek ? | |
620 if(plr.seek < plr.time_ms) { | |
621 plr.p->rewind(plr.subsong); | |
622 plr.time_ms = 0.0f; | |
623 } | |
624 | |
625 // seek to requested position | |
626 while((plr.time_ms < plr.seek) && plr.p->update()) | |
627 plr.time_ms += 1000 / plr.p->getrefresh(); | |
628 | |
629 // Reset output plugin and some values | |
630 adplug_ip.output->flush((int)plr.time_ms); | |
631 plr.seek = -1; | |
632 } | |
633 | |
634 // fill sound buffer | |
635 towrite = SNDBUFSIZE; sndbufpos = sndbuf; | |
636 while (towrite > 0) { | |
637 while (toadd < 0) { | |
638 toadd += freq; | |
639 playing = plr.p->update(); | |
640 plr.time_ms += 1000 / plr.p->getrefresh(); | |
641 } | |
642 i = MIN(towrite, (long)(toadd / plr.p->getrefresh() + 4) & ~3); | |
643 opl.update((short *)sndbufpos, i); | |
644 sndbufpos += i * sampsize; towrite -= i; | |
645 toadd -= (long)(plr.p->getrefresh() * i); | |
646 } | |
647 | |
414
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
648 // write sound buffer |
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
649 while(adplug_ip.output->buffer_free() < SNDBUFSIZE * sampsize) xmms_usleep(10000); |
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
650 produce_audio(adplug_ip.output->written_time(), |
359 | 651 bit16 ? FORMAT_16 : FORMAT_8, |
414
7fa1738514d5
[svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents:
361
diff
changeset
|
652 stereo ? 2 : 1, SNDBUFSIZE * sampsize, sndbuf, NULL); |
359 | 653 |
654 #if 0 | |
655 // update infobox, if necessary | |
656 if(plr.infobox && plr.playing) update_infobox(); | |
657 #endif | |
658 } | |
659 | |
660 // playback finished - deinit | |
661 dbg_printf("play_loop(\"%s\"): ", (char *)filename); | |
662 if(!playing) { // wait for output plugin to finish if song has self-ended | |
663 dbg_printf("wait, "); | |
664 while(adplug_ip.output->buffer_playing()) xmms_usleep(10000); | |
665 } else { // or else, flush its output buffers | |
666 dbg_printf("flush, "); | |
667 adplug_ip.output->buffer_free(); adplug_ip.output->buffer_free(); | |
668 } | |
669 | |
670 // free everything and exit | |
671 dbg_printf("free"); | |
672 delete plr.p; plr.p = 0; | |
673 if(plr.songtitle) { free(plr.songtitle); plr.songtitle = NULL; } | |
674 free(sndbuf); | |
675 plr.playing = false; // important! XMMS won't get a self-ended song without it. | |
676 dbg_printf(".\n"); | |
677 g_thread_exit(NULL); | |
619 | 678 return(NULL); |
359 | 679 } |
680 | |
681 // sampsize macro not useful anymore. | |
682 #undef sampsize | |
683 | |
684 /***** Informational *****/ | |
685 | |
686 static int adplug_is_our_file(char *filename) | |
687 { | |
688 CSilentopl tmpopl; | |
689 CPlayer *p = factory(filename,&tmpopl); | |
690 | |
691 dbg_printf("adplug_is_our_file(\"%s\"): returned ",filename); | |
692 | |
693 if(p) { | |
694 delete p; | |
695 dbg_printf("TRUE\n"); | |
696 return TRUE; | |
697 } | |
698 | |
699 dbg_printf("FALSE\n"); | |
700 return FALSE; | |
701 } | |
702 | |
703 static int adplug_get_time(void) | |
704 { | |
705 if(audio_error) { dbg_printf("adplug_get_time(): returned -2\n"); return -2; } | |
706 if(!plr.playing) { dbg_printf("adplug_get_time(): returned -1\n"); return -1; } | |
707 return adplug_ip.output->output_time(); | |
708 } | |
709 | |
710 static void adplug_song_info(char *filename, char **title, int *length) | |
711 { | |
712 CSilentopl tmpopl; | |
713 CPlayer *p = factory(filename, &tmpopl); | |
714 | |
715 dbg_printf("adplug_song_info(\"%s\", \"%s\", %d): ", filename, *title, *length); | |
716 | |
717 if(p) { | |
718 // allocate and set title string | |
719 if(p->gettitle().empty()) | |
720 *title = 0; | |
721 else { | |
722 *title = (char *)malloc(p->gettitle().length() + 1); | |
723 strcpy(*title, p->gettitle().c_str()); | |
724 } | |
725 | |
726 // get song length | |
727 *length = p->songlength(plr.subsong); | |
728 | |
729 // delete temporary player object | |
730 delete p; | |
731 } | |
732 | |
733 dbg_printf("title = \"%s\", length = %d\n", *title, *length); | |
734 } | |
735 | |
736 /***** Player control *****/ | |
737 | |
738 static void adplug_play(char *filename) | |
739 { | |
740 dbg_printf("adplug_play(\"%s\"): ", filename); | |
741 audio_error = FALSE; | |
742 | |
743 #if 0 | |
744 // On new song, re-open "Song info" dialog, if open | |
745 dbg_printf("dialog, "); | |
746 if(plr.infobox && strcmp(filename, plr.filename)) | |
747 gtk_widget_destroy(GTK_WIDGET(plr.infodlg)); | |
748 #endif | |
749 | |
750 // open output plugin | |
751 dbg_printf("open, "); | |
752 if (!adplug_ip.output->open_audio(cfg.bit16 ? FORMAT_16 : FORMAT_8, cfg.freq, cfg.stereo ? 2 : 1)) { | |
753 audio_error = TRUE; | |
754 return; | |
755 } | |
756 | |
757 // Initialize global player data (this is here to prevent a race condition | |
758 // between adplug_get_time() returning the playback state and adplug_loop() | |
759 // initializing the playback state) | |
760 dbg_printf("init, "); | |
761 plr.playing = true; plr.time_ms = 0.0f; plr.seek = -1; | |
762 | |
763 // start player thread | |
764 dbg_printf("create"); | |
765 plr.play_thread = g_thread_create(play_loop, filename, TRUE, NULL); | |
766 dbg_printf(".\n"); | |
767 } | |
768 | |
769 static void adplug_stop(void) | |
770 { | |
771 dbg_printf("adplug_stop(): join, "); | |
772 plr.playing = false; g_thread_join(plr.play_thread); // stop player thread | |
773 dbg_printf("close"); adplug_ip.output->close_audio(); | |
774 dbg_printf(".\n"); | |
775 } | |
776 | |
777 static void adplug_pause(short paused) | |
778 { | |
779 dbg_printf("adplug_pause(%d)\n", paused); | |
780 adplug_ip.output->pause(paused); | |
781 } | |
782 | |
783 static void adplug_seek(int time) | |
784 { | |
785 dbg_printf("adplug_seek(%d)\n", time); | |
786 plr.seek = time * 1000; // time is in seconds, but we count in ms | |
787 } | |
788 | |
789 /***** Configuration file handling *****/ | |
790 | |
791 #define CFG_VERSION "AdPlug" | |
792 | |
793 static void adplug_init(void) | |
794 { | |
795 dbg_printf("adplug_init(): open, "); | |
796 ConfigDb *db = bmp_cfg_db_open(); | |
797 | |
798 // Read configuration | |
799 dbg_printf("read, "); | |
800 bmp_cfg_db_get_bool(db, CFG_VERSION, "16bit", (gboolean *)&cfg.bit16); | |
801 bmp_cfg_db_get_bool(db, CFG_VERSION, "Stereo", (gboolean *)&cfg.stereo); | |
802 bmp_cfg_db_get_int(db, CFG_VERSION, "Frequency", (gint *)&cfg.freq); | |
803 bmp_cfg_db_get_bool(db, CFG_VERSION, "Endless", (gboolean *)&cfg.endless); | |
804 | |
805 // Read file type exclusion list | |
806 dbg_printf("exclusion, "); | |
807 { | |
808 gchar *cfgstr = "", *exclude; | |
809 gboolean cfgread; | |
810 | |
811 cfgread = bmp_cfg_db_get_string(db, CFG_VERSION, "Exclude", &cfgstr); | |
812 exclude = (char *)malloc(strlen(cfgstr) + 2); strcpy(exclude, cfgstr); | |
813 exclude[strlen(exclude) + 1] = '\0'; | |
814 if(cfgread) free(cfgstr); | |
815 g_strdelimit(exclude, ":", '\0'); | |
816 for(gchar *p = exclude; *p; p += strlen(p) + 1) | |
817 cfg.players.remove(cfg.players.lookup_filetype(p)); | |
818 free(exclude); | |
819 } | |
820 bmp_cfg_db_close(db); | |
821 | |
822 // Load database from disk and hand it to AdPlug | |
823 dbg_printf("database"); | |
824 plr.db = new CAdPlugDatabase; | |
825 | |
826 { | |
827 const char *homedir = getenv("HOME"); | |
828 | |
829 if(homedir) { | |
830 char *userdb = (char *)malloc(strlen(homedir) + strlen(ADPLUG_CONFDIR) + | |
831 strlen(ADPLUGDB_FILE) + 3); | |
832 strcpy(userdb, homedir); strcat(userdb, "/" ADPLUG_CONFDIR "/"); | |
833 strcat(userdb, ADPLUGDB_FILE); | |
834 plr.db->load(userdb); // load user's database | |
835 dbg_printf(" (userdb=\"%s\")", userdb); | |
836 } | |
837 } | |
838 CAdPlug::set_database(plr.db); | |
839 dbg_printf(".\n"); | |
840 } | |
841 | |
842 static void adplug_quit(void) | |
843 { | |
844 dbg_printf("adplug_quit(): open, "); | |
845 ConfigDb *db = bmp_cfg_db_open(); | |
846 | |
847 // Close database | |
848 dbg_printf("db, "); | |
849 if(plr.db) delete plr.db; | |
850 | |
851 // Write configuration | |
852 dbg_printf("write, "); | |
853 bmp_cfg_db_set_bool(db, CFG_VERSION, "16bit", cfg.bit16); | |
854 bmp_cfg_db_set_bool(db, CFG_VERSION, "Stereo", cfg.stereo); | |
855 bmp_cfg_db_set_int(db, CFG_VERSION, "Frequency", cfg.freq); | |
856 bmp_cfg_db_set_bool(db, CFG_VERSION, "Endless", cfg.endless); | |
857 | |
858 dbg_printf("exclude, "); | |
859 std::string exclude; | |
860 for(CPlayers::const_iterator i = CAdPlug::players.begin(); | |
861 i != CAdPlug::players.end(); i++) | |
862 if(find(cfg.players.begin(), cfg.players.end(), *i) == cfg.players.end()) { | |
863 if(!exclude.empty()) exclude += ":"; | |
864 exclude += (*i)->filetype; | |
865 } | |
866 gchar *cfgval = g_strdup(exclude.c_str()); | |
867 bmp_cfg_db_set_string(db, CFG_VERSION, "Exclude", cfgval); | |
868 free(cfgval); | |
869 | |
870 dbg_printf("close"); | |
871 bmp_cfg_db_close(db); | |
872 dbg_printf(".\n"); | |
873 } | |
874 | |
875 /***** Plugin (exported) *****/ | |
876 | |
877 InputPlugin adplug_ip = | |
878 { | |
879 NULL, // handle (filled by XMMS) | |
880 NULL, // filename (filled by XMMS) | |
881 ADPLUG_NAME, // plugin description | |
882 adplug_init, // plugin functions... | |
883 adplug_about, | |
884 adplug_config, | |
885 adplug_is_our_file, | |
886 NULL, // scan_dir (look in Input/cdaudio/cdaudio.c) | |
887 adplug_play, | |
888 adplug_stop, | |
889 adplug_pause, | |
890 adplug_seek, | |
891 NULL, // set_eq | |
892 adplug_get_time, | |
893 NULL, // get_volume (handled by output plugin) | |
894 NULL, // set_volume (...) | |
895 adplug_quit, | |
896 NULL, // OBSOLETE - DO NOT USE! | |
897 NULL, // add_vis_pcm (filled by XMMS) | |
898 NULL, // set_info (filled by XMMS) | |
899 NULL, // set_info_text (filled by XMMS) | |
900 adplug_song_info, | |
901 NULL, // adplug_info_box was here (but it used deprecated GTK+ functions) | |
902 NULL // output plugin (filled by XMMS) | |
903 }; | |
904 | |
905 extern "C" InputPlugin *get_iplugin_info(void) | |
906 { | |
907 return &adplug_ip; | |
908 } |