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