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