More fun with LinuxVSTs & threading
[ardour.git] / gtk2_ardour / editor.cc
index 4407dac256cefd07c2b9878308fd82e9a27135cc..7aaeb466780db1e8e1b5b671f85a4496796427fc 100644 (file)
 #include "gui_object.h"
 #include "gui_thread.h"
 #include "keyboard.h"
-#include "keyeditor.h"
 #include "luainstance.h"
 #include "marker.h"
 #include "midi_region_view.h"
@@ -393,6 +392,7 @@ Editor::Editor ()
        , _all_region_actions_sensitized (false)
        , _ignore_region_action (false)
        , _last_region_menu_was_main (false)
+       , _track_selection_change_without_scroll (false)
        , cd_marker_bar_drag_rect (0)
        , range_bar_drag_rect (0)
        , transport_bar_drag_rect (0)
@@ -828,8 +828,6 @@ Editor::Editor ()
 
        BasicUI::AccessAction.connect (*this, invalidator (*this), boost::bind (&Editor::access_action, this, _1, _2), gui_context());
 
-       PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&Editor::presentation_info_changed, this, _1), gui_context());
-
        /* handle escape */
 
        ARDOUR_UI::instance()->Escape.connect (*this, invalidator (*this), boost::bind (&Editor::escape, this), gui_context());
@@ -868,9 +866,6 @@ Editor::Editor ()
 
        setup_fade_images ();
 
-       LuaInstance::instance(); // instantiate
-       LuaInstance::instance()->ActionChanged.connect (sigc::mem_fun (*this, &Editor::set_script_action_name));
-
        instant_save ();
 }
 
@@ -908,14 +903,6 @@ Editor::~Editor()
        }
 }
 
-void
-Editor::presentation_info_changed (PropertyChange const & what_changed)
-{
-       if (what_changed.contains (Properties::selected)) {
-               track_selection_changed ();
-       }
-}
-
 XMLNode*
 Editor::button_settings () const
 {
@@ -1466,30 +1453,11 @@ Editor::set_session (Session *t)
        _session->register_with_memento_command_factory(id(), this);
        _session->register_with_memento_command_factory(_selection_memento->id(), _selection_memento);
 
-       ActionManager::ui_manager->signal_pre_activate().connect (sigc::mem_fun (*this, &Editor::action_pre_activated));
-
        LuaInstance::instance()->set_session(_session);
 
        start_updating_meters ();
 }
 
-void
-Editor::action_pre_activated (Glib::RefPtr<Action> const & a)
-{
-       if (a->get_name() == "RegionMenu") {
-               /* When the main menu's region menu is opened, we setup the actions so that they look right
-                  in the menu.  I can't find a way of getting a signal when this menu is subsequently closed,
-                  so we resensitize all region actions when the entered regionview or the region selection
-                  changes.  HOWEVER we can't always resensitize on entered_regionview change because that
-                  happens after the region context menu is opened.  So we set a flag here, too.
-
-                  What a carry on :(
-               */
-               sensitize_the_right_region_actions (false, !within_track_canvas);
-               _last_region_menu_was_main = true;
-       }
-}
-
 void
 Editor::fill_xfade_menu (Menu_Helpers::MenuList& items, bool start)
 {
@@ -1717,7 +1685,7 @@ Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type,
        /* When the region menu is opened, we setup the actions so that they look right
           in the menu.
        */
-       sensitize_the_right_region_actions (true, false);
+       sensitize_the_right_region_actions (false);
        _last_region_menu_was_main = false;
 
        menu->signal_hide().connect (sigc::bind (sigc::mem_fun (*this, &Editor::sensitize_all_region_actions), true));
@@ -1954,7 +1922,7 @@ Editor::add_region_context_items (Menu_Helpers::MenuList& edit_items, boost::sha
                _popup_region_menu_item->set_label (menu_item_name);
        }
 
-       /* No latering allowed in later is higher layering model */
+       /* No layering allowed in later is higher layering model */
        RefPtr<Action> act = ActionManager::get_action (X_("EditorMenu"), X_("RegionMenuLayering"));
        if (act && Config->get_layer_model() == LaterHigher) {
                act->set_sensitive (false);
@@ -2365,6 +2333,7 @@ Editor::set_edit_point_preference (EditPoint ep, bool force)
        }
 
        reset_canvas_action_sensitivity (in_track_canvas);
+       sensitize_the_right_region_actions (false);
 
        instant_save ();
 }
