From abedf1fae33bb1215d4e2f2c3b84e1ced80a6e9d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 20 Oct 2011 00:05:31 +0000 Subject: [PATCH] Save marker selection state in instant.xml (#4203). git-svn-id: svn://localhost/ardour2/branches/3.0@10245 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.cc | 71 +++++++++++++++++++---------------- gtk2_ardour/editor.h | 1 + gtk2_ardour/editor_markers.cc | 12 ++++++ gtk2_ardour/public_editor.h | 3 ++ gtk2_ardour/selection.cc | 25 ++++++++++++ 5 files changed, 79 insertions(+), 33 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 08099c2972..67e89e9e3c 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -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 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); diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index d2c626cb78..8114559fa8 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -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; diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index 4ccacecbbd..f66b7d02c6 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -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; +} diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index 0a927c5921..f5d7dad522 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -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; diff --git a/gtk2_ardour/selection.cc b/gtk2_ardour/selection.cc index 35998a2a1d..5b7a88c81e 100644 --- a/gtk2_ardour/selection.cc +++ b/gtk2_ardour/selection.cc @@ -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; -- 2.30.2