It's 2020...
[terminatorX.git] / src / tX_dialog.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2020  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 int oss_select_dsp_only(const struct dirent *entry){
253         return (strstr(entry->d_name, "dsp")!=0);
254 }
255
256 void append_oss_device_list(GtkComboBoxText *combo, char *current) {
257     struct dirent **namelist;
258     int n,i;
259     n = scandir("/dev", &namelist, oss_select_dsp_only, alphasort);
260     
261     if (n>0) {
262         for (i=0; i<n; i++) {
263                         char buffer[256];
264             sprintf(buffer, "/dev/%s", namelist[i]->d_name);
265             free(namelist[i]);
266             gtk_combo_box_text_append_text(combo, strdup(buffer));
267             
268             if (strcmp(buffer, current)==0) {
269                                 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), i);
270                         }
271                 }
272         }
273 }
274
275
276 void append_sampling_rates_list(GtkComboBoxText *combo, int current) {
277
278         gtk_combo_box_text_append_text(combo,  "22000");
279         gtk_combo_box_text_append_text(combo,  "32000");
280         gtk_combo_box_text_append_text(combo,  "44100");
281         gtk_combo_box_text_append_text(combo,  "48000");
282         switch (current) {
283                 case 22000:
284                         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
285                         break;
286                 case 32000:
287                         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 1);
288                         break;
289                 case 44100:
290                         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 2);
291                         break;
292                 case 48000:
293                 default:
294                         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 3);
295         }
296 }
297
298 #define MAX_COLORS 10
299 char *colors[MAX_COLORS]={ NULL };
300
301 #define set_color_button(s,g); \
302         sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", s, s);\
303         gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(lookup_widget(dialog, g)))->data), tmp);\
304         strcpy(colors[ctr], s);\
305         g_object_set_data(G_OBJECT(lookup_widget(dialog, g)), "Color", colors[ctr]);\
306         ctr++;
307
308
309 void init_tx_options(GtkWidget *dialog) {
310         char tmp[256];
311         
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 PULSE: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "pulse_driver")), 1);
328                         break;
329
330                 case OSS: 
331                 default:
332                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")), 1);
333                         break;
334         }
335
336         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "use_realtime")), globals.use_realtime);
337
338 #ifndef USE_CAPABILITIES
339         /* rt's not configurable without capabilities. */
340         gtk_widget_hide(lookup_widget(dialog, "use_realtime"));
341         gtk_widget_hide(lookup_widget(dialog, "use_realtime_label"));   
342 #endif
343         
344 #ifndef USE_OSS
345         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_driver"), 0);
346         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_audio_device"), 0);
347         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffers"), 0);
348         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffersize"), 0);
349         gtk_widget_set_sensitive(lookup_widget(dialog, "oss_samplerate"), 0);
350 #endif
351         
352 #ifndef USE_ALSA
353         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_driver"), 0);      
354         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_audio_device"), 0);
355         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_samplerate"), 0);
356         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_period_time"), 0);
357         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_buffer_time"), 0);
358         gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_free_hwstats"), 0);
359 #endif
360         
361 #ifndef USE_JACK
362         gtk_widget_set_sensitive(lookup_widget(dialog, "jack_driver"), 0);
363 #endif  
364
365 #ifndef USE_PULSE
366         gtk_widget_set_sensitive(lookup_widget(dialog, "pulse_driver"), 0);
367         gtk_widget_set_sensitive(lookup_widget(dialog, "pulse_buffer_size"), 0);
368 #endif
369         
370         /* Audio: OSS */
371         append_oss_device_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_audio_device")), globals.oss_device);
372
373         gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")), globals.oss_buff_no);
374         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")), globals.oss_buff_size);
375         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."); 
376         append_sampling_rates_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_samplerate")), globals.oss_samplerate);
377         
378         /* Audio: ALSA */
379         GtkComboBoxText *combo=GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_audio_device"));
380         last_alsa_device_widget=NULL;
381         
382         append_alsa_device_list(GTK_COMBO_BOX_TEXT(combo), globals.alsa_device_id);
383
384         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")), globals.alsa_buffer_time/1000);
385         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.");        
386         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")), globals.alsa_period_time/1000);
387         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."); 
388
389         append_sampling_rates_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_samplerate")), globals.alsa_samplerate);
390         
391         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")), globals.alsa_free_hwstats);
392         
393         gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "pulse_buffer_size")), globals.pulse_buffer_length);
394         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.");  
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
433         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "override_knob_size")), globals.knob_size_override > 0);
434         if (globals.knob_size_override) {
435                 gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "knob_size")), globals.knob_size_override);
436         } else {
437                 gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "knob_size")), 48);
438         }
439         
440         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_display_history")), globals.wav_display_history);
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         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "quit_confirm")), globals.quit_confirm);
466         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "force_nonrt_plugins")), globals.force_nonrt_plugins);     
467         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "verbose_plugin_loading")), globals.verbose_plugin_loading);       
468 }
469
470 void create_options()
471 {
472         opt_dialog=create_tx_options(GTK_WINDOW(main_window));
473         tX_set_icon(opt_dialog);
474         init_tx_options(opt_dialog);
475         gtk_widget_show(opt_dialog);
476 }
477
478 void display_options()
479 {
480         if (opt_dialog) {
481                 gdk_window_raise(gtk_widget_get_window(opt_dialog));    
482         } else {
483                 create_options();
484         }
485 }
486
487 GtkWidget *about=NULL;
488
489 void raise_about()
490 {
491         if (about) gdk_window_raise(gtk_widget_get_window(about));
492 }
493
494
495 void destroy_about()
496 {
497         if (about) {    
498                 gtk_widget_destroy(about);
499                 about=NULL;
500         }
501 }
502
503 #define add_about_wid(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN); \
504         gtk_widget_show(wid);
505
506 #define add_about_wid_fix(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX); \
507         gtk_widget_show(wid);
508
509 void show_about(int nag)
510 {
511         GtkWidget *window;
512         GtkWidget *btn;
513         GtkWidget *box;
514         GtkWidget *label;
515         GtkWidget *sep;
516         GtkWidget *text;
517         GtkWidget *scroll;
518         GtkWidget *iwid;
519         GtkWidget *expander;
520         
521         /* Only raise the window if it's already open... */
522         if (about)  {
523                 gdk_window_raise(gtk_widget_get_window(about));
524                 return;
525         }
526         
527         /* Create the window... */
528         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
529         gtk_container_set_border_width(GTK_CONTAINER(window), 5);
530         gtk_window_set_title(GTK_WINDOW(window), "terminatorX - About");
531         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
532         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
533         gtk_window_set_resizable(GTK_WINDOW(window), nag ? TRUE: FALSE);
534
535         GdkPixbuf *image=gdk_pixbuf_new_from_xpm_data((const char **)logo_xpm);
536         iwid = gtk_image_new_from_pixbuf(image);
537         
538         if (nag) {
539                 GtkWidget *box=gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
540                 GtkWidget *box2=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
541                 GtkWidget *label;
542                 
543                 gtk_container_add(GTK_CONTAINER(window), box);
544                 gtk_box_pack_start(GTK_BOX(box), iwid, WID_FIX);
545                 gtk_box_pack_start(GTK_BOX(box), box2, WID_FIX);
546                 
547                 label=gtk_label_new(PACKAGE " release " VERSION);
548                 gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
549                 gtk_widget_set_halign(label, GTK_ALIGN_START);
550                 gtk_widget_show(label);
551
552                 label=gtk_label_new("Copyright (C) 1999-2020 by Alexander König");
553                 gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
554                 gtk_widget_set_halign(label, GTK_ALIGN_END);
555                 gtk_widget_show(label);
556                 
557                 gtk_widget_show(box2);
558                 gtk_widget_show(box);
559                 gtk_widget_show(iwid);
560
561                 gtk_window_set_decorated(GTK_WINDOW(window), FALSE);            
562                 gtk_widget_show(window);
563         } else {
564                 box=gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
565                 add_about_wid_fix(iwid);
566                 
567                 sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
568                 add_about_wid_fix(sep);
569                 
570                 label=gtk_label_new("This is " PACKAGE " release " VERSION ".\nCopyright (C) 1999-2020 by Alexander König <alex@lisas.de>");
571
572                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
573                 add_about_wid_fix(label);
574
575                 sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
576                 add_about_wid_fix(sep);
577
578                 expander = gtk_expander_new("Build info");
579                 GtkWidget *exbox=gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
580                 gtk_container_add(GTK_CONTAINER(expander), exbox);
581                 gtk_widget_show(exbox);
582
583                 label=gtk_label_new("Compilation flags: "
584 #ifdef USE_SOX_INPUT
585                 " [sox]"
586 #endif
587 #ifdef USE_MPG123_INPUT
588                 " [mpg123]"
589 #endif
590 #ifdef USE_OGG123_INPUT
591                 " [ogg123]"
592 #endif
593 #ifdef USE_MAD_INPUT
594                 " [mad]"
595 #endif
596 #ifdef USE_VORBIS_INPUT
597                 " [vorbis]"
598 #endif
599 #ifdef USE_AUDIOFILE_INPUT
600                 " [audiofile]"
601 #endif
602                 "\n"
603 #ifdef USE_ALSA_MIDI_IN
604                 " [midi]"
605 #endif
606 #ifdef USE_OSS
607                 " [oss]"
608 #endif
609 #ifdef USE_ALSA
610                 " [alsa]"
611 #endif
612 #ifdef USE_JACK
613                 " [jack]"
614 #endif
615 #ifdef USE_PULSE
616                 " [pulse]"
617 #endif
618 #ifdef USE_LRDF
619                 " [lrdf]"
620 #endif
621 #ifdef USE_SCHEDULER
622                 " [rt]"
623 #endif
624 #ifdef USE_CAPABILITIES
625                 " [cap]"
626 #endif
627                 "");
628         
629                 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
630                 gtk_widget_set_size_request(label, 640, -1);
631                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
632                 gtk_container_add(GTK_CONTAINER(exbox), label);
633                 gtk_widget_show(label);
634                 add_about_wid_fix(expander);
635
636 #ifdef  USE_SCHEDULER
637                 sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
638                 gtk_widget_show(sep);
639                 gtk_container_add(GTK_CONTAINER(exbox), sep);
640
641                 char buffer[4096];
642                 
643                 int policy=-1;
644                 struct sched_param parm;
645                 
646                 pthread_getschedparam(tX_engine::get_instance()->get_thread_id(), &policy, &parm);
647                 char prio_str[32]="";
648                 bool s_enabled = false;
649                 
650                 switch (policy) {
651                         case SCHED_OTHER:
652                                 strcpy(prio_str, "SCHED_OTHER");
653                                 break;
654                         
655                         case SCHED_RR:
656                                 strcpy(prio_str, "SCHED_RR");
657                                 break;
658                         
659                         case SCHED_FIFO:
660                                 strcpy(prio_str, "SCHED_FIFO");
661                                 s_enabled = true;
662                                 break;
663                         
664                         default:
665                                 sprintf(prio_str, "UNKNOWN (%i)", policy);
666                 }
667                 
668                 sprintf(buffer, "Audio engine scheduling policy: %s.\nScheduling with realtime priority is %s.", prio_str, s_enabled ? "enabled" : "disabled");
669
670                 label=gtk_label_new(buffer);
671
672                 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
673                 gtk_widget_show(label);
674                 gtk_container_add(GTK_CONTAINER(exbox), label);
675 #endif
676
677                 sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
678                 add_about_wid_fix(sep);
679
680                 expander = gtk_expander_new("License (GPL V2):");
681
682                 add_about_wid_fix(expander);
683
684                 GtkTextIter iter;
685                 GtkTextBuffer *tbuffer;
686
687                 text=gtk_text_view_new();
688                 tbuffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
689                 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
690                 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), false);
691                 gtk_text_buffer_get_iter_at_offset (tbuffer, &iter, 0);
692                 
693                 scroll=gtk_scrolled_window_new (NULL, NULL);
694         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
695                 gtk_container_add (GTK_CONTAINER (scroll), text);
696                 gtk_text_buffer_create_tag (tbuffer, "courier", "family", "courier", NULL);
697                 
698                 gtk_text_buffer_insert_with_tags_by_name(tbuffer, &iter, license, -1, "courier", NULL);
699                 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
700                 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 5);
701                 gtk_widget_set_size_request(GTK_WIDGET(scroll), 640, 200);
702                 gtk_widget_show(text);          
703                 
704                 gtk_container_add(GTK_CONTAINER(expander), scroll);
705                 gtk_widget_show(scroll);                
706                 
707                 sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
708                 add_about_wid_fix(sep);
709
710                 btn=gtk_button_new_with_label("Close");
711                 add_about_wid_fix(btn);
712
713                 gtk_container_add(GTK_CONTAINER(window), box);
714                 gtk_widget_show(box);
715                 
716                 g_signal_connect(G_OBJECT(btn), "clicked", (GCallback) destroy_about, NULL);            
717                 g_signal_connect(G_OBJECT(window), "delete-event", (GCallback) destroy_about, NULL);            
718         }
719         gtk_widget_show(window);        
720         tX_set_icon(window);
721         
722         while (gtk_events_pending()) gtk_main_iteration();
723                 
724         about=window;
725 }
726
727 static GdkPixbuf *tX_window_icon=NULL;
728
729 void tX_set_icon(GtkWidget *widget)
730 {       
731         if (!tX_window_icon) {
732                 GError *error = NULL;
733                 g_resource_new_from_data(g_bytes_new_static(tX_dialog_resource_data.data, sizeof(tX_dialog_resource_data.data)), &error);
734                 if (error) {
735                     tX_error("Error accesing tX_dialog resources: %s", error->message);
736                 }
737                 tX_window_icon=gdk_pixbuf_new_from_resource("/org/terminatorX/tX_dialog/../../icons/terminatorX.png", &error);
738                 if (error) {
739                     tX_error("Error rendering tX icon: %s", error->message);
740                 }
741         }
742
743         gtk_window_set_icon(GTK_WINDOW(widget), tX_window_icon);
744 }