Addressing gtk+ 2 deprecations.
[terminatorX.git] / src / tX_dialog.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2011  Alexander König
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     File: tX_dialog.cc
20  
21     Description: Contains the implementation of the Options and About
22                  Dialogs. (And some really ugly "WE WANT TO 
23                  TYPE LESS" macros)
24                  
25     Changes:
26     
27     28 Jul 1999: Now display compiletime settings in the about dialog.
28 */    
29
30 #include "config.h"
31 #include "tX_types.h"
32 #include "tX_global.h"
33 #include "tX_dialog.h"
34 #include <gtk/gtk.h>
35 #include <string.h>
36 #include <gdk/gdk.h>
37 #include "tX_icon.h"
38 #include "tX_glade_interface.h"
39 #include "tX_glade_support.h"
40
41 #include "tX_widget.h"
42 #include "tX_flash.h"
43
44 #ifndef WIN32
45 #include <X11/extensions/XInput.h>
46 #include <X11/X.h>
47 #endif
48
49 #include "license.c"
50 #include "tX_mastergui.h"
51 #include "version.h"
52 #include "tX_vtt.h"
53 #include <dirent.h>
54 #include "tX_engine.h"
55
56 #ifdef USE_SCHEDULER
57 #include <sched.h>
58 #include <pthread.h>
59 #endif
60
61 #ifdef USE_JACK
62 extern void jack_check();
63 #endif
64
65 extern char *logo_xpm[];
66 GtkWidget *opt_dialog;
67 int opt_hidden=0;
68
69 static GtkWidget *last_alsa_device_widget=NULL;
70 static GtkWidget *alsa_device_entry=NULL;
71
72 void apply_options(GtkWidget *dialog) {
73         /* Audio */
74         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")))) {
75                 globals.audiodevice_type=ALSA;
76         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")))) {
77                 globals.audiodevice_type=OSS;
78         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")))) {
79                 globals.audiodevice_type=JACK;
80         }
81         globals.use_realtime=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "use_realtime")));
82         
83         /* Audio: OSS */
84         strcpy(globals.oss_device, gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_audio_device"))));
85         globals.oss_buff_no=(int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")));
86         globals.oss_buff_size=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")));
87         globals.oss_samplerate=atoi(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_samplerate"))));
88         
89         /* Audio: ALSA */
90         strcpy(globals.alsa_device_id, gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_audio_device"))));
91         globals.alsa_buffer_time=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")));
92         globals.alsa_buffer_time*=1000;
93         globals.alsa_period_time=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")));
94         globals.alsa_period_time*=1000;
95         globals.alsa_samplerate=atoi(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_samplerate")))); 
96         globals.alsa_free_hwstats=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")));
97         
98         /* TODO: JACK
99         */
100         
101         /* Input */
102         globals.xinput_enable=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "xinput_enable")))==TRUE);
103         strcpy(globals.xinput_device, gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "xinput_device"))));
104         globals.mouse_speed=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")));
105         globals.sense_cycles=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")));
106         globals.vtt_inertia=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")));
107         
108         /* User Interface */ 
109         globals.show_nag=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox")))==TRUE);
110         globals.tooltips=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips")))==TRUE);
111         globals.filename_length=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")));
112 //      if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
113 //      else gtk_tooltips_disable(gui_tooltips);
114 //      TODO: Disable Tooltips no longer possible?
115
116         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")))) {
117                 globals.button_type=BUTTON_TYPE_TEXT;
118         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")))) {
119                 globals.button_type=BUTTON_TYPE_ICON;
120         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")))) {
121                 globals.button_type=BUTTON_TYPE_BOTH;
122         }
123         
124         globals.update_delay=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_delay")));
125         globals.update_idle=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_idle")));
126         globals.flash_response=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")));
127         
128         /* Audio Colors */
129         
130         strcpy(globals.wav_display_bg_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_focus")), "Color"));
131         strcpy(globals.wav_display_bg_no_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_no_focus")), "Color"));
132         strcpy(globals.wav_display_fg_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_focus")), "Color"));
133         strcpy(globals.wav_display_fg_no_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_no_focus")), "Color"));
134         strcpy(globals.wav_display_cursor, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor")), "Color"));
135         strcpy(globals.wav_display_cursor_mute, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor_mute")), "Color"));
136
137         /* VU Colors */ 
138         strcpy(globals.vu_meter_bg, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_bg")), "Color"));
139         strcpy(globals.vu_meter_loud, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_loud")), "Color"));
140         strcpy(globals.vu_meter_normal, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_normal")), "Color"));
141
142         globals.vu_meter_border_intensity=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")));
143         
144         /* Misc */
145         strcpy(globals.file_editor, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor"))));
146         strcpy(globals.lrdf_path, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path"))));
147         globals.compress_set_files=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files")))==TRUE);        
148         globals.prelis=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled")))==TRUE);
149         globals.restore_midi_connections=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled")))==TRUE);
150         globals.quit_confirm=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "quit_confirm")))==TRUE);
151         globals.verbose_plugin_loading=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "verbose_plugin_loading")))==TRUE);
152         globals.force_nonrt_plugins=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "force_nonrt_plugins")))==TRUE);
153         
154         /* update colors */
155         std::list<vtt_class *>::iterator vtt;
156         
157         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
158                 gtk_tx_update_colors(GTK_TX((*vtt)->gui.display));
159                 gtk_widget_queue_draw((*vtt)->gui.display);
160                 gtk_tx_flash_update_colors(GTK_TX_FLASH((*vtt)->gui.flash));
161                 gtk_widget_queue_draw((*vtt)->gui.flash);
162         }
163         
164         gtk_tx_flash_update_colors(GTK_TX_FLASH(main_flash));
165         gtk_widget_queue_draw(main_flash);
166         
167 #ifdef USE_JACK
168         jack_check();
169 #endif  
170 }
171
172
173 #define WID_DYN TRUE, TRUE, 0
174 #define WID_FIX FALSE, FALSE, 0
175
176 #define my_new_subsec(s); \
177         separator=gtk_hseparator_new(); \
178         gtk_box_pack_start(GTK_BOX(vbox), separator, WID_DYN);\
179         gtk_widget_show(separator); \
180         label=gtk_label_new(s); \
181         gtk_misc_set_alignment (GTK_MISC(label), 0 ,0.5); \
182         gtk_box_pack_start(GTK_BOX(vbox), label, WID_DYN); \
183         gtk_widget_show(label); 
184
185 #define my_new_button(btn, s); \
186         btn=gtk_button_new_with_label(s); \
187         gtk_box_pack_start(GTK_BOX(aa), btn, WID_DYN); \
188         gtk_widget_show(btn);
189         
190
191 #define begin_box(); box=gtk_hbox_new(FALSE, 5);
192
193 #define begin_hom_box(); box=gtk_hbox_new(TRUE, 5);
194
195 #define end_box(); gtk_box_pack_start(GTK_BOX(vbox), box, WID_DYN); \
196         gtk_widget_show(box);
197
198 #define add_widget_dyn(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN);\
199         gtk_widget_show(wid);
200         
201 #define add_widget_fix(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX);\
202         gtk_widget_show(wid);
203
204 #define add_expl(s); label=gtk_label_new(s); \
205         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);\
206         add_widget_fix(label);
207
208 #define add_expl_dyn(s); label=gtk_label_new(s); \
209         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);\
210         add_widget_dyn(label);
211
212 #ifdef USE_ALSA
213 void append_alsa_device_list(GtkComboBoxText *combo) {
214         FILE *file;
215         char buffer[PATH_MAX+1];
216         
217         if ((file = fopen("/proc/asound/pcm", "r"))) {
218                 while(fgets(buffer, PATH_MAX, file)) {
219                         buffer[PATH_MAX]=0;
220                         if (strlen(buffer)) buffer[strlen(buffer)-1]=0;
221                         if(strstr(buffer, "playback")) {
222                                 char foo[PATH_MAX];
223                                 char tmp[PATH_MAX];
224                                 memset(foo, 0, PATH_MAX);
225                                 int card;
226                                 int device;
227  
228                                 sscanf(buffer, "%i-%i: %1024c", &card, &device, foo);
229                                 sprintf(tmp, "hw:%i,%i# %s", card, device, foo);
230                                 
231                                 gtk_combo_box_text_append_text(combo, strdup(tmp));
232                         }
233                 }
234                 fclose(file);
235         }
236 }
237 #else
238 void append_alsa_device_list(GtkComboBoxText *combo) {
239 }
240 #endif
241
242
243 #ifdef USE_OSS
244 int oss_select_dsp_only(const struct dirent *entry){
245         return (strstr(entry->d_name, "dsp")!=0);
246 }
247
248 void append_oss_device_list(GtkComboBoxText *combo) {
249     struct dirent **namelist;
250     int n,i;
251     n = scandir("/dev", &namelist, oss_select_dsp_only, alphasort);
252     
253     if (n>0) {
254         for (i=0; i<n; i++) {
255                         char buffer[256];
256             sprintf(buffer, "/dev/%s", namelist[i]->d_name);
257             free(namelist[i]);
258             gtk_combo_box_text_append_text(combo, strdup(buffer));
259                 }
260         }
261 }
262 #endif
263
264 static GList *sampling_rates=NULL;
265
266 GList *get_sampling_rates_list() {
267         if (sampling_rates) {
268                 return sampling_rates;
269         }
270
271         sampling_rates=g_list_append(sampling_rates, (void *) "22000");
272         sampling_rates=g_list_append(sampling_rates, (void *) "32000");
273         sampling_rates=g_list_append(sampling_rates, (void *) "44100");
274         sampling_rates=g_list_append(sampling_rates, (void *) "48000");
275
276         return sampling_rates;  
277 }
278
279 static GList *xinput_devices=NULL;
280
281 GList *get_xinput_devices_list() {
282         if (xinput_devices) {
283                 return xinput_devices;
284         }
285         
286         int devmax;
287         Display *dpy=XOpenDisplay(NULL);
288         XDeviceInfo *xdev=XListInputDevices(dpy, &devmax);
289         XCloseDisplay(dpy);
290
291         for (int i=0; i<devmax; i++) {
292                 xinput_devices=g_list_append(xinput_devices, strdup(xdev[i].name));
293         }
294         
295         XFreeDeviceList(xdev);
296         
297         return xinput_devices;
298 }
299
300 #define MAX_COLORS 10
301 char *colors[MAX_COLORS]={ NULL };
302
303 #define set_color_button(s,g); \
304         sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", s, s);\
305         gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(lookup_widget(dialog, g)))->data), tmp);\
306         strcpy(colors[ctr], s);\
307         g_object_set_data(G_OBJECT(lookup_widget(dialog, g)), "Color", colors[ctr]);\
308         ctr++;
309
310
311 void init_tx_options(GtkWidget *dialog) {
312         if (colors[0]==NULL) {
313                 for (int i=0; i<MAX_COLORS; i++) {
314                         colors[i]=new char[8];
315                         colors[i][0]=0;
316                 }
317         }
318         
319         /* Audio */
320         switch (globals.audiodevice_type) {             
321                 case ALSA: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")), 1);
322                         break;
323                 
324                 case JACK: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")), 1);
325                         break;
326
327                 case OSS: 
328                 default:
329                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")), 1);
330                         break;
331         }
332
333         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "use_realtime")), globals.use_realtime);
334
335 #ifndef USE_CAPABILITIES
336         /* rt's not configurable without capabilities. */
337         gtk_widget_hide(lookup_widget(dialog, "use_realtime"));
338         gtk_widget_hide(lookup_widget(dialog, "use_realtime_label"));   
339 #endif
340         
341 #ifndef USE_OSS
342         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_driver"), 0);
343         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_audio_device"), 0);
344         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffers"), 0);
345         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffersize"), 0);
346 #endif
347         
348 #ifndef USE_ALSA
349         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_driver"), 0);      
350         // TODO: Rest!  
351 #endif
352         
353 #ifndef USE_JACK
354         gtk_widget_set_sensitive(lookup_widget(dialog, "jack_driver"), 0);
355 #endif  
356         
357         /* Audio: OSS */
358         append_oss_device_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_audio_device")));
359         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO_BOX(lookup_widget(dialog, "oss_audio_device"))->entry), globals.oss_device);
360
361         gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")), globals.oss_buff_no);
362         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")), globals.oss_buff_size);
363         gtk_widget_set_tooltip_text(lookup_widget(dialog, "oss_buffersize"), "Set the size of the kernel level audio buffers. On slower systems you might have to increase this value (if you hear \"clicks\" or drop-outs). Lower values mean lower latency though."); 
364         gtk_combo_set_popdown_strings(GTK_COMBO_BOX(lookup_widget(dialog, "oss_samplerate")), get_sampling_rates_list());
365         char tmp[64];
366         sprintf(tmp, "%i", globals.oss_samplerate);
367         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO_BOX(lookup_widget(dialog, "oss_samplerate"))->entry), tmp);
368         
369         
370         /* Audio: ALSA */
371         GtkCombo *combo=GTK_COMBO_BOX(lookup_widget(dialog, "alsa_audio_device"));
372         GList *alsa_list=get_alsa_device_list();
373         last_alsa_device_widget=NULL;
374         alsa_device_entry=combo->entry;
375         
376         append_alsa_device_list(GTK_COMBOBOX_TEXT(combo));
377         gtk_entry_set_text(GTK_ENTRY(combo->entry), globals.alsa_device_id);
378
379         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")), globals.alsa_buffer_time/1000);
380         gtk_widget_set_tooltip_text(lookup_widget(dialog, "alsa_buffer_time"), "Sets the size of the ALSA ring buffer. On slower systems you might have to increase this value (if you hear \"clicks\" or drop-outs). Lower values mean lower latency though.");        
381         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")), globals.alsa_period_time/1000);
382         gtk_widget_set_tooltip_text(lookup_widget(dialog, "alsa_period_time"), "The ALSA period time determines how much audio data will be written to the device at once. It is recommended to set this value to a half or a third of the ALSA buffer time."); 
383
384         gtk_combo_set_popdown_strings(GTK_COMBO_BOX(lookup_widget(dialog, "alsa_samplerate")), get_sampling_rates_list());
385         sprintf(tmp, "%i", globals.alsa_samplerate);
386         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO_BOX(lookup_widget(dialog, "alsa_samplerate"))->entry), tmp);
387         
388         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")), globals.alsa_free_hwstats);
389         
390         /* Input */
391         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "xinput_enable")), globals.xinput_enable);
392         
393         gtk_combo_set_popdown_strings(GTK_COMBO_BOX(lookup_widget(dialog, "xinput_device")), get_xinput_devices_list());
394         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO_BOX(lookup_widget(dialog, "xinput_device"))->entry), globals.xinput_device);
395
396         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")), globals.mouse_speed);
397         gtk_widget_set_tooltip_text(lookup_widget(dialog, "mouse_speed"), "The speed of your mouse in scratch mode. Use negative values to invert motion.");
398         
399         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")), globals.sense_cycles);
400         gtk_widget_set_tooltip_text(lookup_widget(dialog, "stop_sense_cycles"),"If there is no \"motion-event\" for x cycles, where x is the number of cycles you select here, terminatorX assumes mouse motion has stopped. For smaller buffer sizes (=> shorter cycle times) you might have to increase this value"); 
401
402         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")), globals.vtt_inertia);
403         gtk_widget_set_tooltip_text(lookup_widget(dialog, "vtt_inertia"),"This value defines how fast the turntables will adapt to the speed input - the higher this value, the longer it will take the turntable to actually reach the target speed.");        
404
405         gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")), globals.filename_length);
406
407         /* User Interface */ 
408         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox")), globals.show_nag);
409         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips")), globals.tooltips);
410         
411         switch (globals.button_type) {
412                 case BUTTON_TYPE_TEXT:
413                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")), 1);
414                         break;
415                 
416                 case BUTTON_TYPE_ICON:
417                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")), 1);
418                         break;
419                 
420                 case BUTTON_TYPE_BOTH:
421                 default:
422                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")), 1);
423         }
424         
425         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_delay")), globals.update_delay);
426         gtk_widget_set_tooltip_text(lookup_widget(dialog, "update_delay"), "How often to update the slow widgets.");    
427         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_idle")), globals.update_idle);
428         gtk_widget_set_tooltip_text(lookup_widget(dialog, "update_idle"), "The update thread will idle for the selcted amount of milliseconds. If you want to have a more responsive display update reduce this value - if you have performance problems increase this value.");        
429         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")), globals.flash_response);
430         gtk_widget_set_tooltip_text(lookup_widget(dialog, "vumeter_decay"), "Defines how fast the maximum values of the VU meters should be decayed."); 
431
432         /* Audio Colors */
433         int ctr=0;
434         
435         set_color_button(globals.wav_display_bg_focus, "wav_display_bg_focus");
436         set_color_button(globals.wav_display_bg_no_focus, "wav_display_bg_no_focus");
437         set_color_button(globals.wav_display_fg_focus, "wav_display_fg_focus");
438         set_color_button(globals.wav_display_fg_no_focus, "wav_display_fg_no_focus");
439         set_color_button(globals.wav_display_cursor, "wav_display_cursor");
440         set_color_button(globals.wav_display_cursor_mute, "wav_display_cursor_mute");
441         
442         /* VU Colors */
443         set_color_button(globals.vu_meter_bg, "vu_meter_bg");
444         set_color_button(globals.vu_meter_loud, "vu_meter_loud");
445         set_color_button(globals.vu_meter_normal, "vu_meter_normal");
446         
447         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")), globals.vu_meter_border_intensity);
448         
449         /* Misc */
450         gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor")), globals.file_editor);
451         gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path")), globals.lrdf_path);
452         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files")), globals.compress_set_files);
453         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled")), globals.prelis);
454         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled")), globals.restore_midi_connections);
455         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "quit_confirm")), globals.quit_confirm);
456         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "force_nonrt_plugins")), globals.force_nonrt_plugins);     
457         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "verbose_plugin_loading")), globals.verbose_plugin_loading);       
458 }
459
460 void create_options()
461 {
462         opt_dialog=create_tx_options();
463         tX_set_icon(opt_dialog);
464         init_tx_options(opt_dialog);
465         gtk_widget_show(opt_dialog);
466 }
467
468 void display_options()
469 {
470         if (opt_dialog) {
471                 gdk_window_raise(opt_dialog->window);   
472         } else {
473                 create_options();
474         }
475 }
476
477 GtkWidget *about=NULL;
478
479 void raise_about()
480 {
481         if (about) gdk_window_raise(about->window);
482 }
483
484
485 void destroy_about()
486 {
487         if (about) {    
488                 gtk_widget_destroy(about);
489                 about=NULL;
490         }
491 }
492
493 #define add_about_wid(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN); \
494         gtk_widget_show(wid);
495
496 #define add_about_wid_fix(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX); \
497         gtk_widget_show(wid);
498
499 GdkFont *GPL_font=NULL;
500
501 void show_about(int nag)
502 {
503         GtkWidget *window;
504         GtkWidget *btn;
505         GtkWidget *box;
506         GtkWidget *hbox;
507         GtkWidget *label;
508         GtkWidget *sep;
509         GtkWidget *text;
510         GtkWidget *scroll;
511         GtkWidget *iwid;
512         
513         /* Only raise the window if it's already open... */
514         if (about)  {
515                 gdk_window_raise(about->window);
516                 return;
517         }
518         
519         /* Create the window... */
520         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
521         gtk_container_set_border_width(GTK_CONTAINER(window), 5);
522         gtk_window_set_title(GTK_WINDOW(window), "terminatorX - About");
523         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
524         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
525         gtk_window_set_resizable(GTK_WINDOW(window), nag ? TRUE: FALSE);
526
527         GdkPixbuf *image=gdk_pixbuf_new_from_xpm_data((const char **)logo_xpm);
528         iwid = gtk_image_new_from_pixbuf(image);
529         
530         if (nag) {
531                 GtkWidget *box=gtk_vbox_new(FALSE, 2);
532                 GtkWidget *box2=gtk_hbox_new(FALSE, 2);
533                 GtkWidget *label;
534                 
535                 gtk_container_add(GTK_CONTAINER(window), box);
536                 gtk_box_pack_start(GTK_BOX(box), iwid, WID_FIX);
537                 gtk_box_pack_start(GTK_BOX(box), box2, WID_FIX);
538                 
539                 label=gtk_label_new(PACKAGE" release "VERSION);
540                 gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
541                 gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
542                 gtk_widget_show(label);
543
544                 label=gtk_label_new("Copyright (C) 1999-2011 by Alexander König");
545                 gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
546                 gtk_misc_set_alignment(GTK_MISC(label), 0.9, 0.5);
547                 gtk_widget_show(label);
548                 
549                 gtk_widget_show(box2);
550                 gtk_widget_show(box);
551                 gtk_widget_show(iwid);
552
553                 gtk_window_set_decorated(GTK_WINDOW(window), FALSE);            
554                 gtk_widget_show(window);
555         } else {
556                 box=gtk_vbox_new(FALSE, 5);
557                 add_about_wid_fix(iwid);
558                 
559                 sep=gtk_hseparator_new();
560                 add_about_wid_fix(sep);
561                 
562                 label=gtk_label_new("This is "PACKAGE" release "VERSION" - Copyright (C) 1999-2011 by Alexander König"
563                 "\nSend comments, patches and scratches to: alex@lisas.de\nterminatorX-homepage: http://www.terminatorX.org");
564
565                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
566                 add_about_wid_fix(label);
567
568                 sep=gtk_hseparator_new();
569                 add_about_wid_fix(sep);
570                 
571                 label=gtk_label_new(
572                 "Compilation flags: "
573                 "sox: "
574 #ifdef USE_SOX_INPUT
575                 "ON"
576 #else
577                 "OFF"
578 #endif          
579                 " - mpg123: "
580 #ifdef USE_MPG123_INPUT
581                 "ON"
582 #else
583                 "OFF"
584 #endif
585                 " - ogg123: "
586 #ifdef USE_OGG123_INPUT
587                 "ON"
588 #else
589                 "OFF"
590 #endif
591                 " - libmad: "
592 #ifdef USE_MAD_INPUT
593                 "ON"
594 #else
595                 "OFF"
596 #endif
597
598                 " - libvorbis: "
599 #ifdef USE_VORBIS_INPUT
600                 "ON"
601 #else
602                 "OFF"
603 #endif
604
605                 " - libaudiofile: "
606 #ifdef USE_AUDIOFILE_INPUT
607                 "ON"
608 #else
609                 "OFF"
610 #endif
611
612                 " - MIDI: "
613 #ifdef USE_ALSA_MIDI_IN
614                 "ON"
615 #else
616                 "OFF"
617 #endif
618
619                 " - OSS: "
620 #ifdef USE_OSS
621                 "ON"
622 #else
623                 "OFF"
624 #endif
625
626                 " - ALSA: "
627 #ifdef USE_ALSA
628                 "ON"
629 #else
630                 "OFF"
631 #endif
632
633                 " - JACK: "
634 #ifdef USE_JACK
635                 "ON"
636 #else
637                 "OFF"
638 #endif
639
640                 " - liblrdf: "
641 #ifdef USE_LRDF
642                 "ON"
643 #else
644                 "OFF"
645 #endif
646
647                 " - rt scheduling: "
648 #ifdef USE_SCHEDULER
649                 "ON"
650 #else
651                 "OFF"
652 #endif
653
654                 " - capabilities: "
655 #ifdef USE_CAPABILITIES
656                 "ON"
657 #else
658                 "OFF"
659 #endif
660
661                 " - "
662 #ifdef WORDS_BIGENDIAN
663                 "big"
664 #else
665                 "little"
666 #endif
667                 " endian.");
668         
669                 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
670                 gtk_widget_set_size_request(label, 640, -1);
671                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
672                 add_about_wid_fix(label);
673
674 #ifdef  USE_SCHEDULER
675                 sep=gtk_hseparator_new();
676                 add_about_wid_fix(sep);
677
678                 char buffer[4096];
679                 
680                 int policy=-1;
681                 struct sched_param parm;
682                 
683                 pthread_getschedparam(tX_engine::get_instance()->get_thread_id(), &policy, &parm);
684                 char prio_str[32]="";
685                 
686                 switch (policy) {
687                         case SCHED_OTHER:
688                                 strcpy(prio_str, "SCHED_OTHER");
689                                 break;
690                         
691                         case SCHED_RR:
692                                 strcpy(prio_str, "SCHED_RR");
693                                 break;
694                         
695                         case SCHED_FIFO:
696                                 strcpy(prio_str, "SCHED_FIFO");
697                                 break;
698                         
699                         default:
700                                 sprintf(prio_str, "UNKOWN (%i)", policy);
701                 }
702                 
703                 sprintf(buffer, "Audio engine scheduling policy: %s.\n(Note: SCHED_FIFO equals realtime scheduling.)", prio_str);
704
705                 label=gtk_label_new(buffer);
706
707                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
708                 add_about_wid_fix(label);
709 #endif
710
711                 sep=gtk_hseparator_new();
712                 add_about_wid_fix(sep);
713
714                 label=gtk_label_new("License (GPL V2):");
715                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
716                 add_about_wid_fix(label);
717
718                 hbox=gtk_hbox_new(FALSE, 5);            
719
720                 GtkTextIter iter;
721                 GtkTextBuffer *tbuffer;
722
723                 text=gtk_text_view_new();
724                 tbuffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
725                 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
726                 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), false);
727                 gtk_text_buffer_get_iter_at_offset (tbuffer, &iter, 0);
728                 
729                 scroll=gtk_scrolled_window_new (NULL, NULL);
730         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
731                 gtk_container_add (GTK_CONTAINER (scroll), text);
732                 gtk_text_buffer_create_tag (tbuffer, "courier", "family", "courier", NULL);
733                 
734                 gtk_text_buffer_insert_with_tags_by_name(tbuffer, &iter, license, -1, "courier", NULL);
735                 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
736                 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 5);
737                 gtk_widget_set_size_request(GTK_WIDGET(text), 640, 200);
738                 gtk_widget_show(text);          
739                 
740                 gtk_box_pack_start(GTK_BOX(hbox), scroll, WID_DYN);
741                 gtk_widget_show(scroll);                
742                 
743                 add_about_wid(hbox);
744
745                 sep=gtk_hseparator_new();
746                 add_about_wid_fix(sep);
747
748                 btn=gtk_button_new_with_label("Close");
749                 add_about_wid_fix(btn);
750
751                 gtk_container_add(GTK_CONTAINER(window), box);
752                 gtk_widget_show(box);
753                 
754                 g_signal_connect(G_OBJECT(btn), "clicked", (GCallback) destroy_about, NULL);            
755                 g_signal_connect(G_OBJECT(window), "delete-event", (GCallback) destroy_about, NULL);            
756         }
757         gtk_widget_show(window);        
758         tX_set_icon(window);
759         
760         while (gtk_events_pending()) gtk_main_iteration();
761                 
762         about=window;
763 }
764
765 static GdkPixbuf *tX_window_icon=NULL;
766
767 void tX_set_icon(GtkWidget *widget)
768 {       
769         if (!tX_window_icon) {
770                 tX_window_icon=gdk_pixbuf_new_from_inline(-1, tX_icon, FALSE, NULL);
771         }
772
773         gtk_window_set_icon(GTK_WINDOW(widget), tX_window_icon);
774 }