lots of tricks & tweaks related to the monitor section and All That It Uses
[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 */
19
20 #ifndef __ardour_gui_h__
21 #define __ardour_gui_h__
22
23 #include <time.h>
24
25 /* need _BSD_SOURCE to get timersub macros */
26
27 #ifdef _BSD_SOURCE
28 #include <sys/time.h>
29 #else
30 #define _BSD_SOURCE
31 #include <sys/time.h>
32 #undef _BSD_SOURCE
33 #endif
34
35 #include <list>
36 #include <cmath>
37
38 #include <libgnomecanvasmm/canvas.h>
39
40 #include "pbd/xml++.h"
41 #include "pbd/controllable.h"
42 #include <gtkmm/box.h>
43 #include <gtkmm/frame.h>
44 #include <gtkmm/label.h>
45 #include <gtkmm/table.h>
46 #include <gtkmm/fixed.h>
47 #include <gtkmm/drawingarea.h>
48 #include <gtkmm/eventbox.h>
49 #include <gtkmm/menu.h>
50 #include <gtkmm/menuitem.h>
51 #include <gtkmm/button.h>
52 #include <gtkmm/togglebutton.h>
53 #include <gtkmm/treeview.h>
54 #include <gtkmm/menubar.h>
55 #include <gtkmm/textbuffer.h>
56 #include <gtkmm/adjustment.h>
57 #include <gtkmm2ext/gtk_ui.h>
58 #include <gtkmm2ext/click_box.h>
59 #include <gtkmm2ext/stateful_button.h>
60 #include <gtkmm2ext/bindable_button.h>
61 #include "ardour/ardour.h"
62 #include "ardour/types.h"
63 #include "ardour/utils.h"
64 #include "ardour/session_handle.h"
65
66 #include "audio_clock.h"
67 #include "ardour_dialog.h"
68 #include "editing.h"
69 #include "ui_config.h"
70
71 class About;
72 class AddRouteDialog;
73 class ArdourStartup;
74 class ArdourKeyboard;
75 class AudioClock;
76 class BundleManager;
77 class ConnectionEditor;
78 class KeyEditor;
79 class LocationUIWindow;
80 class Mixer_UI;
81 class PublicEditor;
82 class RCOptionEditor;
83 class RouteParams_UI;
84 class SessionOptionEditor;
85 class Splash;
86 class ThemeManager;
87
88 namespace Gtkmm2ext {
89         class TearOff;
90 }
91
92 namespace ARDOUR {
93         class ControlProtocolInfo;
94         class IO;
95         class Port;
96         class Route;
97         class RouteGroup;
98         class Location;
99 }
100
101 extern sigc::signal<void>  ColorsChanged;
102 extern sigc::signal<void>  DPIReset;
103
104 class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
105 {
106   public:
107         ARDOUR_UI (int *argcp, char **argvp[]);
108         ~ARDOUR_UI();
109
110         bool run_startup (bool should_be_new);
111
112         void show ();
113         bool shown() { return shown_flag; }
114
115         void show_splash ();
116         void hide_splash ();
117
118         void launch_chat ();
119         void show_about ();
120         void hide_about ();
121
122         void idle_load (const Glib::ustring& path);
123         void finish();
124
125         int load_session (const Glib::ustring& path, const Glib::ustring& snapshot, Glib::ustring mix_template = Glib::ustring());
126         bool session_loaded;
127         int build_session (const Glib::ustring& path, const Glib::ustring& snapshot,
128                            uint32_t ctl_chns,
129                            uint32_t master_chns,
130                            ARDOUR::AutoConnectOption input_connect,
131                            ARDOUR::AutoConnectOption output_connect,
132                            uint32_t nphysin,
133                            uint32_t nphysout,
134                            nframes_t initial_length);
135         bool session_is_new() const { return _session_is_new; }
136
137         ARDOUR::Session* the_session() { return _session; }
138
139         bool will_create_new_session_automatically() const {
140                 return _will_create_new_session_automatically;
141         }
142
143         void set_will_create_new_session_automatically (bool yn) {
144                 _will_create_new_session_automatically = yn;
145         }
146
147         int get_session_parameters (bool quit_on_cancel, bool should_be_new = false);
148         void parse_cmdline_path (const Glib::ustring& cmdline_path, Glib::ustring& session_name, Glib::ustring& session_path, bool& existing_session);
149         int  load_cmdline_session (const Glib::ustring& session_name, const Glib::ustring& session_path, bool& existing_session);
150         int  build_session_from_nsd (const Glib::ustring& session_name, const Glib::ustring& session_path);
151         bool ask_about_loading_existing_session (const Glib::ustring& session_path);
152
153         /// @return true if session was successfully unloaded.
154         int unload_session (bool hide_stuff = false);
155         void close_session();
156
157         int  save_state_canfail (std::string state_name = "");
158         void save_state (const std::string & state_name = "");
159
160         static double gain_to_slider_position (ARDOUR::gain_t g);
161         static ARDOUR::gain_t slider_position_to_gain (double pos);
162
163         static ARDOUR_UI *instance () { return theArdourUI; }
164         static UIConfiguration *config () { return ui_config; }
165
166         PublicEditor&     the_editor(){return *editor;}
167         Mixer_UI* the_mixer() { return mixer; }
168
169         void toggle_key_editor ();
170         void toggle_location_window ();
171         void toggle_theme_manager ();
172         void toggle_bundle_manager ();
173         void toggle_big_clock_window ();
174         void toggle_route_params_window ();
175         void toggle_editing_space();
176
177         Gtk::Tooltips& tooltips() { return _tooltips; }
178
179         static sigc::signal<void,bool> Blink;
180         static sigc::signal<void>      RapidScreenUpdate;
181         static sigc::signal<void>      SuperRapidScreenUpdate;
182         static sigc::signal<void,nframes_t, bool, nframes_t> Clock;
183
184         XMLNode* editor_settings() const;
185         XMLNode* mixer_settings () const;
186         XMLNode* keyboard_settings () const;
187         XMLNode* tearoff_settings (const char*) const;
188
189         void save_ardour_state ();
190         gboolean configure_handler (GdkEventConfigure* conf);
191
192         void do_transport_locate (nframes_t position);
193         void halt_on_xrun_message ();
194         void xrun_handler (nframes_t);
195         void create_xrun_marker (nframes_t);
196
197         AudioClock primary_clock;
198         AudioClock secondary_clock;
199         AudioClock preroll_clock;
200         AudioClock postroll_clock;
201
202         void store_clock_modes ();
203         void restore_clock_modes ();
204         void reset_main_clocks ();
205
206         void add_route (Gtk::Window* float_window);
207
208         void session_add_audio_track (int input_channels, int32_t output_channels, ARDOUR::TrackMode mode, ARDOUR::RouteGroup* route_group, uint32_t how_many) {
209                 session_add_audio_route (true, false, input_channels, output_channels, mode, route_group, how_many);
210         }
211
212         void session_add_audio_bus (bool aux,  int input_channels, int32_t output_channels, ARDOUR::RouteGroup* route_group, uint32_t how_many) {
213                 session_add_audio_route (false, aux, input_channels, output_channels, ARDOUR::Normal, route_group, how_many);
214         }
215
216         void session_add_midi_track (ARDOUR::RouteGroup* route_group, uint32_t how_many) {
217                 session_add_midi_route (true, route_group, how_many);
218         }
219
220         /*void session_add_midi_bus () {
221                 session_add_midi_route (false);
222         }*/
223
224         int  create_engine ();
225         void post_engine ();
226
227         gint exit_on_main_window_close (GdkEventAny *);
228
229         void maximise_editing_space ();
230         void restore_editing_space ();
231
232         void setup_profile ();
233         void setup_theme ();
234         void setup_tooltips ();
235
236         void set_shuttle_fract (double);
237
238   protected:
239         friend class PublicEditor;
240
241         void toggle_clocking ();
242         void toggle_auto_play ();
243         void toggle_auto_input ();
244         void toggle_punch ();
245         void unset_dual_punch ();
246         bool ignore_dual_punch;
247         void toggle_punch_in ();
248         void toggle_punch_out ();
249         void show_loop_punch_ruler_and_disallow_hide ();
250         void reenable_hide_loop_punch_ruler_if_appropriate ();
251         void toggle_auto_return ();
252         void toggle_click ();
253
254         void toggle_session_auto_loop ();
255
256         void toggle_rc_options_window ();
257         void toggle_session_options_window ();
258
259   private:
260         ArdourStartup*      _startup;
261         ARDOUR::AudioEngine *engine;
262         Gtk::Tooltips        _tooltips;
263
264         void                goto_editor_window ();
265         void                goto_mixer_window ();
266         void                toggle_editor_mixer_on_top ();
267         bool                _mixer_on_top;
268
269         Gtk::ToggleButton   preroll_button;
270         Gtk::ToggleButton   postroll_button;
271
272         int  setup_windows ();
273         void setup_transport ();
274         void setup_clock ();
275
276         static ARDOUR_UI *theArdourUI;
277
278         void backend_audio_error (bool we_set_params, Gtk::Window* toplevel = 0);
279         void startup ();
280         void shutdown ();
281
282         int  ask_about_saving_session (const std::string & why);
283
284         /* periodic safety backup, to be precise */
285         gint autosave_session();
286         void update_autosave();
287         sigc::connection _autosave_connection;
288
289         void map_transport_state ();
290         int32_t do_engine_start ();
291
292         void engine_halted ();
293         void engine_stopped ();
294         void engine_running ();
295
296         void use_config ();
297
298         static gint _blink  (void *);
299         void blink ();
300         gint blink_timeout_tag;
301         bool blink_on;
302         void start_blinking ();
303         void stop_blinking ();
304
305         void about_signal_response(int response);
306
307   private:
308         Gtk::VBox     top_packer;
309
310         sigc::connection clock_signal_connection;
311         void         update_clocks ();
312         void         start_clocking ();
313         void         stop_clocking ();
314
315         void manage_window (Gtk::Window&);
316
317         AudioClock   big_clock;
318         Gtk::Window* big_clock_window;
319         int original_big_clock_width;
320         int original_big_clock_height;
321         double original_big_clock_font_size;
322
323         void big_clock_size_allocate (Gtk::Allocation&);
324         bool idle_big_clock_text_resizer (int width, int height);
325         void big_clock_realized ();
326         bool big_clock_resize_in_progress;
327         int  big_clock_height;
328
329         void float_big_clock (Gtk::Window* parent);
330         bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
331
332         void update_transport_clocks (nframes_t pos);
333         void record_state_changed ();
334
335         /* Transport Control */
336
337         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
338         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
339
340         Gtkmm2ext::TearOff*      transport_tearoff;
341         Gtk::Frame               transport_frame;
342         Gtk::HBox                transport_tearoff_hbox;
343         Gtk::HBox                play_range_hbox;
344         Gtk::VBox                play_range_vbox;
345         Gtk::HBox                transport_hbox;
346         Gtk::Fixed               transport_base;
347         Gtk::Fixed               transport_button_base;
348         Gtk::Frame               transport_button_frame;
349         Gtk::HBox                transport_button_hbox;
350         Gtk::VBox                transport_button_vbox;
351         Gtk::HBox                transport_option_button_hbox;
352         Gtk::VBox                transport_option_button_vbox;
353         Gtk::HBox                transport_clock_hbox;
354         Gtk::VBox                transport_clock_vbox;
355         Gtk::HBox                primary_clock_hbox;
356         Gtk::HBox                secondary_clock_hbox;
357
358
359         struct TransportControllable : public PBD::Controllable {
360             enum ToggleType {
361                     Roll = 0,
362                     Stop,
363                     RecordEnable,
364                     GotoStart,
365                     GotoEnd,
366                     AutoLoop,
367                     PlaySelection,
368                     ShuttleControl
369
370             };
371
372             TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
373             void set_value (float);
374             float get_value (void) const;
375
376             void set_id (const std::string&);
377
378             ARDOUR_UI& ui;
379             ToggleType type;
380         };
381
382         boost::shared_ptr<TransportControllable> roll_controllable;
383         boost::shared_ptr<TransportControllable> stop_controllable;
384         boost::shared_ptr<TransportControllable> goto_start_controllable;
385         boost::shared_ptr<TransportControllable> goto_end_controllable;
386         boost::shared_ptr<TransportControllable> auto_loop_controllable;
387         boost::shared_ptr<TransportControllable> play_selection_controllable;
388         boost::shared_ptr<TransportControllable> rec_controllable;
389         boost::shared_ptr<TransportControllable> shuttle_controllable;
390         BindingProxy shuttle_controller_binding_proxy;
391
392         void set_transport_controllable_state (const XMLNode&);
393         XMLNode& get_transport_controllable_state ();
394
395         BindableButton roll_button;
396         BindableButton stop_button;
397         BindableButton goto_start_button;
398         BindableButton goto_end_button;
399         BindableButton auto_loop_button;
400         BindableButton play_selection_button;
401         BindableButton rec_button;
402         Gtk::ToggleButton join_play_range_button;
403
404         void toggle_external_sync ();
405         void toggle_time_master ();
406         void toggle_video_sync ();
407
408         Gtk::DrawingArea  shuttle_box;
409         Gtk::EventBox     speed_display_box;
410         Gtk::Label        speed_display_label;
411         Gtk::Button       shuttle_units_button;
412         Gtk::ComboBoxText shuttle_style_button;
413         Gtk::Menu*        shuttle_unit_menu;
414         Gtk::Menu*        shuttle_style_menu;
415         float             shuttle_max_speed;
416         Gtk::Menu*        shuttle_context_menu;
417
418         void build_shuttle_context_menu ();
419         void show_shuttle_context_menu ();
420         void shuttle_style_changed();
421         void shuttle_unit_clicked ();
422         void set_shuttle_max_speed (float);
423         void update_speed_display ();
424         float last_speed_displayed;
425
426         gint shuttle_box_button_press (GdkEventButton*);
427         gint shuttle_box_button_release (GdkEventButton*);
428         gint shuttle_box_scroll (GdkEventScroll*);
429         gint shuttle_box_motion (GdkEventMotion*);
430         gint shuttle_box_expose (GdkEventExpose*);
431         gint mouse_shuttle (double x, bool force);
432         void use_shuttle_fract (bool force);
433
434         bool   shuttle_grabbed;
435         double shuttle_fract;
436
437         Gtkmm2ext::StatefulToggleButton punch_in_button;
438         Gtkmm2ext::StatefulToggleButton punch_out_button;
439         Gtkmm2ext::StatefulToggleButton auto_return_button;
440         Gtkmm2ext::StatefulToggleButton auto_play_button;
441         Gtkmm2ext::StatefulToggleButton auto_input_button;
442         Gtkmm2ext::StatefulToggleButton click_button;
443         Gtkmm2ext::StatefulToggleButton time_master_button;
444         Gtkmm2ext::StatefulToggleButton sync_button;
445
446         Gtk::ToggleButton auditioning_alert_button;
447         Gtk::ToggleButton solo_alert_button;
448
449         Gtk::VBox alert_box;
450
451         void solo_blink (bool);
452         void sync_blink (bool);
453         void audition_blink (bool);
454
455         void soloing_changed (bool);
456         void auditioning_changed (bool);
457         void _auditioning_changed (bool);
458
459         bool solo_alert_press (GdkEventButton* ev);
460         bool audition_alert_press (GdkEventButton* ev);
461
462         void big_clock_value_changed ();
463         void primary_clock_value_changed ();
464         void secondary_clock_value_changed ();
465
466         /* called by Blink signal */
467
468         void transport_rec_enable_blink (bool onoff);
469
470         Gtk::Menu*        session_popup_menu;
471
472         struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
473             RecentSessionModelColumns() {
474                     add (visible_name);
475                     add (fullpath);
476             }
477             Gtk::TreeModelColumn<Glib::ustring> visible_name;
478             Gtk::TreeModelColumn<Glib::ustring> fullpath;
479         };
480
481         RecentSessionModelColumns    recent_session_columns;
482         Gtk::TreeView                recent_session_display;
483         Glib::RefPtr<Gtk::TreeStore> recent_session_model;
484
485         ArdourDialog*     session_selector_window;
486         Gtk::FileChooserDialog* open_session_selector;
487
488         void build_session_selector();
489         void redisplay_recent_sessions();
490         void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
491
492         struct RecentSessionsSorter {
493                 bool operator() (std::pair<std::string,std::string> a, std::pair<std::string,std::string> b) const {
494                     return cmp_nocase(a.first, b.first) == -1;
495             }
496         };
497
498         /* menu bar and associated stuff */
499
500         Gtk::MenuBar* menu_bar;
501         Gtk::EventBox menu_bar_base;
502         Gtk::HBox     menu_hbox;
503
504         void use_menubar_as_top_menubar ();
505         void build_menu_bar ();
506
507         Gtk::Label   wall_clock_label;
508         Gtk::EventBox wall_clock_box;
509         gint update_wall_clock ();
510
511         Gtk::Label   disk_space_label;
512         Gtk::EventBox disk_space_box;
513         void update_disk_space ();
514
515         Gtk::Label   cpu_load_label;
516         Gtk::EventBox cpu_load_box;
517         void update_cpu_load ();
518
519         Gtk::Label   buffer_load_label;
520         Gtk::EventBox buffer_load_box;
521         void update_buffer_load ();
522
523         Gtk::Label   sample_rate_label;
524         Gtk::EventBox sample_rate_box;
525         void update_sample_rate (nframes_t);
526
527         gint every_second ();
528         gint every_point_one_seconds ();
529         gint every_point_zero_one_seconds ();
530
531         sigc::connection second_connection;
532         sigc::connection point_one_second_connection;
533         sigc::connection point_oh_five_second_connection;
534         sigc::connection point_zero_one_second_connection;
535
536         gint session_menu (GdkEventButton *);
537
538         bool _will_create_new_session_automatically;
539
540         void open_session ();
541         void open_recent_session ();
542         void save_template ();
543
544         void edit_metadata ();
545         void import_metadata ();
546
547         void session_add_audio_route (bool disk, bool aux, int32_t input_channels, int32_t output_channels, ARDOUR::TrackMode mode, ARDOUR::RouteGroup *, uint32_t how_many);
548         void session_add_midi_route (bool disk, ARDOUR::RouteGroup *, uint32_t how_many);
549
550         void set_transport_sensitivity (bool);
551
552         void remove_last_capture ();
553
554         void transport_goto_zero ();
555         void transport_goto_start ();
556         void transport_goto_end ();
557         void transport_goto_wallclock ();
558         void transport_stop ();
559         void transport_stop_and_forget_capture ();
560         void transport_record (bool roll);
561         void transport_roll ();
562         void transport_play_selection();
563         void transport_forward (int option);
564         void transport_rewind (int option);
565         void transport_loop ();
566         void toggle_roll (bool with_abort, bool roll_out_of_bounded_mode);
567
568         bool _session_is_new;
569         void set_session (ARDOUR::Session *);
570         void connect_dependents_to_session (ARDOUR::Session *);
571         void we_have_dependents ();
572
573         void setup_session_options ();
574
575         guint32  last_key_press_time;
576
577         void snapshot_session ();
578
579         Mixer_UI   *mixer;
580         int         create_mixer ();
581
582         PublicEditor     *editor;
583         int         create_editor ();
584
585         RouteParams_UI *route_params;
586         int             create_route_params ();
587
588         BundleManager *bundle_manager;
589         void create_bundle_manager ();
590
591         LocationUIWindow *location_ui;
592         int               create_location_ui ();
593         void              handle_locations_change (ARDOUR::Location*);
594
595         static UIConfiguration *ui_config;
596         ThemeManager *theme_manager;
597
598         /* Key bindings editor */
599
600         KeyEditor *key_editor;
601
602         /* RC Options window */
603
604         RCOptionEditor *rc_option_editor;
605
606         SessionOptionEditor *session_option_editor;
607
608         /* route dialog */
609
610         AddRouteDialog *add_route_dialog;
611
612         /* Keyboard Handling */
613
614         ArdourKeyboard* keyboard;
615         
616         /* Keymap handling */
617
618         void install_actions ();
619
620         void toggle_record_enable (uint32_t);
621
622         uint32_t rec_enabled_streams;
623         void count_recenabled_streams (ARDOUR::Route&);
624
625         About* about;
626         Splash* splash;
627         void pop_back_splash ();
628         bool shown_flag;
629
630         /* cleanup */
631
632         Gtk::MenuItem *cleanup_item;
633
634         void display_cleanup_results (ARDOUR::CleanupReport& rep, const gchar* list_title,
635                                       const std::string& plural_msg, const std::string& singular_msg);
636         void cleanup ();
637         void flush_trash ();
638
639         bool have_configure_timeout;
640         ARDOUR::microseconds_t last_configure_time;
641         gint configure_timeout ();
642
643         ARDOUR::microseconds_t last_peak_grab;
644         ARDOUR::microseconds_t last_shuttle_request;
645
646         struct DiskBufferStat {
647             time_t when;
648             uint32_t capture;
649             uint32_t playback;
650
651             DiskBufferStat (time_t w, uint32_t c, uint32_t p)
652             : when (w), capture (c), playback (p) {}
653         };
654
655         std::list<DiskBufferStat> disk_buffer_stats;
656         void push_buffer_stats (uint32_t, uint32_t);
657         void write_buffer_stats ();
658
659         bool have_disk_speed_dialog_displayed;
660         void disk_speed_dialog_gone (int ignored_response, Gtk::MessageDialog*);
661         void disk_overrun_handler ();
662         void disk_underrun_handler ();
663
664         void session_dialog (std::string);
665         int pending_state_dialog ();
666         int sr_mismatch_dialog (nframes_t, nframes_t);
667
668         void disconnect_from_jack ();
669         void reconnect_to_jack ();
670         void set_jack_buffer_size (nframes_t);
671
672         Gtk::MenuItem* jack_disconnect_item;
673         Gtk::MenuItem* jack_reconnect_item;
674         Gtk::Menu*     jack_bufsize_menu;
675
676         Glib::RefPtr<Gtk::ActionGroup> common_actions;
677
678         void editor_realized ();
679
680         std::vector<std::string> positional_sync_strings;
681
682         void toggle_send_midi_feedback ();
683         void toggle_use_mmc ();
684         void toggle_send_mmc ();
685         void toggle_send_mtc ();
686         void toggle_send_midi_clock ();
687
688         void toggle_use_osc ();
689
690         void parameter_changed (std::string);
691
692         bool first_idle ();
693
694         void no_memory_warning ();
695         void check_memory_locking ();
696
697         bool check_audioengine();
698         void audioengine_setup ();
699
700         void display_message (const char *prefix, gint prefix_len,
701                         Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
702                         const char *msg);
703         Gtk::Label status_bar_label;
704         Gtk::ToggleButton error_log_button;
705
706         void loading_message (const std::string& msg);
707         void end_loading_messages ();
708
709         void platform_specific ();
710         void platform_setup ();
711         void fontconfig_dialog ();
712
713         PBD::ScopedConnectionList forever_connections;
714 };
715
716 #endif /* __ardour_gui_h__ */
717