@@ -4738,8 +4707,6 @@ Editor::get_preferred_edit_position (EditIgnoreOption ignore, bool from_context_
        framepos_t where = 0;
        EditPoint ep = _edit_point;
 
-       cerr << "ig " << ignore << " fcm " << from_context_menu << " foc " << from_outside_canvas << endl;
-
        if (Profile->get_mixbus()) {
                if (ep == EditAtSelectedMarker) {
                        ep = EditAtPlayhead;
@@ -4749,7 +4716,7 @@ Editor::get_preferred_edit_position (EditIgnoreOption ignore, bool from_context_
        if (from_outside_canvas && (ep == EditAtMouse)) {
                ep = EditAtPlayhead;
        } else if (from_context_menu && (ep == EditAtMouse)) {
-               return  canvas_event_sample (&context_click_event, 0, 0);
+               return canvas_event_sample (&context_click_event, 0, 0);
        }
 
        if (entered_marker) {
@@ -4767,8 +4734,6 @@ Editor::get_preferred_edit_position (EditIgnoreOption ignore, bool from_context_
 
        MusicFrame snap_mf (0, 0);
 
-       cerr << "Using EP " << enum_2_string (ep) << endl;
-
        switch (ep) {
        case EditAtPlayhead:
                if (_dragging_playhead) {
@@ -4970,7 +4935,7 @@ Editor::get_regions_from_selection_and_edit_point (EditIgnoreOption ignore, bool
                        /* no region selected or entered, but some selected tracks:
                         * act on all regions on the selected tracks at the edit point
                         */
-                       framepos_t const where = get_preferred_edit_position (ignore, from_outside_canvas, from_outside_canvas);
+                       framepos_t const where = get_preferred_edit_position (ignore, from_context_menu, from_outside_canvas);
                        get_regions_at(regions, where, tracks);
                }
        }
@@ -5112,6 +5077,38 @@ Editor::get_regions_corresponding_to (boost::shared_ptr<Region> region, vector<R
        }
 }
 
+RegionView*
+Editor::regionview_from_region (boost::shared_ptr<Region> region) const
+{
+       for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) {
+               RouteTimeAxisView* tatv;
+               if ((tatv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
+                       if (!tatv->track()) {
+                               continue;
+                       }
+                       RegionView* marv = tatv->view()->find_view (region);
+                       if (marv) {
+                               return marv;
+                       }
+               }
+       }
+       return NULL;
+}
+
+RouteTimeAxisView*
+Editor::rtav_from_route (boost::shared_ptr<Route> route) const
+{
+       for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) {
+               RouteTimeAxisView* rtav;
+               if ((rtav = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
+                       if (rtav->route() == route) {
+                               return rtav;
+                       }
+               }
+       }
+       return NULL;
+}
+
 void
 Editor::show_rhythm_ferret ()
 {
@@ -5491,6 +5488,9 @@ Editor::timeaxisview_deleted (TimeAxisView *tv)
 void
 Editor::hide_track_in_display (TimeAxisView* tv, bool apply_to_selection)
 {
+       if (!tv) {
+               return;
+       }
        if (apply_to_selection) {
                for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ) {
 
@@ -5513,6 +5513,18 @@ Editor::hide_track_in_display (TimeAxisView* tv, bool apply_to_selection)
        }
 }
 
+void
+Editor::show_track_in_display (TimeAxisView* tv, bool move_into_view)
+{
+       if (!tv) {
+               return;
+       }
+       _routes->show_track_in_display (*tv);
+       if (move_into_view) {
+               ensure_time_axis_view_is_visible (*tv, false);
+       }
+}
+
 bool
 Editor::sync_track_view_list_and_routes ()
 {
@@ -5898,24 +5910,6 @@ Editor::trigger_script (int i)
        LuaInstance::instance()-> call_action (i);
 }
 
-void
-Editor::set_script_action_name (int i, const std::string& n)
-{
-       string const a = string_compose (X_("script-action-%1"), i + 1);
-       Glib::RefPtr<Action> act = ActionManager::get_action(X_("Editor"), a.c_str());
-       assert (act);
-       if (n.empty ()) {
-               act->set_label (string_compose (_("Unset #%1"), i + 1));
-               act->set_tooltip (_("no action bound"));
-               act->set_sensitive (false);
-       } else {
-               act->set_label (n);
-               act->set_tooltip (n);
-               act->set_sensitive (true);
-       }
-       KeyEditor::UpdateBindings ();
-}
-
 void
 Editor::show_editor_list (bool yn)
 {