598374490ef39e031fc20846d30a7b022553d083
[terminatorX.git] / terminatorX / src / tX_mastergui.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2002  Alexander K├Ânig
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     File: tX_mastergui.cc
20  
21     Description: This implements the main (aka master) gtk+ GUI of terminatorX
22                  It serves as a container for the vtt-guis.
23 */    
24
25 #include <gtk/gtk.h>
26 #include <gdk/gdkx.h>
27 #include <X11/Xlib.h>
28 #include <math.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include "version.h"
32 #include "tX_global.h"
33 #include "tX_engine.h"
34 #include "tX_vttgui.h"
35 #include "tX_vtt.h"
36 #include "tX_flash.h"
37 #include "tX_dialog.h"
38 #include "tX_loaddlg.h"
39 #include "tX_seqpar.h"
40 #include "tX_pbutton.h"
41 #include "tX_sequencer.h"
42 #include "tX_mastergui.h"
43 #include "tX_knobloader.h"
44
45 #ifdef USE_SCHEDULER
46 #include <sys/time.h>
47 #include <sys/resource.h>
48 #endif
49
50 #define TX_SET_ID_10 "terminatorX turntable set file - version 1.0 - data:"
51 #define TX_SET_ID_11 "terminatorX turntable set file - version 1.1 - data:"
52 #define TX_SET_ID_12 "terminatorX turntable set file - version 1.2 - data:"
53 #define TX_SET_ID_13 "terminatorX turntable set file - version 1.3 - data:"
54
55 int audioon=0;
56 int sequencer_ready=1;
57
58 GtkWidget *tt_parent;
59 GtkWidget *control_parent;
60 GtkWidget *audio_parent;
61 GtkWidget *main_window;
62 GtkWidget *wav_progress;
63 GtkWidget *grab_button;
64 GtkWidget *main_flash_l;
65 GtkWidget *main_flash_r;
66 GtkWidget *rec_btn;
67
68 GtkWidget *seq_rec_btn;
69 GtkWidget *seq_play_btn;
70 GtkWidget *seq_stop_btn;
71 GtkAdjustment *seq_adj;
72 GtkWidget *seq_slider;
73 GtkWidget *seq_entry;
74 int seq_adj_care=1;
75 int seq_stop_override=0;
76
77 GtkAdjustment *volume_adj;
78 GtkAdjustment *pitch_adj;
79
80 /* seq-pars */
81 tX_seqpar_master_volume sp_master_volume;
82 tX_seqpar_master_pitch sp_master_pitch;
83
84 GtkWidget *AddTable;
85 GtkWidget *LoadSet;
86 GtkWidget *SaveSet;
87
88 GtkWidget *engine_btn;
89
90 int rec_dont_care=0;
91 gint update_tag;
92
93 #define connect_entry(wid, func, ptr); gtk_signal_connect(GTK_OBJECT(wid), "activate", (GtkSignalFunc) func, (void *) ptr);
94 #define connect_adj(wid, func, ptr); gtk_signal_connect(GTK_OBJECT(wid), "value_changed", (GtkSignalFunc) func, (void *) ptr);
95 #define connect_button(wid, func, ptr); gtk_signal_connect(GTK_OBJECT(wid), "clicked", (GtkSignalFunc) func, (void *) ptr);
96
97 Window xwindow;
98 #define WID_DYN TRUE, TRUE, 0
99 #define WID_FIX FALSE, FALSE, 0
100 extern void add_vtt(GtkWidget *ctrl, GtkWidget *audio, char *fn);
101 extern void recreate_gui(vtt_class *vtt, GtkWidget *daddy);
102 extern void destroy_gui(vtt_class *vtt);
103 extern void gui_show_frame(vtt_class *vtt, int show);
104
105 GdkWindow *save_dialog_win=NULL;
106 GdkWindow *load_dialog_win=NULL;
107 GtkWidget *save_dialog=NULL;
108 GtkWidget *load_dialog=NULL;
109
110 GdkWindow *rec_dialog_win=NULL;
111 GtkWidget *rec_dialog=NULL;
112
113 GtkWidget *no_of_vtts=NULL;
114 GtkWidget *used_mem=NULL;
115
116 int stop_update=0;
117 int update_delay;
118
119 int mg_hide_gui=0;
120 vtt_class *old_focus=NULL;
121
122 int grab_status=0;
123 int last_grab_status=0;
124
125 void tx_note(const char *message);
126
127 GtkTooltips *gui_tooltips=NULL;
128
129 void gui_set_tooltip(GtkWidget *wid, char *tip)
130 {
131         gtk_tooltips_set_tip(gui_tooltips, wid, tip, NULL);
132 }
133
134 void turn_audio_off(void)
135 {
136         if (audioon) 
137         {
138                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0);
139                 while (gtk_events_pending()) gtk_main_iteration();              
140         }
141 }
142
143
144 gint pos_update(gpointer data)
145 {
146         f_prec temp;
147
148         if (stop_update) 
149         {               
150                 cleanup_all_vtts();
151                 tX_seqpar :: update_all_graphics();
152                 if (old_focus) gui_show_frame(old_focus, 0);
153                 old_focus=NULL;
154                 gtk_tx_flash_clear(main_flash_l);
155                 gtk_tx_flash_clear(main_flash_r);
156                 gdk_flush();    
157                 update_tag=0;
158                 return(FALSE);
159         }
160         else
161         {
162                 update_all_vtts();
163                 
164                 /*left vu meter */
165                 temp=vtt_class::mix_max_l;
166                 vtt_class::mix_max_l=0;
167                 gtk_tx_flash_set_level(main_flash_l, temp);
168
169                 /*right vu meter */
170                 temp=vtt_class::mix_max_r;
171                 vtt_class::mix_max_r=0;
172                 gtk_tx_flash_set_level(main_flash_r, temp);
173                 
174                 if (vtt_class::focused_vtt!=old_focus)
175                 {
176                         if (old_focus) gui_show_frame(old_focus, 0);
177                         old_focus=vtt_class::focused_vtt;
178                         if (old_focus) gui_show_frame(old_focus, 1);                    
179                 }
180                 if (grab_status!=last_grab_status)
181                 {
182                         last_grab_status=grab_status;
183                         if (!grab_status) 
184                         {
185                                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(grab_button), 0);
186                         }
187                 }
188                 gdk_flush();    
189                 update_delay--;
190                 
191                 if (update_delay < 0)
192                 {
193                         seq_update();
194                         tX_seqpar :: update_all_graphics();
195                         update_delay=globals.update_delay;
196                 }
197                 return(TRUE);
198         }
199 }
200
201 void mg_update_status()
202 {
203         FILE *procfs;
204         pid_t mypid;
205         char filename[PATH_MAX];
206         char buffer[256];
207         int found=0;    
208         int mem;
209         
210         mypid=getpid();
211         sprintf(filename, "/proc/%i/status", mypid);
212         procfs=fopen(filename, "r");
213         if (procfs)
214         {
215                 while((!feof(procfs)) && !found)
216                 {
217                         fgets(buffer, 256, procfs);
218                         if (strncmp("VmSize:", buffer, 7)==0)
219                         {
220                                 found=1;
221                                 sscanf(buffer, "VmSize: %i kB", &mem);
222                                 sprintf(buffer, "%i", mem);
223                                 gtk_label_set(GTK_LABEL(used_mem), buffer);
224                         }
225                 }
226         }
227         fclose(procfs); 
228         
229         sprintf(buffer, "%i", vtt_class::vtt_amount);
230         gtk_label_set(GTK_LABEL(no_of_vtts), buffer);
231 }
232
233 GtkSignalFunc new_table(GtkWidget *, char *fn)
234 {
235         int i;
236         
237         turn_audio_off();
238                 
239                 if (fn) 
240                 {
241                         ld_create_loaddlg(TX_LOADDLG_MODE_SINGLE, 1);
242                         ld_set_filename(fn);
243                 }
244                 
245                 add_vtt(control_parent, audio_parent, fn);                              
246                 
247                 if (fn) ld_destroy();           
248         mg_update_status();
249         return NULL;
250 }
251
252 GtkSignalFunc drop_new_table(GtkWidget *widget, GdkDragContext *context,
253                 gint x, gint y, GtkSelectionData *selection_data,
254                 guint info, guint time, vtt_class *vtt)
255 {
256         char filename[PATH_MAX];
257         char *fn;
258         int s;
259         void *prr;
260         
261         strncpy(filename, (char *) selection_data->data, (size_t) selection_data->length);
262         filename[selection_data->length]=0;
263
264         fn = strchr (filename, '\r');
265         *fn=0;  
266         
267         fn = strchr (filename, ':');
268         if (fn) fn++; else fn=(char *) selection_data->data;
269         
270         new_table(NULL, fn);
271
272         strcpy (filename, "dont segfault workaround ;)");
273         return NULL;
274 }
275
276
277 /* Loading saved setups */
278
279 GtkSignalFunc cancel_load_tables(GtkWidget *wid)
280 {
281         gtk_widget_destroy(load_dialog);
282         load_dialog=NULL;
283         load_dialog_win=NULL;
284         return(0);
285 }
286
287 void load_tt_part(char * buffer)
288 {
289         FILE *in;
290         char idbuff[256];
291         char wbuf[PATH_MAX];
292
293         turn_audio_off();
294         
295         strcpy(globals.tables_filename, buffer);
296
297         in=fopen(buffer, "r");  
298         
299         if (in)
300         {
301                 fread(idbuff, strlen(TX_SET_ID_10), 1, in);
302                 if (strncmp(idbuff, TX_SET_ID_10, strlen(TX_SET_ID_10))==0)
303                 {
304                         if (vtt_class::load_all_10(in, buffer)) tx_note("Error while reading set.");
305                 }
306                 else if (strncmp(idbuff, TX_SET_ID_11, strlen(TX_SET_ID_11))==0)
307                 {
308                         if (vtt_class::load_all_11(in, buffer)) tx_note("Error while reading set.");                    
309                 }
310                 else if (strncmp(idbuff, TX_SET_ID_12, strlen(TX_SET_ID_12))==0)
311                 {
312                         if (vtt_class::load_all_12(in, buffer)) tx_note("Error while reading set.");                    
313                 }
314                 else if (strncmp(idbuff, TX_SET_ID_13, strlen(TX_SET_ID_13))==0)
315                 {
316                         if (vtt_class::load_all_13(in, buffer)) tx_note("Error while reading set.");                    
317                 }
318                 else
319                 {
320                         tx_note("Sorry, this file is not a terminatorX set-file.");
321                         fclose(in);
322                         return;
323                 }
324                 fclose(in);
325                 
326                 tX_seqpar :: init_all_graphics();
327                 vg_init_all_non_seqpars();
328                 
329                 gtk_adjustment_set_value(volume_adj, 2.0-globals.volume);
330                 gtk_adjustment_set_value(pitch_adj, globals.pitch);
331                 sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
332                 gtk_window_set_title(GTK_WINDOW(main_window), wbuf);            
333         }
334         else
335         {
336                 strcpy(idbuff, "Failed to access file: \"");    // I'm stealing the unrelated sting for a temp :)
337                 strcat(idbuff, globals.tables_filename);
338                 strcat(idbuff, "\"");
339                 tx_note(idbuff);
340         }
341 }
342
343 void do_load_tables(GtkWidget *wid)
344 {
345         char buffer[PATH_MAX];
346         
347         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(load_dialog)));
348         
349         gtk_widget_destroy(load_dialog);
350         
351         load_dialog=NULL;
352         load_dialog_win=NULL;
353
354         load_tt_part(buffer);   
355 }
356
357 GtkSignalFunc load_tables()
358 {
359         if (load_dialog_win) 
360         {
361                 gdk_window_raise(load_dialog_win);
362                 return 0;
363         }
364         
365         load_dialog=gtk_file_selection_new("Load Set"); 
366         
367         gtk_file_selection_show_fileop_buttons(GTK_FILE_SELECTION(load_dialog));
368         gtk_file_selection_complete(GTK_FILE_SELECTION(load_dialog), "*.tX");
369         
370         if (strlen(globals.tables_filename))
371         {
372                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(load_dialog), globals.tables_filename);
373         }
374         
375         gtk_widget_show(load_dialog);
376         
377         load_dialog_win=load_dialog->window;
378         
379         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(load_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_load_tables), NULL);
380         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(load_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_load_tables), NULL); 
381         gtk_signal_connect (GTK_OBJECT(load_dialog), "delete-event", GTK_SIGNAL_FUNC(cancel_load_tables), NULL);        
382 }
383
384 GtkSignalFunc drop_set(GtkWidget *widget, GdkDragContext *context,
385                 gint x, gint y, GtkSelectionData *selection_data,
386                 guint info, guint time, vtt_class *vtt)
387 {
388         char filename[PATH_MAX];
389         char *fn;
390         int s;
391         void *prr;
392         
393         strncpy(filename, (char *) selection_data->data, (size_t) selection_data->length);
394         filename[selection_data->length]=0;
395
396         fn = strchr (filename, '\r');
397         *fn=0;  
398         
399         fn = strchr (filename, ':');
400         if (fn) fn++; else fn=(char *) selection_data->data;
401         
402         load_tt_part(fn);
403
404         strcpy (filename, "dont segfault workaround ;)");
405         return NULL;
406 }
407
408
409 /* save tables */
410
411 GtkSignalFunc cancel_save_tables(GtkWidget *wid)
412 {
413         gtk_widget_destroy(save_dialog);
414         save_dialog=NULL;
415         save_dialog_win=NULL;
416         return(0);
417 }
418
419 void do_save_tables(GtkWidget *wid)
420 {
421         FILE *out;
422         char buffer[PATH_MAX];
423         char wbuf[PATH_MAX];
424         char *ext;
425         char idbuffer[256];
426         
427         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(save_dialog)));
428         strcpy(globals.tables_filename, buffer);
429         
430         gtk_widget_destroy(save_dialog);
431         
432         save_dialog=NULL;
433         save_dialog_win=NULL;
434         
435         ext=strrchr(buffer, '.');
436         
437         if (ext)
438         {
439                 if (strcmp(ext, ".tX")) strcat(buffer, ".tX");
440         }
441         else
442         {
443                 strcat(buffer, ".tX");
444         }
445         
446         out=fopen(buffer, "w");
447         
448         if (out)
449         {
450                 strcpy(idbuffer, TX_SET_ID_13);
451                 fwrite(idbuffer, strlen(idbuffer), 1, out);
452                 if (vtt_class::save_all(out)) tx_note("Error while saving set.");
453                 fclose(out);
454                 sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
455                 gtk_window_set_title(GTK_WINDOW(main_window), wbuf);                            
456         }
457         else
458         {
459                 tx_note("Failed to access file.");
460         }
461 }
462
463 GtkSignalFunc save_tables()
464 {
465         if (save_dialog_win) 
466         {
467                 gdk_window_raise(save_dialog_win);
468                 return 0;
469         }
470         
471         save_dialog=gtk_file_selection_new("Save Set"); 
472         
473         if (strlen(globals.tables_filename))
474         {
475                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(save_dialog), globals.tables_filename);
476         }
477         
478         gtk_widget_show(save_dialog);
479         
480         save_dialog_win=save_dialog->window;
481         
482         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(save_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_save_tables), NULL);
483         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(save_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_save_tables), NULL); 
484         gtk_signal_connect (GTK_OBJECT(save_dialog), "delete-event", GTK_SIGNAL_FUNC(cancel_save_tables), NULL);        
485 }
486
487 GtkSignalFunc master_volume_changed (GtkWidget *wid, void *d)
488 {
489         sp_master_volume.receive_gui_value((float) 2.0-GTK_ADJUSTMENT(wid)->value);
490         return NULL;    
491 }
492
493 GtkSignalFunc master_pitch_changed(GtkWidget *wid, void *d)
494 {
495         sp_master_pitch.receive_gui_value((float) GTK_ADJUSTMENT(wid)->value);  
496         return NULL;    
497 }
498
499 GtkSignalFunc saturate_changed(GtkWidget *w, void *d)
500 {
501         vtt_class::enable_saturate (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)));
502         return NULL;    
503 }
504
505 void mg_enable_critical_buttons(int enable)
506 {
507         gtk_widget_set_sensitive(seq_rec_btn, enable);
508         gtk_widget_set_sensitive(seq_play_btn, enable);
509         gtk_widget_set_sensitive(seq_slider, enable);
510
511         gtk_widget_set_sensitive(rec_btn, enable);
512         vg_enable_critical_buttons(enable);
513 }
514
515
516 #ifdef USE_SCHEDULER
517 int mg_oldprio;
518 #endif
519
520 GtkSignalFunc seq_stop(GtkWidget *w, void *);
521
522 GtkSignalFunc audio_on(GtkWidget *w, void *d)
523 {
524         int res;
525         
526         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
527         {               
528                 sequencer_ready=0;
529                 mg_enable_critical_buttons(0);
530                 res=run_engine();
531                 sequencer_ready=1;
532
533                 if (res!=TX_ENG_OK)
534                 {
535                         mg_enable_critical_buttons(1);
536                         switch(res)
537                         {
538                                 case TX_ENG_ERR_BUSY:
539                                 tx_note("Error starting engine: engine is already running.");
540                                 break;
541                                 case TX_ENG_ERR_DEVICE:
542                                 tx_note("Error starting engine: failed to access audiodevice.");
543                                 break;
544                                 case TX_ENG_ERR_TAPE:
545                                 tx_note("Error starting engine: failed to open the recording file.");
546                                 break;
547                                 case TX_ENG_ERR_THREAD:
548                                 tx_note("Error starting engine: failed to create the engine thread.");
549                                 break;
550                                 default:tx_note("Error starting engine: Unknown error.");
551                         }
552                         return 0;
553                 }
554
555                 stop_update=0;
556                 audioon=1;
557                 update_delay=globals.update_delay;
558                 update_tag=gtk_timeout_add(globals.update_idle, (GtkFunction) pos_update, NULL);
559                 gtk_widget_set_sensitive(grab_button, 1);
560         }
561         else
562         {               
563                 if (!sequencer_ready) return NULL;
564                 gtk_widget_set_sensitive(grab_button, 0);
565                 stop_engine();
566                 stop_update=1;
567                 audioon=0;
568                 if ((want_recording) && (!globals.autoname))
569                 {
570                         want_recording=0;
571                         rec_dont_care=1;
572                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rec_btn), 0);
573                         rec_dont_care=0;
574                 }
575                 seq_stop(NULL, NULL);
576                 mg_enable_critical_buttons(1);
577         }
578 }
579
580 GtkSignalFunc cancel_rec(GtkWidget *wid)
581 {
582         gtk_widget_destroy(rec_dialog);
583         rec_dialog=NULL;
584         rec_dialog_win=NULL;
585         rec_dont_care=0;
586         return(0);
587 }
588
589 void do_rec(GtkWidget *wid)
590 {
591         char buffer[PATH_MAX];
592         
593         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(rec_dialog)));
594
595         if (strlen(buffer))
596         {
597                 strcpy(globals.record_filename, buffer);                
598                 want_recording=1;
599                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rec_btn), 1);
600         }
601         
602         rec_dont_care=0;
603         
604         gtk_widget_destroy(rec_dialog);
605         
606         rec_dialog=NULL;
607         rec_dialog_win=NULL;
608 }
609
610 GtkSignalFunc select_rec_file()
611 {
612         if (rec_dialog_win) 
613         {
614                 gdk_window_raise(rec_dialog_win);
615                 return 0;
616         }
617         
618         rec_dialog=gtk_file_selection_new("Record To Disk");    
619         
620         if (strlen(globals.record_filename))
621         {
622                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(rec_dialog), globals.record_filename);
623         }
624         
625         gtk_widget_show(rec_dialog);
626         
627         rec_dialog_win=rec_dialog->window;
628         
629         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(rec_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_rec), NULL);
630         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(rec_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_rec), NULL);  
631         gtk_signal_connect (GTK_OBJECT(rec_dialog), "delete-event", GTK_SIGNAL_FUNC(cancel_rec), NULL); 
632 }
633
634 GtkSignalFunc tape_on(GtkWidget *w, void *d)
635 {
636         if (rec_dont_care) return 0;
637
638         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
639         {       
640                 {
641                         rec_dont_care=1;
642                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
643                         select_rec_file();
644                 }
645         }
646         else
647         {
648                         want_recording=0;
649         }
650 }
651
652 void grab_on(GtkWidget *w, void *d)
653 {
654         grab_mouse(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)));
655         grab_status=1;
656 }
657
658 void grab_off()
659 {
660         grab_status=0;
661 }
662
663 void hide_clicked(GtkWidget *w, void *d)
664 {
665         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
666         {
667                 mg_hide_gui=1;
668         }
669         else
670         {
671                 mg_hide_gui=0;
672         }
673 }
674
675 void quit()
676 {
677         turn_audio_off();
678         if (update_tag)
679         gtk_timeout_remove(update_tag);
680         globals.width=main_window->allocation.width;
681         globals.height=main_window->allocation.height;
682
683         gtk_main_quit();
684 }
685
686 void mplcfitx()
687 /* Most Probably Least Called Function In terminatorX :) */
688 {
689         show_about(0);
690 }
691
692 GtkSignalFunc seq_play(GtkWidget *w, void *)
693 {
694         if (sequencer.is_empty()) {
695                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
696                         tx_note("Sequencer playback triggered - but no events\nrecorded yet - nothing to playback!\n\nTo perform live with terminatorX just activate the\naudio engine with the \"Power\" button.");
697                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
698                 }
699         } else {
700                 if (seq_stop_override) return NULL;
701                         
702                 seq_adj_care=0;
703                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
704                 sequencer.trig_play();
705         
706                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 1);
707         }
708 }
709
710 GtkSignalFunc seq_stop(GtkWidget *w, void *)
711 {
712         if (!sequencer_ready) return NULL;
713         sequencer.trig_stop();
714         seq_adj_care=1;
715         seq_stop_override=1;
716         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_play_btn), 0);
717         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_rec_btn), 0);
718         while (gtk_events_pending()) gtk_main_iteration();              
719         seq_stop_override=0;
720         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0); 
721         gtk_widget_set_sensitive(seq_slider, 1);        
722         gtk_widget_set_sensitive(engine_btn, 1);
723         gtk_widget_set_sensitive(seq_rec_btn, 1);
724 }
725
726 GtkSignalFunc seq_rec(GtkWidget *w, void *)
727 {
728         seq_adj_care=0;
729         gtk_widget_set_sensitive(seq_slider, 0);
730
731         if (seq_stop_override) return NULL;
732         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
733         gtk_widget_set_sensitive(engine_btn, 0);
734         gtk_widget_set_sensitive(seq_rec_btn, 0);
735         sequencer.trig_rec();
736 }
737
738 void seq_update_entry(const guint32 timestamp)
739 {
740         char buffer[20];
741         guint32 samples;
742         guint32 minu,sec,hun;   
743         
744         samples=timestamp*globals.true_block_size;
745         
746         if (samples>0)
747         {
748                 minu=samples/2646000;
749                 samples-=2646000*minu;
750         
751                 sec=samples/44100;
752                 samples-=44100*sec;
753         
754                 hun=samples/441;
755         }
756         else
757         {
758                 minu=sec=hun=0;
759         }
760         
761         sprintf(buffer, "%02li:%02li.%02li", minu, sec, hun);
762         gtk_entry_set_text(GTK_ENTRY(seq_entry), buffer);
763 }
764
765 void seq_update()
766 {
767         seq_update_entry(sequencer.get_timestamp());
768         gtk_adjustment_set_value(seq_adj, sequencer.get_timestamp_as_float());
769         
770 }
771 void seq_slider_released(GtkWidget *wid, void *d)
772 {
773         seq_adj_care=0;
774         gtk_widget_set_sensitive(seq_slider, 0);        
775         sequencer.forward_to_start_timestamp(0);
776         gtk_widget_set_sensitive(seq_slider, 1);        
777         seq_adj_care=1;
778 }
779 void sequencer_move(GtkWidget *wid, void *d)
780 {
781         guint32 pos;
782         
783         if (seq_adj_care)
784         {
785                 pos=sequencer.set_start_timestamp((float) GTK_ADJUSTMENT(wid)->value);
786                 seq_update_entry(pos);  
787         }
788 }
789
790 #define add_sep();      dummy=gtk_hseparator_new ();\
791         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);\
792         gtk_widget_show(dummy);\
793
794 #define add_sep2();     dummy=gtk_hseparator_new ();\
795         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);\
796         gtk_widget_show(dummy);\
797
798 void create_mastergui(int x, int y)
799 {
800         GtkWidget *main_vbox;
801         GtkWidget *right_hbox;
802         GtkWidget *left_hbox;
803         GtkWidget *control_box;
804         GtkWidget *sequencer_box;
805         GtkAdjustment *dumadj;
806         GtkWidget *dummy;
807         GtkWidget *small_box;
808         GtkWidget *smaller_box;
809         
810         int i;
811         static GtkTargetEntry drop_types [] = {
812                 { "text/uri-list", 0, 0}
813         };
814         static gint n_drop_types = sizeof (drop_types) / sizeof(drop_types[0]);
815         
816         gui_tooltips=gtk_tooltips_new();
817
818         main_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
819
820         gtk_window_set_wmclass(GTK_WINDOW(main_window), "terminatorX", "tX_mastergui");
821
822         gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
823         
824         gtk_container_set_border_width(GTK_CONTAINER(main_window), 5);
825
826         gtk_widget_realize(main_window);
827         
828         main_vbox=gtk_hbox_new(FALSE, 5);
829         
830         gtk_container_add(GTK_CONTAINER(main_window), main_vbox);
831         gtk_widget_show(main_vbox);
832         
833         left_hbox=gtk_vbox_new(FALSE, 5);
834         gtk_box_pack_start(GTK_BOX(main_vbox), left_hbox, WID_DYN);
835         gtk_widget_show(left_hbox);
836         
837         control_box=gtk_hbox_new(FALSE, 5);
838         gtk_box_pack_start(GTK_BOX(left_hbox), control_box, WID_FIX);
839         gtk_widget_show(control_box);
840         
841 /*      dummy=gtk_hseparator_new();
842         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
843         gtk_widget_show(dummy);*/
844
845         sequencer_box=gtk_hbox_new(FALSE, 5);
846         gtk_box_pack_start(GTK_BOX(left_hbox), sequencer_box, WID_FIX);
847         gtk_widget_show(sequencer_box);
848
849         dummy=gtk_hseparator_new();
850         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
851         gtk_widget_show(dummy);
852
853         dummy=tx_xpm_label_box(TX_ICON_AUDIOENGINE, "Audio Eng.");
854         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
855         gtk_widget_show(dummy);
856         
857         dummy=tx_xpm_button_new(TX_ICON_POWER,"Power ", 1);
858         connect_button(dummy,audio_on, NULL);
859         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
860         gui_set_tooltip(dummy, "Turn the audio engine on/off.");
861         gtk_widget_show(dummy);
862         engine_btn=dummy;
863         
864         grab_button=tx_xpm_button_new(TX_ICON_GRAB, "Mouse Grab ", 1);
865         gtk_box_pack_start(GTK_BOX(control_box), grab_button, WID_FIX);
866         connect_button(grab_button, grab_on, NULL);
867         gui_set_tooltip(grab_button, "Enter the mouse grab mode operation. Press <ESCAPE> to exit grab mode.");
868         gtk_widget_show(grab_button);
869
870         dummy=gtk_check_button_new_with_label("Record");
871         rec_btn=dummy;
872         connect_button(dummy,tape_on, NULL);
873         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
874         gui_set_tooltip(dummy, "Record the audio the terminatorX' audio engine renders. You will be prompted to enter a name for the target wav-file.");
875         gtk_widget_show(dummy);
876         
877         dummy=gtk_label_new("Pitch:");
878         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
879         gtk_widget_show(dummy);
880
881         dumadj=(GtkAdjustment*) gtk_adjustment_new(globals.pitch, -3, 3, 0.001, 0.001, 0.01);
882         pitch_adj=dumadj;
883         connect_adj(dumadj, master_pitch_changed, NULL);        
884         dummy=gtk_hscale_new(dumadj);
885         gtk_scale_set_digits(GTK_SCALE(dummy), 2);
886         gtk_scale_set_value_pos(GTK_SCALE(dummy), GTK_POS_LEFT);
887         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_DYN);
888         gui_set_tooltip(dummy, "Use this scale to adjust the master pitch (affecting *all* turntables).");
889         gtk_widget_show(dummy);
890
891         dummy=tx_xpm_label_box(TX_ICON_SEQUENCER, "Sequencer");
892         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
893         gtk_widget_show(dummy);
894
895         dummy=tx_xpm_button_new(TX_ICON_PLAY,"Play ", 1);
896         connect_button(dummy, seq_play, NULL);
897         seq_play_btn=dummy;
898         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
899         gui_set_tooltip(dummy, "Playback previously recorded events from the sequencer. This will turn on the audio engine automagically.");
900         gtk_widget_show(dummy);
901
902         dummy=tx_xpm_button_new(TX_ICON_STOP,"Stop ", 0);
903         seq_stop_btn=dummy;
904         connect_button(dummy, seq_stop, NULL);  
905         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
906         gui_set_tooltip(dummy, "Stop the playback of sequencer events.");
907         gtk_widget_show(dummy);
908
909         dummy=tx_xpm_button_new(TX_ICON_RECORD,"Record ", 1);
910         connect_button(dummy, seq_rec, NULL);
911         seq_rec_btn=dummy;
912         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
913         gui_set_tooltip(dummy, "Enable recording of *events* into the sequencer. All touched controls will be recorded. Existing events for the song-time recording will be overwritten for touched controls.");
914         gtk_widget_show(dummy);
915
916         dummy=gtk_label_new("Pos:");
917         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
918         gtk_widget_show(dummy);
919         
920         dummy=gtk_entry_new_with_max_length(12);
921         seq_entry=dummy;
922         gtk_widget_set_usize(dummy, 55, 20);
923         gtk_entry_set_text(GTK_ENTRY(dummy), "00:00.00");
924         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
925         gtk_widget_show(dummy);
926
927         dumadj=(GtkAdjustment*) gtk_adjustment_new(0, 0, 100, 0.1, 1, 1);
928         seq_adj=dumadj;
929         connect_adj(dumadj, sequencer_move, NULL);      
930         dummy=gtk_hscale_new(dumadj);
931         seq_slider=dummy;
932         gtk_signal_connect(GTK_OBJECT(seq_slider), "button-release-event", (GtkSignalFunc) seq_slider_released, NULL);
933         gtk_scale_set_draw_value(GTK_SCALE(dummy), FALSE);
934         
935         gui_set_tooltip(dummy, "Select the start position for the sequencer in song-time.");
936         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_DYN);
937         gtk_widget_show(dummy);
938         
939         dummy=gtk_hbox_new(FALSE,2);
940         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_DYN);
941         gtk_widget_show(dummy);
942         
943         tt_parent=dummy;
944         
945         control_parent=gtk_hbox_new(FALSE,0);
946         gtk_box_pack_start(GTK_BOX(tt_parent), control_parent, WID_FIX);
947         gtk_widget_show(control_parent);
948
949         dummy=gtk_vseparator_new();
950         gtk_box_pack_start(GTK_BOX(tt_parent), dummy, WID_FIX);
951         gtk_widget_show(dummy);
952
953         audio_parent=gtk_vbox_new(FALSE,0);
954         gtk_box_pack_start(GTK_BOX(tt_parent), audio_parent, WID_DYN);
955         gtk_widget_show(audio_parent);
956         
957         dummy=gtk_vseparator_new();
958         gtk_box_pack_start(GTK_BOX(main_vbox), dummy, WID_FIX);
959         gtk_widget_show(dummy);
960                 
961         right_hbox=gtk_vbox_new(FALSE, 5);
962         gtk_box_pack_start(GTK_BOX(main_vbox), right_hbox, WID_FIX);
963         gtk_widget_show(right_hbox);
964         
965         dummy=gtk_button_new_with_label("Add Turntable");
966         AddTable=dummy; 
967         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
968         gui_set_tooltip(dummy, "Click this button to add a new turntable to the current set.");
969         gtk_widget_show(dummy);
970
971         gtk_drag_dest_set (GTK_WIDGET (dummy), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
972                         drop_types, n_drop_types,
973                         GDK_ACTION_COPY);
974                                                 
975         gtk_signal_connect (GTK_OBJECT (dummy), "drag_data_received",
976                         GTK_SIGNAL_FUNC(drop_new_table), NULL);
977         
978         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(new_table), NULL);       
979
980         dummy=gtk_button_new_with_label("Load Set");
981         LoadSet=dummy;
982         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
983         gtk_widget_show(dummy);
984         gui_set_tooltip(dummy, "Click to load a previously saved terminatorX-set-file. As an alternative you can drop a set file over this button.");
985         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(load_tables), NULL);     
986
987         gtk_drag_dest_set (GTK_WIDGET (dummy), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
988                         drop_types, n_drop_types,
989                         GDK_ACTION_COPY);
990                                                 
991         gtk_signal_connect (GTK_OBJECT (dummy), "drag_data_received",
992                         GTK_SIGNAL_FUNC(drop_set), NULL);
993         
994         dummy=gtk_button_new_with_label("Save Set");
995         SaveSet=dummy;
996         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
997         gtk_widget_show(dummy);
998         gui_set_tooltip(dummy, "Click here to save the current set.");
999         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(save_tables), NULL);     
1000
1001         add_sep();
1002         
1003         dummy=gtk_button_new_with_label("Options");
1004         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1005         gtk_widget_show(dummy);
1006         gui_set_tooltip(dummy, "Click here to configure terminatorX.");
1007         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) display_options, NULL);
1008
1009         dummy=gtk_button_new_with_label("About/Legal");
1010         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1011         gtk_widget_show(dummy);
1012         gui_set_tooltip(dummy, "Click here to read the license and to get some information about this binary.");
1013         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) mplcfitx, NULL);      
1014
1015         dummy=gtk_button_new_with_label("Quit");
1016         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1017         gtk_widget_show(dummy);
1018         gui_set_tooltip(dummy, "Click here to exit terminatorX.");
1019         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) quit, NULL);
1020         
1021         add_sep();              
1022
1023         small_box=gtk_hbox_new(FALSE, 5);
1024         gtk_box_pack_start(GTK_BOX(right_hbox), small_box, WID_DYN);
1025         gtk_widget_show(small_box);
1026         
1027         smaller_box=gtk_vbox_new(FALSE, 0);
1028         gtk_box_pack_start(GTK_BOX(small_box), smaller_box, WID_FIX);
1029         gtk_widget_show(smaller_box);
1030         
1031         dummy = tx_pixmap_widget(TX_ICON_LOGO);
1032         gtk_box_pack_start(GTK_BOX(smaller_box), dummy, WID_FIX);
1033         gtk_widget_show( dummy );
1034
1035         dummy=gtk_label_new("0");
1036         used_mem=dummy;
1037         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1038         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1039         gtk_widget_show(dummy);
1040
1041         dummy=gtk_label_new("Mem/kB:");
1042         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1043         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1044         gtk_widget_show(dummy);
1045         
1046         add_sep2();
1047
1048         dummy=gtk_label_new("1");
1049         no_of_vtts=dummy;
1050         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1051         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1052         gtk_widget_show(dummy);
1053
1054         dummy=gtk_label_new("Vtts:");
1055         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1056         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1057         gtk_widget_show(dummy);
1058
1059         add_sep2();
1060
1061         dummy=gtk_label_new(VERSION);
1062         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1063         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1064         gtk_widget_show(dummy);
1065
1066         dummy=gtk_label_new("Release:");
1067         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1068         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1069         gtk_widget_show(dummy);
1070         
1071         add_sep2();
1072
1073         dummy=gtk_label_new("Status:");
1074         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1075         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1076         gtk_widget_show(dummy);
1077         
1078         dumadj=(GtkAdjustment*) gtk_adjustment_new(2.0-globals.volume, 0, 2, 0.01, 0.05, 0.005);
1079         volume_adj=dumadj;
1080
1081         connect_adj(dumadj, master_volume_changed, NULL);       
1082         dummy=gtk_vscale_new(dumadj);
1083         gtk_scale_set_draw_value(GTK_SCALE(dummy), False);
1084         gtk_box_pack_end(GTK_BOX(small_box), dummy, WID_DYN);
1085         gtk_widget_show(dummy); 
1086         gui_set_tooltip(dummy, "Adjust the master volume. This parameter will effect *all* turntables in the set.");
1087         
1088 #ifdef USE_FLASH        
1089         main_flash_r=gtk_tx_flash_new();
1090         gtk_box_pack_end(GTK_BOX(small_box), main_flash_r, WID_DYN);
1091         gtk_widget_show(main_flash_r);
1092
1093         main_flash_l=gtk_tx_flash_new();
1094         gtk_box_pack_end(GTK_BOX(small_box), main_flash_l, WID_DYN);
1095         gtk_widget_show(main_flash_l);
1096 #endif  
1097         gtk_window_set_default_size(GTK_WINDOW(main_window), x, y);     
1098         gtk_widget_set_sensitive(grab_button, 0);
1099
1100         new_table(NULL, NULL); // to give the user something to start with ;)
1101
1102         gtk_signal_connect (GTK_OBJECT(main_window), "delete-event", (GtkSignalFunc) quit, NULL);       
1103         
1104         if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
1105         else gtk_tooltips_disable(gui_tooltips);
1106 }
1107
1108 gfloat old_percent=-1;
1109
1110 void wav_progress_update(gfloat percent)
1111 {
1112         percent=floor(percent*10.0)/10.0; //Updating statusbars with gtk-themes eats up hell of a lot CPU-time
1113                                           // which is why we update every 10% only.
1114         
1115         if (wav_progress)
1116         {
1117                 if (old_percent != percent)
1118                 {
1119                         old_percent = percent;
1120                         gtk_progress_bar_update(GTK_PROGRESS_BAR(wav_progress), percent);
1121                         while (gtk_events_pending()) gtk_main_iteration();      
1122                 }
1123         }
1124
1125 }
1126
1127 void note_destroy(GtkWidget *widget, GtkWidget *mbox)
1128 {
1129         gtk_widget_destroy(GTK_WIDGET(mbox));
1130 }
1131
1132 void tx_note(const char *message)
1133 {
1134         char buffer[4096]="\nterminatorX Note:\n\n";
1135         
1136         GtkWidget *mbox;
1137         GtkWidget *label;
1138         GtkWidget *btn;
1139         GtkWidget *sp;
1140         GtkWindow *win;
1141         
1142         mbox=gtk_dialog_new();
1143         win=&(GTK_DIALOG(mbox)->window);
1144
1145         gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(mbox)->vbox), 2);
1146         gtk_container_set_border_width(GTK_CONTAINER(mbox), 10);
1147         
1148         label=gtk_label_new("terminatorX Note");
1149         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
1150         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0);
1151         gtk_widget_show(label);
1152
1153         sp=gtk_hseparator_new();
1154         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), sp, TRUE, TRUE, 0);
1155         gtk_widget_show(sp);
1156
1157         strcpy(buffer, "\n");
1158         strcat(buffer, message);
1159         strcat(buffer, "\n");
1160         label=gtk_label_new(buffer);
1161         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0);
1162         gtk_widget_show(label); 
1163
1164         btn = gtk_button_new_with_label("Ok");
1165         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->action_area), btn, TRUE, TRUE, 0);
1166
1167         gtk_signal_connect(GTK_OBJECT(btn), "clicked", GtkSignalFunc(note_destroy), mbox);
1168
1169         gtk_window_set_default_size(win, 200, 100);
1170         gtk_window_set_position(win, GTK_WIN_POS_CENTER_ALWAYS);        
1171
1172         GTK_WIDGET_SET_FLAGS (btn, GTK_CAN_DEFAULT);
1173         gtk_widget_grab_default(btn);
1174         gtk_widget_show(btn);
1175         gtk_widget_show(mbox);
1176 }
1177
1178
1179 void tx_l_note(const char *message)
1180 {
1181         char buffer[4096]="\n   Plugin Info:  \n   ------------  \n\n";
1182         
1183         GtkWidget *mbox;
1184         GtkWidget *label;
1185         GtkWidget *btn;
1186         GtkWindow *win;
1187         
1188         mbox=gtk_dialog_new();
1189         win=&(GTK_DIALOG(mbox)->window);
1190         strcat(buffer, message);
1191         strcat(buffer, "\n");
1192         label=gtk_label_new(buffer);
1193         gtk_label_set_justify (GTK_LABEL(label),  GTK_JUSTIFY_LEFT);
1194         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0);
1195         gtk_widget_show(label);
1196
1197         btn = gtk_button_new_with_label("Ok");
1198         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->action_area), btn, TRUE, TRUE, 0);
1199         gtk_widget_show(btn);
1200         
1201         gtk_signal_connect(GTK_OBJECT(btn), "clicked", GtkSignalFunc(note_destroy), mbox);
1202
1203         gtk_window_set_default_size(win, 200, 100);
1204         gtk_window_set_position(win, GTK_WIN_POS_CENTER_ALWAYS);        
1205         gtk_widget_show(mbox);
1206 }
1207
1208 void display_mastergui()
1209 {
1210         GtkWidget *top;
1211         gtk_widget_realize(main_window);
1212         tX_set_icon(main_window, "terminatorX");
1213         load_knob_pixs(main_window);
1214
1215         gtk_widget_show(main_window);
1216         top=gtk_widget_get_toplevel(main_window);
1217         xwindow=GDK_WINDOW_XWINDOW(top->window);
1218 }