comparison Plugins/Output/CoreAudio/configure.c @ 1637:5261e37b4d55 trunk

[svn] - fully working CoreAudio plugin, based on the OSS plugin and an incomplete xmms coreaudio plugin (fink)
author nenolod
date Thu, 07 Sep 2006 11:32:59 -0700
parents
children 365a2b043447
comparison
equal deleted inserted replaced
1636:09905c29250d 1637:5261e37b4d55
1 /* XMMS - Cross-platform multimedia player
2 * Copyright (C) 1998-2001 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies
3 * Copyright (C) 1999-2001 Håvard Kvålen
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 //#include <glib/gi18n.h>
21 #include "coreaudio.h"
22 #include "libaudacious/configdb.h"
23 #include <CoreAudio/CoreAudio.h>
24
25 static GtkWidget *configure_win = NULL;
26 static GtkWidget *mixer_usemaster_check, *buffer_size_spin, *buffer_pre_spin;
27 static GtkWidget *adevice_use_alt_check, *audio_alt_device_entry;
28 static GtkWidget *mdevice_use_alt_check, *mixer_alt_device_entry;
29 static gint audio_device, mixer_device;
30
31 static void configure_win_ok_cb(GtkWidget * w, gpointer data)
32 {
33 ConfigDb *cfgfile;
34
35 osx_cfg.audio_device = audio_device;
36 osx_cfg.mixer_device = mixer_device;
37 osx_cfg.buffer_size =
38 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_size_spin));
39 osx_cfg.prebuffer =
40 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(buffer_pre_spin));
41 osx_cfg.use_master =
42 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mixer_usemaster_check));
43 osx_cfg.use_alt_audio_device =
44 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adevice_use_alt_check));
45 osx_cfg.use_alt_mixer_device =
46 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mdevice_use_alt_check));
47 g_free(osx_cfg.alt_audio_device);
48 osx_cfg.alt_audio_device =
49 gtk_editable_get_chars(GTK_EDITABLE(audio_alt_device_entry), 0, -1);
50 g_strstrip(osx_cfg.alt_audio_device);
51 g_free(osx_cfg.alt_mixer_device);
52 osx_cfg.alt_mixer_device =
53 gtk_editable_get_chars(GTK_EDITABLE(mixer_alt_device_entry), 0, -1);
54 g_strstrip(osx_cfg.alt_mixer_device);
55
56 if (osx_cfg.use_alt_audio_device)
57 /* do a minimum of sanity checking */
58 if (osx_cfg.alt_audio_device[0] != '/')
59 osx_cfg.use_alt_audio_device = FALSE;
60 if (osx_cfg.use_alt_mixer_device)
61 if (osx_cfg.alt_mixer_device[0] != '/')
62 osx_cfg.use_alt_mixer_device = FALSE;
63
64 cfgfile = bmp_cfg_db_open();
65
66 bmp_cfg_db_set_int(cfgfile, "OSX", "audio_device", osx_cfg.audio_device);
67 bmp_cfg_db_set_int(cfgfile, "OSX", "mixer_device", osx_cfg.mixer_device);
68 bmp_cfg_db_set_int(cfgfile, "OSX", "buffer_size", osx_cfg.buffer_size);
69 bmp_cfg_db_set_int(cfgfile, "OSX", "prebuffer", osx_cfg.prebuffer);
70 bmp_cfg_db_set_bool(cfgfile,"OSX","use_master",osx_cfg.use_master);
71 bmp_cfg_db_set_bool(cfgfile, "OSX", "use_alt_audio_device", osx_cfg.use_alt_audio_device);
72 bmp_cfg_db_set_string(cfgfile, "OSX", "alt_audio_device", osx_cfg.alt_audio_device);
73 bmp_cfg_db_set_bool(cfgfile, "OSX", "use_alt_mixer_device", osx_cfg.use_alt_mixer_device);
74 bmp_cfg_db_set_string(cfgfile, "OSX", "alt_mixer_device", osx_cfg.alt_mixer_device);
75 bmp_cfg_db_close(cfgfile);
76
77 gtk_widget_destroy(configure_win);
78 }
79
80 static void configure_win_audio_dev_cb(GtkWidget * widget, gint device)
81 {
82 audio_device = device;
83 }
84
85 static void configure_win_mixer_dev_cb(GtkWidget * widget, gint device)
86 {
87 mixer_device = device;
88 }
89
90 static void audio_device_toggled(GtkToggleButton * widget, gpointer data)
91 {
92 gboolean use_alt_audio_device = gtk_toggle_button_get_active(widget);
93 gtk_widget_set_sensitive(GTK_WIDGET(data), !use_alt_audio_device);
94 gtk_widget_set_sensitive(audio_alt_device_entry, use_alt_audio_device);
95 }
96
97 static void mixer_device_toggled(GtkToggleButton * widget, gpointer data)
98 {
99 gboolean use_alt_device = gtk_toggle_button_get_active(widget);
100 gtk_widget_set_sensitive(GTK_WIDGET(data), !use_alt_device);
101 gtk_widget_set_sensitive(mixer_alt_device_entry, use_alt_device);
102 }
103
104 static void scan_devices(gchar * type, GtkWidget * option_menu, GtkSignalFunc sigfunc)
105 {
106 GtkWidget *menu, *item;
107 FILE *file;
108 UInt32 size,len,i;
109 AudioDeviceID * devicelist;
110 char device_name[128];
111
112 menu = gtk_menu_new();
113
114 if (AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,&size,NULL))
115 {
116 item = gtk_menu_item_new_with_label("Default");
117 gtk_signal_connect(GTK_OBJECT(item), "activate", sigfunc, (gpointer) 0);
118 gtk_widget_show(item);
119 gtk_menu_append(GTK_MENU(menu), item);
120 }
121 else
122 {
123 printf("there are %d devices\n",size/sizeof(AudioDeviceID));
124
125 devicelist = (AudioDeviceID*) malloc(size);
126
127 if (AudioHardwareGetProperty(kAudioHardwarePropertyDevices,&size,devicelist))
128 {
129 printf("failed to get device list");
130 }
131
132 for (i = 0; i < size/sizeof(AudioDeviceID); i++)
133 {
134 len = 128;
135 AudioDeviceGetProperty(devicelist[i],1,0,kAudioDevicePropertyDeviceName,&len,device_name);
136
137 item = gtk_menu_item_new_with_label(device_name);
138 gtk_signal_connect(GTK_OBJECT(item), "activate", sigfunc, (gpointer) 0);
139 gtk_widget_show(item);
140 gtk_menu_append(GTK_MENU(menu), item);
141
142 }
143 }
144
145 gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
146 }
147
148 void osx_configure(void)
149 {
150 GtkWidget *vbox, *notebook;
151 GtkWidget *dev_vbox, *adevice_frame, *adevice_box, *adevice;
152 GtkWidget *mdevice_frame, *mdevice_box, *mdevice;
153 GtkWidget *buffer_frame, *buffer_vbox, *buffer_table;
154 GtkWidget *buffer_size_box, *buffer_size_label;
155 GtkObject *buffer_size_adj, *buffer_pre_adj;
156 GtkWidget *buffer_pre_box, *buffer_pre_label;
157 GtkWidget *audio_alt_box, *mixer_alt_box;
158 GtkWidget *bbox, *ok, *cancel;
159 GtkWidget *mixer_table, *mixer_frame;
160
161 if (configure_win)
162 {
163 gdk_window_raise(configure_win->window);
164 return;
165 }
166
167 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
168 gtk_signal_connect(GTK_OBJECT(configure_win), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &configure_win);
169 gtk_window_set_title(GTK_WINDOW(configure_win), "CoreAudio Plugin Configuration");
170 gtk_window_set_policy(GTK_WINDOW(configure_win), FALSE, FALSE, FALSE);
171 gtk_window_set_position(GTK_WINDOW(configure_win), GTK_WIN_POS_MOUSE);
172 gtk_container_border_width(GTK_CONTAINER(configure_win), 10);
173
174
175 vbox = gtk_vbox_new(FALSE, 10);
176 gtk_container_add(GTK_CONTAINER(configure_win), vbox);
177
178 notebook = gtk_notebook_new();
179 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
180
181 dev_vbox = gtk_vbox_new(FALSE, 5);
182 gtk_container_set_border_width(GTK_CONTAINER(dev_vbox), 5);
183
184 adevice_frame = gtk_frame_new("Audio device:");
185 gtk_box_pack_start(GTK_BOX(dev_vbox), adevice_frame, FALSE, FALSE, 0);
186
187 adevice_box = gtk_vbox_new(FALSE, 5);
188 gtk_container_set_border_width(GTK_CONTAINER(adevice_box), 5);
189 gtk_container_add(GTK_CONTAINER(adevice_frame), adevice_box);
190
191 adevice = gtk_option_menu_new();
192 gtk_box_pack_start(GTK_BOX(adevice_box), adevice, TRUE, TRUE, 0);
193
194 scan_devices("Audio devices:", adevice, configure_win_audio_dev_cb);
195
196 audio_device = osx_cfg.audio_device;
197 gtk_option_menu_set_history(GTK_OPTION_MENU(adevice), osx_cfg.audio_device);
198
199 /*
200 audio_alt_box = gtk_hbox_new(FALSE, 0);
201 gtk_box_pack_start_defaults(GTK_BOX(adevice_box), audio_alt_box);
202 adevice_use_alt_check = gtk_check_button_new_with_label("Use alternate device:");
203 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adevice_use_alt_check), osx_cfg.use_alt_audio_device);
204 gtk_signal_connect(GTK_OBJECT(adevice_use_alt_check), "toggled", audio_device_toggled, adevice);
205
206 gtk_box_pack_start(GTK_BOX(audio_alt_box), adevice_use_alt_check, FALSE, FALSE, 0);
207 audio_alt_device_entry = gtk_entry_new();
208
209 gtk_box_pack_start_defaults(GTK_BOX(audio_alt_box), audio_alt_device_entry);
210 */
211
212 gtk_box_pack_start(GTK_BOX(dev_vbox), mdevice_frame, FALSE, FALSE, 0);
213
214 mdevice_box = gtk_vbox_new(FALSE, 0);
215 gtk_container_set_border_width(GTK_CONTAINER(mdevice_box), 5);
216 gtk_container_add(GTK_CONTAINER(mdevice_frame), mdevice_box);
217
218 mdevice = gtk_option_menu_new();
219 gtk_box_pack_start(GTK_BOX(mdevice_box), mdevice, TRUE, TRUE, 0);
220
221 scan_devices("Mixers:", mdevice, configure_win_mixer_dev_cb);
222
223 mixer_device = osx_cfg.mixer_device;
224 gtk_option_menu_set_history(GTK_OPTION_MENU(mdevice), osx_cfg.mixer_device);
225 mixer_alt_box = gtk_hbox_new(FALSE, 0);
226 gtk_box_pack_start_defaults(GTK_BOX(mdevice_box), mixer_alt_box);
227 mdevice_use_alt_check = gtk_check_button_new_with_label("Use alternate device:");
228 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mdevice_use_alt_check), osx_cfg.use_alt_mixer_device);
229 gtk_signal_connect(GTK_OBJECT(mdevice_use_alt_check), "toggled", mixer_device_toggled, mdevice);
230 gtk_box_pack_start(GTK_BOX(mixer_alt_box), mdevice_use_alt_check, FALSE, FALSE, 0);
231 mixer_alt_device_entry = gtk_entry_new();
232
233 if (osx_cfg.alt_mixer_device != NULL)
234 gtk_entry_set_text(GTK_ENTRY(mixer_alt_device_entry), osx_cfg.alt_mixer_device);
235 else
236 gtk_entry_set_text(GTK_ENTRY(mixer_alt_device_entry), "/dev/mixer");
237
238 gtk_box_pack_start_defaults(GTK_BOX(mixer_alt_box), mixer_alt_device_entry);
239
240 if (osx_cfg.use_alt_mixer_device)
241 gtk_widget_set_sensitive(mdevice, FALSE);
242 else
243 gtk_widget_set_sensitive(mixer_alt_device_entry, FALSE);
244
245 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dev_vbox, gtk_label_new("Devices"));
246
247
248 buffer_frame = gtk_frame_new("Buffering:");
249 gtk_container_set_border_width(GTK_CONTAINER(buffer_frame), 5);
250
251 buffer_vbox = gtk_vbox_new(FALSE, 0);
252 gtk_container_add(GTK_CONTAINER(buffer_frame), buffer_vbox);
253
254 buffer_table = gtk_table_new(2, 1, TRUE);
255 gtk_container_set_border_width(GTK_CONTAINER(buffer_table), 5);
256 gtk_box_pack_start(GTK_BOX(buffer_vbox), buffer_table, FALSE, FALSE, 0);
257
258 buffer_size_box = gtk_hbox_new(FALSE, 5);
259 gtk_table_attach_defaults(GTK_TABLE(buffer_table), buffer_size_box, 0, 1, 0, 1);
260 buffer_size_label = gtk_label_new("Buffer size (ms):");
261 gtk_box_pack_start(GTK_BOX(buffer_size_box), buffer_size_label, FALSE, FALSE, 0);
262 buffer_size_adj = gtk_adjustment_new(osx_cfg.buffer_size, 200, 10000, 100, 100, 100);
263 buffer_size_spin = gtk_spin_button_new(GTK_ADJUSTMENT(buffer_size_adj), 8, 0);
264 gtk_widget_set_usize(buffer_size_spin, 60, -1);
265 gtk_box_pack_start(GTK_BOX(buffer_size_box), buffer_size_spin, FALSE, FALSE, 0);
266
267 buffer_pre_box = gtk_hbox_new(FALSE, 5);
268 gtk_table_attach_defaults(GTK_TABLE(buffer_table), buffer_pre_box, 1, 2, 0, 1);
269 buffer_pre_label = gtk_label_new("Pre-buffer (percent):");
270 gtk_box_pack_start(GTK_BOX(buffer_pre_box), buffer_pre_label, FALSE, FALSE, 0);
271 buffer_pre_adj = gtk_adjustment_new(osx_cfg.prebuffer, 0, 90, 1, 1, 1);
272 buffer_pre_spin = gtk_spin_button_new(GTK_ADJUSTMENT(buffer_pre_adj), 1, 0);
273 gtk_widget_set_usize(buffer_pre_spin, 60, -1);
274 gtk_box_pack_start(GTK_BOX(buffer_pre_box), buffer_pre_spin, FALSE, FALSE, 0);
275
276 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), buffer_frame, gtk_label_new("Buffering"));
277
278
279 bbox = gtk_hbutton_box_new();
280 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
281 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
282 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
283
284 ok = gtk_button_new_with_label("Ok");
285 gtk_signal_connect(GTK_OBJECT(ok), "clicked", GTK_SIGNAL_FUNC(configure_win_ok_cb), NULL);
286 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT);
287 gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0);
288 gtk_widget_grab_default(ok);
289
290 cancel = gtk_button_new_with_label("Cancel");
291 gtk_signal_connect_object(GTK_OBJECT(cancel), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(configure_win));
292 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT);
293 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0);
294
295 gtk_widget_show_all(configure_win);
296 }