Save marker selection state in instant.xml (#4203).
authorCarl Hetherington <carl@carlh.net>
Thu, 20 Oct 2011 00:05:31 +0000 (00:05 +0000)
committerCarl Hetherington <carl@carlh.net>
Thu, 20 Oct 2011 00:05:31 +0000 (00:05 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10245 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_markers.cc
gtk2_ardour/public_editor.h
gtk2_ardour/selection.cc

index 08099c2972b14c4090164c6c869817f28d5501f8..67e89e9e3ce6e9c09757469b7bce40dd2d922823 100644 (file)
@@ -1137,6 +1137,44 @@ Editor::set_session (Session *t)
 
        compute_fixed_ruler_scale ();
 
+       /* Make sure we have auto loop and auto punch ranges */
+
+       Location* loc = _session->locations()->auto_loop_location();
+       if (loc == 0) {
+               loc = new Location (*_session, 0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
+
+               if (loc->start() == loc->end()) {
+                       loc->set_end (loc->start() + 1);
+               }
+
+               _session->locations()->add (loc, false);
+               _session->set_auto_loop_location (loc);
+       } else {
+               // force name
+               loc->set_name (_("Loop"));
+       }
+
+       loc = _session->locations()->auto_punch_location();
+
+       if (loc == 0) {
+               loc = new Location (*_session, 0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
+
+               if (loc->start() == loc->end()) {
+                       loc->set_end (loc->start() + 1);
+               }
+
+               _session->locations()->add (loc, false);
+               _session->set_auto_punch_location (loc);
+       } else {
+               // force name
+               loc->set_name (_("Punch"));
+       }
+
+       refresh_location_display ();
+
+       /* This must happen after refresh_location_display(), as (amongst other things) we restore
+          the selected Marker; this needs the LocationMarker list to be available.
+       */
        XMLNode* node = ARDOUR_UI::instance()->editor_settings();
        set_state (*node, Stateful::loading_state_version);
 
@@ -1182,43 +1220,10 @@ Editor::set_session (Session *t)
 
        playhead_cursor->canvas_item.show ();
 
-       Location* loc = _session->locations()->auto_loop_location();
-       if (loc == 0) {
-               loc = new Location (*_session, 0, _session->current_end_frame(), _("Loop"),(Location::Flags) (Location::IsAutoLoop | Location::IsHidden));
-
-               if (loc->start() == loc->end()) {
-                       loc->set_end (loc->start() + 1);
-               }
-
-               _session->locations()->add (loc, false);
-               _session->set_auto_loop_location (loc);
-       } else {
-               // force name
-               loc->set_name (_("Loop"));
-       }
-
-       loc = _session->locations()->auto_punch_location();
-
-       if (loc == 0) {
-               loc = new Location (*_session, 0, _session->current_end_frame(), _("Punch"), (Location::Flags) (Location::IsAutoPunch | Location::IsHidden));
-
-               if (loc->start() == loc->end()) {
-                       loc->set_end (loc->start() + 1);
-               }
-
-               _session->locations()->add (loc, false);
-               _session->set_auto_punch_location (loc);
-       } else {
-               // force name
-               loc->set_name (_("Punch"));
-       }
-
        boost::function<void (string)> pc (boost::bind (&Editor::parameter_changed, this, _1));
        Config->map_parameters (pc);
        _session->config.map_parameters (pc);
 
-       refresh_location_display ();
-
        restore_ruler_visibility ();
        //tempo_map_changed (PropertyChange (0));
        _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
index d2c626cb786b50806f0b6e0909e00ccee7d76a5e..8114559fa83526df4c0bd5d193ce8382fc6fabe2 100644 (file)
@@ -590,6 +590,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        LocationMarkers  *find_location_markers (ARDOUR::Location *) const;
        ARDOUR::Location* find_location_from_marker (Marker *, bool& is_start) const;
+       Marker* find_marker_from_location_id (PBD::ID const &, bool) const;
        Marker* entered_marker;
        bool _show_marker_lines;
 
index 4ccacecbbdb20872dcd80297ba287dbfa5871bdd..f66b7d02c63808b6485c3588e08430b2cce91fe3 100644 (file)
@@ -1505,3 +1505,15 @@ Editor::remove_sorted_marker (Marker* m)
                i->second.remove (m);
        }
 }
+
+Marker *
+Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
+{
+       for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
+               if (i->first->id() == id) {
+                       return is_start ? i->second->start : i->second->end;
+               }
+       }
+
+       return 0;
+}
index 0a927c592174f400b3abb29cffe986aaecf0fb06..f5d7dad522a2130825c1bd130b5c61578e02c28f 100644 (file)
@@ -384,6 +384,9 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulDestructible {
 
        virtual void get_pointer_position (double &, double &) const = 0;
 
+       virtual ARDOUR::Location* find_location_from_marker (Marker *, bool &) const = 0;
+       virtual Marker* find_marker_from_location_id (PBD::ID const &, bool) const = 0;
+
        /// Singleton instance, set up by Editor::Editor()
 
        static PublicEditor* _instance;
index 35998a2a1d4baf3a0049433038c367f39fef8b08..5b7a88c81e5ff0e3d10057f2ba1c21540a2cc02e 100644 (file)
@@ -1141,6 +1141,16 @@ Selection::get_state () const
                }
        }
 
+       for (MarkerSelection::const_iterator i = markers.begin(); i != markers.end(); ++i) {
+               XMLNode* t = node->add_child (X_("Marker"));
+
+               bool is_start;
+               Location* loc = editor->find_location_from_marker (*i, is_start);
+
+               t->add_property (X_("id"), atoi (loc->id().to_s().c_str()));
+               t->add_property (X_("start"), is_start ? X_("yes") : X_("no"));
+       }
+
        return *node;
 }
 
@@ -1186,7 +1196,22 @@ Selection::set_state (XMLNode const & node, int)
                                        add (atv.get());
                                }
                        }
+
+               } else if ((*i)->name() == X_("Marker")) {
+
+                       XMLProperty* prop_id = (*i)->property (X_("id"));
+                       XMLProperty* prop_start = (*i)->property (X_("start"));
+                       assert (prop_id);
+                       assert (prop_start);
+
+                       PBD::ID id (prop_id->value ());
+                       Marker* m = editor->find_marker_from_location_id (id, string_is_affirmative (prop_start->value ()));
+                       if (m) {
+                               add (m);
+                       }
+                       
                }
+               
        }
 
        return 0;