fix crash when copy'ing latent plugins
[ardour.git] / gtk2_ardour / ardour_ui.h
index ab67c0214de801fd556966c1ce88b12f58e63089..59a3c963e5f417062b3e07c2e5da9e72c7da08a8 100644 (file)
 #include <gtkmm/menubar.h>
 #include <gtkmm/textbuffer.h>
 #include <gtkmm/adjustment.h>
-#include <gtkmm2ext/gtk_ui.h>
-#include <gtkmm2ext/click_box.h>
-#include <gtkmm2ext/stateful_button.h>
-#include <gtkmm2ext/bindable_button.h>
+
+#include "gtkmm2ext/gtk_ui.h"
+#include "gtkmm2ext/click_box.h"
+#include "gtkmm2ext/stateful_button.h"
+#include "gtkmm2ext/bindable_button.h"
+#include "gtkmm2ext/bindings.h"
+#include "gtkmm2ext/visibility_tracker.h"
 
 #include "ardour/ardour.h"
 #include "ardour/types.h"
@@ -86,6 +89,7 @@
 #include "global_port_matrix.h"
 #include "keyeditor.h"
 #include "location_ui.h"
+#include "lua_script_manager.h"
 #include "rc_option_editor.h"
 #include "route_params_ui.h"
 #include "session_option_editor.h"
@@ -100,6 +104,7 @@ class EngineControl;
 class ExportVideoDialog;
 class KeyEditor;
 class LocationUIWindow;
+class LuaScriptManager;
 class RCOptionEditor;
 class RouteParams_UI;
 class SessionOptionEditor;
@@ -119,11 +124,12 @@ class ArdourPrompter;
 class PublicEditor;
 class SaveAsDialog;
 class SessionDialog;
-class SessionOptionEditor;
+class SessionOptionEditorWindow;
 class ShuttleControl;
 class Splash;
 class TimeInfoBox;
 class Meterbridge;
+class LuaWindow;
 class MidiTracer;
 class NSM_Client;
 class LevelMeterHBox;
@@ -139,17 +145,17 @@ namespace ARDOUR {
        class ProcessThread;
 }
 
-namespace Gtkmm2ext {
-       class TearOff;
-}
-
 namespace Gtk {
        class ProgressBar;
 }
 
