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