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