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