comparison src/CoreAudio/configure.c @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Output/CoreAudio/configure.c@088092a52fea
children d124034ebea3
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
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 "audacious/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 devicelist = (AudioDeviceID*) malloc(size);
124
125 if (AudioHardwareGetProperty(kAudioHardwarePropertyDevices,&size,devicelist))
126 return;
127
128 for (i = 0; i < size/sizeof(AudioDeviceID); i++)
129 {
130 len = 128;
131 AudioDeviceGetProperty(devicelist[i],1,0,kAudioDevicePropertyDeviceName,&len,device_name);
132
133 item = gtk_menu_item_new_with_label(device_name);
134 gtk_signal_connect(GTK_OBJECT(item), "activate", sigfunc, (gpointer) 0);
135 gtk_widget_show(item);
136 gtk_menu_append(GTK_MENU(menu), item);
137
138 }
139 }
140
141 gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
142 }
143
144 void osx_configure(void)
145 {
146 GtkWidget *vbox, *notebook;
147 GtkWidget *dev_vbox, *adevice_frame, *adevice_box, *adevice;
148 GtkWidget *mdevice_frame, *mdevice_box, *mdevice;
149 GtkWidget *buffer_frame, *buffer_vbox, *buffer_table;
150 GtkWidget *buffer_size_box, *buffer_size_label;
151 GtkObject *buffer_size_adj, *buffer_pre_adj;
152 GtkWidget *buffer_pre_box, *buffer_pre_label;
153 GtkWidget *audio_alt_box, *mixer_alt_box;
154 GtkWidget *bbox, *ok, *cancel;
155 GtkWidget *mixer_table, *mixer_frame;
156
157 if (configure_win)
158 {
159 gdk_window_raise(configure_win->window);
160 return;
161 }
162
163 configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
164 gtk_signal_connect(GTK_OBJECT(configure_win), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &configure_win);
165 gtk_window_set_title(GTK_WINDOW(configure_win), "CoreAudio Plugin Configuration");
166 gtk_window_set_policy(GTK_WINDOW(configure_win), FALSE, FALSE, FALSE);
167 gtk_window_set_position(GTK_WINDOW(configure_win), GTK_WIN_POS_MOUSE);
168 gtk_container_border_width(GTK_CONTAINER(configure_win), 10);
169
170
171 vbox = gtk_vbox_new(FALSE, 10);
172 gtk_container_add(GTK_CONTAINER(configure_win), vbox);
173
174 notebook = gtk_notebook_new();
175 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
176
177 dev_vbox = gtk_vbox_new(FALSE, 5);
178 gtk_container_set_border_width(GTK_CONTAINER(dev_vbox), 5);
179
180 adevice_frame = gtk_frame_new("Audio device:");
181 gtk_box_pack_start(GTK_BOX(dev_vbox), adevice_frame, FALSE, FALSE, 0);
182
183 adevice_box = gtk_vbox_new(FALSE, 5);
184 gtk_container_set_border_width(GTK_CONTAINER(adevice_box), 5);
185 gtk_container_add(GTK_CONTAINER(adevice_frame), adevice_box);
186
187 adevice = gtk_option_menu_new();
188 gtk_box_pack_start(GTK_BOX(adevice_box), adevice, TRUE, TRUE, 0);
189
190 scan_devices("Audio devices:", adevice, configure_win_audio_dev_cb);
191
192 audio_device = osx_cfg.audio_device;
193 gtk_option_menu_set_history(GTK_OPTION_MENU(adevice), osx_cfg.audio_device);
194
195 gtk_box_pack_start(GTK_BOX(dev_vbox), mdevice_frame, FALSE, FALSE, 0);
196
197 mdevice_box = gtk_vbox_new(FALSE, 0);
198 gtk_container_set_border_width(GTK_CONTAINER(mdevice_box), 5);
199 gtk_container_add(GTK_CONTAINER(mdevice_frame), mdevice_box);
200
201 mdevice = gtk_option_menu_new();
202 gtk_box_pack_start(GTK_BOX(mdevice_box), mdevice, TRUE, TRUE, 0);
203
204 scan_devices("Mixers:", mdevice, configure_win_mixer_dev_cb);
205
206 mixer_device = osx_cfg.mixer_device;
207 gtk_option_menu_set_history(GTK_OPTION_MENU(mdevice), osx_cfg.mixer_device);
208 mixer_alt_box = gtk_hbox_new(FALSE, 0);
209 gtk_box_pack_start_defaults(GTK_BOX(mdevice_box), mixer_alt_box);
210 mdevice_use_alt_check = gtk_check_button_new_with_label("Use alternate device:");
211 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mdevice_use_alt_check), osx_cfg.use_alt_mixer_device);
212 gtk_signal_connect(GTK_OBJECT(mdevice_use_alt_check), "toggled", mixer_device_toggled, mdevice);
213 gtk_box_pack_start(GTK_BOX(mixer_alt_box), mdevice_use_alt_check, FALSE, FALSE, 0);
214 mixer_alt_device_entry = gtk_entry_new();
215
216 if (osx_cfg.alt_mixer_device != NULL)
217 gtk_entry_set_text(GTK_ENTRY(mixer_alt_device_entry), osx_cfg.alt_mixer_device);
218 else
219 gtk_entry_set_text(GTK_ENTRY(mixer_alt_device_entry), "/dev/mixer");
220
221 gtk_box_pack_start_defaults(GTK_BOX(mixer_alt_box), mixer_alt_device_entry);
222
223 if (osx_cfg.use_alt_mixer_device)
224 gtk_widget_set_sensitive(mdevice, FALSE);
225 else
226 gtk_widget_set_sensitive(mixer_alt_device_entry, FALSE);
227
228 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dev_vbox, gtk_label_new("Devices"));
229
230
231 buffer_frame = gtk_frame_new("Buffering:");
232 gtk_container_set_border_width(GTK_CONTAINER(buffer_frame), 5);
233
234 buffer_vbox = gtk_vbox_new(FALSE, 0);
235 gtk_container_add(GTK_CONTAINER(buffer_frame), buffer_vbox);
236
237 buffer_table = gtk_table_new(2, 1, TRUE);
238 gtk_container_set_border_width(GTK_CONTAINER(buffer_table), 5);
239 gtk_box_pack_start(GTK_BOX(buffer_vbox), buffer_table, FALSE, FALSE, 0);
240
241 buffer_size_box = gtk_hbox_new(FALSE, 5);
242 gtk_table_attach_defaults(GTK_TABLE(buffer_table), buffer_size_box, 0, 1, 0, 1);
243 buffer_size_label = gtk_label_new("Buffer size (ms):");
244 gtk_box_pack_start(GTK_BOX(buffer_size_box), buffer_size_label, FALSE, FALSE, 0);
245 buffer_size_adj = gtk_adjustment_new(osx_cfg.buffer_size, 200, 10000, 100, 100, 100);
246 buffer_size_spin = gtk_spin_button_new(GTK_ADJUSTMENT(buffer_size_adj), 8, 0);
247 gtk_widget_set_usize(buffer_size_spin, 60, -1);
248 gtk_box_pack_start(GTK_BOX(buffer_size_box), buffer_size_spin, FALSE, FALSE, 0);
249
250 buffer_pre_box = gtk_hbox_new(FALSE, 5);
251 gtk_table_attach_defaults(GTK_TABLE(buffer_table), buffer_pre_box, 1, 2, 0, 1);
252 buffer_pre_label = gtk_label_new("Pre-buffer (percent):");
253 gtk_box_pack_start(GTK_BOX(buffer_pre_box), buffer_pre_label, FALSE, FALSE, 0);
254 buffer_pre_adj = gtk_adjustment_new(osx_cfg.prebuffer, 0, 90, 1, 1, 1);
255 buffer_pre_spin = gtk_spin_button_new(GTK_ADJUSTMENT(buffer_pre_adj), 1, 0);
256 gtk_widget_set_usize(buffer_pre_spin, 60, -1);
257 gtk_box_pack_start(GTK_BOX(buffer_pre_box), buffer_pre_spin, FALSE, FALSE, 0);
258
259 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), buffer_frame, gtk_label_new("Buffering"));
260
261
262 bbox = gtk_hbutton_box_new();
263 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
264 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
265 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
266
267 ok = gtk_button_new_with_label("Ok");
268 gtk_signal_connect(GTK_OBJECT(ok), "clicked", GTK_SIGNAL_FUNC(configure_win_ok_cb), NULL);
269 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT);
270 gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0);
271 gtk_widget_grab_default(ok);
272
273 cancel = gtk_button_new_with_label("Cancel");
274 gtk_signal_connect_object(GTK_OBJECT(cancel), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(configure_win));
275 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT);
276 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0);
277
278 gtk_widget_show_all(configure_win);
279 }