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