Last minute stuff - Alex
[terminatorX.git] / src / tX_mastergui.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2003  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 <gdk/gdkkeysyms.h>
32 #include "version.h"
33 #include "tX_global.h"
34 #include "tX_engine.h"
35 #include "tX_vttgui.h"
36 #include "tX_vtt.h"
37 #include "tX_flash.h"
38 #include "tX_dialog.h"
39 #include "tX_loaddlg.h"
40 #include "tX_seqpar.h"
41 #include "tX_pbutton.h"
42 #include "tX_sequencer.h"
43 #include "tX_mastergui.h"
44 #include "tX_knobloader.h"
45 #include "tX_glade_interface.h"
46 #include "tX_glade_support.h"
47 #include <sys/time.h>
48 #include <sys/wait.h>
49 #include "tX_midiin.h"
50
51 #ifdef USE_SCHEDULER
52 #include <sys/resource.h>
53 #endif
54
55 #define TX_SET_ID_10 "terminatorX turntable set file - version 1.0 - data:"
56 #define TX_SET_ID_11 "terminatorX turntable set file - version 1.1 - data:"
57 #define TX_SET_ID_12 "terminatorX turntable set file - version 1.2 - data:"
58 #define TX_SET_ID_13 "terminatorX turntable set file - version 1.3 - data:"
59 #define TX_SET_ID_14 "terminatorX turntable set file - version 1.4 - data:"
60
61 int audioon=0;
62 int sequencer_ready=1;
63
64 bool tX_shutdown=false;
65
66 GtkWidget *tt_parent;
67 GtkWidget *control_parent;
68 GtkWidget *audio_parent;
69 GtkWidget *main_window;
70 GtkWidget *grab_button;
71 GtkWidget *main_flash_l;
72 GtkWidget *main_flash_r;
73
74 GtkWidget *seq_rec_btn;
75 GtkWidget *seq_play_btn;
76 GtkWidget *seq_stop_btn;
77 GtkAdjustment *seq_adj;
78 GtkWidget *seq_slider;
79 GtkWidget *seq_entry;
80 GtkWidget *panel_bar;
81
82 int buttons_on_panel_bar=0;
83
84 int seq_adj_care=1;
85 int seq_stop_override=0;
86
87 GtkAdjustment *volume_adj;
88 GtkAdjustment *pitch_adj;
89
90 /* seq-pars */
91 tX_seqpar_master_volume sp_master_volume;
92 tX_seqpar_master_pitch sp_master_pitch;
93
94 GtkWidget *engine_btn;
95
96 GtkWidget *main_menubar;
97 GtkWidget *rec_menu_item;
98 GtkWidget *fullscreen_item;
99
100 int rec_dont_care=0;
101 gint update_tag;
102
103 #define connect_entry(wid, func, ptr); g_signal_connect(G_OBJECT(wid), "activate", (GtkSignalFunc) func, (void *) ptr);
104 #define connect_adj(wid, func, ptr); g_signal_connect(G_OBJECT(wid), "value_changed", (GtkSignalFunc) func, (void *) ptr);
105 #define connect_button(wid, func, ptr); g_signal_connect(G_OBJECT(wid), "clicked", (GtkSignalFunc) func, (void *) ptr);
106
107 Window xwindow;
108 #define WID_DYN TRUE, TRUE, 0
109 #define WID_FIX FALSE, FALSE, 0
110 extern void add_vtt(GtkWidget *ctrl, GtkWidget *audio, char *fn);
111 extern void destroy_gui(vtt_class *vtt);
112 extern void gui_show_frame(vtt_class *vtt, int show);
113
114 GdkWindow *save_dialog_win=NULL;
115 GdkWindow *load_dialog_win=NULL;
116 GtkWidget *save_dialog=NULL;
117 GtkWidget *load_dialog=NULL;
118
119 GdkWindow *rec_dialog_win=NULL;
120 GtkWidget *rec_dialog=NULL;
121
122 GtkWidget *no_of_vtts=NULL;
123 GtkWidget *used_mem=NULL;
124
125 int stop_update=0;
126 int update_delay;
127
128 vtt_class *old_focus=NULL;
129
130 int grab_status=0;
131 int last_grab_status=0;
132
133 GtkWidget *delete_all_item=NULL;
134 GtkWidget *delete_all_vtt_item=NULL;
135
136 GtkTooltips *gui_tooltips=NULL;
137
138 void gui_set_tooltip(GtkWidget *wid, char *tip)
139 {
140         gtk_tooltips_set_tip(gui_tooltips, wid, tip, NULL);
141 }
142
143 void turn_audio_off(void)
144 {
145         if (audioon) {
146                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0);
147                 while (gtk_events_pending()) gtk_main_iteration();              
148         }
149 }
150
151
152 gint pos_update(gpointer data)
153 {
154         f_prec temp;
155
156         if (stop_update) {              
157                 cleanup_all_vtts();
158                 tX_seqpar :: update_all_graphics();
159                 if (old_focus) gui_show_frame(old_focus, 0);
160                 old_focus=NULL;
161                 gtk_tx_flash_clear(main_flash_l);
162                 gtk_tx_flash_clear(main_flash_r);
163                 gdk_flush();    
164                 update_tag=0;
165                 return(FALSE);
166         } else {
167                 update_all_vtts();
168                 
169                 /*left vu meter */
170                 temp=vtt_class::mix_max_l;
171                 vtt_class::mix_max_l=0;
172                 gtk_tx_flash_set_level(main_flash_l, temp);
173
174                 /*right vu meter */
175                 temp=vtt_class::mix_max_r;
176                 vtt_class::mix_max_r=0;
177                 gtk_tx_flash_set_level(main_flash_r, temp);
178                 
179                 if (vtt_class::focused_vtt!=old_focus) {
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                         last_grab_status=grab_status;
186                         if (!grab_status) {
187                                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(grab_button), 0);
188                         }
189                 }
190                 gdk_flush();    
191                 update_delay--;
192                 
193                 if (update_delay < 0) {
194                         seq_update();
195                         tX_seqpar :: update_all_graphics();
196                         update_delay=globals.update_delay;
197                 }
198                 return(TRUE);
199         }
200 }
201
202 void mg_update_status()
203 {
204         FILE *procfs;
205         pid_t mypid;
206         char filename[PATH_MAX];
207         char buffer[256];
208         int found=0;    
209         int mem;
210         
211         mypid=getpid();
212         sprintf(filename, "/proc/%i/status", mypid);
213         procfs=fopen(filename, "r");
214         if (procfs) {
215                 while((!feof(procfs)) && !found) {
216                         fgets(buffer, 256, procfs);
217                         
218                         if (strncmp("VmSize:", buffer, 7)==0) {
219                                 found=1;
220                                 sscanf(buffer, "VmSize: %i kB", &mem);
221                                 sprintf(buffer, "%i", mem);
222                                 gtk_label_set_text(GTK_LABEL(used_mem), buffer);
223                         }
224                 }
225         }
226         fclose(procfs); 
227         
228         sprintf(buffer, "%i", vtt_class::vtt_amount);
229         gtk_label_set_text(GTK_LABEL(no_of_vtts), buffer);
230 }
231
232 GtkSignalFunc new_table(GtkWidget *, char *fn)
233 {
234         turn_audio_off();
235                 
236         if (fn) {
237                 ld_create_loaddlg(TX_LOADDLG_MODE_SINGLE, 1);
238                 ld_set_filename(fn);
239         }
240         
241         add_vtt(control_parent, audio_parent, fn);                              
242         
243         if (fn) ld_destroy();           
244         mg_update_status();
245         
246 #ifdef USE_ALSA_MIDI_IN
247         if (globals.auto_assign_midi) tX_midiin::auto_assign_midi_mappings(NULL, NULL);
248 #endif
249         
250         return NULL;
251 }
252
253 bool tx_mg_have_setname=false;
254 char tx_mg_current_setname[PATH_MAX]="";
255
256 GtkSignalFunc new_tables() {
257         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), 
258                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
259                 "Are you sure you want to loose all turntables and events?");
260         
261         int res=gtk_dialog_run(GTK_DIALOG(dialog));
262         gtk_widget_destroy(dialog);
263                 
264         if (res!=GTK_RESPONSE_YES) {
265                 return NULL;
266         }
267
268         vtt_class::delete_all();
269         new_table(NULL, NULL);
270
271 #ifdef USE_ALSA_MIDI_IN
272         if (globals.auto_assign_midi) tX_midiin::auto_assign_midi_mappings(NULL, NULL);
273 #endif
274         
275         gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
276
277         return NULL;
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         char idbuff[256];
293         char wbuf[PATH_MAX];
294         xmlDocPtr doc;
295 #ifdef ENABLE_TX_LEGACY
296         FILE *in;
297 #endif  
298         turn_audio_off();
299         
300         strcpy(globals.tables_filename, buffer);
301         
302         doc = xmlParseFile(buffer);
303         if (doc) {
304                 vtt_class::load_all(doc, buffer);
305                 xmlFreeDoc(doc);
306         } 
307         
308 #ifdef ENABLE_TX_LEGACY
309         else {  
310                 in=fopen(buffer, "r");  
311         
312                 if (in) {
313                         fread(idbuff, strlen(TX_SET_ID_10), 1, in);
314                         if (strncmp(idbuff, TX_SET_ID_10, strlen(TX_SET_ID_10))==0) {
315                                 if (vtt_class::load_all_10(in, buffer)) tx_note("Error while reading set.", true);
316                         } else if (strncmp(idbuff, TX_SET_ID_11, strlen(TX_SET_ID_11))==0)      {
317                                 if (vtt_class::load_all_11(in, buffer)) tx_note("Error while reading set.", true);                      
318                         } else if (strncmp(idbuff, TX_SET_ID_12, strlen(TX_SET_ID_12))==0) {
319                                 if (vtt_class::load_all_12(in, buffer)) tx_note("Error while reading set.", true);                      
320                         } else if (strncmp(idbuff, TX_SET_ID_13, strlen(TX_SET_ID_13))==0) {
321                                 if (vtt_class::load_all_13(in, buffer)) tx_note("Error while reading set.", true);                      
322                         } else if (strncmp(idbuff, TX_SET_ID_14, strlen(TX_SET_ID_14))==0) {
323                                 if (vtt_class::load_all_14(in, buffer)) tx_note("Error while reading set.", true);                      
324                         }       else {
325                                 tx_note("This file is not a terminatorX set-file.", true);
326                                 fclose(in);
327                                 return;
328                         }
329                         fclose(in);     
330                 } else {
331                         strcpy(idbuff, "Failed to access file: \"");    // I'm stealing the unrelated sting for a temp :)
332                         strcat(idbuff, globals.tables_filename);
333                         strcat(idbuff, "\"");
334                         tx_note(idbuff, true);
335                         
336                         return;
337                 }
338         }
339 #else
340         else {
341                 strcpy(idbuff, "Failed to access file: \"");    // I'm stealing the unrelated sting for a temp :)
342                 strcat(idbuff, globals.tables_filename);
343                 strcat(idbuff, "\"");
344                 tx_note(idbuff, true);
345                 
346                 return;
347         }
348 #endif  
349         
350         tx_mg_have_setname=true;
351         strcpy(tx_mg_current_setname, buffer);
352         
353         tX_seqpar :: init_all_graphics();
354         vg_init_all_non_seqpars();
355                 
356         gtk_adjustment_set_value(volume_adj, globals.volume);
357         gtk_adjustment_set_value(pitch_adj, globals.pitch);
358         sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
359 #ifdef USE_ALSA_MIDI_IN
360         if (globals.auto_assign_midi) tX_midiin::auto_assign_midi_mappings(NULL, NULL);
361 #endif  
362         gtk_window_set_title(GTK_WINDOW(main_window), wbuf);            
363 }
364
365 void do_load_tables(GtkWidget *wid)
366 {
367         char buffer[PATH_MAX];
368         
369         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(load_dialog)));
370         
371         gtk_widget_destroy(load_dialog);
372         
373         load_dialog=NULL;
374         load_dialog_win=NULL;
375
376         tX_cursor::set_cursor(tX_cursor::WAIT_CURSOR);
377         load_tt_part(buffer);
378         tX_cursor::reset_cursor();
379 }
380
381 GtkSignalFunc load_tables()
382 {
383         if (load_dialog_win) {
384                 gdk_window_raise(load_dialog_win);
385                 return 0;
386         }
387         
388         load_dialog=gtk_file_selection_new("Load Set"); 
389         
390         gtk_file_selection_show_fileop_buttons(GTK_FILE_SELECTION(load_dialog));
391         gtk_file_selection_complete(GTK_FILE_SELECTION(load_dialog), "*.tX");
392         
393         if (strlen(globals.tables_filename)) {
394                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(load_dialog), globals.tables_filename);
395         }
396         
397         gtk_widget_show(load_dialog);
398         
399         load_dialog_win=load_dialog->window;
400         
401         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(load_dialog)->ok_button), "clicked", G_CALLBACK(do_load_tables), NULL);
402         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(load_dialog)->cancel_button), "clicked", G_CALLBACK (cancel_load_tables), NULL);  
403         g_signal_connect (G_OBJECT(load_dialog), "delete-event", G_CALLBACK(cancel_load_tables), NULL); 
404         
405         return NULL;
406 }
407
408 GtkSignalFunc drop_set(GtkWidget *widget, GdkDragContext *context,
409                 gint x, gint y, GtkSelectionData *selection_data,
410                 guint info, guint time, vtt_class *vtt)
411 {
412         char filename[PATH_MAX];
413         char *fn;
414         
415         strncpy(filename, (char *) selection_data->data, (size_t) selection_data->length);
416         filename[selection_data->length]=0;
417
418         fn = strchr (filename, '\r');
419         *fn=0;  
420         
421         fn = strchr (filename, ':');
422         if (fn) fn++; else fn=(char *) selection_data->data;
423         
424         load_tt_part(fn);
425
426         strcpy (filename, "dont segfault workaround ;)");
427         return NULL;
428 }
429
430
431 /* save tables */
432
433 GtkSignalFunc cancel_save_tables(GtkWidget *wid)
434 {
435         gtk_widget_destroy(save_dialog);
436         save_dialog=NULL;
437         save_dialog_win=NULL;
438         return(0);
439 }
440
441 gboolean do_save_tables(GtkWidget *wid)
442 {
443         FILE *out;
444         gzFile zout;
445         char buffer[PATH_MAX];
446         char wbuf[PATH_MAX];
447         char *ext;
448         
449         if (wid) {
450                 strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(save_dialog)));
451                 int len=strlen(buffer);
452                 if (!len || (buffer[len-1]=='/')) {                     
453                         tx_note("Invalid filename for set file.", true);                        
454                         return FALSE;
455                 }
456                 strcpy(globals.tables_filename, buffer);
457                 gtk_widget_destroy(save_dialog);
458                 save_dialog=NULL;
459                 save_dialog_win=NULL;
460         } else {
461                 strcpy(buffer, tx_mg_current_setname);
462         }
463         
464         ext=strrchr(buffer, '.');
465         
466         if (ext) {
467                 if (strcmp(ext, ".tX")) strcat(buffer, ".tX");
468         } else {
469                 strcat(buffer, ".tX");
470         }
471
472         tx_mg_have_setname=true;
473         strcpy(tx_mg_current_setname, buffer);
474         
475         if (globals.compress_set_files) {
476                 _store_compress_xml=1;
477                 out=NULL;
478                 zout=gzopen(buffer, "w");
479         } else {
480                 _store_compress_xml=0;
481                 out=fopen(buffer, "w");
482                 zout=NULL;
483         }
484         
485         if (out || zout) {
486                 if (vtt_class::save_all(out, zout)) tx_note("Error while saving set.", true);
487                 if (out) fclose(out); 
488                 else if (zout) gzclose(zout);
489                 sprintf(wbuf,"terminatorX - %s", strip_path(buffer));
490                 gtk_window_set_title(GTK_WINDOW(main_window), wbuf);                            
491         } else {
492                 tx_note("Failed to open file for write access.", true);
493         }
494         
495         return FALSE;
496 }
497
498 GtkSignalFunc save_tables_as()
499 {
500         if (save_dialog_win) {
501                 gtk_widget_destroy(save_dialog);
502                 save_dialog=NULL;
503                 save_dialog_win=NULL;
504         }
505         
506         save_dialog=gtk_file_selection_new("Save Set"); 
507
508         if (tx_mg_have_setname) {
509                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(save_dialog), tx_mg_current_setname);
510         }
511         
512         gtk_widget_show(save_dialog);
513         
514         save_dialog_win=save_dialog->window;
515         
516         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(save_dialog)->ok_button), "clicked", G_CALLBACK(do_save_tables), NULL);
517         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(save_dialog)->cancel_button), "clicked", G_CALLBACK (cancel_save_tables), NULL);  
518         g_signal_connect (G_OBJECT(save_dialog), "delete-event", G_CALLBACK(cancel_save_tables), NULL); 
519
520         return NULL;
521 }
522
523 GtkSignalFunc save_tables()
524 {
525         if (!tx_mg_have_setname) {
526                 save_tables_as();
527         } else {
528                 do_save_tables(NULL);
529         }
530         
531         return NULL;
532 }
533
534 GtkSignalFunc master_volume_changed (GtkWidget *wid, void *d)
535 {
536         sp_master_volume.receive_gui_value((float) GTK_ADJUSTMENT(wid)->value);
537         return NULL;    
538 }
539
540 GtkSignalFunc master_pitch_changed(GtkWidget *wid, void *d)
541 {
542         sp_master_pitch.receive_gui_value((float) GTK_ADJUSTMENT(wid)->value);  
543         return NULL;    
544 }
545
546 void mg_enable_critical_buttons(int enable)
547 {
548         gtk_widget_set_sensitive(seq_rec_btn, enable);
549         gtk_widget_set_sensitive(seq_play_btn, enable);
550         gtk_widget_set_sensitive(seq_slider, enable);
551
552         gtk_widget_set_sensitive(rec_menu_item, enable);
553         gtk_widget_set_sensitive(delete_all_item, enable);
554         gtk_widget_set_sensitive(delete_all_vtt_item, enable);
555         
556         vg_enable_critical_buttons(enable);
557 }
558
559
560 GtkSignalFunc seq_stop(GtkWidget *w, void *);
561
562 static bool stop_override=false;
563
564 GtkSignalFunc audio_on(GtkWidget *w, void *d)
565 {
566         tX_engine_error res;
567         
568         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {               
569                 sequencer_ready=0;
570                 mg_enable_critical_buttons(0);
571                 res=tX_engine::get_instance()->run();
572
573                 if (res!=NO_ERROR) {
574                         mg_enable_critical_buttons(1);
575                         stop_override=true;
576                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
577                         stop_override=false;                    
578
579                         switch(res) {
580                                 case ERROR_BUSY:
581                                 tx_note("Error starting engine: engine is already running.", true);
582                                 break;
583                                 case ERROR_AUDIO:
584                                 tx_note("Error starting engine: failed to access audiodevice.\nPlease check the audio device settings in the \"Preferences\" dialog.", true);
585                                 break;
586                                 case ERROR_TAPE:
587                                 tx_note("Error starting engine: failed to open the recording file.", true);
588                                 break;
589                                 default:tx_note("Error starting engine: Unknown error.", true);
590                         }
591                         
592                         return 0;
593                 }
594                 
595                 sequencer_ready=1;
596                 stop_update=0;
597                 audioon=1;
598                 update_delay=globals.update_delay;
599                 update_tag=gtk_timeout_add(globals.update_idle, (GtkFunction) pos_update, NULL);
600                 gtk_widget_set_sensitive(grab_button, 1);
601         } else {        
602                 if (stop_override) return NULL;
603                 if (!sequencer_ready) return NULL;
604                 gtk_widget_set_sensitive(grab_button, 0);
605                 tX_engine::get_instance()->stop();
606                 stop_update=1;
607                 audioon=0;
608                 if (tX_engine::get_instance()->get_recording_request()) {
609                         tX_engine::get_instance()->set_recording_request(false);
610                         rec_dont_care=1;
611                         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(rec_menu_item), 0);
612                         rec_dont_care=0;
613                 }
614                 
615                 seq_stop(NULL, NULL);
616                 mg_enable_critical_buttons(1);
617         }
618         
619         return NULL;
620 }
621
622 GtkSignalFunc cancel_rec(GtkWidget *wid)
623 {
624         gtk_widget_destroy(rec_dialog);
625         rec_dialog=NULL;
626         rec_dialog_win=NULL;
627         rec_dont_care=0;
628         return(0);
629 }
630
631 void do_rec(GtkWidget *wid)
632 {
633         char buffer[PATH_MAX];
634         
635         strcpy(buffer, gtk_file_selection_get_filename(GTK_FILE_SELECTION(rec_dialog)));
636
637         if (strlen(buffer)) {
638                 strcpy(globals.record_filename, buffer);                
639                 tX_engine::get_instance()->set_recording_request(true);
640                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(rec_menu_item), 1);
641         }
642         
643         rec_dont_care=0;
644         
645         gtk_widget_destroy(rec_dialog);
646         
647         rec_dialog=NULL;
648         rec_dialog_win=NULL;
649 }
650
651 GtkSignalFunc select_rec_file()
652 {
653         if (rec_dialog_win) {
654                 gdk_window_raise(rec_dialog_win);
655                 return 0;
656         }
657         
658         rec_dialog=gtk_file_selection_new("Record To Disk");    
659         
660         if (strlen(globals.record_filename)) {
661                 gtk_file_selection_set_filename(GTK_FILE_SELECTION(rec_dialog), globals.record_filename);
662         }
663         
664         gtk_widget_show(rec_dialog);
665         
666         rec_dialog_win=rec_dialog->window;
667         
668         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(rec_dialog)->ok_button), "clicked", G_CALLBACK(do_rec), NULL);
669         g_signal_connect (G_OBJECT(GTK_FILE_SELECTION(rec_dialog)->cancel_button), "clicked", G_CALLBACK (cancel_rec), NULL);   
670         g_signal_connect (G_OBJECT(rec_dialog), "delete-event", G_CALLBACK(cancel_rec), NULL);  
671         
672         return NULL;
673 }
674
675 GtkSignalFunc tape_on(GtkWidget *w, void *d)
676 {
677         if (rec_dont_care) return 0;
678
679         if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))) {   
680                 rec_dont_care=1;
681                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 0);
682                 select_rec_file();
683         } else {
684                         tX_engine::get_instance()->set_recording_request(false);
685         }
686         
687         return NULL;
688 }
689
690 void grab_on(GtkWidget *w, void *d)
691 {
692         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
693                 tX_engine::get_instance()->set_grab_request();
694         }
695         grab_status=1;
696 }
697
698 void grab_off()
699 {
700         grab_status=0;
701 }
702
703 gboolean quit()
704 {       
705         if (globals.quit_confirm) {
706                 GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), 
707                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
708                 "Exit terminatorX and loose all unsaved data?");
709                 
710                 int res=gtk_dialog_run(GTK_DIALOG(dialog));
711                 gtk_widget_destroy(dialog);
712                         
713                 if (res!=GTK_RESPONSE_YES) {
714                         return TRUE;
715                 }
716         }
717         
718         tX_shutdown=true;
719         
720         turn_audio_off();
721         vtt_class::delete_all();
722
723         if (update_tag)
724         gtk_timeout_remove(update_tag);
725         globals.width=main_window->allocation.width;
726         globals.height=main_window->allocation.height;
727
728         gtk_main_quit();
729         
730         return true;
731 }
732
733 void mplcfitx()
734 /* Most Probably Least Called Function In terminatorX :) */
735 {
736         show_about(0);
737 }
738
739 GtkSignalFunc seq_play(GtkWidget *w, void *)
740 {
741         if ((sequencer.is_empty()) &&   (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(seq_rec_btn)))) {
742                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
743                  {
744                         tx_note("Sequencer playback triggered - but no events recorded yet - nothing to playback!\n\nTo perform live with terminatorX just activate the audio engine with the \"Power\" button.");
745                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);
746                  }
747         } else {
748                 if (seq_stop_override) return NULL;
749                         
750                 seq_adj_care=0;
751                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
752                 sequencer.trig_play();
753         
754                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 1);
755         }
756         
757         return NULL;
758 }
759
760 GtkSignalFunc seq_stop(GtkWidget *w, void *)
761 {
762         if (!sequencer_ready) return NULL;
763         sequencer.trig_stop();
764         seq_adj_care=1;
765         seq_stop_override=1;
766         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_play_btn), 0);
767         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(seq_rec_btn), 0);
768         while (gtk_events_pending()) gtk_main_iteration();              
769         seq_stop_override=0;
770         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(engine_btn), 0); 
771         gtk_widget_set_sensitive(seq_slider, 1);        
772         gtk_widget_set_sensitive(engine_btn, 1);
773         gtk_widget_set_sensitive(seq_rec_btn, 1);
774
775         return NULL;
776 }
777
778 GtkSignalFunc seq_rec(GtkWidget *w, void *)
779 {
780         seq_adj_care=0;
781         gtk_widget_set_sensitive(seq_slider, 0);
782
783         if (seq_stop_override) return NULL;
784         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1);
785         gtk_widget_set_sensitive(engine_btn, 0);
786         gtk_widget_set_sensitive(seq_rec_btn, 0);
787         sequencer.trig_rec();
788         
789         return NULL;
790 }
791
792 void seq_update_entry(const guint32 timestamp)
793 {
794         char buffer[20];
795         guint32 samples;
796         guint32 minu,sec,hun;   
797         guint32 sr;
798         
799         samples=timestamp*vtt_class::get_mix_buffer_size();
800         sr=vtt_class::get_last_sample_rate();
801         
802         if (samples>0) {
803                 minu=samples/(sr*60);
804                 samples-=(sr*60)*minu;
805         
806                 sec=samples/sr;
807                 samples-=sr*sec;
808         
809                 hun=samples/(sr/100);
810         } else {
811                 minu=sec=hun=0;
812         }
813         
814         sprintf(buffer, "%02i:%02i.%02i", minu, sec, hun);
815         gtk_entry_set_text(GTK_ENTRY(seq_entry), buffer);
816 }
817
818 void seq_update()
819 {
820         seq_update_entry(sequencer.get_timestamp());
821         gtk_adjustment_set_value(seq_adj, sequencer.get_timestamp_as_float());
822         
823 }
824 gboolean seq_slider_released(GtkWidget *wid, void *d)
825 {
826         seq_adj_care=0;
827         gtk_widget_set_sensitive(seq_slider, 0);        
828         sequencer.forward_to_start_timestamp(0);
829         gtk_widget_set_sensitive(seq_slider, 1);        
830         seq_adj_care=1;
831         
832         return FALSE;
833 }
834 void sequencer_move(GtkWidget *wid, void *d)
835 {
836         guint32 pos;
837         
838         if (seq_adj_care) {
839                 pos=sequencer.set_start_timestamp((float) GTK_ADJUSTMENT(wid)->value);
840                 seq_update_entry(pos);  
841         }
842 }
843
844 #define add_sep();      dummy=gtk_hseparator_new ();\
845         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);\
846         gtk_widget_show(dummy);\
847
848 #define add_sep2();     dummy=gtk_hseparator_new ();\
849         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);\
850         gtk_widget_show(dummy);\
851
852 void fullscreen_toggle(GtkCheckMenuItem *item, gpointer data);
853 void display_help();
854 void display_browser();
855
856 tX_seqpar *del_sp=NULL;
857 vtt_class *del_vtt=NULL;
858 tx_menu_del_mode menu_del_mode=ALL_EVENTS_ALL_TURNTABLES;
859
860 GtkWidget *del_dialog=NULL;
861
862 GCallback menu_delete_all_events(GtkWidget *, void *param)
863 {       
864         del_dialog=create_tx_del_mode();
865         tX_set_icon(del_dialog);
866         
867         GtkWidget *label=lookup_widget(del_dialog, "delmode_label");
868         
869         menu_del_mode=ALL_EVENTS_ALL_TURNTABLES;
870         
871         gtk_label_set_markup(GTK_LABEL(label), "Delete <b>all</b> events for <b>all</b> turntables.");
872         gtk_widget_show(del_dialog);
873         
874         return NULL;
875 }
876
877 GCallback menu_delete_all_events_for_vtt(GtkWidget *, vtt_class *vtt)
878 {       
879         if (!vtt) {
880                 tX_error("No vtt passed to menu_delete_all_events_for_vtt().");
881                 return FALSE;
882         }
883         
884         char label_str[512];
885         
886         del_dialog=create_tx_del_mode();
887         tX_set_icon(del_dialog);
888
889         del_vtt=vtt;
890         GtkWidget *label=lookup_widget(del_dialog, "delmode_label");
891         
892         menu_del_mode=ALL_EVENTS_FOR_TURNTABLE;
893         
894         sprintf(label_str, "Delete <b>all</b> events for turntable <b>%s</b>.", vtt->name);
895         gtk_label_set_markup(GTK_LABEL(label), label_str);
896         gtk_widget_show(del_dialog);
897         
898         return NULL;
899 }
900
901 GCallback menu_delete_all_events_for_sp(GtkWidget *, tX_seqpar *sp)
902 {       
903         if (!sp) {
904                 tX_error("No sp passed to menu_delete_all_events_for_sp().");
905                 return FALSE;
906         }
907         
908         char label_str[512];
909         
910         del_dialog=create_tx_del_mode();
911         tX_set_icon(del_dialog);
912         
913         GtkWidget *label=lookup_widget(del_dialog, "delmode_label");
914         
915         menu_del_mode=ALL_EVENTS_FOR_SP;
916         del_sp=sp;
917         sprintf(label_str, "Delete all <b>%s</b> events for turntable <b>%s</b>.", sp->get_name(), ((vtt_class *) sp->vtt)->name);
918         gtk_label_set_markup(GTK_LABEL(label), label_str);
919         gtk_widget_show(del_dialog);
920
921         return NULL;
922 }
923
924 static GtkWidget *table_menu=NULL;
925 static GtkWidget *table_menu_item=NULL;
926
927 GCallback create_table_sequencer_menu(GtkWidget *widget, void *param) 
928 {
929         char label[328];
930         table_menu=gtk_menu_new();
931         
932         list <vtt_class *> :: iterator vtt;
933
934         for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
935                 GtkWidget *menu_item=gtk_menu_item_new_with_label((*vtt)->name);
936                 gtk_container_add (GTK_CONTAINER (table_menu), menu_item);
937                 gtk_widget_show(menu_item);
938                 
939                 GtkWidget *seqpar_menu=gtk_menu_new();
940                 list <tX_seqpar *> :: iterator sp;
941                 
942                 GtkWidget *all=gtk_menu_item_new_with_label("Delete All Events");
943                 gtk_container_add (GTK_CONTAINER (seqpar_menu), all);
944                 g_signal_connect(all, "activate", (GCallback) menu_delete_all_events_for_vtt, (*vtt));
945                 gtk_widget_show(all);
946
947                 GtkWidget *sep = gtk_menu_item_new ();
948                 gtk_widget_show(sep);
949                 gtk_container_add(GTK_CONTAINER (seqpar_menu), sep);
950                 gtk_widget_set_sensitive (sep, FALSE);
951                 
952                 for (sp=tX_seqpar::all.begin(); sp!=tX_seqpar::all.end(); sp++) {
953                         if ((*sp)->vtt==(*vtt)) {
954                                 sprintf(label, "Delete '%s' Events", (*sp)->get_name());
955                                 GtkWidget *menu_item=gtk_menu_item_new_with_label(label);
956                                 g_signal_connect(menu_item, "activate", (GCallback) menu_delete_all_events_for_sp, (*sp));
957                                 gtk_container_add(GTK_CONTAINER(seqpar_menu), menu_item);
958                                 gtk_widget_show(menu_item);
959                         }
960                 }
961                 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), seqpar_menu);
962         }
963         
964         gtk_menu_item_set_submenu(GTK_MENU_ITEM(table_menu_item), table_menu);
965         
966         return NULL;
967 }
968
969 GCallback toggle_confirm_events(GtkWidget *widget, void *dummy)
970 {       
971         globals.confirm_events=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));     
972         return NULL;    
973 }
974
975 GCallback toggle_auto_assign(GtkWidget *widget, void *dummy)
976 {       
977         globals.auto_assign_midi=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
978 #ifdef USE_ALSA_MIDI_IN
979         tX_midiin::auto_assign_midi_mappings(NULL, NULL);
980 #endif
981 /*      if (globals.auto_assign_midi) {
982                 GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), 
983                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO,
984                 "Note: Enabling \"Auto Assign Default MIDI Settings\" will constantly overwrite the\
985 MIDI mappings for the standard parameters. \
986 Are you sure you really want this?");
987                 
988                 int res=gtk_dialog_run(GTK_DIALOG(dialog));
989                 gtk_widget_destroy(dialog);
990                         
991                 if (res!=GTK_RESPONSE_YES) {
992                         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), 0);
993                 }                       
994         } */
995         return NULL;    
996 }
997
998 void create_master_menu() 
999 {
1000         GtkWidget *menu_item;
1001         GtkWidget *sub_menu;
1002         GtkAccelGroup* accel_group=gtk_accel_group_new();
1003         gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group);
1004
1005         /* FILE */
1006         menu_item = gtk_menu_item_new_with_mnemonic ("_File");
1007         gtk_widget_show (menu_item);
1008         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1009
1010         sub_menu = gtk_menu_new ();
1011         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1012
1013         menu_item = gtk_image_menu_item_new_from_stock ("gtk-new", accel_group);
1014         gtk_widget_show (menu_item);
1015         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1016         g_signal_connect(menu_item, "activate", (GCallback) new_tables, NULL);
1017
1018         menu_item = gtk_image_menu_item_new_from_stock ("gtk-open", accel_group);
1019         gtk_widget_show (menu_item);
1020         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1021         g_signal_connect(menu_item, "activate", (GCallback) load_tables, NULL);
1022
1023         menu_item = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
1024         gtk_widget_show (menu_item);
1025         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1026         g_signal_connect(menu_item, "activate", (GCallback) save_tables, NULL);
1027
1028         menu_item = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
1029         gtk_widget_show (menu_item);
1030         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1031         g_signal_connect(menu_item, "activate", (GCallback) save_tables_as, NULL);
1032
1033         menu_item = gtk_menu_item_new ();
1034         gtk_widget_show (menu_item);
1035         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1036         gtk_widget_set_sensitive (menu_item, FALSE);
1037
1038         menu_item = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
1039         gtk_widget_show (menu_item);
1040         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1041         g_signal_connect(menu_item, "activate", (GCallback) quit, NULL);
1042
1043         /* Turntables */
1044         menu_item = gtk_menu_item_new_with_mnemonic ("_Turntables");
1045         gtk_widget_show (menu_item);
1046         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1047         
1048         sub_menu = gtk_menu_new ();
1049         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1050
1051         menu_item = gtk_menu_item_new_with_mnemonic("_Add Turntable");
1052         gtk_widget_show (menu_item);
1053         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1054         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_A, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);    
1055         g_signal_connect(menu_item, "activate", (GCallback) new_table, NULL);
1056
1057         menu_item = gtk_menu_item_new ();
1058         gtk_widget_show (menu_item);
1059         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1060         gtk_widget_set_sensitive (menu_item, FALSE);
1061
1062         menu_item = gtk_menu_item_new_with_mnemonic("Assign _Default MIDI Mappings");
1063         gtk_widget_show (menu_item);
1064         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1065         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_M, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
1066
1067 #ifdef USE_ALSA_MIDI_IN
1068         g_signal_connect(menu_item, "activate", G_CALLBACK(tX_midiin::auto_assign_midi_mappings), (void *) true);
1069 #else
1070         gtk_widget_set_sensitive(menu_item, FALSE);
1071 #endif
1072
1073         menu_item = gtk_check_menu_item_new_with_mnemonic("A_uto Assign Default MIDI Mappings");
1074         gtk_widget_show (menu_item);
1075         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1076         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), globals.auto_assign_midi);
1077 #ifdef USE_ALSA_MIDI_IN 
1078         g_signal_connect(menu_item, "activate", (GCallback) toggle_auto_assign, NULL);
1079 #else
1080         gtk_widget_set_sensitive(menu_item, FALSE);
1081 #endif
1082
1083         menu_item = gtk_menu_item_new_with_mnemonic("_Clear MIDI Mappings");
1084         gtk_widget_show (menu_item);
1085         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1086         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_C, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
1087
1088 #ifdef USE_ALSA_MIDI_IN
1089         g_signal_connect(menu_item, "activate", G_CALLBACK(tX_midiin::clear_midi_mappings), (void *) true);
1090 #else
1091         gtk_widget_set_sensitive(menu_item, FALSE);
1092 #endif
1093
1094         menu_item = gtk_menu_item_new ();
1095         gtk_widget_show (menu_item);
1096         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1097         gtk_widget_set_sensitive (menu_item, FALSE);
1098
1099         menu_item = gtk_check_menu_item_new_with_mnemonic("_Record Audio To Disk");
1100         rec_menu_item = menu_item;
1101         gtk_widget_show (menu_item);
1102         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1103         g_signal_connect(menu_item, "activate", (GCallback) tape_on, NULL);
1104
1105         /* Sequencer */
1106         
1107         menu_item = gtk_menu_item_new_with_mnemonic("_Sequencer");
1108         gtk_widget_show (menu_item);
1109         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1110
1111         sub_menu = gtk_menu_new ();
1112         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1113                 
1114         table_menu = gtk_menu_new();
1115         menu_item = gtk_menu_item_new_with_mnemonic("Delete _Events");
1116         delete_all_vtt_item = menu_item;
1117         table_menu_item = menu_item;
1118         gtk_menu_item_set_submenu(GTK_MENU_ITEM(table_menu_item), table_menu);
1119         
1120         gtk_widget_show (menu_item);
1121         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1122         g_signal_connect_swapped (G_OBJECT (menu_item), "select", G_CALLBACK (create_table_sequencer_menu), NULL);
1123         
1124         menu_item = gtk_menu_item_new_with_mnemonic("Delete _All Events");
1125         delete_all_item = menu_item;
1126         gtk_widget_show (menu_item);
1127         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1128         g_signal_connect(menu_item, "activate", (GCallback) menu_delete_all_events, NULL);
1129
1130         menu_item = gtk_menu_item_new ();
1131         gtk_widget_show (menu_item);
1132         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1133         gtk_widget_set_sensitive (menu_item, FALSE);
1134
1135         menu_item = gtk_check_menu_item_new_with_mnemonic("_Confirm Recorded Events");
1136         //rec_menu_item = menu_item;
1137         gtk_widget_show (menu_item);
1138         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1139         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), globals.confirm_events);
1140         g_signal_connect(menu_item, "activate", (GCallback) toggle_confirm_events, NULL);
1141
1142         /* Options */
1143         menu_item = gtk_menu_item_new_with_mnemonic ("_Options");
1144         gtk_widget_show (menu_item);
1145         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1146
1147         sub_menu = gtk_menu_new ();
1148         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1149                 
1150         menu_item = gtk_check_menu_item_new_with_mnemonic("_Fullscreen");
1151         fullscreen_item = menu_item;
1152         gtk_widget_show (menu_item);
1153         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1154
1155         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), globals.fullscreen_enabled);
1156         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_F11, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
1157         g_signal_connect(menu_item, "activate", (GCallback) fullscreen_toggle, NULL);
1158         
1159         menu_item = gtk_menu_item_new ();
1160         gtk_widget_show (menu_item);
1161         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1162         gtk_widget_set_sensitive (menu_item, FALSE);
1163
1164         menu_item = gtk_image_menu_item_new_from_stock ("gtk-preferences", accel_group);
1165         gtk_widget_show (menu_item);
1166         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1167         g_signal_connect(menu_item, "activate", (GCallback) display_options, NULL);
1168
1169         /* HELP */ 
1170         menu_item = gtk_menu_item_new_with_mnemonic ("_Help");
1171         gtk_widget_show (menu_item);
1172         gtk_container_add (GTK_CONTAINER (main_menubar), menu_item);
1173         gtk_menu_item_set_right_justified(GTK_MENU_ITEM(menu_item), TRUE);
1174         
1175         sub_menu = gtk_menu_new ();
1176         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
1177
1178         menu_item = gtk_menu_item_new_with_mnemonic ("_Contents");
1179         gtk_widget_show (menu_item);
1180         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1181         g_signal_connect(menu_item, "activate", (GCallback) display_help, NULL);
1182         gtk_widget_add_accelerator (menu_item, "activate", accel_group, GDK_F1, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
1183
1184         menu_item = gtk_menu_item_new_with_mnemonic ("_About");
1185         gtk_widget_show (menu_item);
1186         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1187         g_signal_connect(menu_item, "activate", (GCallback) mplcfitx, NULL);
1188         
1189         menu_item = gtk_menu_item_new ();
1190         gtk_widget_show (menu_item);
1191         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1192         gtk_widget_set_sensitive (menu_item, FALSE);
1193
1194         menu_item = gtk_menu_item_new_with_mnemonic ("_Visit terminatorX.cx");
1195         gtk_widget_show (menu_item);
1196         gtk_container_add (GTK_CONTAINER (sub_menu), menu_item);
1197         g_signal_connect(menu_item, "activate", (GCallback) display_browser, NULL);
1198 }
1199
1200 void create_mastergui(int x, int y)
1201 {
1202         GtkWidget *mother_of_all_boxen;
1203         GtkWidget *main_vbox;
1204         GtkWidget *right_hbox;
1205         GtkWidget *left_hbox;
1206         GtkWidget *control_box;
1207         //GtkWidget *sequencer_box;
1208         GtkAdjustment *dumadj;
1209         GtkWidget *dummy;
1210         GtkWidget *master_vol_box;
1211         GtkWidget *status_box;
1212         
1213         gui_tooltips=gtk_tooltips_new();
1214
1215         main_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
1216
1217         gtk_window_set_wmclass(GTK_WINDOW(main_window), "terminatorX", "tX_mastergui");
1218
1219         gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
1220         
1221         gtk_container_set_border_width(GTK_CONTAINER(main_window), 5);
1222
1223         gtk_widget_realize(main_window);
1224         
1225         mother_of_all_boxen=gtk_vbox_new(FALSE, 5);
1226         gtk_container_add(GTK_CONTAINER(main_window), mother_of_all_boxen);
1227         gtk_widget_show(mother_of_all_boxen);   
1228         
1229         main_menubar=gtk_menu_bar_new();
1230         gtk_box_pack_start(GTK_BOX(mother_of_all_boxen), main_menubar, WID_FIX);
1231         gtk_widget_show(main_menubar);  
1232         
1233         create_master_menu();
1234         
1235         main_vbox=gtk_hbox_new(FALSE, 5);
1236         gtk_box_pack_start(GTK_BOX(mother_of_all_boxen), main_vbox, WID_DYN);
1237         gtk_widget_show(main_vbox);
1238         
1239         left_hbox=gtk_vbox_new(FALSE, 5);
1240         gtk_box_pack_start(GTK_BOX(main_vbox), left_hbox, WID_DYN);
1241         gtk_widget_show(left_hbox);
1242         
1243         control_box=gtk_hbox_new(FALSE, 5);
1244         gtk_box_pack_start(GTK_BOX(left_hbox), control_box, WID_FIX);
1245         gtk_widget_show(control_box);
1246         
1247         dummy=gtk_hseparator_new();
1248         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_FIX);
1249         gtk_widget_show(dummy);
1250
1251     /* control_box contents */
1252
1253         dummy=tx_xpm_label_box(TX_ICON_AUDIOENGINE, "Audio");
1254         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1255         gtk_widget_show(dummy);
1256         
1257         dummy=tx_xpm_button_new(TX_ICON_POWER,"Power ", 1);
1258         connect_button(dummy,audio_on, NULL);
1259         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1260         gui_set_tooltip(dummy, "Turn the audio engine on/off.");
1261         gtk_widget_show(dummy);
1262         engine_btn=dummy;
1263         
1264         grab_button=tx_xpm_button_new(TX_ICON_GRAB, "Mouse Grab ", 1);
1265         gtk_box_pack_start(GTK_BOX(control_box), grab_button, WID_FIX);
1266         connect_button(grab_button, grab_on, NULL);
1267         gui_set_tooltip(grab_button, "Enter the mouse grab mode operation. Press <ESCAPE> to exit grab mode.");
1268         gtk_widget_show(grab_button);
1269
1270         dummy=gtk_vseparator_new();
1271         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1272         gtk_widget_show(dummy);
1273     
1274         dummy=tx_xpm_label_box(TX_ICON_SEQUENCER, "Seq.");
1275         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1276         gtk_widget_show(dummy);
1277
1278         dummy=tx_xpm_button_new(TX_ICON_PLAY,"Play ", 1);
1279         connect_button(dummy, seq_play, NULL);
1280         seq_play_btn=dummy;
1281         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1282         gui_set_tooltip(dummy, "Playback previously recorded events from the sequencer. This will turn on the audio engine automagically.");
1283         gtk_widget_show(dummy);
1284
1285         dummy=tx_xpm_button_new(TX_ICON_STOP,"Stop ", 0);
1286         seq_stop_btn=dummy;
1287         connect_button(dummy, seq_stop, NULL);  
1288         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1289         gui_set_tooltip(dummy, "Stop the playback of sequencer events.");
1290         gtk_widget_show(dummy);
1291
1292         dummy=tx_xpm_button_new(TX_ICON_RECORD,"Record ", 1);
1293         connect_button(dummy, seq_rec, NULL);
1294         seq_rec_btn=dummy;
1295         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1296         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.");
1297         gtk_widget_show(dummy);
1298
1299         dummy=gtk_label_new("Pos:");
1300         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1301         gtk_widget_show(dummy);
1302         
1303         dummy=gtk_entry_new();
1304         gtk_entry_set_max_length(GTK_ENTRY(dummy), 12);
1305         seq_entry=dummy;
1306         //gtk_widget_set_usize(dummy, 65, 20);
1307         gtk_entry_set_text(GTK_ENTRY(dummy), "00:00.00");
1308         gtk_entry_set_width_chars(GTK_ENTRY(dummy), 9);
1309         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1310         gtk_widget_show(dummy);
1311
1312         dumadj=(GtkAdjustment*) gtk_adjustment_new(0, 0, 100, 0.1, 1, 1);
1313         seq_adj=dumadj;
1314         connect_adj(dumadj, sequencer_move, NULL);      
1315         dummy=gtk_hscale_new(dumadj);
1316         gtk_widget_set_size_request(dummy, 65, 20);
1317         seq_slider=dummy;
1318         g_signal_connect(G_OBJECT(seq_slider), "button-release-event", (GtkSignalFunc) seq_slider_released, NULL);
1319         gtk_scale_set_draw_value(GTK_SCALE(dummy), FALSE);
1320         
1321         gui_set_tooltip(dummy, "Select the start position for the sequencer in song-time.");
1322         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_DYN);
1323         gtk_widget_show(dummy);
1324         
1325         dummy=gtk_hbox_new(FALSE,2); //gtk_hpaned_new ();
1326         gtk_box_pack_start(GTK_BOX(left_hbox), dummy, WID_DYN);
1327         gtk_widget_show(dummy);
1328         
1329         tt_parent=dummy;
1330
1331     panel_bar=gtk_hbox_new(TRUE,2);
1332         gtk_box_pack_start(GTK_BOX(left_hbox), panel_bar, WID_FIX);
1333
1334         control_parent=gtk_hbox_new(FALSE,0);
1335         gtk_box_pack_start(GTK_BOX(tt_parent), control_parent, WID_FIX);
1336         gtk_widget_show(control_parent);
1337
1338         dummy=gtk_vseparator_new();
1339         gtk_box_pack_start(GTK_BOX(tt_parent), dummy, WID_FIX);
1340         gtk_widget_show(dummy);
1341
1342         audio_parent=gtk_vbox_new(FALSE,0);
1343         gtk_box_pack_start(GTK_BOX(tt_parent), audio_parent, WID_DYN);
1344         gtk_widget_show(audio_parent);
1345         
1346         dummy=gtk_vseparator_new();
1347         gtk_box_pack_start(GTK_BOX(main_vbox), dummy, WID_FIX);
1348         gtk_widget_show(dummy);
1349                 
1350         right_hbox=gtk_vbox_new(FALSE, 5);
1351         gtk_box_pack_start(GTK_BOX(main_vbox), right_hbox, WID_FIX);
1352         gtk_widget_show(right_hbox);
1353
1354         /* Master */
1355         
1356         dummy=gtk_label_new(NULL);
1357         gtk_label_set_markup(GTK_LABEL(dummy),"<b>Master</b>");
1358         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1359         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1360         gtk_widget_show(dummy); 
1361
1362         dummy=gtk_hseparator_new();
1363         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1364         gtk_widget_show(dummy);
1365
1366          /* Pitch */
1367          
1368         /*dummy=gtk_label_new("Pitch:");
1369         gtk_box_pack_start(GTK_BOX(control_box), dummy, WID_FIX);
1370         gtk_widget_show(dummy);*/
1371
1372         dumadj=(GtkAdjustment*) gtk_adjustment_new(globals.pitch, -3, 3, 0.001, 0.001, 0.01);
1373         pitch_adj=dumadj;
1374         connect_adj(dumadj, master_pitch_changed, NULL);
1375         
1376         tX_extdial *pdial=new tX_extdial("Pitch", pitch_adj, &sp_master_pitch, true);
1377         gtk_box_pack_start(GTK_BOX(right_hbox), pdial->get_widget(), WID_FIX);
1378         gui_set_tooltip(pdial->get_entry(), "Use this dial to adjust the master pitch (affecting *all* turntables).");
1379         
1380         dummy=gtk_hseparator_new();
1381         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1382         gtk_widget_show(dummy);
1383         
1384         /* Volume */
1385         master_vol_box=gtk_hbox_new(FALSE, 2);
1386         gtk_box_pack_start(GTK_BOX(right_hbox), master_vol_box, WID_DYN);
1387         gtk_widget_show(master_vol_box);        
1388         
1389         dumadj=(GtkAdjustment*) gtk_adjustment_new(globals.volume, 0, 2, 0.01, 0.05, 0.005);
1390         volume_adj=dumadj;
1391
1392         connect_adj(dumadj, master_volume_changed, NULL);       
1393         dummy=gtk_vscale_new(dumadj);
1394         gtk_range_set_inverted(GTK_RANGE(dummy), TRUE);
1395         gtk_scale_set_draw_value(GTK_SCALE(dummy), False);
1396         g_signal_connect(G_OBJECT(dummy), "button_press_event", (GtkSignalFunc) tX_seqpar::tX_seqpar_press, &sp_master_volume); 
1397         
1398         gtk_box_pack_end(GTK_BOX(master_vol_box), dummy, WID_FIX);
1399         gtk_widget_show(dummy); 
1400         gui_set_tooltip(dummy, "Adjust the master volume. This parameter will effect *all* turntables in the set.");
1401         
1402         main_flash_r=gtk_tx_flash_new();
1403         gtk_box_pack_end(GTK_BOX(master_vol_box), main_flash_r, WID_DYN);
1404         gtk_widget_show(main_flash_r);
1405
1406         main_flash_l=gtk_tx_flash_new();
1407         gtk_box_pack_end(GTK_BOX(master_vol_box), main_flash_l, WID_DYN);
1408         gtk_widget_show(main_flash_l);
1409
1410         dummy=gtk_label_new("Volume");
1411         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1412         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1413         gtk_widget_show(dummy);
1414
1415         /* STATUS BOX */ 
1416         dummy=gtk_hseparator_new();
1417         gtk_box_pack_start(GTK_BOX(right_hbox), dummy, WID_FIX);
1418         gtk_widget_show(dummy);
1419         
1420         status_box=gtk_vbox_new(FALSE, 0);
1421         gtk_box_pack_start(GTK_BOX(right_hbox), status_box, WID_FIX);
1422         gtk_widget_show(status_box);
1423         
1424         dummy=gtk_label_new("0");
1425         used_mem=dummy;
1426         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1427         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1428         gtk_widget_show(dummy);
1429
1430         dummy=gtk_label_new("Mem/kB:");
1431         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1432         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1433         gtk_widget_show(dummy);
1434         
1435         add_sep2();
1436
1437         dummy=gtk_label_new("1");
1438         no_of_vtts=dummy;
1439         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1440         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1441         gtk_widget_show(dummy);
1442
1443         dummy=gtk_label_new("Vtts:");
1444         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1445         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1446         gtk_widget_show(dummy);
1447
1448         add_sep2();
1449
1450         dummy=gtk_label_new(VERSION);
1451         gtk_misc_set_alignment(GTK_MISC(dummy), 1, 0.5);
1452         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1453         gtk_widget_show(dummy);
1454
1455         dummy=gtk_label_new("Release:");
1456         gtk_misc_set_alignment(GTK_MISC(dummy), 0, 0.5);
1457         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1458         gtk_widget_show(dummy);
1459         
1460         add_sep2();
1461
1462         dummy=gtk_label_new(NULL);
1463         gtk_label_set_markup(GTK_LABEL(dummy), "<b>Status</b>");
1464         gtk_misc_set_alignment(GTK_MISC(dummy), 0.5, 0.5);
1465         gtk_box_pack_end(GTK_BOX(status_box), dummy, WID_FIX);
1466         gtk_widget_show(dummy);
1467         
1468         /* END GUI */
1469         
1470         gtk_window_set_default_size(GTK_WINDOW(main_window), x, y);     
1471         gtk_widget_set_sensitive(grab_button, 0);
1472
1473         new_table(NULL, NULL); // to give the user something to start with ;)
1474
1475         g_signal_connect (G_OBJECT(main_window), "delete-event", (GtkSignalFunc) quit, NULL);   
1476         
1477         if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
1478         else gtk_tooltips_disable(gui_tooltips);
1479 }
1480
1481 gfloat old_percent=-1;
1482
1483 void note_destroy(GtkWidget *widget, GtkWidget *mbox)
1484 {
1485         gtk_widget_destroy(GTK_WIDGET(mbox));
1486 }
1487
1488 void tx_note(const char *message, bool isError)
1489 {
1490         char buffer[4096]="terminatorX ";
1491         if (isError) {
1492                 strcat(buffer, "note:\n\n");
1493         } else {
1494                 strcat(buffer, "error:\n\n");
1495         }
1496         
1497         strcat(buffer, message);
1498         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window),
1499                 GTK_DIALOG_DESTROY_WITH_PARENT,
1500                 isError ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
1501         gtk_dialog_run(GTK_DIALOG(dialog));
1502         gtk_widget_destroy(dialog);     
1503 }
1504
1505
1506 void tx_l_note(const char *message)
1507 {
1508         char buffer[4096]="Plugin info:\n\n";
1509         strcat(buffer, message);
1510         
1511         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window),
1512                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
1513         gtk_dialog_run(GTK_DIALOG(dialog));
1514         gtk_widget_destroy(dialog);     
1515 }
1516
1517
1518 void add_to_panel_bar(GtkWidget *button) 
1519 {
1520         buttons_on_panel_bar++;
1521         gtk_box_pack_start(GTK_BOX(panel_bar), button, WID_DYN);
1522         gtk_widget_show(panel_bar);
1523 }
1524
1525 void remove_from_panel_bar(GtkWidget *button) 
1526 {
1527         buttons_on_panel_bar--;
1528         gtk_container_remove(GTK_CONTAINER(panel_bar), button);
1529         if (buttons_on_panel_bar==0) gtk_widget_hide(panel_bar);
1530 }
1531
1532 /* Fullscreen code... */
1533 #define _WIN_LAYER_TOP          -1
1534 #define _WIN_LAYER_NORMAL       4
1535 #define _NET_WM_STATE_REMOVE    0
1536 #define _NET_WM_STATE_ADD       1
1537 #define _NET_WM_STATE_TOGGLE    2
1538
1539 void fullscreen_toggle(GtkCheckMenuItem *item, gpointer data) {
1540         XEvent xev;
1541         Window win=GDK_WINDOW_XID(main_window->window);
1542         Display *disp=GDK_WINDOW_XDISPLAY(main_window->window);
1543         
1544         globals.fullscreen_enabled=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(fullscreen_item));
1545         
1546         /* Top layer.. */
1547         xev.xclient.type = ClientMessage;
1548         xev.xclient.serial = 0;
1549         xev.xclient.send_event = True;
1550         xev.xclient.display = disp;
1551         xev.xclient.window = win;
1552         xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_WIN_LAYER");
1553         xev.xclient.format = 32;
1554         xev.xclient.data.l[0] = globals.fullscreen_enabled ? _WIN_LAYER_TOP : _WIN_LAYER_NORMAL ;
1555         XSendEvent(disp, GDK_WINDOW_XID (gdk_get_default_root_window ()),
1556                 False, SubstructureRedirectMask | SubstructureNotifyMask,
1557                 &xev);
1558         
1559         /* Fullscreen */
1560         xev.xclient.type = ClientMessage;
1561         xev.xclient.serial = 0;
1562         xev.xclient.send_event = True;
1563         xev.xclient.display = disp;
1564         xev.xclient.window = win;
1565         xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1566         xev.xclient.format = 32;
1567         xev.xclient.data.l[0] = globals.fullscreen_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
1568         xev.xclient.data.l[1] = gdk_x11_atom_to_xatom (gdk_atom_intern ("_NET_WM_STATE_FULLSCREEN", TRUE));
1569         xev.xclient.data.l[2] = gdk_x11_atom_to_xatom (GDK_NONE);
1570         XSendEvent(gdk_display, GDK_WINDOW_XID (gdk_get_default_root_window ()),
1571                 False, SubstructureRedirectMask | SubstructureNotifyMask,
1572                 &xev);  
1573 }
1574
1575 void fullscreen_setup() {
1576         if (globals.fullscreen_enabled) {
1577                 fullscreen_toggle(NULL, NULL);
1578         }
1579 }
1580
1581 void display_mastergui()
1582 {
1583         GtkWidget *top;
1584         gtk_widget_realize(main_window);
1585         tX_set_icon(main_window);
1586         load_knob_pixs();
1587         gtk_widget_show(main_window);
1588         fullscreen_setup();     
1589         top=gtk_widget_get_toplevel(main_window);
1590         xwindow=GDK_WINDOW_XWINDOW(top->window);
1591 }
1592
1593 pid_t help_child=0;
1594 GTimer *help_timer=NULL;
1595 int help_tag=-1;
1596
1597 int help_checker()
1598 {
1599         gdouble time;
1600         gulong ms;
1601         int status;
1602         int result=waitpid(help_child, &status, WNOHANG);
1603         
1604         if (result==0) {
1605                 time=g_timer_elapsed(help_timer, &ms);
1606                 if (time > 5) {
1607                         /* 5 seconds and it's still running - so we assume everything's OK. */
1608                         tX_debug("No longer waiting for gnome-help..");
1609                         gtk_idle_remove(help_tag);
1610                         help_tag=-1;
1611                 }
1612         } else {
1613                 /* We are still here and the child exited - that could mean trouble. */
1614                 tx_note("Couldn't run the gnome-help command (alias \"yelp\") to display the terminatorX manual. Please ensure that \"yelp\" is installed.", true);             
1615                 
1616                 gtk_idle_remove(help_tag);
1617                 help_tag=-1;
1618         }
1619         return TRUE;    
1620 }
1621
1622 #ifndef INSTALL_PREFIX
1623 #define INSTALL_PREFIX "/usr/local/share"
1624 #endif
1625
1626 void display_help()
1627 {       
1628         help_child=fork();
1629
1630         if (help_tag!=-1) {
1631                 gtk_idle_remove(help_tag);
1632                 if (help_timer) g_timer_destroy(help_timer);
1633                 help_child=0;
1634                 help_tag=-1;
1635                 help_timer=NULL;
1636         }
1637         
1638         if (help_child==0) {
1639                 // child
1640                 // execlp("gnome-help","gnome-help","ghelp:/" INSTALL_PREFIX "/terminatorX/doc/terminatorX-manual/C/terminatorX-manual.xml", NULL);
1641                 execlp("gnome-help","gnome-help","ghelp:/" XML_MANUAL, NULL);           
1642                 _exit(-1);
1643         } else if (help_child==-1) {
1644                 tx_note("System error: couldn't fork() to run the help process.", true);
1645         } else {
1646                 help_timer=g_timer_new();
1647                 g_timer_start(help_timer);
1648         
1649                 help_tag=gtk_idle_add((GtkFunction) help_checker, NULL);
1650         }
1651 }
1652
1653 pid_t browser_child=0;
1654 GTimer *browser_timer=NULL;
1655 int browser_tag=-1;
1656
1657 int browser_checker()
1658 {
1659         gdouble time;
1660         gulong ms;
1661         int status;
1662         int result=waitpid(browser_child, &status, WNOHANG);
1663         
1664         if (result==0) {
1665                 time=g_timer_elapsed(browser_timer, &ms);
1666                 if (time > 5) {
1667                         /* 5 seconds and it's still running - so we assume everything's OK. */
1668                         tX_debug("No longer waiting for a browser..");
1669                         gtk_idle_remove(browser_tag);
1670                         browser_tag=-1;
1671                 }
1672         } else {
1673                 /* We are still here and the child exited - that could mean trouble. */
1674                 tx_note("Failed to run a suitable web browser - if there's one installed on this system, please run it and forward yourself to:\nhttp://terminatorX.cx", true);         
1675                 
1676                 gtk_idle_remove(browser_tag);
1677                 browser_tag=-1;
1678         }
1679         return TRUE;    
1680 }
1681
1682 void display_browser()
1683 {       
1684         browser_child=fork();
1685
1686         if (browser_tag!=-1) {
1687                 gtk_idle_remove(browser_tag);
1688                 if (browser_timer) g_timer_destroy(browser_timer);
1689                 browser_child=0;
1690                 browser_tag=-1;
1691                 browser_timer=NULL;
1692         }
1693         
1694         if (browser_child==0) {
1695                 // child
1696                 execlp("mozilla","mozilla","http://terminatorX.cx", NULL);
1697                 execlp("netscape","netscape","http://terminatorX.cx", NULL);
1698                 execlp("galeon","galeon","http://terminatorX.cx", NULL);
1699                 execlp("konqueror","konqueror","http://terminatorX.cx", NULL);          
1700                 _exit(-1);
1701         } else if (browser_child==-1) {
1702                 tx_note("System error: couldn't fork() to run the browser process.", true);
1703         } else {
1704                 browser_timer=g_timer_new();
1705                 g_timer_start(browser_timer);
1706         
1707                 browser_tag=gtk_idle_add((GtkFunction) browser_checker, NULL);
1708         }
1709 }
1710
1711
1712
1713 GdkCursor *tX_cursor::cursors[MAX_CURSOR]={NULL, NULL, NULL};
1714 tX_cursor::cursor_shape tX_cursor::current_shape=tX_cursor::DEFAULT_CURSOR;
1715
1716 void tX_cursor::set_cursor(cursor_shape shape)
1717 {
1718         switch (shape) {
1719                 case DEFAULT_CURSOR:
1720                         cursors[shape]=NULL;
1721                         break;
1722                 
1723                 case WAIT_CURSOR:
1724                         if (!cursors[shape]) cursors[shape]=gdk_cursor_new(GDK_WATCH);
1725                         break;
1726                 
1727                 case WAIT_A_SECOND_CURSOR:
1728                         /* FIXME: What's that short-time wait cursor's id? */
1729                         if (!cursors[shape]) cursors[shape]=gdk_cursor_new(GDK_WATCH);
1730                         break;
1731                 
1732                 default:
1733                         tX_debug("No such cursor shape.");
1734                         return;
1735         }
1736         
1737         /* Still here? Ok... */
1738         current_shape=shape;
1739         
1740         gdk_window_set_cursor(main_window->window, cursors[shape]);
1741 }
1742
1743 GdkCursor *tX_cursor::get_cursor()
1744 {
1745         return cursors[current_shape];
1746 }
1747
1748 void tX_cursor::reset_cursor()
1749 {
1750         current_shape=DEFAULT_CURSOR;
1751         gdk_window_set_cursor(main_window->window, cursors[current_shape]);
1752 }