7f5e02d0b1bafaac980376e41717f9e30936081b
[terminatorX.git] / terminatorX / src / tX_mastergui.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2002  Alexander K├Ânig
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     File: tX_mastergui.cc
20  
21     Description: This implements the main (aka master) gtk+ GUI of terminatorX
22                  It serves as a container for the vtt-guis.
23 */    
24
25 #include <gtk/gtk.h>
26 #include <gdk/gdkx.h>
27 #include <X11/Xlib.h>
28 #include <math.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include "version.h"
32 #include "tX_global.h"
33 #include "tX_engine.h"
34 #include "tX_vttgui.h"
35 #include "tX_vtt.h"
36 #include "tX_flash.h"
37 #include "tX_dialog.h"
38 #include "tX_loaddlg.h"
39 #include "tX_seqpar.h"
40 #include "tX_pbutton.h"
41 #include "tX_sequencer.h"
42 #include "tX_mastergui.h"
43 #include "tX_knobloader.h"
44
45 #ifdef USE_SCHEDULER
46 #include <sys/time.h>
47 #include <sys/resource.h>
48 #endif
49
50 #define TX_SET_ID_10 "terminatorX turntable set file - version 1.0 - data:"
51 #define TX_SET_ID_11 "terminatorX turntable set file - version 1.1 - data:"
52 #define TX_SET_ID_12 "terminatorX turntable set file - version 1.2 - data:"
53 #define TX_SET_ID_13 "terminatorX turntable set file - version 1.3 - data:"
54 #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         tX_engine_error 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=engine->run();
540                 sequencer_ready=1;
541
542                 if (res!=NO_ERROR)
543                 {
544                         mg_enable_critical_buttons(1);
545                         switch(res)
546                         {
547                                 case ERROR_BUSY:
548                                 tx_note("Error starting engine: engine is already running.");
549                                 break;
550                                 case ERROR_AUDIO:
551                                 tx_note("Error starting engine: failed to access audiodevice.");
552                                 break;
553                                 case ERROR_TAPE:
554                                 tx_note("Error starting engine: failed to open the recording file.");
555                                 break;
556                                 default:tx_note("Error starting engine: Unknown error.");
557                         }
558                         return 0;
559                 }
560
561                 stop_update=0;
562                 audioon=1;
563                 update_delay=globals.update_delay;
564                 update_tag=gtk_timeout_add(globals.update_idle, (GtkFunction) pos_update, NULL);
565                 gtk_widget_set_sensitive(grab_button, 1);
566         }
567         else
568         {               
569                 if (!sequencer_ready) return NULL;
570                 gtk_widget_set_sensitive(grab_button, 0);
571                 engine->stop();
572                 stop_update=1;
573                 audioon=0;
574                 if (engine->get_recording_request()) {
575                         engine->set_recording_request(false);
576                         rec_dont_care=1;
577                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rec_btn), 0);
578                         rec_dont_care=0;
579                 }
580                 seq_stop(NULL, NULL);
581                 mg_enable_critical_buttons(1);
582         }
583 }
584
585 GtkSignalFunc cancel_rec(GtkWidget *wid)
586 {
587         gtk_widget_destroy(rec_dialog);
588         rec_dialog=NULL;
589         rec_dialog_win=NULL;
590         rec_dont_care=0;
591         return(0);
592 }
593
594 void do_rec(GtkWidget *wid)
595 {
596         char buffer[PATH_MAX];
597         
598         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(rec_dialog)));
599
600         if (strlen(buffer))
601         {
602                 strcpy(globals.record_filename, buffer);                
603                 engine->set_recording_request(true);
604                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rec_btn), 1);
605         }
606         
607         rec_dont_care=0;
608         
609         gtk_widget_destroy(rec_dialog);
610         
611         rec_dialog=NULL;
612         rec_dialog_win=NULL;
613 }
614
615 GtkSignalFunc select_rec_file()
616 {
617         if (rec_dialog_win) 
618         {
619                 gdk_window_raise(rec_dialog_win);
620                 return 0;
621         }
622         
623         rec_dialog=gtk_file_selection_new("Record To Disk");    
624         
625         if (strlen(globals.record_filename))
626         {
627                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(rec_dialog), globals.record_filename);
628         }
629         
630         gtk_widget_show(rec_dialog);
631         
632         rec_dialog_win=rec_dialog->window;
633         
634         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(rec_dialog)->ok_button), "clicked", GTK_SIGNAL_FUNC(do_rec), NULL);
635         gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(rec_dialog)->cancel_button), "clicked", GTK_SIGNAL_FUNC (cancel_rec), NULL);  
636         gtk_signal_connect (GTK_OBJECT(rec_dialog), "delete-event", GTK_SIGNAL_FUNC(cancel_rec), NULL); 
637 }
638
639 GtkSignalFunc tape_on(GtkWidget *w, void *d)
640 {
641         if (rec_dont_care) return 0;
642
643         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
644         {       
645                 {
646                         rec_dont_care=1;
647                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
648                         select_rec_file();
649                 }
650         }
651         else
652         {
653                         engine->set_recording_request(false);
654         }
655 }
656
657 void grab_on(GtkWidget *w, void *d)
658 {
659         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
660                 engine->set_grab_request();
661         }
662         grab_status=1;
663 }
664
665 void grab_off()
666 {
667         grab_status=0;
668 }
669
670 void hide_clicked(GtkWidget *w, void *d)
671 {
672         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
673         {
674                 mg_hide_gui=1;
675         }
676         else
677         {
678                 mg_hide_gui=0;
679         }
680 }
681
682 void quit()
683 {
684         turn_audio_off();
685         if (update_tag)
686         gtk_timeout_remove(update_tag);
687         globals.width=main_window->allocation.width;
688         globals.height=main_window->allocation.height;
689
690         gtk_main_quit();
691 }
692
693 void mplcfitx()
694 /* Most Probably Least Called Function In terminatorX :) */
695 {
696         show_about(0);
697 }
698
699 GtkSignalFunc seq_play(GtkWidget *w, void *)
700 {
701         if ((sequencer.is_empty()) &&   (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(seq_rec_btn)))) {
702                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
703                  {
704                         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.");
705                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
706                  }
707         } else {
708                 if (seq_stop_override) return NULL;
709                         
710                 seq_adj_care=0;
711                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
712                 sequencer.trig_play();
713         
714                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 1);
715         }
716 }
717
718 GtkSignalFunc seq_stop(GtkWidget *w, void *)
719 {
720         if (!sequencer_ready) return NULL;
721         sequencer.trig_stop();
722         seq_adj_care=1;
723         seq_stop_override=1;
724         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_play_btn), 0);
725         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_rec_btn), 0);
726         while (gtk_events_pending()) gtk_main_iteration();              
727         seq_stop_override=0;
728         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0); 
729         gtk_widget_set_sensitive(seq_slider, 1);        
730         gtk_widget_set_sensitive(engine_btn, 1);
731         gtk_widget_set_sensitive(seq_rec_btn, 1);
732 }
733
734 GtkSignalFunc seq_rec(GtkWidget *w, void *)
735 {
736         seq_adj_care=0;
737         gtk_widget_set_sensitive(seq_slider, 0);
738
739         if (seq_stop_override) return NULL;
740         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
741         gtk_widget_set_sensitive(engine_btn, 0);
742         gtk_widget_set_sensitive(seq_rec_btn, 0);
743         sequencer.trig_rec();
744 }
745
746 void seq_update_entry(const guint32 timestamp)
747 {
748         char buffer[20];
749         guint32 samples;
750         guint32 minu,sec,hun;   
751         
752         samples=timestamp*globals.true_block_size;
753         
754         if (samples>0)
755         {
756                 minu=samples/2646000;
757                 samples-=2646000*minu;
758         
759                 sec=samples/44100;
760                 samples-=44100*sec;
761         
762                 hun=samples/441;
763         }
764         else
765         {
766                 minu=sec=hun=0;
767         }
768         
769         sprintf(buffer, "%02li:%02li.%02li", minu, sec, hun);
770         gtk_entry_set_text(GTK_ENTRY(seq_entry), buffer);
771 }
772
773 void seq_update()
774 {
775         seq_update_entry(sequencer.get_timestamp());
776         gtk_adjustment_set_value(seq_adj, sequencer.get_timestamp_as_float());
777         
778 }
779 void seq_slider_released(GtkWidget *wid, void *d)
780 {
781         seq_adj_care=0;
782         gtk_widget_set_sensitive(seq_slider, 0);        
783         sequencer.forward_to_start_timestamp(0);
784         gtk_widget_set_sensitive(seq_slider, 1);        
785         seq_adj_care=1;
786 }
787 void sequencer_move(GtkWidget *wid, void *d)
788 {
789         guint32 pos;
790         
791         if (seq_adj_care)
792         {
793                 pos=sequencer.set_start_timestamp((float) GTK_ADJUSTMENT(wid)->value);
794                 seq_update_entry(pos);  
795         }
796 }
797
798 #define add_sep();      dummy=gtk_hseparator_new ();\
799         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);\
800         gtk_widget_show(dummy);\
801
802 #define add_sep2();     dummy=gtk_hseparator_new ();\
803         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);\
804         gtk_widget_show(dummy);\
805
806 void create_mastergui(int x, int y)
807 {
808         GtkWidget *main_vbox;
809         GtkWidget *right_hbox;
810         GtkWidget *left_hbox;
811         GtkWidget *control_box;
812         GtkWidget *sequencer_box;
813         GtkAdjustment *dumadj;
814         GtkWidget *dummy;
815         GtkWidget *small_box;
816         GtkWidget *smaller_box;
817         
818         int i;
819         static GtkTargetEntry drop_types [] = {
820                 { "text/uri-list", 0, 0}
821         };
822         static gint n_drop_types = sizeof (drop_types) / sizeof(drop_types[0]);
823         
824         gui_tooltips=gtk_tooltips_new();
825
826         main_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
827
828         gtk_window_set_wmclass(GTK_WINDOW(main_window), "terminatorX", "tX_mastergui");
829
830         gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
831         
832         gtk_container_set_border_width(GTK_CONTAINER(main_window), 5);
833
834         gtk_widget_realize(main_window);
835         
836         main_vbox=gtk_hbox_new(FALSE, 5);
837         
838         gtk_container_add(GTK_CONTAINER(main_window), main_vbox);
839         gtk_widget_show(main_vbox);
840         
841         left_hbox=gtk_vbox_new(FALSE, 5);
842         gtk_box_pack_start(GTK_BOX(main_vbox), left_hbox, WID_DYN);
843         gtk_widget_show(left_hbox);
844         
845         control_box=gtk_hbox_new(FALSE, 5);
846         gtk_box_pack_start(GTK_BOX(left_hbox), control_box, WID_FIX);
847         gtk_widget_show(control_box);
848         
849 /*      dummy=gtk_hseparator_new();
850         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
851         gtk_widget_show(dummy);*/
852
853         sequencer_box=gtk_hbox_new(FALSE, 5);
854         gtk_box_pack_start(GTK_BOX(left_hbox), sequencer_box, WID_FIX);
855         gtk_widget_show(sequencer_box);
856
857         dummy=gtk_hseparator_new();
858         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
859         gtk_widget_show(dummy);
860
861         dummy=tx_xpm_label_box(TX_ICON_AUDIOENGINE, "Audio Eng.");
862         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
863         gtk_widget_show(dummy);
864         
865         dummy=tx_xpm_button_new(TX_ICON_POWER,"Power ", 1);
866         connect_button(dummy,audio_on, NULL);
867         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
868         gui_set_tooltip(dummy, "Turn the audio engine on/off.");
869         gtk_widget_show(dummy);
870         engine_btn=dummy;
871         
872         grab_button=tx_xpm_button_new(TX_ICON_GRAB, "Mouse Grab ", 1);
873         gtk_box_pack_start(GTK_BOX(control_box), grab_button, WID_FIX);
874         connect_button(grab_button, grab_on, NULL);
875         gui_set_tooltip(grab_button, "Enter the mouse grab mode operation. Press <ESCAPE> to exit grab mode.");
876         gtk_widget_show(grab_button);
877
878         dummy=gtk_check_button_new_with_label("Record");
879         rec_btn=dummy;
880         connect_button(dummy,tape_on, NULL);
881         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
882         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.");
883         gtk_widget_show(dummy);
884         
885         dummy=gtk_label_new("Pitch:");
886         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
887         gtk_widget_show(dummy);
888
889         dumadj=(GtkAdjustment*) gtk_adjustment_new(globals.pitch, -3, 3, 0.001, 0.001, 0.01);
890         pitch_adj=dumadj;
891         connect_adj(dumadj, master_pitch_changed, NULL);        
892         dummy=gtk_hscale_new(dumadj);
893         gtk_scale_set_digits(GTK_SCALE(dummy), 2);
894         gtk_scale_set_value_pos(GTK_SCALE(dummy), GTK_POS_LEFT);
895         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_DYN);
896         gui_set_tooltip(dummy, "Use this scale to adjust the master pitch (affecting *all* turntables).");
897         gtk_widget_show(dummy);
898
899         dummy=tx_xpm_label_box(TX_ICON_SEQUENCER, "Sequencer");
900         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
901         gtk_widget_show(dummy);
902
903         dummy=tx_xpm_button_new(TX_ICON_PLAY,"Play ", 1);
904         connect_button(dummy, seq_play, NULL);
905         seq_play_btn=dummy;
906         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
907         gui_set_tooltip(dummy, "Playback previously recorded events from the sequencer. This will turn on the audio engine automagically.");
908         gtk_widget_show(dummy);
909
910         dummy=tx_xpm_button_new(TX_ICON_STOP,"Stop ", 0);
911         seq_stop_btn=dummy;
912         connect_button(dummy, seq_stop, NULL);  
913         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
914         gui_set_tooltip(dummy, "Stop the playback of sequencer events.");
915         gtk_widget_show(dummy);
916
917         dummy=tx_xpm_button_new(TX_ICON_RECORD,"Record ", 1);
918         connect_button(dummy, seq_rec, NULL);
919         seq_rec_btn=dummy;
920         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
921         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.");
922         gtk_widget_show(dummy);
923
924         dummy=gtk_label_new("Pos:");
925         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
926         gtk_widget_show(dummy);
927         
928         dummy=gtk_entry_new_with_max_length(12);
929         seq_entry=dummy;
930         gtk_widget_set_usize(dummy, 55, 20);
931         gtk_entry_set_text(GTK_ENTRY(dummy), "00:00.00");
932         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_FIX);
933         gtk_widget_show(dummy);
934
935         dumadj=(GtkAdjustment*) gtk_adjustment_new(0, 0, 100, 0.1, 1, 1);
936         seq_adj=dumadj;
937         connect_adj(dumadj, sequencer_move, NULL);      
938         dummy=gtk_hscale_new(dumadj);
939         seq_slider=dummy;
940         gtk_signal_connect(GTK_OBJECT(seq_slider), "button-release-event", (GtkSignalFunc) seq_slider_released, NULL);
941         gtk_scale_set_draw_value(GTK_SCALE(dummy), FALSE);
942         
943         gui_set_tooltip(dummy, "Select the start position for the sequencer in song-time.");
944         gtk_box_pack_start(GTK_BOX(sequencer_box), dummy, WID_DYN);
945         gtk_widget_show(dummy);
946         
947         dummy=gtk_hbox_new(FALSE,2);
948         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_DYN);
949         gtk_widget_show(dummy);
950         
951         tt_parent=dummy;
952
953     panel_bar=gtk_hbox_new(TRUE,2);
954         gtk_box_pack_start(GTK_BOX(left_hbox), panel_bar, WID_FIX);
955         //gtk_widget_show(panel_bar);
956
957         control_parent=gtk_hbox_new(FALSE,0);
958         gtk_box_pack_start(GTK_BOX(tt_parent), control_parent, WID_FIX);
959         gtk_widget_show(control_parent);
960
961         dummy=gtk_vseparator_new();
962         gtk_box_pack_start(GTK_BOX(tt_parent), dummy, WID_FIX);
963         gtk_widget_show(dummy);
964
965         audio_parent=gtk_vbox_new(FALSE,0);
966         gtk_box_pack_start(GTK_BOX(tt_parent), audio_parent, WID_DYN);
967         gtk_widget_show(audio_parent);
968         
969         dummy=gtk_vseparator_new();
970         gtk_box_pack_start(GTK_BOX(main_vbox), dummy, WID_FIX);
971         gtk_widget_show(dummy);
972                 
973         right_hbox=gtk_vbox_new(FALSE, 5);
974         gtk_box_pack_start(GTK_BOX(main_vbox), right_hbox, WID_FIX);
975         gtk_widget_show(right_hbox);
976         
977         dummy=gtk_button_new_with_label("Add Turntable");
978         AddTable=dummy; 
979         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
980         gui_set_tooltip(dummy, "Click this button to add a new turntable to the current set.");
981         gtk_widget_show(dummy);
982
983         gtk_drag_dest_set (GTK_WIDGET (dummy), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
984                         drop_types, n_drop_types,
985                         GDK_ACTION_COPY);
986                                                 
987         gtk_signal_connect (GTK_OBJECT (dummy), "drag_data_received",
988                         GTK_SIGNAL_FUNC(drop_new_table), NULL);
989         
990         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(new_table), NULL);       
991
992         dummy=gtk_button_new_with_label("Load Set");
993         LoadSet=dummy;
994         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
995         gtk_widget_show(dummy);
996         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.");
997         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(load_tables), NULL);     
998
999         gtk_drag_dest_set (GTK_WIDGET (dummy), (GtkDestDefaults) (GTK_DEST_DEFAULT_MOTION |GTK_DEST_DEFAULT_HIGHLIGHT |GTK_DEST_DEFAULT_DROP),
1000                         drop_types, n_drop_types,
1001                         GDK_ACTION_COPY);
1002                                                 
1003         gtk_signal_connect (GTK_OBJECT (dummy), "drag_data_received",
1004                         GTK_SIGNAL_FUNC(drop_set), NULL);
1005         
1006         dummy=gtk_button_new_with_label("Save Set");
1007         SaveSet=dummy;
1008         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1009         gtk_widget_show(dummy);
1010         gui_set_tooltip(dummy, "Click here to save the current set.");
1011         gtk_signal_connect(GTK_OBJECT(dummy), "clicked", GtkSignalFunc(save_tables), NULL);     
1012
1013         add_sep();
1014         
1015         dummy=gtk_button_new_with_label("Options");
1016         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1017         gtk_widget_show(dummy);
1018         gui_set_tooltip(dummy, "Click here to configure terminatorX.");
1019         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) display_options, NULL);
1020
1021         dummy=gtk_button_new_with_label("About/Legal");
1022         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1023         gtk_widget_show(dummy);
1024         gui_set_tooltip(dummy, "Click here to read the license and to get some information about this binary.");
1025         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) mplcfitx, NULL);      
1026
1027         dummy=gtk_button_new_with_label("Quit");
1028         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1029         gtk_widget_show(dummy);
1030         gui_set_tooltip(dummy, "Click here to exit terminatorX.");
1031         gtk_signal_connect (GTK_OBJECT(dummy), "clicked", (GtkSignalFunc) quit, NULL);
1032         
1033         add_sep();              
1034
1035         small_box=gtk_hbox_new(FALSE, 5);
1036         gtk_box_pack_start(GTK_BOX(right_hbox), small_box, WID_DYN);
1037         gtk_widget_show(small_box);
1038         
1039         smaller_box=gtk_vbox_new(FALSE, 0);
1040         gtk_box_pack_start(GTK_BOX(small_box), smaller_box, WID_FIX);
1041         gtk_widget_show(smaller_box);
1042         
1043         dummy = tx_pixmap_widget(TX_ICON_LOGO);
1044         gtk_box_pack_start(GTK_BOX(smaller_box), dummy, WID_FIX);
1045         gtk_widget_show( dummy );
1046
1047         dummy=gtk_label_new("0");
1048         used_mem=dummy;
1049         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1050         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1051         gtk_widget_show(dummy);
1052
1053         dummy=gtk_label_new("Mem/kB:");
1054         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1055         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1056         gtk_widget_show(dummy);
1057         
1058         add_sep2();
1059
1060         dummy=gtk_label_new("1");
1061         no_of_vtts=dummy;
1062         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1063         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1064         gtk_widget_show(dummy);
1065
1066         dummy=gtk_label_new("Vtts:");
1067         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1068         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1069         gtk_widget_show(dummy);
1070
1071         add_sep2();
1072
1073         dummy=gtk_label_new(VERSION);
1074         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1075         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1076         gtk_widget_show(dummy);
1077
1078         dummy=gtk_label_new("Release:");
1079         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1080         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1081         gtk_widget_show(dummy);
1082         
1083         add_sep2();
1084
1085         dummy=gtk_label_new("Status:");
1086         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1087         gtk_box_pack_end(GTK_BOX(smaller_box), dummy, WID_FIX);
1088         gtk_widget_show(dummy);
1089         
1090         dumadj=(GtkAdjustment*) gtk_adjustment_new(2.0-globals.volume, 0, 2, 0.01, 0.05, 0.005);
1091         volume_adj=dumadj;
1092
1093         connect_adj(dumadj, master_volume_changed, NULL);       
1094         dummy=gtk_vscale_new(dumadj);
1095         gtk_scale_set_draw_value(GTK_SCALE(dummy), False);
1096         gtk_box_pack_end(GTK_BOX(small_box), dummy, WID_DYN);
1097         gtk_widget_show(dummy); 
1098         gui_set_tooltip(dummy, "Adjust the master volume. This parameter will effect *all* turntables in the set.");
1099         
1100 #ifdef USE_FLASH        
1101         main_flash_r=gtk_tx_flash_new();
1102         gtk_box_pack_end(GTK_BOX(small_box), main_flash_r, WID_DYN);
1103         gtk_widget_show(main_flash_r);
1104
1105         main_flash_l=gtk_tx_flash_new();
1106         gtk_box_pack_end(GTK_BOX(small_box), main_flash_l, WID_DYN);
1107         gtk_widget_show(main_flash_l);
1108 #endif  
1109         gtk_window_set_default_size(GTK_WINDOW(main_window), x, y);     
1110         gtk_widget_set_sensitive(grab_button, 0);
1111
1112         new_table(NULL, NULL); // to give the user something to start with ;)
1113
1114         gtk_signal_connect (GTK_OBJECT(main_window), "delete-event", (GtkSignalFunc) quit, NULL);       
1115         
1116         if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
1117         else gtk_tooltips_disable(gui_tooltips);
1118 }
1119
1120 gfloat old_percent=-1;
1121
1122 void wav_progress_update(gfloat percent)
1123 {
1124         percent=floor(percent*10.0)/10.0; //Updating statusbars with gtk-themes eats up hell of a lot CPU-time
1125                                           // which is why we update every 10% only.
1126         
1127         if (wav_progress)
1128         {
1129                 if (old_percent != percent)
1130                 {
1131                         old_percent = percent;
1132                         gtk_progress_bar_update(GTK_PROGRESS_BAR(wav_progress), percent);
1133                         while (gtk_events_pending()) gtk_main_iteration();      
1134                 }
1135         }
1136
1137 }
1138
1139 void note_destroy(GtkWidget *widget, GtkWidget *mbox)
1140 {
1141         gtk_widget_destroy(GTK_WIDGET(mbox));
1142 }
1143
1144 void tx_note(const char *message)
1145 {
1146         char buffer[4096]="\nterminatorX Note:\n\n";
1147         
1148         GtkWidget *mbox;
1149         GtkWidget *label;
1150         GtkWidget *btn;
1151         GtkWidget *sp;
1152         GtkWindow *win;
1153         
1154         mbox=gtk_dialog_new();
1155         win=&(GTK_DIALOG(mbox)->window);
1156
1157         gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(mbox)->vbox), 2);
1158         gtk_container_set_border_width(GTK_CONTAINER(mbox), 10);
1159         
1160         label=gtk_label_new("terminatorX Note");
1161         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
1162         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0);
1163         gtk_widget_show(label);
1164
1165         sp=gtk_hseparator_new();
1166         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), sp, TRUE, TRUE, 0);
1167         gtk_widget_show(sp);
1168
1169         strcpy(buffer, "\n");
1170         strcat(buffer, message);
1171         strcat(buffer, "\n");
1172         label=gtk_label_new(buffer);
1173         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0);
1174         gtk_widget_show(label); 
1175
1176         btn = gtk_button_new_with_label("Ok");
1177         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->action_area), btn, TRUE, TRUE, 0);
1178
1179         gtk_signal_connect(GTK_OBJECT(btn), "clicked", GtkSignalFunc(note_destroy), mbox);
1180
1181         gtk_window_set_default_size(win, 200, 100);
1182         gtk_window_set_position(win, GTK_WIN_POS_CENTER_ALWAYS);        
1183
1184         GTK_WIDGET_SET_FLAGS (btn, GTK_CAN_DEFAULT);
1185         gtk_widget_grab_default(btn);
1186         gtk_widget_show(btn);
1187         gtk_widget_show(mbox);
1188 }
1189
1190
1191 void tx_l_note(const char *message)
1192 {
1193         char buffer[4096]="\n   Plugin Info:  \n   ------------  \n\n";
1194         
1195         GtkWidget *mbox;
1196         GtkWidget *label;
1197         GtkWidget *btn;
1198         GtkWindow *win;
1199         
1200         mbox=gtk_dialog_new();
1201         win=&(GTK_DIALOG(mbox)->window);
1202         strcat(buffer, message);
1203         strcat(buffer, "\n");
1204         label=gtk_label_new(buffer);
1205         gtk_label_set_justify (GTK_LABEL(label),  GTK_JUSTIFY_LEFT);
1206         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0);
1207         gtk_widget_show(label);
1208
1209         btn = gtk_button_new_with_label("Ok");
1210         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->action_area), btn, TRUE, TRUE, 0);
1211         gtk_widget_show(btn);
1212         
1213         gtk_signal_connect(GTK_OBJECT(btn), "clicked", GtkSignalFunc(note_destroy), mbox);
1214
1215         gtk_window_set_default_size(win, 200, 100);
1216         gtk_window_set_position(win, GTK_WIN_POS_CENTER_ALWAYS);        
1217         gtk_widget_show(mbox);
1218 }
1219
1220 void display_mastergui()
1221 {
1222         GtkWidget *top;
1223         gtk_widget_realize(main_window);
1224         tX_set_icon(main_window, "terminatorX");
1225         load_knob_pixs(main_window);
1226
1227         gtk_widget_show(main_window);
1228         top=gtk_widget_get_toplevel(main_window);
1229         xwindow=GDK_WINDOW_XWINDOW(top->window);
1230 }
1231
1232 void add_to_panel_bar(GtkWidget *button) {
1233         buttons_on_panel_bar++;
1234         gtk_box_pack_start(GTK_BOX(panel_bar), button, WID_DYN);
1235         gtk_widget_show(panel_bar);
1236 }
1237
1238 void remove_from_panel_bar(GtkWidget *button) {
1239         buttons_on_panel_bar--;
1240         gtk_container_remove(GTK_CONTAINER(panel_bar), button);
1241         if (buttons_on_panel_bar==0) gtk_widget_hide(panel_bar);
1242 }
1243