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