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