Fly my pretties!
[ardour.git] / gtk2_ardour / ardour_ui.h
1 /*
2     Copyright (C) 1999-2002 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __ardour_gui_h__
22 #define __ardour_gui_h__
23
24 /* need _BSD_SOURCE to get timersub macros */
25
26 #ifdef _BSD_SOURCE
27 #include <sys/time.h>
28 #else
29 #define _BSD_SOURCE
30 #include <sys/time.h>
31 #undef _BSD_SOURCE
32 #endif
33
34 #include <list>
35
36 #include <cmath>
37
38 #include <gtk-canvas.h>
39
40 #include <pbd/xml++.h>
41 #include <gtkmm2ext/gtk_ui.h>
42 #include <gtkmm2ext/pix.h>
43 #include <gtkmm2ext/spinner.h>
44 #include <gtkmm2ext/pixmap_button.h>
45 #include <gtkmm2ext/popup_selector.h>
46 #include <gtkmm2ext/click_box.h>
47 #include <gtkmm2ext/selector.h>
48 #include <ardour/ardour.h>
49 #include <ardour/session.h>
50
51 #include "audio_clock.h"
52 #include "ardour_dialog.h"
53 #include "editing.h"
54
55 class AudioClock;
56 class PublicEditor;
57 class Keyboard;
58 class MeterBridge;
59 class OptionEditor;
60 class Mixer_UI;
61 class ConnectionEditor;
62 class RouteParams_UI;
63 class SoundFileSelector;
64 class About;
65 class AddRouteDialog;
66 class NewSessionDialog;
67 class LocationUI;
68
69 namespace Gtkmm2ext {
70         class TearOff;
71 };
72
73 namespace ARDOUR {
74         class AudioEngine;
75         class Route;
76         class Port;
77         class IO;
78 };
79
80 namespace ALSA {
81         class MultiChannelDevice;
82 };
83
84 #define FRAME_NAME "BaseFrame"
85
86 class ARDOUR_UI : public Gtkmm2ext::UI
87 {
88   public:
89         ARDOUR_UI (int *argcp, char **argvp[], string rcfile);
90         ~ARDOUR_UI();
91         
92         void show ();
93         bool shown() { return shown_flag; }
94         
95         void show_splash ();
96         void hide_splash ();
97         
98         int load_session (string path, string snapshot, string* mix_template = 0);
99         bool session_loaded;
100         int build_session (string path, string snapshot, 
101                            uint32_t ctl_chns, 
102                            uint32_t master_chns,
103                            ARDOUR::Session::AutoConnectOption input_connect,
104                            ARDOUR::Session::AutoConnectOption output_connect,
105                            uint32_t nphysin,
106                            uint32_t nphysout,
107                            jack_nframes_t initial_length);
108         bool session_is_new() const { return _session_is_new; }
109
110         ARDOUR::Session* the_session() { return session; }
111
112         bool will_create_new_session_automatically() const {
113                 return _will_create_new_session_automatically;
114         }
115
116         void set_will_create_new_session_automatically (bool yn) {
117                 _will_create_new_session_automatically = yn;
118         }
119
120         void new_session (bool startup = false, std::string path = string());
121         gint cmdline_new_session (std::string path);
122         int  unload_session ();
123         void close_session() { unload_session(); }
124
125         int  save_state_canfail (string state_name = "");
126         void save_state (string state_name = "");
127         void restore_state (string state_name = "");
128
129         static double gain_to_slider_position (ARDOUR::gain_t g);
130         static ARDOUR::gain_t slider_position_to_gain (double pos);
131
132         static ARDOUR_UI *instance () { return theArdourUI; }
133
134         PublicEditor&     the_editor(){return *editor;}
135         Mixer_UI* the_mixer() { return mixer; }
136         
137         void allow_focus (bool yn);
138
139         static gint generic_focus_in_event (GdkEventFocus *);
140         static gint generic_focus_out_event (GdkEventFocus *);
141
142         void toggle_location_window ();
143         void toggle_big_clock_window ();
144         void toggle_connection_editor ();
145         void toggle_route_params_window ();
146         void toggle_tempo_window ();
147         void toggle_sfdb_window ();
148
149         SoundFileSelector& get_sfdb_window();
150
151         gint32 select_diskstream (GdkEventButton *ev);
152
153         Gtk::Tooltips& tooltips() { return _tooltips; }
154
155         static sigc::signal<void,bool> Blink;
156         static sigc::signal<void>      RapidScreenUpdate;
157         static sigc::signal<void>      SuperRapidScreenUpdate;
158         static sigc::signal<void,jack_nframes_t> Clock;
159
160         /* this is a helper function to centralize the (complex) logic for
161            blinking rec-enable buttons.
162         */
163
164         void rec_enable_button_blink (bool onoff, ARDOUR::DiskStream *, Gtk::Widget *w);
165
166         void name_io_setup (ARDOUR::AudioEngine&, string&, ARDOUR::IO& io, bool in);
167         void choose_io (ARDOUR::IO&, bool input);
168
169         static gint hide_and_quit (GdkEventAny *ev, ArdourDialog *);
170
171         XMLNode* editor_settings() const;
172         XMLNode* mixer_settings () const;
173         XMLNode* keyboard_settings () const;
174
175         void save_ardour_state ();
176         gboolean configure_handler (GdkEventConfigure* conf);
177
178         void do_transport_locate (jack_nframes_t position);
179         void halt_on_xrun_message ();
180
181         AudioClock primary_clock;
182         AudioClock secondary_clock;
183         AudioClock preroll_clock;
184         AudioClock postroll_clock;
185
186         void add_route ();
187         
188         void session_add_audio_track (int input_channels, int32_t output_channels) {
189                 session_add_audio_route (true, input_channels, output_channels);
190         }
191
192         void session_add_audio_bus (int input_channels, int32_t output_channels) {
193                 session_add_audio_route (false, input_channels, output_channels);
194         }
195
196         void session_add_midi_track ();
197
198         void set_engine (ARDOUR::AudioEngine&);
199
200         gint exit_on_main_window_close (GdkEventAny *);
201
202   protected:
203         friend class PublicEditor;
204
205         void toggle_metering ();
206         void toggle_clocking ();
207         void toggle_auto_play ();
208         void toggle_auto_input ();
209         void toggle_punch_in ();
210         void toggle_punch_out ();
211         void toggle_auto_return ();
212         void toggle_click ();
213         void toggle_follow ();
214
215         void toggle_session_auto_loop ();
216         void toggle_session_punch_in ();
217         
218         void toggle_options_window ();
219
220   private:
221         struct GlobalClickBox : public Gtk::VBox {
222             Gtkmm2ext::ClickBox  *box;
223             Gtk::Frame      frame;
224             Gtk::Label      label;
225             vector<string> &strings;
226             Gtk::Adjustment adjustment;
227
228             static void printer (char buf[32], Gtk::Adjustment &adj, void *arg);
229
230             GlobalClickBox (const string &str, vector<string> &vs)
231                     : strings (vs),
232                       adjustment (0, 0, vs.size() - 1, 1, 1, 0) {
233                     box = new Gtkmm2ext::ClickBox (&adjustment, "ClickButton");
234                     label.set_text (str);
235                     label.set_name ("GlobalButtonLabel");
236                     frame.add (*box);
237                     frame.set_shadow_type (Gtk::SHADOW_IN);
238                     pack_start (label);
239                     pack_start (frame);
240                     box->set_print_func (printer, this);
241                     box->set_wrap (true);
242             };
243         };
244
245         ARDOUR::AudioEngine                 *engine;
246         ARDOUR::Session                     *session;
247
248         Gtk::Tooltips          _tooltips;
249
250         void                     goto_editor_window ();
251         void                     goto_mixer_window ();
252         
253         Gtk::Table               adjuster_table;
254         Gtk::Frame               adjuster_frame;
255         Gtk::Fixed               adjuster_base;
256
257         GlobalClickBox     *online_control_button;
258         vector<string>      online_control_strings;
259
260         GlobalClickBox    *crossfade_time_button;
261         vector<string>     crossfade_time_strings;
262
263         GlobalClickBox    *mmc_id_button;
264         vector<string>     mmc_id_strings;
265
266         Gtk::ToggleButton   preroll_button;
267         Gtk::ToggleButton   postroll_button;
268
269         Gtk::Table          transport_table;
270         Gtk::Table          option_table;
271
272         static SoundFileSelector* sfdb_window;
273
274         int  setup_windows ();
275         void setup_session_menu ();
276         void setup_transport ();
277         void setup_clock ();
278         void setup_session_info ();
279         void setup_adjustables ();
280
281         Gtk::MenuBar* make_menubar ();
282         
283         static ARDOUR_UI *theArdourUI;
284
285         void startup ();
286         void shutdown ();
287
288         void finish();
289         int  ask_about_saving_session (string why);
290         gint ask_about_save_deleted (GdkEventAny*);
291         void save_session_choice_made (int);
292         int  save_the_session;
293
294         void queue_transport_change ();
295         void map_transport_state ();
296         int32_t do_engine_start ();
297         gint start_engine ();
298         
299         void engine_halted ();
300         void engine_stopped ();
301         void engine_running ();
302
303         void map_some_session_state (Gtk::ToggleButton& button,
304                                      bool (ARDOUR::Session::*get)() const);
305
306         void toggle_some_session_state (Gtk::ToggleButton& button,
307                                      bool (ARDOUR::Session::*get)() const,
308                                      void (ARDOUR::Session::*set)(bool));
309         void map_button_state ();
310
311         void clear_meters ();
312
313         static gint _blink  (void *);
314         void blink ();
315         gint blink_timeout_tag;
316         bool blink_on;
317         void start_blinking ();
318         void stop_blinking ();
319
320         void control_methods_adjusted ();
321         void mmc_device_id_adjusted ();
322
323   private:
324         Gtk::VBox     top_packer;
325
326         sigc::connection clock_signal_connection;
327         void         update_clocks ();
328         void         start_clocking ();
329         void         stop_clocking ();
330
331         class BigClockWindow : public ArdourDialog
332         {
333           public:
334                 BigClockWindow () : ArdourDialog ("big clock window") {};
335         };
336
337         AudioClock               big_clock;
338         Gtk::Frame               big_clock_frame;
339         BigClockWindow*          big_clock_window;
340
341         void big_clock_size_event (GtkAllocation *alloc);
342         void big_clock_realize ();
343
344         /* Transport Control */
345
346         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
347         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
348
349         Gtkmm2ext::TearOff*       transport_tearoff;
350         Gtk::Frame               transport_frame;
351         Gtk::HBox                transport_tearoff_hbox;
352         Gtk::HBox                transport_hbox;
353         Gtk::Fixed               transport_base;
354         Gtk::Fixed               transport_button_base;
355         Gtk::Frame               transport_button_frame;
356         Gtk::HBox                transport_button_hbox;
357         Gtk::VBox                transport_button_vbox;
358         Gtk::HBox                transport_option_button_hbox;
359         Gtk::VBox                transport_option_button_vbox;
360         Gtk::HBox                transport_clock_hbox;
361         Gtk::VBox                transport_clock_vbox;
362         Gtk::HBox                primary_clock_hbox;
363         Gtk::HBox                secondary_clock_hbox;
364
365         Gtk::Button goto_start_button;
366         Gtk::Button goto_end_button;
367         Gtk::Button rewind_button;
368         Gtk::Button forward_button;
369         Gtk::Button stop_button;
370
371         enum ShuttleBehaviour {
372                 Sprung,
373                 Wheel
374         };
375
376         enum ShuttleUnits {
377                 Percentage,
378                 Semitones
379         };
380
381         Gtk::DrawingArea shuttle_box;
382         Gtk::EventBox    speed_display_box;
383         Gtk::Label       speed_display_label;
384         Gtk::Button      shuttle_units_button;
385         Gtk::Button      shuttle_style_button;
386         Gtk::Menu        shuttle_unit_menu;
387         Gtk::Menu        shuttle_style_menu;
388         ShuttleBehaviour shuttle_behaviour;
389         ShuttleUnits     shuttle_units;
390
391         void shuttle_style_clicked ();
392         void shuttle_unit_clicked ();
393         void set_shuttle_behaviour (ShuttleBehaviour);
394         void set_shuttle_units (ShuttleUnits);
395         void update_speed_display ();
396
397         gint shuttle_box_button_press (GdkEventButton*);
398         gint shuttle_box_button_release (GdkEventButton*);
399         gint shuttle_box_motion (GdkEventMotion*);
400         gint shuttle_box_expose (GdkEventExpose*);
401         gint mouse_shuttle (double x, bool force);
402         void use_shuttle_fract (bool force);
403
404         bool   shuttle_grabbed;
405         double shuttle_fract;
406
407         Gtk::ToggleButton auto_loop_button;
408         Gtk::ToggleButton play_selection_button;
409         Gtk::ToggleButton roll_button;
410
411         Gtk::ToggleButton rec_button;
412         Gtk::ToggleButton punch_in_button;
413         Gtk::ToggleButton punch_out_button;
414         Gtk::ToggleButton auto_return_button;
415         Gtk::ToggleButton auto_play_button;
416         Gtk::ToggleButton auto_input_button;
417         Gtk::ToggleButton click_button;
418         Gtk::ToggleButton follow_button;
419         Gtk::ToggleButton auditioning_alert_button;
420         Gtk::ToggleButton solo_alert_button;
421
422         Gtk::VBox alert_box;
423         
424         void follow_changed ();
425
426         void solo_blink (bool);
427         void audition_blink (bool);
428
429         void soloing_changed (bool);
430         void auditioning_changed (bool);
431         void _auditioning_changed (bool);
432
433         void solo_alert_toggle ();
434         void audition_alert_toggle ();
435
436         void primary_clock_value_changed ();
437         void secondary_clock_value_changed ();
438
439         /* called by Blink signal */
440
441         void transport_rec_enable_blink (bool onoff);
442
443         /* These change where we accept control from:
444            MMC, X (local) or both.
445         */
446
447         void allow_mmc_only ();
448         void allow_mmc_and_local ();
449         void allow_local_only ();
450
451         static void rate_printer (char buf[32], Gtk::Adjustment &, void *);
452
453         Gtk::Menu*   session_popup_menu;
454         Gtk::CTree   session_selector;
455         ArdourDialog* session_selector_window;
456         
457         Gtk::FileSelection* open_session_selector;
458         
459         void build_session_selector();
460         void session_selection (Gtk::CTree::Row, gint col);
461         struct RecentSessionsSorter {
462           bool operator() (std::pair<string,string> a, std::pair<string,string> b) const {
463             return cmp_nocase(a.first, b.first) == -1;
464             }
465         };
466         void redisplay_recent_sessions();
467
468         /* menu bar and associated stuff */
469
470         Gtk::MenuBar menu_bar;
471         Gtk::Fixed   menu_bar_base;
472         Gtk::HBox    menu_hbox;
473
474         void build_menu_bar ();
475         void pack_toplevel_controls();
476
477         /* handles on the menu bar items that need to 
478            be sensitive to whether or not we have
479            a session loaded.
480         */
481
482         Gtk::MenuItem *add_track_item;
483         Gtk::MenuItem *save_item;
484         Gtk::MenuItem *snapshot_item;
485         Gtk::MenuItem *save_as_item;
486         Gtk::MenuItem *save_template_item;
487         Gtk::MenuItem *export_item;
488         Gtk::MenuItem *close_item;
489
490         Gtk::CheckMenuItem *meter_bridge_dialog_check;
491         Gtk::CheckMenuItem *connection_editor_check;
492         Gtk::CheckMenuItem *route_params_check;
493         Gtk::CheckMenuItem *locations_dialog_check;
494         Gtk::CheckMenuItem *big_clock_check;
495         Gtk::CheckMenuItem *tempo_editor_check;
496         Gtk::CheckMenuItem *sfdb_check;
497         Gtk::CheckMenuItem *options_window_check;
498         
499         /* <CMT Additions> */
500         Gtk::MenuItem *image_compositor_item ;
501         /* </CMT Additions> */
502
503
504         Gtk::Label   wall_clock_label;
505         Gtk::EventBox wall_clock_box;
506         gint update_wall_clock ();
507
508         Gtk::Label   disk_space_label;
509         Gtk::EventBox disk_space_box;
510         void update_disk_space ();
511
512         Gtk::Label   cpu_load_label;
513         Gtk::EventBox cpu_load_box;
514         void update_cpu_load ();
515
516         Gtk::Label   disk_rate_label;
517         Gtk::EventBox disk_rate_box;
518         void update_disk_rate();
519
520         Gtk::Label   buffer_load_label;
521         Gtk::EventBox buffer_load_box;
522         void update_buffer_load ();
523
524         Gtk::Label   sample_rate_label;
525         Gtk::EventBox sample_rate_box;
526         void update_sample_rate (jack_nframes_t);
527
528         gint every_second ();
529         gint every_point_one_seconds ();
530         gint every_point_zero_one_seconds ();
531
532         sigc::connection second_connection;
533         sigc::connection point_one_second_connection;
534         sigc::connection point_zero_one_second_connection;
535
536         void diskstream_added (ARDOUR::DiskStream*);
537
538         gint session_menu (GdkEventButton *);
539
540         bool _will_create_new_session_automatically;
541
542         NewSessionDialog* new_session_window;
543         string template_name;
544
545         void new_session_ok_clicked ();
546         void new_session_template_choice (Gtkmm2ext::Selector *, Gtkmm2ext::SelectionResult*);
547         void hide_dialog (ArdourDialog *dialog);
548
549         void fs_cancel_clicked (Gtk::FileSelection*);
550         gint fs_delete_event (GdkEventAny*, Gtk::FileSelection*);
551
552         void open_session ();
553         void open_recent_session ();
554         void open_ok_clicked ();
555
556         void save_template ();
557
558
559         void session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels);
560
561         void add_diskstream_to_menu (ARDOUR::DiskStream&);
562         void diskstream_selected (gint32);
563         Gtk::Menu *diskstream_menu;
564         gint32 selected_dstream;
565         
566         gint mouse_transport_goto_start (GdkEventButton *) {
567                 transport_goto_start (); return TRUE;
568         }
569         gint mouse_transport_goto_end (GdkEventButton *) {
570                 transport_goto_end (); return TRUE;
571         }
572         gint mouse_transport_record (GdkEventButton *) {
573                 transport_record (); return TRUE;
574         }
575         gint mouse_transport_forward (GdkEventButton *) {
576                 transport_forward (0); return TRUE;
577         }
578         gint mouse_transport_rewind (GdkEventButton *) {
579                 transport_rewind (0); return TRUE;
580         }
581         gint mouse_transport_loop (GdkEventButton *) {
582                 transport_loop (); return TRUE;
583         }
584         gint mouse_transport_play_selection (GdkEventButton *) {
585                 transport_play_selection (); return TRUE;
586         }
587
588         gint mouse_transport_roll (GdkEventButton *);
589         gint mouse_transport_stop (GdkEventButton *);
590
591         void set_transport_sensitivity (bool);
592
593         void remove_last_capture ();
594
595         void transport_goto_start ();
596         void transport_goto_end ();
597         void transport_stop ();
598         void transport_stop_and_forget_capture ();
599         void transport_record ();
600         void transport_roll ();
601         void transport_play_selection(); 
602         void transport_forward (int option);
603         void transport_rewind (int option);
604         void transport_loop ();
605
606         void transport_locating ();
607         void transport_rolling ();
608         void transport_rewinding ();
609         void transport_forwarding ();
610         void transport_stopped ();
611
612         void send_all_midi_feedback ();
613         
614         bool _session_is_new;
615         void connect_to_session (ARDOUR::Session *);
616         void connect_dependents_to_session (ARDOUR::Session *);
617         void we_have_dependents ();
618         void setup_keybindings ();
619
620         guint32  last_key_press_time;
621
622         void snapshot_session ();
623
624         void map_control_change (ARDOUR::Session::ControlType);
625         void queue_map_control_change (ARDOUR::Session::ControlType);
626         void map_record_state ();
627         void queue_map_record_state ();
628
629         Mixer_UI   *mixer;
630         int         create_mixer ();
631         
632         PublicEditor     *editor;
633         int         create_editor ();
634
635         MeterBridge  *meter_bridge;
636         int          create_meter_bridge ();
637
638         RouteParams_UI *route_params;
639         int             create_route_params ();
640
641         ConnectionEditor *connection_editor;
642         int               create_connection_editor ();
643
644         LocationUI *location_ui;
645         int         create_location_ui ();
646
647         void meter_bridge_hiding ();
648         void location_ui_hiding ();
649         void big_clock_hiding ();
650         void route_params_hiding ();
651         void connection_editor_hiding ();
652         void sfdb_hiding ();
653         void option_hiding ();
654
655         /* Various options */
656
657         void toggle_recording_plugins ();
658
659         /* Options window */
660         
661         OptionEditor *option_editor;
662         
663         /* route dialog */
664
665         AddRouteDialog *add_route_dialog;
666         void add_route_dialog_done (int status);
667         
668         /* Keyboard Handling */
669         
670         Keyboard* keyboard;
671
672         /* Keymap handling */
673
674         void install_keybindings ();
675         void test_binding_action (const char *);
676         void start_keyboard_prefix();
677
678         void toggle_record_enable (guint32);
679         void toggle_monitor_enable (guint32);
680
681         uint32_t rec_enabled_diskstreams;
682         void count_recenabled_diskstreams (ARDOUR::DiskStream&);
683
684         About* about;
685         bool shown_flag;
686         /* cleanup */
687
688         Gtk::MenuItem *cleanup_item;
689
690         void display_cleanup_results (ARDOUR::Session::cleanup_report& rep, const gchar* list_title, string msg);
691         void cleanup ();
692         void flush_trash ();
693
694         bool have_configure_timeout;
695         struct timeval last_configure_time;
696         gint configure_timeout ();
697
698         struct timeval last_peak_grab;
699         struct timeval last_shuttle_request;
700
701         void cannot_record_no_input (ARDOUR::DiskStream*);
702
703         void delete_sources_in_the_right_thread (list<ARDOUR::Source*>*);
704
705         void editor_display_control_changed (Editing::DisplayControl c);
706
707         bool have_disk_overrun_displayed;
708         bool have_disk_underrun_displayed;
709
710         void disk_overrun_message_gone ();
711         void disk_underrun_message_gone ();
712         void disk_overrun_handler ();
713         void disk_underrun_handler ();
714
715         int pending_state_dialog ();
716         
717         void disconnect_from_jack ();
718         void reconnect_to_jack ();
719         void set_jack_buffer_size (jack_nframes_t);
720
721         Gtk::MenuItem* jack_disconnect_item;
722         Gtk::MenuItem* jack_reconnect_item;
723         Gtk::Menu*     jack_bufsize_menu;
724
725         int make_session_clean ();
726 };
727
728 #endif /* __ardour_gui_h__ */