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