Fix --template commandline option
[ardour.git] / gtk2_ardour / editor.cc
index ef301370c6aeb6acb4ce35044dfaf070be8225c1..ff587b2fc14683886a363d346e6e0ffeaa3fe3a0 100644 (file)
@@ -262,11 +262,6 @@ Editor::Editor ()
        , clicked_control_point (0)
        , button_release_can_deselect (true)
        , _mouse_changed_selection (false)
-       , region_edit_menu_split_item (0)
-       , region_edit_menu_split_multichannel_item (0)
-       , track_region_edit_playlist_menu (0)
-       , track_edit_playlist_submenu (0)
-       , track_selection_edit_playlist_submenu (0)
        , _popup_region_menu_item (0)
        , _track_canvas (0)
        , _track_canvas_viewport (0)
@@ -375,9 +370,7 @@ Editor::Editor ()
        , meter_marker_menu (0)
        , marker_menu (0)
        , range_marker_menu (0)
-       , transport_marker_menu (0)
        , new_transport_marker_menu (0)
-       , cd_marker_menu (0)
        , marker_menu_item (0)
        , bbt_beat_subdivision (4)
        , _visible_track_count (-1)
@@ -774,8 +767,8 @@ Editor::Editor ()
 
        /* register actions now so that set_state() can find them and set toggles/checks etc */
 
-       register_actions ();
        load_bindings ();
+       register_actions ();
 
        setup_toolbar ();
 
@@ -836,7 +829,6 @@ Editor::Editor ()
 
        _ignore_region_action = false;
        _last_region_menu_was_main = false;
-       _popup_region_menu_item = 0;
 
        _show_marker_lines = false;
 
@@ -860,12 +852,18 @@ Editor::Editor ()
        setup_fade_images ();
 
        set_grid_to (GridTypeNone);
