Mercurial > audlegacy
annotate Plugins/Output/OSS/configure.c @ 1458:f12d7e208b43 trunk
[svn] Update FSF address in copyright notices. Update autotools templates.
author | chainsaw |
---|---|
date | Wed, 02 Aug 2006 15:44:07 -0700 |
parents | 3c2bb116f4db |
children | 705d4c089fce |
rev | line source |
---|---|
61 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
1458
f12d7e208b43
[svn] Update FSF address in copyright notices. Update autotools templates.
chainsaw
parents:
733
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. |
61 | 20 */ |
21 | |
22 #include "OSS.h" | |
23 | |
24 #include <glib.h> | |
25 #include <glib/gi18n.h> | |
26 #include <gtk/gtk.h> | |
27 #include <stdio.h> | |
28 #include <string.h> | |
29 | |
30 #include <libaudacious/configdb.h> | |
31 | |
32 | |
33 static GtkWidget *configure_win = NULL; | |
34 static GtkWidget *mixer_usemaster_check, *buffer_size_spin, *buffer_pre_spin; | |
35 static GtkWidget *adevice_use_alt_check, *audio_alt_device_entry; | |
36 static GtkWidget *mdevice_use_alt_check, *mixer_alt_device_entry; | |
37 static gint audio_device, mixer_device; | |
38 | |
39 static void | |
40 configure_win_ok_cb(GtkWidget * w, gpointer data) | |
41 { | |
42 ConfigDb *db; | |
43 | |
44 oss_cfg.audio_device = audio_device; | |
45 oss_cfg.mixer_device = mixer_device; | |
46 oss_cfg.buffer_size = | |
47 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_spin)); | |
48 oss_cfg.prebuffer = | |
49 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_pre_spin)); | |
50 oss_cfg.use_master = | |
51 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON | |
52 (mixer_usemaster_check)); | |
53 oss_cfg.use_alt_audio_device = | |
54 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON | |
55 (adevice_use_alt_check)); | |
56 oss_cfg.use_alt_mixer_device = | |
57 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON | |
58 (mdevice_use_alt_check)); | |
59 g_free(oss_cfg.alt_audio_device); | |
60 oss_cfg.alt_audio_device = | |
61 gtk_editable_get_chars(GTK_EDITABLE(audio_alt_device_entry), 0, -1); | |
62 g_strstrip(oss_cfg.alt_audio_device); | |
63 g_free(oss_cfg.alt_mixer_device); | |
64 oss_cfg.alt_mixer_device = | |
65 gtk_editable_get_chars(GTK_EDITABLE(mixer_alt_device_entry), 0, -1); | |
66 g_strstrip(oss_cfg.alt_mixer_device); | |
67 | |
68 if (oss_cfg.use_alt_audio_device) | |
69 /* do a minimum of sanity checking */ | |
70 if (oss_cfg.alt_audio_device[0] != '/') | |
71 oss_cfg.use_alt_audio_device = FALSE; | |
72 if (oss_cfg.use_alt_mixer_device) | |
73 if (oss_cfg.alt_mixer_device[0] != '/') | |
74 oss_cfg.use_alt_mixer_device = FALSE; | |
75 | |
76 db = bmp_cfg_db_open(); | |
77 | |
78 bmp_cfg_db_set_int(db, "OSS", "audio_device", oss_cfg.audio_device); | |
79 bmp_cfg_db_set_int(db, "OSS", "mixer_device", oss_cfg.mixer_device); | |
80 bmp_cfg_db_set_int(db, "OSS", "buffer_size", oss_cfg.buffer_size); | |
81 bmp_cfg_db_set_int(db, "OSS", "prebuffer", oss_cfg.prebuffer); | |
82 bmp_cfg_db_set_bool(db, "OSS", "use_master", oss_cfg.use_master); | |
83 bmp_cfg_db_set_bool(db, "OSS", "use_alt_audio_device", | |
84 oss_cfg.use_alt_audio_device); | |
85 bmp_cfg_db_set_string(db, "OSS", "alt_audio_device", | |
86 oss_cfg.alt_audio_device); | |
87 bmp_cfg_db_set_bool(db, "OSS", "use_alt_mixer_device", | |
88 oss_cfg.use_alt_mixer_device); | |
89 bmp_cfg_db_set_string(db, "OSS", "alt_mixer_device", | |
90 oss_cfg.alt_mixer_device); | |
91 bmp_cfg_db_close(db); | |
92 } | |
93 | |
94 static void | |
95 configure_win_audio_dev_cb(GtkWidget * widget, gint device) | |
96 { | |
97 audio_device = device; | |
98 } | |
99 | |
100 static void | |
101 configure_win_mixer_dev_cb(GtkWidget * widget, gint device) | |
102 { | |
103 mixer_device = device; | |
104 } | |
105 | |
106 static void | |
107 audio_device_toggled(GtkToggleButton * widget, gpointer data) | |
108 { | |
109 gboolean use_alt_audio_device = gtk_toggle_button_get_active(widget); | |
110 gtk_widget_set_sensitive(GTK_WIDGET(data), !use_alt_audio_device); | |
111 gtk_widget_set_sensitive(audio_alt_device_entry, use_alt_audio_device); | |
112 } | |
113 | |
114 static void | |
115 mixer_device_toggled(GtkToggleButton * widget, gpointer data) | |
116 { | |
117 gboolean use_alt_device = gtk_toggle_button_get_active(widget); | |
118 gtk_widget_set_sensitive(GTK_WIDGET(data), !use_alt_device); | |
119 gtk_widget_set_sensitive(mixer_alt_device_entry, use_alt_device); | |
120 } | |
121 | |
122 static void | |
123 scan_devices(gchar * type, GtkWidget * option_menu, GtkSignalFunc sigfunc) | |
124 { | |
125 GtkWidget *menu, *item; | |
126 FILE *file; | |
127 gchar buffer[256], *temp, *tmp2; | |
128 gboolean found = FALSE; | |
129 gint index = 0; | |
130 | |
131 menu = gtk_menu_new(); | |
132 | |
133 if ((file = fopen("/dev/sndstat", "r"))) { | |
134 while (fgets(buffer, 255, file)) { | |
135 if (found && buffer[0] == '\n') | |
136 break; | |
137 if (buffer[strlen(buffer) - 1] == '\n') | |
138 buffer[strlen(buffer) - 1] = '\0'; | |
139 if (found) { | |
140 if (index == 0) { | |
141 tmp2 = strchr(buffer, ':'); | |
142 if (tmp2) { | |
143 tmp2++; | |
144 while (*tmp2 == ' ') | |
145 tmp2++; | |
146 } | |
147 else | |
148 tmp2 = buffer; | |
149 temp = g_strdup_printf(_("Default (%s)"), tmp2); | |
150 item = gtk_menu_item_new_with_label(temp); | |
151 g_free(temp); | |
152 } | |
153 else | |
154 item = gtk_menu_item_new_with_label(buffer); | |
155 g_signal_connect(G_OBJECT(item), "activate", | |
733
3c2bb116f4db
[svn] - remerge fixed version of OSS patch. Submitted by Bren <spike -at- spykes.net>
nenolod
parents:
731
diff
changeset
|
156 G_CALLBACK(sigfunc), (gpointer)(long)(index++)); |
61 | 157 gtk_widget_show(item); |
158 gtk_menu_append(GTK_MENU(menu), item); | |
159 } | |
160 if (!strcasecmp(buffer, type)) | |
161 found = 1; | |
162 | |
163 } | |
164 fclose(file); | |
165 } | |
166 else { | |
167 item = gtk_menu_item_new_with_label(_("Default")); | |
168 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(sigfunc), | |
169 (gpointer) 0); | |
170 gtk_widget_show(item); | |
171 gtk_menu_append(GTK_MENU(menu), item); | |
172 } | |
173 gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu); | |
174 } | |
175 | |
176 void | |
177 oss_configure(void) | |
178 { | |
179 GtkWidget *vbox, *notebook; | |
180 GtkWidget *dev_vbox, *adevice_frame, *adevice_box, *adevice; | |
181 GtkWidget *mdevice_frame, *mdevice_box, *mdevice; | |
182 GtkWidget *buffer_frame, *buffer_vbox, *buffer_table; | |
183 GtkWidget *buffer_size_box, *buffer_size_label; | |
184 GtkObject *buffer_size_adj, *buffer_pre_adj; | |
185 GtkWidget *buffer_pre_box, *buffer_pre_label; | |
186 GtkWidget *audio_alt_box, *mixer_alt_box; | |
187 GtkWidget *bbox, *ok, *cancel; | |
188 GtkWidget *mixer_table, *mixer_frame; | |
189 | |
190 if (configure_win) { | |
191 gtk_window_present(GTK_WINDOW(configure_win)); | |
192 return; | |
193 } | |
194 | |
195 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
196 g_signal_connect(G_OBJECT(configure_win), "destroy", | |
197 G_CALLBACK(gtk_widget_destroyed), &configure_win); | |
198 gtk_window_set_title(GTK_WINDOW(configure_win), | |
199 _("OSS Driver configuration")); | |
200 gtk_window_set_type_hint(GTK_WINDOW(configure_win), | |
201 GDK_WINDOW_TYPE_HINT_DIALOG); | |
202 gtk_window_set_resizable(GTK_WINDOW(configure_win), FALSE); | |
203 gtk_window_set_position(GTK_WINDOW(configure_win), GTK_WIN_POS_CENTER); | |
204 gtk_container_border_width(GTK_CONTAINER(configure_win), 10); | |
205 | |
206 vbox = gtk_vbox_new(FALSE, 10); | |
207 gtk_container_add(GTK_CONTAINER(configure_win), vbox); | |
208 | |
209 notebook = gtk_notebook_new(); | |
210 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); | |
211 | |
212 dev_vbox = gtk_vbox_new(FALSE, 5); | |
213 gtk_container_set_border_width(GTK_CONTAINER(dev_vbox), 5); | |
214 | |
215 adevice_frame = gtk_frame_new(_("Audio device:")); | |
216 gtk_box_pack_start(GTK_BOX(dev_vbox), adevice_frame, FALSE, FALSE, 0); | |
217 | |
218 adevice_box = gtk_vbox_new(FALSE, 5); | |
219 gtk_container_set_border_width(GTK_CONTAINER(adevice_box), 5); | |
220 gtk_container_add(GTK_CONTAINER(adevice_frame), adevice_box); | |
221 | |
222 adevice = gtk_option_menu_new(); | |
223 gtk_box_pack_start(GTK_BOX(adevice_box), adevice, TRUE, TRUE, 0); | |
224 #if defined(HAVE_NEWPCM) | |
225 scan_devices("Installed devices:", adevice, | |
226 GTK_SIGNAL_FUNC(configure_win_audio_dev_cb)); | |
227 #else | |
228 scan_devices("Audio devices:", adevice, | |
229 GTK_SIGNAL_FUNC(configure_win_audio_dev_cb)); | |
230 #endif | |
231 audio_device = oss_cfg.audio_device; | |
232 gtk_option_menu_set_history(GTK_OPTION_MENU(adevice), | |
233 oss_cfg.audio_device); | |
234 audio_alt_box = gtk_hbox_new(FALSE, 0); | |
235 gtk_box_pack_start_defaults(GTK_BOX(adevice_box), audio_alt_box); | |
236 adevice_use_alt_check = | |
237 gtk_check_button_new_with_label(_("Use alternate device:")); | |
238 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adevice_use_alt_check), | |
239 oss_cfg.use_alt_audio_device); | |
240 g_signal_connect(G_OBJECT(adevice_use_alt_check), "toggled", | |
241 G_CALLBACK(audio_device_toggled), adevice); | |
242 gtk_box_pack_start(GTK_BOX(audio_alt_box), adevice_use_alt_check, | |
243 FALSE, FALSE, 0); | |
244 audio_alt_device_entry = gtk_entry_new(); | |
245 if (oss_cfg.alt_audio_device != NULL) | |
246 gtk_entry_set_text(GTK_ENTRY(audio_alt_device_entry), | |
247 oss_cfg.alt_audio_device); | |
248 else | |
249 gtk_entry_set_text(GTK_ENTRY(audio_alt_device_entry), DEV_DSP); | |
250 gtk_box_pack_start_defaults(GTK_BOX(audio_alt_box), | |
251 audio_alt_device_entry); | |
252 | |
253 if (oss_cfg.use_alt_audio_device) | |
254 gtk_widget_set_sensitive(adevice, FALSE); | |
255 else | |
256 gtk_widget_set_sensitive(audio_alt_device_entry, FALSE); | |
257 | |
258 mdevice_frame = gtk_frame_new(_("Mixer device:")); | |
259 gtk_box_pack_start(GTK_BOX(dev_vbox), mdevice_frame, FALSE, FALSE, 0); | |
260 | |
261 mdevice_box = gtk_vbox_new(FALSE, 0); | |
262 gtk_container_set_border_width(GTK_CONTAINER(mdevice_box), 5); | |
263 gtk_container_add(GTK_CONTAINER(mdevice_frame), mdevice_box); | |
264 | |
265 mdevice = gtk_option_menu_new(); | |
266 gtk_box_pack_start(GTK_BOX(mdevice_box), mdevice, TRUE, TRUE, 0); | |
267 #if defined(HAVE_NEWPCM) | |
268 scan_devices("Installed devices:", mdevice, configure_win_mixer_dev_cb); | |
269 #else | |
270 scan_devices("Mixers:", mdevice, G_CALLBACK(configure_win_mixer_dev_cb)); | |
271 #endif | |
272 mixer_device = oss_cfg.mixer_device; | |
273 gtk_option_menu_set_history(GTK_OPTION_MENU(mdevice), | |
274 oss_cfg.mixer_device); | |
275 mixer_alt_box = gtk_hbox_new(FALSE, 0); | |
276 gtk_box_pack_start_defaults(GTK_BOX(mdevice_box), mixer_alt_box); | |
277 mdevice_use_alt_check = | |
278 gtk_check_button_new_with_label(_("Use alternate device:")); | |
279 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mdevice_use_alt_check), | |
280 oss_cfg.use_alt_mixer_device); | |
281 g_signal_connect(G_OBJECT(mdevice_use_alt_check), "toggled", | |
282 G_CALLBACK(mixer_device_toggled), mdevice); | |
283 gtk_box_pack_start(GTK_BOX(mixer_alt_box), mdevice_use_alt_check, | |
284 FALSE, FALSE, 0); | |
285 mixer_alt_device_entry = gtk_entry_new(); | |
286 if (oss_cfg.alt_mixer_device != NULL) | |
287 gtk_entry_set_text(GTK_ENTRY(mixer_alt_device_entry), | |
288 oss_cfg.alt_mixer_device); | |
289 else | |
290 gtk_entry_set_text(GTK_ENTRY(mixer_alt_device_entry), DEV_MIXER); | |
291 gtk_box_pack_start_defaults(GTK_BOX(mixer_alt_box), | |
292 mixer_alt_device_entry); | |
293 | |
294 if (oss_cfg.use_alt_mixer_device) | |
295 gtk_widget_set_sensitive(mdevice, FALSE); | |
296 else | |
297 gtk_widget_set_sensitive(mixer_alt_device_entry, FALSE); | |
298 | |
299 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dev_vbox, | |
300 gtk_label_new(_("Devices"))); | |
301 | |
302 buffer_frame = gtk_frame_new(_("Buffering:")); | |
303 gtk_container_set_border_width(GTK_CONTAINER(buffer_frame), 5); | |
304 | |
305 buffer_vbox = gtk_vbox_new(FALSE, 0); | |
306 gtk_container_add(GTK_CONTAINER(buffer_frame), buffer_vbox); | |
307 | |
308 buffer_table = gtk_table_new(2, 1, TRUE); | |
309 gtk_container_set_border_width(GTK_CONTAINER(buffer_table), 5); | |
310 gtk_box_pack_start(GTK_BOX(buffer_vbox), buffer_table, FALSE, FALSE, 0); | |
311 | |
312 buffer_size_box = gtk_hbox_new(FALSE, 5); | |
313 gtk_table_attach_defaults(GTK_TABLE(buffer_table), buffer_size_box, 0, | |
314 1, 0, 1); | |
315 buffer_size_label = gtk_label_new(_("Buffer size (ms):")); | |
316 gtk_box_pack_start(GTK_BOX(buffer_size_box), buffer_size_label, FALSE, | |
317 FALSE, 0); | |
318 buffer_size_adj = | |
319 gtk_adjustment_new(oss_cfg.buffer_size, 200, 10000, 100, 100, 100); | |
320 buffer_size_spin = | |
321 gtk_spin_button_new(GTK_ADJUSTMENT(buffer_size_adj), 8, 0); | |
322 gtk_widget_set_usize(buffer_size_spin, 60, -1); | |
323 gtk_box_pack_start(GTK_BOX(buffer_size_box), buffer_size_spin, FALSE, | |
324 FALSE, 0); | |
325 | |
326 buffer_pre_box = gtk_hbox_new(FALSE, 5); | |
327 gtk_table_attach_defaults(GTK_TABLE(buffer_table), buffer_pre_box, 1, | |
328 2, 0, 1); | |
329 buffer_pre_label = gtk_label_new(_("Pre-buffer (percent):")); | |
330 gtk_box_pack_start(GTK_BOX(buffer_pre_box), buffer_pre_label, FALSE, | |
331 FALSE, 0); | |
332 buffer_pre_adj = gtk_adjustment_new(oss_cfg.prebuffer, 0, 90, 1, 1, 1); | |
333 buffer_pre_spin = | |
334 gtk_spin_button_new(GTK_ADJUSTMENT(buffer_pre_adj), 1, 0); | |
335 gtk_widget_set_usize(buffer_pre_spin, 60, -1); | |
336 gtk_box_pack_start(GTK_BOX(buffer_pre_box), buffer_pre_spin, FALSE, | |
337 FALSE, 0); | |
338 | |
339 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), buffer_frame, | |
340 gtk_label_new(_("Buffering"))); | |
341 mixer_frame = gtk_frame_new(_("Mixer Settings:")); | |
342 gtk_container_set_border_width(GTK_CONTAINER(mixer_frame), 5); | |
343 mixer_table = gtk_table_new(3, 2, TRUE); | |
344 gtk_container_add(GTK_CONTAINER(mixer_frame), mixer_table); | |
345 gtk_container_set_border_width(GTK_CONTAINER(mixer_table), 5); | |
346 mixer_usemaster_check = | |
347 gtk_check_button_new_with_label(_("Volume controls Master not PCM")); | |
348 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mixer_usemaster_check), | |
349 oss_cfg.use_master); | |
350 gtk_table_attach_defaults(GTK_TABLE(mixer_table), | |
351 mixer_usemaster_check, 0, 1, 0, 1); | |
352 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), mixer_frame, | |
353 gtk_label_new(_("Mixer"))); | |
354 | |
355 bbox = gtk_hbutton_box_new(); | |
356 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
357 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
358 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
359 | |
360 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
361 g_signal_connect_swapped(G_OBJECT(cancel), "clicked", | |
362 G_CALLBACK(gtk_widget_destroy), | |
363 GTK_OBJECT(configure_win)); | |
364 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
365 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); | |
366 | |
367 ok = gtk_button_new_from_stock(GTK_STOCK_APPLY); | |
368 g_signal_connect(G_OBJECT(ok), "clicked", | |
369 G_CALLBACK(configure_win_ok_cb), NULL); | |
370 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); | |
371 gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0); | |
372 gtk_widget_grab_default(ok); | |
373 | |
374 gtk_widget_show_all(configure_win); | |
375 } |