Use boost::shared_ptr instead of raw pointers for RouteUI track (etc) accessors ...
[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 /* need _BSD_SOURCE to get timersub macros */
24
25 #ifdef _BSD_SOURCE
26 #include <sys/time.h>
27 #else
28 #define _BSD_SOURCE
29 #include <sys/time.h>
30 #undef _BSD_SOURCE
31 #endif
32
33 #include <list>
34
35 #include <cmath>
36
37 #include <libgnomecanvasmm/canvas.h>
38
39 #include <pbd/xml++.h>
40 #include <gtkmm/box.h>
41 #include <gtkmm/frame.h>
42 #include <gtkmm/label.h>
43 #include <gtkmm/table.h>
44 #include <gtkmm/fixed.h>
45 #include <gtkmm/drawingarea.h>
46 #include <gtkmm/eventbox.h>
47 #include <gtkmm/menu.h>
48 #include <gtkmm/menuitem.h>
49 #include <gtkmm/button.h>
50 #include <gtkmm/togglebutton.h>
51 #include <gtkmm/treeview.h>
52 #include <gtkmm/menubar.h>
53 #include <gtkmm/adjustment.h>
54 #include <gtkmm2ext/gtk_ui.h>
55 #include <gtkmm2ext/click_box.h>
56 #include <gtkmm2ext/stateful_button.h>
57 #include <gtkmm2ext/bindable_button.h>
58 #include <ardour/ardour.h>
59 #include <ardour/session.h>
60
61 #include "audio_clock.h"
62 #include "ardour_dialog.h"
63 #include "editing.h"
64
65 class AudioClock;
66 class PublicEditor;
67 class Keyboard;
68 class OptionEditor;
69 class Mixer_UI;
70 class ConnectionEditor;
71 class RouteParams_UI;
72 class About;
73 class AddRouteDialog;
74 class NewSessionDialog;
75 class LocationUI;
76 class ThemeManager;
77
78 namespace Gtkmm2ext {
79         class TearOff;
80 }
81
82 namespace ARDOUR {
83         class AudioEngine;
84         class Route;
85         class Port;
86         class IO;
87         class ControlProtocolInfo;
88 }
89
90 namespace ALSA {
91         class MultiChannelDevice;
92 }
93
94 extern sigc::signal<int,string> ThemeChanged;
95
96 #define FRAME_NAME "BaseFrame"
97
98 class ARDOUR_UI : public Gtkmm2ext::UI
99 {
100   public:
101         ARDOUR_UI (int *argcp, char **argvp[]);
102         ~ARDOUR_UI();
103
104         void show ();
105         bool shown() { return shown_flag; }
106         
107         void show_splash ();
108         void hide_splash ();
109         
110         int load_session (const string & path, const string & snapshot, string* mix_template = 0);
111         bool session_loaded;
112         /// @return true if building the session was successful
113         bool build_session (const string & path, const string & snapshot, 
114                            uint32_t ctl_chns, 
115                            uint32_t master_chns,
116                            ARDOUR::AutoConnectOption input_connect,
117                            ARDOUR::AutoConnectOption output_connect,
118                            uint32_t nphysin,
119                            uint32_t nphysout,
120                            nframes_t initial_length);
121         bool session_is_new() const { return _session_is_new; }
122
123         ARDOUR::Session* the_session() { return session; }
124
125         bool new_session(std::string path = string());
126         gint cmdline_new_session (string path);
127         
128         /// @return true if session was successfully unloaded.
129         bool unload_session ();
130         void close_session(); 
131
132         int  save_state_canfail (string state_name = "");
133         void save_state (const string & state_name = "");
134         void restore_state (string state_name = "");
135
136         static double gain_to_slider_position (ARDOUR::gain_t g);
137         static ARDOUR::gain_t slider_position_to_gain (double pos);
138
139         static ARDOUR_UI *instance () { return theArdourUI; }
140
141         PublicEditor&     the_editor(){return *editor;}
142         Mixer_UI* the_mixer() { return mixer; }
143         
144         void toggle_location_window ();
145         void toggle_theme_manager ();
146         void toggle_big_clock_window ();
147         void toggle_connection_editor ();
148         void toggle_route_params_window ();
149         void toggle_editing_space();
150
151         Gtk::Tooltips& tooltips() { return _tooltips; }
152
153         static sigc::signal<void,bool> Blink;
154         static sigc::signal<void>      RapidScreenUpdate;
155         static sigc::signal<void>      SuperRapidScreenUpdate;
156         static sigc::signal<void,nframes_t, bool, nframes_t> Clock;
157
158         /* this is a helper function to centralize the (complex) logic for
159            blinking rec-enable buttons.
160         */
161
162         void rec_enable_button_blink (bool onoff, ARDOUR::AudioDiskstream *, Gtk::Widget *w);
163
164         void name_io_setup (ARDOUR::AudioEngine&, string&, ARDOUR::IO& io, bool in);
165
166         static gint hide_and_quit (GdkEventAny *ev, ArdourDialog *);
167
168         XMLNode* editor_settings() const;
169         XMLNode* mixer_settings () const;
170         XMLNode* keyboard_settings () const;
171
172         void save_ardour_state ();
173         gboolean configure_handler (GdkEventConfigure* conf);
174
175         void do_transport_locate (nframes_t position);
176         void halt_on_xrun_message ();
177
178         AudioClock primary_clock;
179         AudioClock secondary_clock;
180         AudioClock preroll_clock;
181         AudioClock postroll_clock;
182
183         void store_clock_modes ();
184         void restore_clock_modes ();
185
186         void add_route (Gtk::Window* float_window);
187         
188         void session_add_audio_track (int input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many) {
189                 session_add_audio_route (true, input_channels, output_channels, mode, how_many);
190         }
191
192         void session_add_audio_bus (int input_channels, int32_t output_channels, uint32_t how_many) {
193                 session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, how_many);
194         }
195
196         void session_add_midi_track (uint32_t how_many) {
197                 session_add_midi_route (true, how_many);
198         }
199
200         /*void session_add_midi_bus () {
201                 session_add_midi_route (false);
202         }*/
203
204         void set_engine (ARDOUR::AudioEngine&);
205         gint start_engine ();
206
207         gint exit_on_main_window_close (GdkEventAny *);
208
209         void maximise_editing_space ();
210         void restore_editing_space ();
211
212         void set_native_file_header_format (ARDOUR::HeaderFormat sf);
213         void set_native_file_data_format (ARDOUR::SampleFormat sf);
214
215         void set_keybindings_path (std::string path);
216         void save_keybindings ();
217
218         void setup_profile ();
219         void setup_theme ();
220
221   protected:
222         friend class PublicEditor;
223
224         void toggle_clocking ();
225         void toggle_auto_play ();
226         void toggle_auto_input ();
227         void toggle_punch_in ();
228         void toggle_punch_out ();
229         void toggle_auto_return ();
230         void toggle_click ();
231
232         void toggle_session_auto_loop ();
233         
234         void toggle_options_window ();
235
236   private:
237         struct GlobalClickBox : public Gtk::VBox {
238             Gtkmm2ext::ClickBox  *box;
239             Gtk::Frame      frame;
240             Gtk::Label      label;
241             vector<string> &strings;
242             Gtk::Adjustment adjustment;
243
244             static void printer (char buf[32], Gtk::Adjustment &adj, void *arg);
245
246             GlobalClickBox (const string &str, vector<string> &vs)
247                     : strings (vs),
248                       adjustment (0, 0, vs.size() - 1, 1, 1, 0) {
249                     box = new Gtkmm2ext::ClickBox (&adjustment, "ClickButton");
250                     label.set_text (str);
251                     label.set_name ("GlobalButtonLabel");
252                     frame.add (*box);
253                     frame.set_shadow_type (Gtk::SHADOW_IN);
254                     pack_start (label);
255                     pack_start (frame);
256                     box->set_print_func (printer, this);
257                     box->set_wrap (true);
258             };
259         };
260
261         ARDOUR::AudioEngine                 *engine;
262         ARDOUR::Session                     *session;
263
264         bool check_audioengine();
265
266         Gtk::Tooltips          _tooltips;
267
268         void                     goto_editor_window ();
269         void                     goto_mixer_window ();
270         
271         Gtk::Table               adjuster_table;
272         Gtk::Frame               adjuster_frame;
273         Gtk::Fixed               adjuster_base;
274
275         GlobalClickBox     *online_control_button;
276         vector<string>      online_control_strings;
277
278         GlobalClickBox    *crossfade_time_button;
279         vector<string>     crossfade_time_strings;
280
281         Gtk::ToggleButton   preroll_button;
282         Gtk::ToggleButton   postroll_button;
283
284         Gtk::Table          transport_table;
285         Gtk::Table          option_table;
286
287         int  setup_windows ();
288         void setup_transport ();
289         void setup_clock ();
290
291         static ARDOUR_UI *theArdourUI;
292
293         void startup ();
294         void shutdown ();
295
296         void finish();
297         int  ask_about_saving_session (const string & why);
298         int  save_the_session;
299
300         /* periodic safety backup, to be precise */
301         gint autosave_session();
302         void update_autosave();
303         sigc::connection _autosave_connection;
304
305         void queue_transport_change ();
306         void map_transport_state ();
307         int32_t do_engine_start ();
308         
309         void engine_halted ();
310         void engine_stopped ();
311         void engine_running ();
312
313         void use_config ();
314
315         static gint _blink  (void *);
316         void blink ();
317         gint blink_timeout_tag;
318         bool blink_on;
319         void start_blinking ();
320         void stop_blinking ();
321
322         void about_signal_response(int response);
323
324   private:
325         Gtk::VBox     top_packer;
326
327         sigc::connection clock_signal_connection;
328         void         update_clocks ();
329         void         start_clocking ();
330         void         stop_clocking ();
331
332         void manage_window (Gtk::Window&);
333         
334         AudioClock   big_clock;
335         Gtk::Frame   big_clock_frame;
336         Gtk::Window* big_clock_window;
337
338         void update_transport_clocks (nframes_t pos);
339         void record_state_changed ();
340
341         /* Transport Control */
342
343         void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
344         void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
345
346         Gtkmm2ext::TearOff*      transport_tearoff;
347         Gtk::Frame               transport_frame;
348         Gtk::HBox                transport_tearoff_hbox;
349         Gtk::HBox                transport_hbox;
350         Gtk::Fixed               transport_base;
351         Gtk::Fixed               transport_button_base;
352         Gtk::Frame               transport_button_frame;
353         Gtk::HBox                transport_button_hbox;
354         Gtk::VBox                transport_button_vbox;
355         Gtk::HBox                transport_option_button_hbox;
356         Gtk::VBox                transport_option_button_vbox;
357         Gtk::HBox                transport_clock_hbox;
358         Gtk::VBox                transport_clock_vbox;
359         Gtk::HBox                primary_clock_hbox;
360         Gtk::HBox                secondary_clock_hbox;
361
362
363         struct TransportControllable : public PBD::Controllable {
364             enum ToggleType {
365                     Roll = 0,
366                     Stop,
367                     RecordEnable,
368                     GotoStart,
369                     GotoEnd,
370                     AutoLoop,
371                     PlaySelection,
372                     ShuttleControl
373                     
374             };
375             
376             TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
377             void set_value (float);
378             float get_value (void) const;
379             
380             void set_id (const std::string&);
381             
382             ARDOUR_UI& ui;
383             ToggleType type;
384         };
385
386         TransportControllable roll_controllable;
387         TransportControllable stop_controllable;
388         TransportControllable goto_start_controllable;
389         TransportControllable goto_end_controllable;
390         TransportControllable auto_loop_controllable;
391         TransportControllable play_selection_controllable;
392         TransportControllable rec_controllable;
393         TransportControllable shuttle_controllable;
394         BindingProxy shuttle_controller_binding_proxy;
395
396         void set_transport_controllable_state (const XMLNode&);
397         XMLNode& get_transport_controllable_state ();
398
399         BindableButton roll_button;
400         BindableButton stop_button;
401         BindableButton goto_start_button;
402         BindableButton goto_end_button;
403         BindableButton auto_loop_button;
404         BindableButton play_selection_button;
405         BindableButton rec_button;
406
407         Gtk::ComboBoxText sync_option_combo;
408
409         void sync_option_changed ();
410         void toggle_time_master ();
411         void toggle_video_sync ();
412
413         Gtk::DrawingArea  shuttle_box;
414         Gtk::EventBox     speed_display_box;
415         Gtk::Label        speed_display_label;
416         Gtk::Button       shuttle_units_button;
417         Gtk::ComboBoxText shuttle_style_button;
418         Gtk::Menu*        shuttle_unit_menu;
419         Gtk::Menu*        shuttle_style_menu;
420         float             shuttle_max_speed;
421         Gtk::Menu*        shuttle_context_menu;
422
423         void build_shuttle_context_menu ();
424         void show_shuttle_context_menu ();
425         void shuttle_style_changed();
426         void shuttle_unit_clicked ();
427         void set_shuttle_max_speed (float);
428         void update_speed_display ();
429         float last_speed_displayed;
430
431         gint shuttle_box_button_press (GdkEventButton*);
432         gint shuttle_box_button_release (GdkEventButton*);
433         gint shuttle_box_scroll (GdkEventScroll*);
434         gint shuttle_box_motion (GdkEventMotion*);
435         gint shuttle_box_expose (GdkEventExpose*);
436         gint mouse_shuttle (double x, bool force);
437         void use_shuttle_fract (bool force);
438         void set_shuttle_fract (double);
439
440         bool   shuttle_grabbed;
441         double shuttle_fract;
442
443         Gtkmm2ext::StatefulToggleButton punch_in_button;
444         Gtkmm2ext::StatefulToggleButton punch_out_button;
445         Gtkmm2ext::StatefulToggleButton auto_return_button;
446         Gtkmm2ext::StatefulToggleButton auto_play_button;
447         Gtkmm2ext::StatefulToggleButton auto_input_button;
448         Gtkmm2ext::StatefulToggleButton click_button;
449         Gtkmm2ext::StatefulToggleButton time_master_button;
450
451         Gtk::ToggleButton auditioning_alert_button;
452         Gtk::ToggleButton solo_alert_button;
453
454         Gtk::VBox alert_box;
455
456         void solo_blink (bool);
457         void audition_blink (bool);
458
459         void soloing_changed (bool);
460         void auditioning_changed (bool);
461         void _auditioning_changed (bool);
462
463         void solo_alert_toggle ();
464         void audition_alert_toggle ();
465
466         void primary_clock_value_changed ();
467         void secondary_clock_value_changed ();
468
469         /* called by Blink signal */
470
471         void transport_rec_enable_blink (bool onoff);
472
473         Gtk::Menu*        session_popup_menu;
474
475         struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord {
476             RecentSessionModelColumns() { 
477                     add (visible_name);
478                     add (fullpath);
479             }
480             Gtk::TreeModelColumn<Glib::ustring> visible_name;
481             Gtk::TreeModelColumn<Glib::ustring> fullpath;
482         };
483
484         RecentSessionModelColumns    recent_session_columns;
485         Gtk::TreeView                recent_session_display;
486         Glib::RefPtr<Gtk::TreeStore> recent_session_model;
487
488         ArdourDialog*     session_selector_window;
489         Gtk::FileChooserDialog* open_session_selector;
490         
491         void build_session_selector();
492         void redisplay_recent_sessions();
493         void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col);
494
495         struct RecentSessionsSorter {
496             bool operator() (std::pair<string,string> a, std::pair<string,string> b) const {
497                     return cmp_nocase(a.first, b.first) == -1;
498             }
499         };
500
501         /* menu bar and associated stuff */
502
503         Gtk::MenuBar* menu_bar;
504         Gtk::EventBox menu_bar_base;
505         Gtk::HBox     menu_hbox;
506
507         void build_menu_bar ();
508         void build_control_surface_menu ();
509
510         Gtk::Label   wall_clock_label;
511         Gtk::EventBox wall_clock_box;
512         gint update_wall_clock ();
513
514         Gtk::Label   disk_space_label;
515         Gtk::EventBox disk_space_box;
516         void update_disk_space ();
517
518         Gtk::Label   cpu_load_label;
519         Gtk::EventBox cpu_load_box;
520         void update_cpu_load ();
521
522         Gtk::Label   buffer_load_label;
523         Gtk::EventBox buffer_load_box;
524         void update_buffer_load ();
525
526         Gtk::Label   sample_rate_label;
527         Gtk::EventBox sample_rate_box;
528         void update_sample_rate (nframes_t);
529
530         gint every_second ();
531         gint every_point_one_seconds ();
532         gint every_point_zero_one_seconds ();
533
534         sigc::connection second_connection;
535         sigc::connection point_one_second_connection;
536         sigc::connection point_oh_five_second_connection;
537         sigc::connection point_zero_one_second_connection;
538
539         gint session_menu (GdkEventButton *);
540
541         NewSessionDialog* new_session_dialog;
542         
543         void open_session ();
544         void open_recent_session ();
545         void save_template ();
546
547         void session_add_audio_route (bool disk, int32_t input_channels, int32_t output_channels, ARDOUR::TrackMode mode, uint32_t how_many);
548         void session_add_midi_route (bool disk, 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_stop ();
558         void transport_stop_and_forget_capture ();
559         void transport_record ();
560         void transport_roll ();
561         void transport_play_selection(); 
562         void transport_forward (int option);
563         void transport_rewind (int option);
564         void transport_loop ();
565
566         void transport_rolling ();
567         void transport_rewinding ();
568         void transport_forwarding ();
569         void transport_stopped ();
570
571         bool _session_is_new;
572         void connect_to_session (ARDOUR::Session *);
573         void connect_dependents_to_session (ARDOUR::Session *);
574         void we_have_dependents ();
575         
576         std::string keybindings_path;
577
578         void setup_keybindings ();
579         void setup_session_options ();
580         
581         guint32  last_key_press_time;
582
583         void snapshot_session ();
584
585         Mixer_UI   *mixer;
586         int         create_mixer ();
587         
588         PublicEditor     *editor;
589         int         create_editor ();
590
591         RouteParams_UI *route_params;
592         int             create_route_params ();
593
594         ConnectionEditor *connection_editor;
595         int               create_connection_editor ();
596
597         LocationUI *location_ui;
598         int         create_location_ui ();
599         void        handle_locations_change (ARDOUR::Location*);
600
601         ThemeManager* theme_manager;
602
603         /* Options window */
604         
605         OptionEditor *option_editor;
606         
607         /* route dialog */
608
609         AddRouteDialog *add_route_dialog;
610         
611         /* Keyboard Handling */
612         
613         Keyboard* keyboard;
614
615         /* Keymap handling */
616
617         void install_actions ();
618
619         void toggle_record_enable (uint32_t);
620
621         uint32_t rec_enabled_streams;
622         void count_recenabled_streams (ARDOUR::Route&);
623
624         About* about;
625         bool shown_flag;
626         /* cleanup */
627
628         Gtk::MenuItem *cleanup_item;
629
630         void display_cleanup_results (ARDOUR::Session::cleanup_report& rep, const gchar* list_title, const string & msg);
631         void cleanup ();
632         void flush_trash ();
633
634         bool have_configure_timeout;
635         struct timeval last_configure_time;
636         gint configure_timeout ();
637
638         struct timeval last_peak_grab;
639         struct timeval last_shuttle_request;
640
641         bool have_disk_speed_dialog_displayed;
642         void disk_speed_dialog_gone (int ignored_response, Gtk::MessageDialog*);
643         void disk_overrun_handler ();
644         void disk_underrun_handler ();
645
646         int pending_state_dialog ();
647         
648         void disconnect_from_jack ();
649         void reconnect_to_jack ();
650         void set_jack_buffer_size (nframes_t);
651
652         Gtk::MenuItem* jack_disconnect_item;
653         Gtk::MenuItem* jack_reconnect_item;
654         Gtk::Menu*     jack_bufsize_menu;
655
656         int make_session_clean ();
657         bool filter_ardour_session_dirs (const Gtk::FileFilter::Info&);
658
659         Glib::RefPtr<Gtk::ActionGroup> common_actions;
660
661         void editor_realized ();
662
663         std::vector<std::string> positional_sync_strings;
664
665         void toggle_send_midi_feedback ();
666         void toggle_use_mmc ();
667         void toggle_send_mmc ();
668         void toggle_send_mtc ();
669
670         void toggle_use_osc ();
671
672         void toggle_denormal_protection ();
673
674         void set_input_auto_connect (ARDOUR::AutoConnectOption);
675         void set_output_auto_connect (ARDOUR::AutoConnectOption);
676         void set_solo_model (ARDOUR::SoloModel);
677         void set_monitor_model (ARDOUR::MonitorModel);
678         void set_remote_model (ARDOUR::RemoteModel);
679         void set_denormal_model (ARDOUR::DenormalModel);
680
681         void toggle_StopPluginsWithTransport();
682         void toggle_DoNotRunPluginsWhileRecording();
683         void toggle_VerifyRemoveLastCapture();
684         void toggle_PeriodicSafetyBackups();
685         void toggle_StopRecordingOnXrun();
686         void toggle_StopTransportAtEndOfSession();
687         void toggle_GainReduceFastTransport();
688         void toggle_LatchedSolo();
689         void toggle_ShowSoloMutes();
690         void toggle_LatchedRecordEnable ();
691         void toggle_RegionEquivalentsOverlap ();
692         void toggle_PrimaryClockDeltaEditCursor ();
693         void toggle_SecondaryClockDeltaEditCursor ();
694
695         void mtc_port_changed ();
696         void map_solo_model ();
697         void map_monitor_model ();
698         void map_denormal_model ();
699         void map_remote_model ();
700         void map_file_header_format ();
701         void map_file_data_format ();
702         void map_input_auto_connect ();
703         void map_output_auto_connect ();
704         void parameter_changed (const char*);
705
706         void set_meter_hold (ARDOUR::MeterHold);
707         void set_meter_falloff (ARDOUR::MeterFalloff);
708         void map_meter_hold ();
709         void map_meter_falloff ();
710
711         void toggle_control_protocol (ARDOUR::ControlProtocolInfo*);
712         void toggle_control_protocol_feedback (ARDOUR::ControlProtocolInfo*, const char* group_name, std::string action_name);
713
714         bool can_save_keybindings;
715         bool first_idle ();
716
717         void no_memory_warning ();
718         void check_memory_locking ();
719
720         bool ab_direction;
721         void disable_all_plugins ();
722         void ab_all_plugins ();
723 };
724
725 #endif /* __ardour_gui_h__ */
726