-
-       instant_save ();
 }
 
 Editor::~Editor()
 {
+       delete tempo_marker_menu;
+       delete meter_marker_menu;
+       delete marker_menu;
+       delete range_marker_menu;
+       delete new_transport_marker_menu;
+       delete editor_ruler_menu;
+       delete _popup_region_menu_item;
+
        delete button_bindings;
        delete _routes;
        delete _route_groups;
@@ -983,15 +981,11 @@ Editor::set_entered_track (TimeAxisView* tav)
 void
 Editor::instant_save ()
 {
-       if (!constructed || !ARDOUR_UI::instance()->session_loaded || no_save_instant) {
+       if (!constructed || !_session || no_save_instant) {
                return;
        }
 
-       if (_session) {
-               _session->add_instant_xml(get_state());
-       } else {
-               Config->add_instant_xml(get_state());
-       }
+       _session->add_instant_xml(get_state());
 }
 
 void
@@ -1148,10 +1142,13 @@ Editor::access_action (const std::string& action_group, const std::string& actio
        ENSURE_GUI_THREAD (*this, &Editor::access_action, action_group, action_item)
 
        RefPtr<Action> act;
-       act = ActionManager::get_action (action_group.c_str(), action_item.c_str());
-
-       if (act) {
-               act->activate();
+       try {
+               act = ActionManager::get_action (action_group.c_str(), action_item.c_str());
+               if (act) {
+                       act->activate();
+               }
+       } catch ( ActionManager::MissingActionException const& e) {
+               cerr << "MissingActionException:" << e.what () << endl;
        }
 }
 
@@ -1611,22 +1608,6 @@ Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type,
        case RegionViewNameHighlight:
        case LeftFrameHandle:
        case RightFrameHandle:
-               if (!with_selection) {
-                       if (region_edit_menu_split_item) {
-                               if (clicked_regionview && clicked_regionview->region()->covers (get_preferred_edit_position())) {
-                                       ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, true);
-                               } else {
-                                       ActionManager::set_sensitive (ActionManager::edit_point_in_region_sensitive_actions, false);
-                               }
-                       }
-                       if (region_edit_menu_split_multichannel_item) {
-                               if (clicked_regionview && clicked_regionview->region()->n_channels() > 1) {
-                                       region_edit_menu_split_multichannel_item->set_sensitive (true);
-                               } else {
-                                       region_edit_menu_split_multichannel_item->set_sensitive (false);
-                               }
-                       }
-               }
                break;
 
        case SelectionItem:
@@ -1713,9 +1694,6 @@ Editor::build_track_region_context_menu ()
        /* we've just cleared the track region context menu, so the menu that these
           two items were on will have disappeared; stop them dangling.
        */
-       region_edit_menu_split_item = 0;
-       region_edit_menu_split_multichannel_item = 0;
-
        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
 
        if (rtv) {
@@ -2111,7 +2089,7 @@ Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
        edit_items.push_back (MenuElem (_("Select"), *select_menu));
 
        /* Cut-n-Paste */
-
+#if 0 // unused, why?
        Menu *cutnpaste_menu = manage (new Menu);
        MenuList& cutnpaste_items = cutnpaste_menu->items();
        cutnpaste_menu->set_name ("ArdourContextMenu");
@@ -2119,6 +2097,7 @@ Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
        cutnpaste_items.push_back (MenuElem (_("Cut"), sigc::mem_fun(*this, &Editor::cut)));
        cutnpaste_items.push_back (MenuElem (_("Copy"), sigc::mem_fun(*this, &Editor::copy)));
        cutnpaste_items.push_back (MenuElem (_("Paste"), sigc::bind (sigc::mem_fun(*this, &Editor::paste), 1.0f, true)));
+#endif
 
        Menu *nudge_menu = manage (new Menu());
        MenuList& nudge_items = nudge_menu->items();
@@ -2323,12 +2302,15 @@ Editor::set_snap_mode (SnapMode mode)
 void
 Editor::set_edit_point_preference (EditPoint ep, bool force)
 {
+       if (Profile->get_mixbus()) {
+               if (ep == EditAtSelectedMarker) {
+                       ep = EditAtPlayhead;
+               }
+       }
+
        bool changed = (_edit_point != ep);
 
        _edit_point = ep;
-       if (Profile->get_mixbus())
-               if (ep == EditAtSelectedMarker)
-                       ep = EditAtPlayhead;
 
        string str = edit_point_strings[(int)ep];
        if (str != edit_point_selector.get_text ()) {
@@ -2348,17 +2330,15 @@ Editor::set_edit_point_preference (EditPoint ep, bool force)
                action = "edit-at-playhead";
                break;
        case EditAtSelectedMarker:
-               action = "edit-at-marker";
+               action = "edit-at-selected-marker";
                break;
        case EditAtMouse:
                action = "edit-at-mouse";
                break;
        }
 
-       Glib::RefPtr<Action> act = ActionManager::get_action ("Editor", action);
-       if (act) {
-               Glib::RefPtr<RadioAction>::cast_dynamic(act)->set_active (true);
-       }
+       Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Editor", action);
+       tact->set_active (true);
 
        samplepos_t foo;
        bool in_track_canvas;
@@ -2456,13 +2436,13 @@ Editor::set_state (const XMLNode& node, int version)
                reset_y_origin (y_origin);
        }
 
-       if (node.get_property ("join-object-range", yn)) {
-               RefPtr<Action> act = ActionManager::get_action (X_("MouseMode"), X_("set-mouse-mode-object-range"));
-               if (act) {
-                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-                       tact->set_active (!yn);
-                       tact->set_active (yn);
-               }
+       yn = false;
+       node.get_property ("join-object-range", yn);
+       {
+               RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("MouseMode"), X_("set-mouse-mode-object-range"));
+               /* do it twice to force the change */
+               tact->set_active (!yn);
+               tact->set_active (yn);
                set_mouse_mode(mouse_mode, true);
        }
 
@@ -2486,28 +2466,20 @@ Editor::set_state (const XMLNode& node, int version)
                _regions->reset_sort_type (sort_type, true);
        }
 
-       if (node.get_property ("show-editor-mixer", yn)) {
-
-               Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
-               assert (act);
-
-               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
-
+       yn = false;
+       node.get_property ("show-editor-mixer", yn);
+       {
+               Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("show-editor-mixer"));
                /* do it twice to force the change */
-
                tact->set_active (!yn);
                tact->set_active (yn);
        }
 
-       if (node.get_property ("show-editor-list", yn)) {
-
-               Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
-               assert (act);
-
-               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
-
+       yn = false;
+       node.get_property ("show-editor-list", yn);
+       {
+               Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("show-editor-list"));
                /* do it twice to force the change */
-
                tact->set_active (!yn);
                tact->set_active (yn);
        }
@@ -2517,11 +2489,11 @@ Editor::set_state (const XMLNode& node, int version)
                _the_notebook.set_current_page (el_page);
        }
 
-       if (node.get_property (X_("show-marker-lines"), yn)) {
-               Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-marker-lines"));
-               assert (act);
-               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
-
+       yn = false;
+       node.get_property (X_("show-marker-lines"), yn);
+       {
+               Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("show-marker-lines"));
+               /* do it twice to force the change */
                tact->set_active (!yn);
                tact->set_active (yn);
        }
@@ -2534,10 +2506,8 @@ Editor::set_state (const XMLNode& node, int version)
        }
 
        if (node.get_property ("maximised", yn)) {
-               Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleMaximalEditor"));
-               assert (act);
-               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
-               bool fs = tact && tact->get_active();
+               Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Common"), X_("ToggleMaximalEditor"));
+               bool fs = tact->get_active();
                if (yn ^ fs) {
                        ActionManager::do_action ("Common", "ToggleMaximalEditor");
                }
@@ -2556,24 +2526,18 @@ Editor::set_state (const XMLNode& node, int version)
                 * Not all properties may have been in XML, but
                 * those that are linked to a private variable may need changing
                 */
-               RefPtr<Action> act;
+               RefPtr<ToggleAction> tact;
 
-               act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
+               tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-follow-playhead"));
                yn = _follow_playhead;
-               if (act) {
-                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-                       if (tact->get_active() != yn) {
-                               tact->set_active (yn);
-                       }
+               if (tact->get_active() != yn) {
+                       tact->set_active (yn);
                }
 
-               act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
+               tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-stationary-playhead"));
                yn = _stationary_playhead;
-               if (act) {
-                       RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-                       if (tact->get_active() != yn) {
-                               tact->set_active (yn);
-                       }
+               if (tact->get_active() != yn) {
+                       tact->set_active (yn);
                }
        }
 
@@ -2618,17 +2582,11 @@ Editor::get_state ()
        node->set_property ("mouse-mode", mouse_mode);
        node->set_property ("join-object-range", smart_mode_action->get_active ());
 
-       Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
-       if (act) {
-               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
-               node->set_property (X_("show-editor-mixer"), tact->get_active());
-       }
+       Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("show-editor-mixer"));
+       node->set_property (X_("show-editor-mixer"), tact->get_active());
 
-       act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
-       if (act) {
-               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
-               node->set_property (X_("show-editor-list"), tact->get_active());
-       }
+       tact = ActionManager::get_toggle_action (X_("Editor"), X_("show-editor-list"));
+       node->set_property (X_("show-editor-list"), tact->get_active());
 
        node->set_property (X_("editor-list-page"), _the_notebook.get_current_page ());
 
@@ -2821,7 +2779,7 @@ MusicSample
 Editor::snap_to_minsec (MusicSample presnap, RoundMode direction, SnapPref gpref)
 {
        MusicSample ret(presnap);
-       
+
        const samplepos_t one_second = _session->sample_rate();
        const samplepos_t one_minute = one_second * 60;
        const samplepos_t one_hour = one_minute * 60;
@@ -2863,7 +2821,7 @@ Editor::snap_to_minsec (MusicSample presnap, RoundMode direction, SnapPref gpref
                        }
                } break;
        }
