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