From 46715fec669e31a5b6d29c3b691cfb57d4f5dd78 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 24 Jul 2024 19:00:48 -0600 Subject: [PATCH] locations: extend API for first_mark_{before,after}_flagged to allow returning the found location Also use newer C++ loop syntax for syntactic sugariness --- libs/ardour/ardour/location.h | 4 ++-- libs/ardour/location.cc | 44 ++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/libs/ardour/ardour/location.h b/libs/ardour/ardour/location.h index 7a36bfde5f..54b2e787d8 100644 --- a/libs/ardour/ardour/location.h +++ b/libs/ardour/ardour/location.h @@ -301,8 +301,8 @@ public: void set_clock_origin (Location*, void *src); - timepos_t first_mark_before_flagged (timepos_t const &, bool include_special_ranges = false, Location::Flags whitelist = Location::Flags (0), Location::Flags blacklist = Location::Flags (0), Location::Flags equalist = Location::Flags (0)); - timepos_t first_mark_after_flagged (timepos_t const &, bool include_special_ranges = false, Location::Flags whitelist = Location::Flags (0), Location::Flags blacklist = Location::Flags (0), Location::Flags equalist = Location::Flags (0)); + timepos_t first_mark_before_flagged (timepos_t const &, bool include_special_ranges = false, Location::Flags whitelist = Location::Flags (0), Location::Flags blacklist = Location::Flags (0), Location::Flags equalist = Location::Flags (0), Location** retval = nullptr); + timepos_t first_mark_after_flagged (timepos_t const &, bool include_special_ranges = false, Location::Flags whitelist = Location::Flags (0), Location::Flags blacklist = Location::Flags (0), Location::Flags equalist = Location::Flags (0), Location** retval = nullptr); timepos_t first_mark_after (timepos_t const & t, bool include_special_ranges = false) { return first_mark_after_flagged (t, include_special_ranges); diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index d396364ee1..f807590834 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -1417,7 +1417,7 @@ struct LocationStartLaterComparison }; timepos_t -Locations::first_mark_before_flagged (timepos_t const & pos, bool include_special_ranges, Location::Flags whitelist, Location::Flags blacklist, Location::Flags equalist) +Locations::first_mark_before_flagged (timepos_t const & pos, bool include_special_ranges, Location::Flags whitelist, Location::Flags blacklist, Location::Flags equalist, Location** retval) { vector locs; { @@ -1436,30 +1436,33 @@ Locations::first_mark_before_flagged (timepos_t const & pos, bool include_specia /* locs is sorted in ascending order */ - for (vector::iterator i = locs.begin(); i != locs.end(); ++i) { - if ((*i).second->is_hidden()) { + for (auto & loc : locs) { + if (loc.second->is_hidden()) { continue; } - if (!include_special_ranges && ((*i).second->is_auto_loop() || (*i).second->is_auto_punch())) { + if (!include_special_ranges && (loc.second->is_auto_loop() || loc.second->is_auto_punch())) { continue; } if (whitelist != Location::Flags (0)) { - if (!((*i).second->flags() & whitelist)) { + if (!(loc.second->flags() & whitelist)) { continue; } } if (blacklist != Location::Flags (0)) { - if ((*i).second->flags() & blacklist) { + if (loc.second->flags() & blacklist) { continue; } } if (equalist != Location::Flags (0)) { - if (!((*i).second->flags() == equalist)) { + if (!(loc.second->flags() == equalist)) { continue; } } - if ((*i).first < pos) { - return (*i).first; + if (loc.first < pos) { + if (retval) { + *retval = loc.second; + } + return loc.first; } } @@ -1480,7 +1483,7 @@ Locations::mark_at (timepos_t const & pos, timecnt_t const & slop, Location::Fla Glib::Threads::RWLock::ReaderLock lm (_lock); for (LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) { - if ((*i)->is_mark() && (flags && ((*i)->flags() == flags))) { + if ((*i)->is_mark() && (!flags || ((*i)->flags() == flags))) { if (pos > (*i)->start()) { delta = (*i)->start().distance (pos); } else { @@ -1505,7 +1508,7 @@ Locations::mark_at (timepos_t const & pos, timecnt_t const & slop, Location::Fla } timepos_t -Locations::first_mark_after_flagged (timepos_t const & pos, bool include_special_ranges, Location::Flags whitelist, Location::Flags blacklist, Location::Flags equalist) +Locations::first_mark_after_flagged (timepos_t const & pos, bool include_special_ranges, Location::Flags whitelist, Location::Flags blacklist, Location::Flags equalist, Location** retval) { vector locs; @@ -1525,30 +1528,33 @@ Locations::first_mark_after_flagged (timepos_t const & pos, bool include_special /* locs is sorted in reverse order */ - for (vector::iterator i = locs.begin(); i != locs.end(); ++i) { - if ((*i).second->is_hidden()) { + for (auto & loc : locs) { + if (loc.second->is_hidden()) { continue; } - if (!include_special_ranges && ((*i).second->is_auto_loop() || (*i).second->is_auto_punch())) { + if (!include_special_ranges && (loc.second->is_auto_loop() || loc.second->is_auto_punch())) { continue; } if (whitelist != Location::Flags (0)) { - if (!((*i).second->flags() & whitelist)) { + if (!(loc.second->flags() & whitelist)) { continue; } } if (blacklist != Location::Flags (0)) { - if ((*i).second->flags() & blacklist) { + if (loc.second->flags() & blacklist) { continue; } } if (equalist != Location::Flags (0)) { - if (!((*i).second->flags() == equalist)) { + if (!(loc.second->flags() == equalist)) { continue; } } - if ((*i).first > pos) { - return (*i).first; + if (loc.first > pos) { + if (retval) { + *retval = loc.second; + } + return loc.first; } }