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