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