1239258cf31b06f4a0befb534386f2626b5d8e14
[terminatorX.git] / src / tX_dialog.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2003  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
55 #ifdef USE_JACK
56 extern void jack_check();
57 #endif
58
59 extern char *logo_xpm[];
60 GtkWidget *opt_dialog;
61 int opt_hidden=0;
62
63 static GtkWidget *last_alsa_device_widget=NULL;
64 static GtkWidget *alsa_device_entry=NULL;
65
66 void apply_options(GtkWidget *dialog) {
67         /* Audio */
68         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")))) {
69                 globals.audiodevice_type=ALSA;
70         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")))) {
71                 globals.audiodevice_type=OSS;
72         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")))) {
73                 globals.audiodevice_type=JACK;
74         }
75         
76         /* Audio: OSS */
77         strcpy(globals.oss_device, gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "oss_audio_device"))->entry)));
78         globals.oss_buff_no=(int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")));
79         globals.oss_buff_size=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")));
80         globals.oss_samplerate=atoi(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "oss_samplerate"))->entry)));
81         
82         /* Audio: ALSA */
83         strcpy(globals.alsa_device_id, gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "alsa_audio_device"))->entry)));
84         globals.alsa_buffer_time=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")));
85         globals.alsa_buffer_time*=1000;
86         globals.alsa_period_time=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")));
87         globals.alsa_period_time*=1000;
88         globals.alsa_samplerate=atoi(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "alsa_samplerate"))->entry)));        
89         globals.alsa_free_hwstats=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")));
90         
91         /* TODO: JACK
92         */
93         
94         /* Input */
95         globals.xinput_enable=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "xinput_enable")))==TRUE);
96         strcpy(globals.xinput_device, gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "xinput_device"))->entry)));
97         globals.mouse_speed=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")));
98         globals.sense_cycles=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")));
99         globals.vtt_inertia=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")));
100         
101         /* User Interface */ 
102         globals.show_nag=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox")))==TRUE);
103         globals.tooltips=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips")))==TRUE);
104         globals.filename_length=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")));
105         if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
106         else gtk_tooltips_disable(gui_tooltips);
107
108         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")))) {
109                 globals.button_type=BUTTON_TYPE_TEXT;
110         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")))) {
111                 globals.button_type=BUTTON_TYPE_ICON;
112         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")))) {
113                 globals.button_type=BUTTON_TYPE_BOTH;
114         }
115         
116         globals.update_delay=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_delay")));
117         globals.update_idle=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_idle")));
118         globals.flash_response=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")));
119         
120         /* Audio Colors */
121         
122         strcpy(globals.wav_display_bg_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_focus")), "Color"));
123         strcpy(globals.wav_display_bg_no_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_no_focus")), "Color"));
124         strcpy(globals.wav_display_fg_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_focus")), "Color"));
125         strcpy(globals.wav_display_fg_no_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_no_focus")), "Color"));
126         strcpy(globals.wav_display_cursor, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor")), "Color"));
127         strcpy(globals.wav_display_cursor_mute, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor_mute")), "Color"));
128
129         /* VU Colors */ 
130         strcpy(globals.vu_meter_bg, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_bg")), "Color"));
131         strcpy(globals.vu_meter_loud, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_loud")), "Color"));
132         strcpy(globals.vu_meter_normal, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_normal")), "Color"));
133
134         globals.vu_meter_border_intensity=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")));
135         
136         /* Misc */
137         strcpy(globals.file_editor, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor"))));
138         strcpy(globals.lrdf_path, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path"))));
139         globals.compress_set_files=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files")))==TRUE);        
140         globals.prelis=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled")))==TRUE);
141         globals.restore_midi_connections=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled")))==TRUE);
142         
143         /* update colors */
144         std::list<vtt_class *>::iterator vtt;
145         
146         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
147                 gtk_tx_update_colors(GTK_TX((*vtt)->gui.display));
148                 gtk_widget_queue_draw((*vtt)->gui.display);
149                 gtk_tx_flash_update_colors(GTK_TX_FLASH((*vtt)->gui.flash));
150                 gtk_widget_queue_draw((*vtt)->gui.flash);
151         }
152         
153         gtk_tx_flash_update_colors(GTK_TX_FLASH(main_flash_l));
154         gtk_widget_queue_draw(main_flash_l);
155         gtk_tx_flash_update_colors(GTK_TX_FLASH(main_flash_r));
156         gtk_widget_queue_draw(main_flash_r);
157         
158 #ifdef USE_JACK
159         jack_check();
160 #endif  
161 }
162
163
164 #define WID_DYN TRUE, TRUE, 0
165 #define WID_FIX FALSE, FALSE, 0
166
167 #define my_new_subsec(s); \
168         separator=gtk_hseparator_new(); \
169         gtk_box_pack_start(GTK_BOX(vbox), separator, WID_DYN);\
170         gtk_widget_show(separator); \
171         label=gtk_label_new(s); \
172         gtk_misc_set_alignment (GTK_MISC(label), 0 ,0.5); \
173         gtk_box_pack_start(GTK_BOX(vbox), label, WID_DYN); \
174         gtk_widget_show(label); 
175
176 #define my_new_button(btn, s); \
177         btn=gtk_button_new_with_label(s); \
178         gtk_box_pack_start(GTK_BOX(aa), btn, WID_DYN); \
179         gtk_widget_show(btn);
180         
181
182 #define begin_box(); box=gtk_hbox_new(FALSE, 5);
183
184 #define begin_hom_box(); box=gtk_hbox_new(TRUE, 5);
185
186 #define end_box(); gtk_box_pack_start(GTK_BOX(vbox), box, WID_DYN); \
187         gtk_widget_show(box);
188
189 #define add_widget_dyn(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN);\
190         gtk_widget_show(wid);
191         
192 #define add_widget_fix(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX);\
193         gtk_widget_show(wid);
194
195 #define add_expl(s); label=gtk_label_new(s); \
196         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);\
197         add_widget_fix(label);
198
199 #define add_expl_dyn(s); label=gtk_label_new(s); \
200         gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);\
201         add_widget_dyn(label);
202
203 #ifdef USE_ALSA
204 static GList *alsa_devices=NULL;
205
206 GList *get_alsa_device_list() {
207         if (alsa_devices) {
208                 return alsa_devices;
209         }
210         
211         FILE *file;
212         char buffer[PATH_MAX+1];
213         alsa_devices=NULL;
214         
215         if ((file = fopen("/proc/asound/pcm", "r"))) {
216                 while(fgets(buffer, PATH_MAX, file)) {
217                         buffer[PATH_MAX]=0;
218                         if (strlen(buffer)) buffer[strlen(buffer)-1]=0;
219                         if(strstr(buffer, "playback")) {
220                                 char foo[PATH_MAX];
221                                 char tmp[PATH_MAX];
222                                 memset(foo, 0, PATH_MAX);
223                                 int card;
224                                 int device;
225  
226                                 sscanf(buffer, "%i-%i: %1024c", &card, &device, foo);
227                                 sprintf(tmp, "hw:%i,%i# %s", card, device, foo);
228                                 
229                                 alsa_devices=g_list_append (alsa_devices, strdup(tmp));
230                         }
231                 }
232                 fclose(file);
233         }
234         
235         return alsa_devices;
236 }
237 #else
238 GList *get_alsa_device_list() {
239         return NULL;
240 }
241 #endif
242
243
244 #ifdef USE_OSS
245 static GList *oss_devices=NULL;
246
247 int oss_select_dsp_only(const struct dirent *entry){
248         return (strstr(entry->d_name, "dsp")!=0);
249 }
250
251 GList *get_oss_device_list() {
252         if (oss_devices) {
253                 return oss_devices;
254         }
255                 
256     struct dirent **namelist;
257     int n,i;
258     n = scandir("/dev", &namelist, oss_select_dsp_only, alphasort);
259     
260         oss_devices=NULL;
261         
262     if (n>0) {
263         for (i=0; i<n; i++) {
264                         char buffer[256];
265             sprintf(buffer, "/dev/%s", namelist[i]->d_name);
266             free(namelist[i]);
267                         oss_devices=g_list_append (oss_devices, strdup(buffer));
268                 }
269         }
270         
271         return oss_devices;
272 }
273 #endif
274
275 static GList *sampling_rates=NULL;
276
277 GList *get_sampling_rates_list() {
278         if (sampling_rates) {
279                 return sampling_rates;
280         }
281
282         sampling_rates=g_list_append(sampling_rates, (void *) "22000");
283         sampling_rates=g_list_append(sampling_rates, (void *) "32000");
284         sampling_rates=g_list_append(sampling_rates, (void *) "44100");
285         sampling_rates=g_list_append(sampling_rates, (void *) "48000");
286
287         return sampling_rates;  
288 }
289
290 static GList *xinput_devices=NULL;
291
292 GList *get_xinput_devices_list() {
293         if (xinput_devices) {
294                 return xinput_devices;
295         }
296         
297         int devmax;
298         Display *dpy=XOpenDisplay(NULL);
299         XDeviceInfo *xdev=XListInputDevices(dpy, &devmax);
300         XCloseDisplay(dpy);
301
302         for (int i=0; i<devmax; i++) {
303                 xinput_devices=g_list_append(xinput_devices, strdup(xdev[i].name));
304         }
305         
306         XFreeDeviceList(xdev);
307         
308         return xinput_devices;
309 }
310
311 #define MAX_COLORS 10
312 char *colors[MAX_COLORS]={ NULL };
313
314 #define set_color_button(s,g); \
315         sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", s, s);\
316         gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(lookup_widget(dialog, g)))->data), tmp);\
317         strcpy(colors[ctr], s);\
318         g_object_set_data(G_OBJECT(lookup_widget(dialog, g)), "Color", colors[ctr]);\
319         ctr++;
320
321
322 void init_tx_options(GtkWidget *dialog) {
323         GtkTooltips *tooltips=GTK_TOOLTIPS(lookup_widget(dialog, "tooltips"));
324         
325         if (colors[0]==NULL) {
326                 for (int i=0; i<MAX_COLORS; i++) {
327                         colors[i]=new char[8];
328                         colors[i][0]=0;
329                 }
330         }
331         
332         /* Audio */
333         switch (globals.audiodevice_type) {             
334                 case ALSA: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")), 1);
335                         break;
336                 
337                 case JACK: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")), 1);
338                         break;
339
340                 case OSS: 
341                 default:
342                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")), 1);
343                         break;
344         }
345         
346 #ifndef USE_OSS
347         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_driver"), 0);
348         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_audio_device"), 0);
349         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffers"), 0);
350         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffersize"), 0);
351 #endif
352         
353 #ifndef USE_ALSA
354         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_driver"), 0);      
355         // TODO: Rest!  
356 #endif
357         
358 #ifndef USE_JACK
359         gtk_widget_set_sensitive(lookup_widget(dialog, "jack_driver"), 0);
360 #endif  
361         
362         /* Audio: OSS */
363         GList *oss_list=get_oss_device_list();
364         if (oss_list) {
365                 gtk_combo_set_popdown_strings(GTK_COMBO(lookup_widget(dialog, "oss_audio_device")), oss_list);
366         }
367         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "oss_audio_device"))->entry), globals.oss_device);
368
369         gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")), globals.oss_buff_no);
370         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")), globals.oss_buff_size);
371         gtk_tooltips_set_tip(tooltips, 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.", NULL);        
372         gtk_combo_set_popdown_strings(GTK_COMBO(lookup_widget(dialog, "oss_samplerate")), get_sampling_rates_list());
373         char tmp[64];
374         sprintf(tmp, "%i", globals.oss_samplerate);
375         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "oss_samplerate"))->entry), tmp);
376         
377         
378         /* Audio: ALSA */
379         GtkCombo *combo=GTK_COMBO(lookup_widget(dialog, "alsa_audio_device"));
380         GList *alsa_list=get_alsa_device_list();
381         last_alsa_device_widget=NULL;
382         alsa_device_entry=combo->entry;
383         
384         if (alsa_list) {
385                 gtk_combo_set_popdown_strings(combo, get_alsa_device_list());
386         }
387         gtk_entry_set_text(GTK_ENTRY(combo->entry), globals.alsa_device_id);
388
389         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")), globals.alsa_buffer_time/1000);
390         gtk_tooltips_set_tip(tooltips, 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.", NULL);       
391         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")), globals.alsa_period_time/1000);
392         gtk_tooltips_set_tip(tooltips, 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.", NULL);        
393
394         gtk_combo_set_popdown_strings(GTK_COMBO(lookup_widget(dialog, "alsa_samplerate")), get_sampling_rates_list());
395         sprintf(tmp, "%i", globals.alsa_samplerate);
396         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "alsa_samplerate"))->entry), tmp);
397         
398         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")), globals.alsa_free_hwstats);
399         
400         /* Input */
401         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "xinput_enable")), globals.xinput_enable);
402         
403         gtk_combo_set_popdown_strings(GTK_COMBO(lookup_widget(dialog, "xinput_device")), get_xinput_devices_list());
404         gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(lookup_widget(dialog, "xinput_device"))->entry), globals.xinput_device);
405
406         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")), globals.mouse_speed);
407         gtk_tooltips_set_tip(tooltips, lookup_widget(dialog, "mouse_speed"), "The speed of your mouse in scratch mode. Use negative values to invert motion.", NULL);
408         
409         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")), globals.sense_cycles);
410         gtk_tooltips_set_tip(tooltips, 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", NULL);        
411
412         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")), globals.vtt_inertia);
413         gtk_tooltips_set_tip(tooltips, 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.", NULL);       
414
415         gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")), globals.filename_length);
416
417         /* User Interface */ 
418         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox")), globals.show_nag);
419         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips")), globals.tooltips);
420         
421         switch (globals.button_type) {
422                 case BUTTON_TYPE_TEXT:
423                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")), 1);
424                         break;
425                 
426                 case BUTTON_TYPE_ICON:
427                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")), 1);
428                         break;
429                 
430                 case BUTTON_TYPE_BOTH:
431                 default:
432                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")), 1);
433         }
434         
435         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_delay")), globals.update_delay);
436         gtk_tooltips_set_tip(tooltips, lookup_widget(dialog, "update_delay"), "How often to update the slow widgets.", NULL);   
437         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_idle")), globals.update_idle);
438         gtk_tooltips_set_tip(tooltips, 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 increase this value - if you have performance problems reduce this value.", NULL);       
439         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")), globals.flash_response);
440         gtk_tooltips_set_tip(tooltips, lookup_widget(dialog, "vumeter_decay"), "Defines how fast the maximum values of the VU meters should be decayed.", NULL);        
441
442         /* Audio Colors */
443         int ctr=0;
444         
445         set_color_button(globals.wav_display_bg_focus, "wav_display_bg_focus");
446         set_color_button(globals.wav_display_bg_no_focus, "wav_display_bg_no_focus");
447         set_color_button(globals.wav_display_fg_focus, "wav_display_fg_focus");
448         set_color_button(globals.wav_display_fg_no_focus, "wav_display_fg_no_focus");
449         set_color_button(globals.wav_display_cursor, "wav_display_cursor");
450         set_color_button(globals.wav_display_cursor_mute, "wav_display_cursor_mute");
451         
452         /* VU Colors */
453         set_color_button(globals.vu_meter_bg, "vu_meter_bg");
454         set_color_button(globals.vu_meter_loud, "vu_meter_loud");
455         set_color_button(globals.vu_meter_normal, "vu_meter_normal");
456         
457         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")), globals.vu_meter_border_intensity);
458         
459         /* Misc */
460         gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor")), globals.file_editor);
461         gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path")), globals.lrdf_path);
462         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files")), globals.compress_set_files);
463         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled")), globals.prelis);
464         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled")), globals.restore_midi_connections);
465 }
466
467 void create_options()
468 {
469         opt_dialog=create_tx_options();
470         //gtk_widget_hide(lookup_widget(opt_dialog, "jack_driver"));    
471         init_tx_options(opt_dialog);
472         gtk_widget_show(opt_dialog);
473 }
474
475 void display_options()
476 {
477         if (opt_dialog) {
478                 gdk_window_raise(opt_dialog->window);   
479         } else {
480                 create_options();
481         }
482 }
483
484 GtkWidget *about=NULL;
485
486 void raise_about()
487 {
488         if (about) gdk_window_raise(about->window);
489 }
490
491
492 void destroy_about()
493 {
494         if (about) {    
495                 gtk_widget_destroy(about);
496                 about=NULL;
497         }
498 }
499
500 #define add_about_wid(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN); \
501         gtk_widget_show(wid);
502
503 #define add_about_wid_fix(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX); \
504         gtk_widget_show(wid);
505
506 GdkFont *GPL_font=NULL;
507
508 void show_about(int nag)
509 {
510         GtkWidget *window, *pwid;
511         GdkBitmap *mask;
512         GtkStyle *style;
513         GtkWidget *btn;
514         GtkWidget *box;
515         GtkWidget *hbox;
516         GtkWidget *label;
517         GtkWidget *sep;
518         GtkWidget *text;
519         GtkWidget *scroll;
520         GdkPixmap *pmap=NULL;
521         
522         /* Only raise the window if it's already open... */
523         if (about)  {
524                 gdk_window_raise(about->window);
525                 return;
526         }
527         
528         /* Create the window... */
529         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
530         gtk_container_set_border_width(GTK_CONTAINER(window), 5);
531         gtk_window_set_title(GTK_WINDOW (window), "terminatorX - About");
532         gtk_window_set_position(GTK_WINDOW (window), GTK_WIN_POS_CENTER);
533         gtk_window_set_modal(GTK_WINDOW (window), TRUE);
534         gtk_window_set_policy(GTK_WINDOW (window), TRUE, TRUE, FALSE);  
535         
536         /*
537         gtk_window_set_wmclass(GTK_WINDOW(window), "terminatorX", "tX_about");
538         g_object_set (G_OBJECT (window), "type", GTK_WINDOW_TOPLEVEL, NULL);
539         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
540         gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
541         gtk_window_set_title(GTK_WINDOW(window), "terminatorX - About");
542         gtk_window_set_decorated(GTK_WINDOW(window), nag ? TRUE : FALSE);
543         */
544         
545         GdkPixbuf *image=gdk_pixbuf_new_from_xpm_data((const char **)logo_xpm);
546         gdk_pixbuf_render_pixmap_and_mask(image, &pmap, &mask, 0);
547         
548         pwid = gtk_pixmap_new( pmap, mask );
549         
550         if (nag) {
551                 GtkWidget *box=gtk_vbox_new(FALSE, 2);
552                 GtkWidget *box2=gtk_hbox_new(FALSE, 2);
553                 GtkWidget *label;
554                 
555                 gtk_container_add(GTK_CONTAINER(window), box);
556                 gtk_box_pack_start(GTK_BOX(box), pwid, WID_FIX);
557                 gtk_box_pack_start(GTK_BOX(box), box2, WID_FIX);
558                 
559                 label=gtk_label_new(PACKAGE" release "VERSION);
560                 gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
561                 gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
562                 gtk_widget_show(label);
563
564                 label=gtk_label_new("Copyright (C) 1999-2003 by Alexander K\xC3\xB6nig");
565                 gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
566                 gtk_misc_set_alignment(GTK_MISC(label), 0.9, 0.5);
567                 gtk_widget_show(label);
568                 
569                 gtk_widget_show(box2);
570                 gtk_widget_show(box);
571                 gtk_widget_show(pwid);
572
573                 gtk_window_set_decorated(GTK_WINDOW(window), FALSE);            
574                 gtk_widget_show(window);
575         } else {
576                 box=gtk_vbox_new(FALSE, 5);
577                 add_about_wid_fix(pwid);
578                 
579                 sep=gtk_hseparator_new();
580                 add_about_wid_fix(sep);
581                 char about_prefix_umlaut[]="\nThis is "PACKAGE" Release "VERSION" - Copyright (C) 1999-2003 by Alexander K\xC3\xB6nig";
582                 char about_rest[]="\n\nSend comments, patches and scratches to: alex@lisas.de\n"
583                 "terminatorX-homepage: http://www.terminatorX.cx\n\nThis binary has been compiled with the following flags: "
584                 "Sox support: "
585 #ifdef USE_SOX_INPUT
586                 "ON"
587 #else
588                 "OFF"
589 #endif          
590                 " - mpg123 support: "
591 #ifdef USE_MPG123_INPUT
592                 "ON"
593 #else
594                 "OFF"
595 #endif
596                 " - \nogg123 support: "
597 #ifdef USE_OGG123_INPUT
598                 "ON"
599 #else
600                 "OFF"
601 #endif
602
603                 " - enhanced scheduling: "
604 #ifdef USE_SCHEDULER
605                 "ON"
606 #else
607                 "OFF"
608 #endif
609                 " - for a "
610 #ifdef WORDS_BIGENDIAN
611                 "big"
612                 
613 #else
614                 "little"
615 #endif
616                 " endian machine.\n";
617                 
618                 char buffer[4096];
619                 
620                 strcpy(buffer, about_prefix_umlaut);
621                 strcat(buffer, about_rest);
622                 
623                 label=gtk_label_new(buffer);
624
625                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
626                 add_about_wid_fix(label);
627                 
628                 sep=gtk_hseparator_new();
629                 add_about_wid_fix(sep);
630
631                 label=gtk_label_new("License (GPL V2):");
632                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
633                 add_about_wid_fix(label);
634
635                 hbox=gtk_hbox_new(FALSE, 5);            
636
637                 GtkTextIter iter;
638                 GtkTextBuffer *tbuffer;
639
640                 text=gtk_text_view_new();
641                 tbuffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
642                 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
643                 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), false);
644                 gtk_text_buffer_get_iter_at_offset (tbuffer, &iter, 0);
645                 
646                 scroll=gtk_scrolled_window_new (NULL, NULL);
647         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
648                 gtk_container_add (GTK_CONTAINER (scroll), text);
649                 gtk_text_buffer_create_tag (tbuffer, "courier", "family", "courier", NULL);
650                 
651                 gtk_text_buffer_insert_with_tags_by_name(tbuffer, &iter, license, -1, "courier", NULL);
652                 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
653                 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 5);
654                 gtk_widget_set_usize(GTK_WIDGET(text), 640, 180);
655                 gtk_widget_show(text);          
656                 
657                 gtk_box_pack_start(GTK_BOX(hbox), scroll, WID_DYN);
658                 gtk_widget_show(scroll);                
659                 
660                 add_about_wid(hbox);
661
662                 sep=gtk_hseparator_new();
663                 add_about_wid_fix(sep);
664
665                 btn=gtk_button_new_with_label("Close");
666                 add_about_wid_fix(btn);
667
668                 gtk_container_add(GTK_CONTAINER(window), box);
669                 gtk_widget_show(box);
670                 
671                 gtk_signal_connect(GTK_OBJECT(btn), "clicked", (GtkSignalFunc) destroy_about, NULL);            
672                 gtk_signal_connect(GTK_OBJECT(window), "delete-event", (GtkSignalFunc) destroy_about, NULL);            
673         }
674         gtk_widget_show(window);        
675         tX_set_icon(window, "tX About");
676         
677         while (gtk_events_pending()) gtk_main_iteration();
678                 
679         about=window;
680 }
681
682 GdkPixbuf *tX_window_icon=NULL;
683
684 void tX_set_icon(GtkWidget *widget, char *name)
685 {       
686         if (!tX_window_icon) {
687                 tX_window_icon=gdk_pixbuf_new_from_inline(-1, tX_icon, FALSE, NULL);
688         }
689
690         gtk_window_set_icon(GTK_WINDOW(widget), tX_window_icon);
691         gdk_window_set_icon_name(widget->window, name); 
692 }