-       
+
        return ret;
 }
 
@@ -2872,12 +2830,12 @@ Editor::snap_to_cd_frames (MusicSample presnap, RoundMode direction, SnapPref gp
 {
        if ((gpref != SnapToGrid_Unscaled) && (minsec_ruler_scale != minsec_show_msecs)) {
                return snap_to_minsec (presnap, direction, gpref);
-       }       
-       
+       }
+
        const samplepos_t one_second = _session->sample_rate();
 
        MusicSample ret(presnap);
-       
+
        if ((direction == RoundUpMaybe || direction == RoundDownMaybe) &&
                presnap.sample % (one_second/75) == 0) {
                /* start is already on a whole CD sample, do nothing */
@@ -2894,7 +2852,7 @@ MusicSample
 Editor::snap_to_bbt (MusicSample presnap, RoundMode direction, SnapPref gpref)
 {
        MusicSample ret(presnap);
-       
+
        if (gpref != SnapToGrid_Unscaled) { // use the visual grid lines which are limited by the zoom scale that the user selected
 
                int divisor = 2;
@@ -2944,7 +2902,7 @@ Editor::snap_to_bbt (MusicSample presnap, RoundMode direction, SnapPref gpref)
        } else {
                ret = _session->tempo_map().round_to_quarter_note_subdivision (presnap.sample, get_grid_beat_divisions(_grid_type), direction);
        }
-       
+
        return ret;
 }
 
@@ -2952,11 +2910,11 @@ ARDOUR::MusicSample
 Editor::snap_to_grid (MusicSample presnap, RoundMode direction, SnapPref gpref)
 {
        MusicSample ret(presnap);
-       
+
        if (grid_musical()) {
                ret = snap_to_bbt (presnap, direction, gpref);
        }
-       
+
        switch (_grid_type) {
                case GridTypeTimecode:
                        ret = snap_to_timecode(presnap, direction, gpref);
@@ -3097,10 +3055,14 @@ Editor::setup_toolbar ()
        Glib::RefPtr<SizeGroup> mouse_mode_size_group = SizeGroup::create (SIZE_GROUP_VERTICAL);
        mouse_mode_size_group->add_widget (smart_mode_button);
        mouse_mode_size_group->add_widget (mouse_move_button);
-       mouse_mode_size_group->add_widget (mouse_cut_button);
+       if (!Profile->get_mixbus()) {
+               mouse_mode_size_group->add_widget (mouse_cut_button);
+       }
        mouse_mode_size_group->add_widget (mouse_select_button);
        mouse_mode_size_group->add_widget (mouse_timefx_button);
-       mouse_mode_size_group->add_widget (mouse_audition_button);
+       if (!Profile->get_mixbus()) {
+               mouse_mode_size_group->add_widget (mouse_audition_button);
+       }
        mouse_mode_size_group->add_widget (mouse_draw_button);
        mouse_mode_size_group->add_widget (mouse_content_button);
 
@@ -4080,11 +4042,8 @@ Editor::update_grid ()
 void
 Editor::toggle_follow_playhead ()
 {
-       RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
-       if (act) {
-               RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-               set_follow_playhead (tact->get_active());
-       }
+       RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-follow-playhead"));
+       set_follow_playhead (tact->get_active());
 }
 
 /** @param yn true to follow playhead, otherwise false.
@@ -4105,11 +4064,8 @@ Editor::set_follow_playhead (bool yn, bool catch_up)
 void
 Editor::toggle_stationary_playhead ()
 {
-       RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-stationary-playhead"));
-       if (act) {
-               RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
-               set_stationary_playhead (tact->get_active());
-       }
+       RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-stationary-playhead"));
+       set_stationary_playhead (tact->get_active());
 }
 
 void
@@ -4423,7 +4379,7 @@ Editor::new_playlists (TimeAxisView* v)
 {
        begin_reversible_command (_("new playlists"));
        vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
-       _session->playlists->get (playlists);
+       _session->playlists()->get (playlists);
        mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, ARDOUR::Properties::group_select.property_id);
        commit_reversible_command ();
 }
@@ -4439,7 +4395,7 @@ Editor::copy_playlists (TimeAxisView* v)
 {
        begin_reversible_command (_("copy playlists"));
        vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
-       _session->playlists->get (playlists);
+       _session->playlists()->get (playlists);
        mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, ARDOUR::Properties::group_select.property_id);
        commit_reversible_command ();
 }
@@ -4454,7 +4410,7 @@ Editor::clear_playlists (TimeAxisView* v)
 {
        begin_reversible_command (_("clear playlists"));
        vector<boost::shared_ptr<ARDOUR::Playlist> > playlists;
-       _session->playlists->get (playlists);
+       _session->playlists()->get (playlists);
        mapover_tracks (sigc::mem_fun (*this, &Editor::mapped_clear_playlist), v, ARDOUR::Properties::group_select.property_id);
        commit_reversible_command ();
 }
@@ -5628,7 +5584,7 @@ Editor::timeaxisview_deleted (TimeAxisView *tv)
                         * button to inactive (which also unticks the menu option)
                         */
 
-                       ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
+                       ActionManager::uncheck_toggleaction ("Editor/show-editor-mixer");
                }
        }
 }