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