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