From 7ee5a3f24d8f5fd5de3da35ccbaef241c2be057b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 9 Dec 2023 02:26:49 +0100 Subject: [PATCH] Keep location lists ordered by start-time --- gtk2_ardour/location_ui.cc | 31 ++++++++++++++++++++++++++++++- gtk2_ardour/location_ui.h | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gtk2_ardour/location_ui.cc b/gtk2_ardour/location_ui.cc index 77e82da5a4..4a8cd31e83 100644 --- a/gtk2_ardour/location_ui.cc +++ b/gtk2_ardour/location_ui.cc @@ -890,7 +890,6 @@ LocationUI::location_remove_requested (ARDOUR::Location *loc) Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc)); } - void LocationUI::location_redraw_ranges () { @@ -979,6 +978,35 @@ LocationUI::location_removed (Location* location) } } +void +LocationUI::start_changed (Location *location) +{ + Gtk::VBox& box = location->is_range_marker() ? range_rows : location_rows; + LocationEditRow* r = NULL; + for (auto const& i : box.children ()) { + r = dynamic_cast (i.get_widget()); + if (r && r->get_location() == location) { + break; + } + } + assert (r); + + int pos = 0; + Locations::LocationList loc = _session->locations()->list (); + loc.sort (LocationSortByStart ()); + for (auto const& l : loc) { + if (location->is_range_marker() != l->is_range_marker()) { + /* Skip locations in the session list that aren't of the right type */ + continue; + } + if (l == location) { + box.reorder_child (*r, pos); + break; + } + ++pos; + } +} + void LocationUI::map_locations (const Locations::LocationList& locations) { @@ -1097,6 +1125,7 @@ LocationUI::set_session(ARDOUR::Session* s) _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context()); _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context()); _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context()); + Location::start_changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::start_changed, this, _1), gui_context()); _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ()); } else { diff --git a/gtk2_ardour/location_ui.h b/gtk2_ardour/location_ui.h index 5c9368bc76..b04e7af890 100644 --- a/gtk2_ardour/location_ui.h +++ b/gtk2_ardour/location_ui.h @@ -203,6 +203,8 @@ private: void location_redraw_ranges (); + void start_changed (ARDOUR::Location*); + gint do_location_remove (ARDOUR::Location *); guint32 i_am_the_modifier;