+namespace Gtkmm2ext {
+       class Tabbable;
+}
+
 class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 {
-    public:
+public:
        ARDOUR_UI (int *argcp, char **argvp[], const char* localedir);
        ~ARDOUR_UI();
 
@@ -184,7 +190,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        bool get_smart_mode () const;
 
        int get_session_parameters (bool quit_on_cancel, bool should_be_new = false, std::string load_template = "");
-        int  build_session_from_dialog (SessionDialog&, const std::string& session_name, const std::string& session_path);
+       int  build_session_from_dialog (SessionDialog&, const std::string& session_name, const std::string& session_path);
        bool ask_about_loading_existing_session (const std::string& session_path);
 
        /// @return true if session was successfully unloaded.
@@ -196,12 +202,20 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 
        static ARDOUR_UI *instance () { return theArdourUI; }
 
+       /* signal emitted when escape key is pressed. All UI components that
+          need to respond to Escape in some way (e.g. break drag, clear
+          selection, etc) should connect to and handle this.
+       */
+       PBD::Signal0<void> Escape;
+
        PublicEditor&     the_editor() { return *editor;}
        Mixer_UI* the_mixer() { return mixer; }
 
        void new_midi_tracer_window ();
        void toggle_editing_space();
        void toggle_mixer_space();
+       void toggle_mixer_list();
+       void toggle_monitor_section_visibility ();
        void toggle_keep_tearoffs();
 
        static PublicEditor* _instance;
@@ -214,9 +228,11 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        static sigc::signal<void, framepos_t, bool, framepos_t> Clock;
 
        static void close_all_dialogs () { CloseAllDialogs(); }
-        static sigc::signal<void> CloseAllDialogs;
+       static sigc::signal<void> CloseAllDialogs;
 
+       XMLNode* main_window_settings() const;
        XMLNode* editor_settings() const;
+       XMLNode* preferences_settings() const;
        XMLNode* mixer_settings () const;
        XMLNode* keyboard_settings () const;
        XMLNode* tearoff_settings (const char*) const;
@@ -245,12 +261,17 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 
        void synchronize_sync_source_and_video_pullup ();
 
-       void add_route (Gtk::Window* float_window);
-        void add_routes_part_two ();
-        void add_routes_thread ();
+       void add_route ();
+       void add_route_dialog_finished (int);
+
+       void add_routes_part_two ();
+       void add_routes_thread ();
 
        void start_duplicate_routes ();
 
+       void add_lua_script ();
+       void remove_lua_script ();
+
        void add_video (Gtk::Window* float_window);
        void remove_video ();
        void start_video_server_menu (Gtk::Window* float_window);
@@ -259,36 +280,57 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        void flush_videotimeline_cache (bool localcacheonly=false);
        void export_video (bool range = false);
 
+       void session_add_vca (std::string const &, uint32_t);
+
+       void session_add_audio_route (bool, int32_t, int32_t, ARDOUR::TrackMode, ARDOUR::RouteGroup *, uint32_t, std::string const &, bool, ARDOUR::PresentationInfo::order_t order);
        void session_add_audio_track (
                int input_channels,
                int32_t output_channels,
                ARDOUR::TrackMode mode,
                ARDOUR::RouteGroup* route_group,
                uint32_t how_many,
-               std::string const & name_template
+               std::string const & name_template,
+               bool strict_io,
+               ARDOUR::PresentationInfo::order_t order
                ) {
-
-               session_add_audio_route (true, input_channels, output_channels, mode, route_group, how_many, name_template);
+               session_add_audio_route (true, input_channels, output_channels, mode, route_group, how_many, name_template, strict_io, order);
        }
 
-       void session_add_audio_bus (int input_channels, int32_t output_channels, ARDOUR::RouteGroup* route_group,
-                                   uint32_t how_many, std::string const & name_template) {
-               session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, route_group, how_many, name_template);
+       void session_add_audio_bus (
+                       int input_channels,
+                       int32_t output_channels,
+                       ARDOUR::RouteGroup* route_group,
+                       uint32_t how_many,
+                       std::string const & name_template,
+                       bool strict_io,
+                       ARDOUR::PresentationInfo::order_t order
+                       ) {
+               session_add_audio_route (false, input_channels, output_channels, ARDOUR::Normal, route_group, how_many, name_template, strict_io, order);
        }
 
-       void session_add_midi_track (ARDOUR::RouteGroup* route_group, uint32_t how_many, std::string const & name_template,
-                                    ARDOUR::PluginInfoPtr instrument) {
-               session_add_midi_route (true, route_group, how_many, name_template, instrument);
+       void session_add_midi_track (
+                       ARDOUR::RouteGroup* route_group,
+                       uint32_t how_many,
+                       std::string const & name_template,
+                       bool strict_io,
+                       ARDOUR::PluginInfoPtr instrument,
+                       ARDOUR::Plugin::PresetRecord* preset,
+                       ARDOUR::PresentationInfo::order_t order
+               ) {
+               session_add_midi_route (true, route_group, how_many, name_template, strict_io, instrument, preset, order);
        }
 
-        void session_add_mixed_track (const ARDOUR::ChanCount& input, const ARDOUR::ChanCount& output, ARDOUR::RouteGroup* route_group, uint32_t how_many, std::string const & name_template,
-                                     ARDOUR::PluginInfoPtr instrument);
-
-       /*void session_add_midi_bus () {
-               session_add_midi_route (false);
-       }*/
-
-        void attach_to_engine ();
+       void session_add_mixed_track (const ARDOUR::ChanCount&, const ARDOUR::ChanCount&, ARDOUR::RouteGroup*, uint32_t, std::string const &, bool,
+                                     ARDOUR::PluginInfoPtr, ARDOUR::Plugin::PresetRecord* pset,
+                                     ARDOUR::PresentationInfo::order_t order);
+       void session_add_midi_bus (ARDOUR::RouteGroup*, uint32_t, std::string const &, bool, ARDOUR::PluginInfoPtr, ARDOUR::Plugin::PresetRecord* pset,
+                                  ARDOUR::PresentationInfo::order_t order);
+       void session_add_midi_route (bool, ARDOUR::RouteGroup *, uint32_t, std::string const &, bool,
+                                    ARDOUR::PluginInfoPtr, ARDOUR::Plugin::PresetRecord*,
+                                    ARDOUR::PresentationInfo::order_t order);
+       void display_insufficient_ports_message ();
+
+       void attach_to_engine ();
        void post_engine ();
 
        gint exit_on_main_window_close (GdkEventAny *);
@@ -300,8 +342,6 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 
        bool check_audioengine(Gtk::Window&);
 
-       void update_tearoff_visibility ();
-
        void setup_profile ();
        void setup_tooltips ();
 
@@ -314,11 +354,29 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        void reset_route_peak_display (ARDOUR::Route*);
        void reset_group_peak_display (ARDOUR::RouteGroup*);
 
-        const std::string& announce_string() const { return _announce_string; }
+       const std::string& announce_string() const { return _announce_string; }
 
        void hide_application ();
 
-  protected:
+       Gtk::Notebook& tabs();
+       Gtk::Window& main_window () { return _main_window; }
+
+       void setup_toplevel_window (Gtk::Window&, const std::string& name, void* owner);
+
+       /* called from a static C function */
+
+       GtkNotebook* tab_window_root_drop (GtkNotebook* src,
+                                          GtkWidget* w,
+                                          gint x,
+                                          gint y,
+                                          gpointer user_data);
+
+       bool tabbed_window_state_event_handler (GdkEventWindowState*, void* object);
+       bool key_event_handler (GdkEventKey*, Gtk::Window* window);
+
+       Gtkmm2ext::ActionMap global_actions;
+
+protected:
        friend class PublicEditor;
 
        void toggle_auto_play ();
@@ -332,33 +390,47 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        void reenable_hide_loop_punch_ruler_if_appropriate ();
        void toggle_auto_return ();
        void toggle_click ();
-        void toggle_audio_midi_setup ();
+       void toggle_audio_midi_setup ();
        void toggle_session_auto_loop ();
        void toggle_rc_options_window ();
        void toggle_session_options_window ();
 
-  private:
-       PublicEditor*        editor;
-       Mixer_UI*            mixer;
-       NSM_Client*          nsm;
-       bool                _was_dirty;
-        bool                _mixer_on_top;
-        bool                _initial_verbose_plugin_scan;
-        bool first_time_engine_run;
-
-       void goto_editor_window ();
-       void goto_mixer_window ();
-       void toggle_mixer_window ();
+private:
+       Gtk::Window   _main_window;
+       Gtkmm2ext::VisibilityTracker* main_window_visibility;
+       Gtk::VBox      main_vpacker;
+       Gtk::HBox      status_bar_hpacker;
+       Gtk::Notebook _tabs;
+       PublicEditor*  editor;
+       Mixer_UI*      mixer;
+       Gtk::Tooltips _tooltips;
+       NSM_Client*    nsm;
+       bool          _was_dirty;
+       bool          _mixer_on_top;
+       bool          _initial_verbose_plugin_scan;
+       bool           first_time_engine_run;
+
+       void show_tabbable (Gtkmm2ext::Tabbable*);
+       void hide_tabbable (Gtkmm2ext::Tabbable*);
+       void detach_tabbable (Gtkmm2ext::Tabbable*);
+       void attach_tabbable (Gtkmm2ext::Tabbable*);
+       void button_change_tabbable_visibility (Gtkmm2ext::Tabbable*);
+       void key_change_tabbable_visibility (Gtkmm2ext::Tabbable*);
+       void toggle_editor_and_mixer ();
+
+       void tabbable_state_change (Gtkmm2ext::Tabbable&);
+
        void toggle_meterbridge ();
-        void toggle_editor_mixer ();
+       void toggle_luawindow ();
 
        int  setup_windows ();
        void setup_transport ();
        void setup_clock ();
 
        static ARDOUR_UI *theArdourUI;
+       SessionDialog *_session_dialog;
 
-        int starting ();
+       int starting ();
 
        int  ask_about_saving_session (const std::vector<std::string>& actions);
 
@@ -368,6 +440,9 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        void update_autosave();
        sigc::connection _autosave_connection;
 
+       void session_dirty_changed ();
+       void update_title ();
+
        void map_transport_state ();
        int32_t do_engine_start ();
 
@@ -386,22 +461,14 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        void         start_clocking ();
        void         stop_clocking ();
 
-       bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
-
        void update_transport_clocks (framepos_t pos);
        void record_state_changed ();
 
        std::list<MidiTracer*> _midi_tracer_windows;
 
-       void detach_tearoff (Gtk::Box* parent, Gtk::Widget* contents);
-       void reattach_tearoff (Gtk::Box* parent, Gtk::Widget* contents, int32_t order);
-       void reattach_all_tearoffs ();
-
        /* Transport Control */
 
-       Gtkmm2ext::TearOff*      transport_tearoff;
        Gtk::Frame               transport_frame;
-       Gtk::HBox                transport_tearoff_hbox;
        Gtk::HBox                transport_hbox;
        Gtk::Fixed               transport_base;
        Gtk::Fixed               transport_button_base;
@@ -427,7 +494,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
            };
 
            TransportControllable (std::string name, ARDOUR_UI&, ToggleType);
-           void set_value (double);
+           void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
            double get_value (void) const;
 
            ARDOUR_UI& ui;
@@ -472,6 +539,9 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        ArdourButton feedback_alert_button;
        ArdourButton error_alert_button;
 
+       ArdourButton action_script_call_btn[10];
+       Gtk::Table action_script_table;
+
        Gtk::VBox alert_box;
        Gtk::VBox meter_box;
        LevelMeterHBox * editor_meter;
@@ -565,9 +635,6 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        void edit_metadata ();
        void import_metadata ();
 
-       void session_add_audio_route (bool, int32_t, int32_t, ARDOUR::TrackMode, ARDOUR::RouteGroup *, uint32_t, std::string const &);
-       void session_add_midi_route (bool, ARDOUR::RouteGroup *, uint32_t, std::string const &, ARDOUR::PluginInfoPtr);
-
        void set_transport_sensitivity (bool);
 
        //stuff for ProTools-style numpad
@@ -606,46 +673,56 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        bool process_snapshot_session_prompter (ArdourPrompter& prompter, bool switch_to_it);
        void snapshot_session (bool switch_to_it);
 
+       void quick_snapshot_session (bool switch_to_it);  //does not promtp for name, just makes a timestamped file
+
        SaveAsDialog* save_as_dialog;
 
        bool save_as_progress_update (float fraction, int64_t cnt, int64_t total, Gtk::Label* label, Gtk::ProgressBar* bar);
        void save_session_as ();
        void rename_session ();
-       void setup_order_hint (AddRouteDialog::InsertAt);
+       ARDOUR::PresentationInfo::order_t translate_order (AddRouteDialog::InsertAt);
 
        int         create_mixer ();
        int         create_editor ();
+       int         create_meterbridge ();
+       int         create_luawindow ();
+       int         create_masters ();
 
        Meterbridge  *meterbridge;
-       int         create_meterbridge ();
-        /* Dialogs that can be created via new<T> */
-
-        WM::Proxy<SpeakerDialog> speaker_config_window;
-        WM::Proxy<KeyEditor> key_editor;
-        WM::Proxy<RCOptionEditor> rc_option_editor;
-        WM::Proxy<AddRouteDialog> add_route_dialog;
-        WM::Proxy<About> about;
-        WM::Proxy<LocationUIWindow> location_ui;
-        WM::Proxy<RouteParams_UI> route_params;
-        WM::Proxy<EngineControl> audio_midi_setup;
-        WM::Proxy<ExportVideoDialog> export_video_dialog;
-
-        /* Windows/Dialogs that require a creator method */
-
-        WM::ProxyWithConstructor<SessionOptionEditor> session_option_editor;
-        WM::ProxyWithConstructor<AddVideoDialog> add_video_dialog;
-        WM::ProxyWithConstructor<BundleManager> bundle_manager;
-        WM::ProxyWithConstructor<BigClockWindow> big_clock_window;
-        WM::ProxyWithConstructor<GlobalPortMatrixWindow> audio_port_matrix;
-        WM::ProxyWithConstructor<GlobalPortMatrixWindow> midi_port_matrix;
-
-        /* creator methods */
-
-        SessionOptionEditor*    create_session_option_editor ();
-        BundleManager*          create_bundle_manager ();
-        AddVideoDialog*         create_add_video_dialog ();
-        BigClockWindow*         create_big_clock_window();
-        GlobalPortMatrixWindow* create_global_port_matrix (ARDOUR::DataType);
+       LuaWindow    *luawindow;
+
+       /* Dialogs that can be created via new<T> */
+
+       RCOptionEditor* rc_option_editor;
+       Gtk::HBox rc_option_editor_placeholder;
+
+       WM::Proxy<SpeakerDialog> speaker_config_window;
+       WM::Proxy<AddRouteDialog> add_route_dialog;
+       WM::Proxy<About> about;
+       WM::Proxy<LocationUIWindow> location_ui;
+       WM::Proxy<RouteParams_UI> route_params;
+       WM::Proxy<EngineControl> audio_midi_setup;
+       WM::Proxy<ExportVideoDialog> export_video_dialog;
+       WM::Proxy<LuaScriptManager> lua_script_window;
+
+       /* Windows/Dialogs that require a creator method */
+
+       WM::ProxyWithConstructor<SessionOptionEditor> session_option_editor;
+       WM::ProxyWithConstructor<AddVideoDialog> add_video_dialog;
+       WM::ProxyWithConstructor<BundleManager> bundle_manager;
+       WM::ProxyWithConstructor<BigClockWindow> big_clock_window;
+       WM::ProxyWithConstructor<GlobalPortMatrixWindow> audio_port_matrix;
+       WM::ProxyWithConstructor<GlobalPortMatrixWindow> midi_port_matrix;
+       WM::ProxyWithConstructor<KeyEditor> key_editor;
+
+       /* creator methods */
+
+       SessionOptionEditor*    create_session_option_editor ();
+       BundleManager*          create_bundle_manager ();
+       AddVideoDialog*         create_add_video_dialog ();
+       BigClockWindow*         create_big_clock_window();
+       GlobalPortMatrixWindow* create_global_port_matrix (ARDOUR::DataType);
+       KeyEditor*              create_key_editor ();
 
        ARDOUR::SystemExec *video_server_process;
 
@@ -659,7 +736,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 
        void install_actions ();
 
-       void toggle_record_enable (uint32_t);
+       void toggle_record_enable (uint16_t);
 
        uint32_t rec_enabled_streams;
        void count_recenabled_streams (ARDOUR::Route&);
@@ -695,11 +772,12 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
        void plugin_scan_dialog (std::string type, std::string plugin, bool);
        void plugin_scan_timeout (int);
 
-        void session_format_mismatch (std::string, std::string);
+       void session_format_mismatch (std::string, std::string);
 
        void session_dialog (std::string);
        int pending_state_dialog ();
        int sr_mismatch_dialog (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
+       void sr_mismatch_message (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
 
        Gtk::MenuItem* jack_disconnect_item;
        Gtk::MenuItem* jack_reconnect_item;
@@ -732,26 +810,22 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
                        Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
                        const char *msg);
        Gtk::Label status_bar_label;
-        bool status_bar_button_press (GdkEventButton*);
+       bool status_bar_button_press (GdkEventButton*);
 
        void loading_message (const std::string& msg);
 
        PBD::ScopedConnectionList forever_connections;
-        PBD::ScopedConnection halt_connection;
+       PBD::ScopedConnection halt_connection;
 
-        void step_edit_status_change (bool);
+       void step_edit_status_change (bool);
 
-       void platform_specific ();
-       void platform_setup ();
-
-       /* these are used only in response to a platform-specific "ShouldQuit" signal
-        */
+       /* these are used only in response to a platform-specific "ShouldQuit" signal */
        bool idle_finish ();
        void queue_finish ();
        void fontconfig_dialog ();
 
-        int missing_file (ARDOUR::Session*s, std::string str, ARDOUR::DataType type);
-        int ambiguous_file (std::string file, std::vector<std::string> hits);
+       int missing_file (ARDOUR::Session*s, std::string str, ARDOUR::DataType type);
+       int ambiguous_file (std::string file, std::vector<std::string> hits);
 
        bool click_button_clicked (GdkEventButton *);
 
@@ -783,13 +857,37 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 
        bool xrun_button_release (GdkEventButton* ev);
 
-        std::string _announce_string;
-        void check_announcements ();
+       std::string _announce_string;
+       void check_announcements ();
 
-        int do_audio_midi_setup (uint32_t);
+       int do_audio_midi_setup (uint32_t);
        void audioengine_became_silent ();
 
        DuplicateRouteDialog* duplicate_routes_dialog;
+
+       void grab_focus_after_dialog ();
+
+       void tabs_switch (GtkNotebookPage*, guint page_number);
+       void tabs_page_added (Gtk::Widget*, guint);
+       void tabs_page_removed (Gtk::Widget*, guint);
+       ArdourButton editor_visibility_button;
+       ArdourButton mixer_visibility_button;
+       ArdourButton prefs_visibility_button;
+
+       bool key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev, Gtkmm2ext::Bindings*);
+       bool try_gtk_accel_binding (GtkWindow* win, GdkEventKey* ev, bool translate, GdkModifierType modifier);
+
+       bool main_window_delete_event (GdkEventAny*);
+       bool idle_ask_about_quit ();
+
+       void load_bindings ();
+       bool tabbable_visibility_button_press (GdkEventButton* ev, std::string const& tabbable_name);
+
+       void step_up_through_tabs ();
+       void step_down_through_tabs ();
+
+       void escape ();
+       void pre_release_dialog ();
 };
 
 #endif /* __ardour_gui_h__ */