From 84896dbd56fb92c753bc589f2dd84072520a7c81 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Mon, 9 Dec 2024 11:31:02 +0100 Subject: [PATCH 1/2] Add const overload to GetTstampStaves --- include/vrv/timeinterface.h | 5 ++++- src/timeinterface.cpp | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/vrv/timeinterface.h b/include/vrv/timeinterface.h index ed723564bf0..e569d1a6c03 100644 --- a/include/vrv/timeinterface.h +++ b/include/vrv/timeinterface.h @@ -87,7 +87,10 @@ class TimePointInterface : public Interface, public AttStaffIdent, public AttSta /** * Return a vector of staves looking at the @staff attribute or at the parent staff or the @startid */ - std::vector GetTstampStaves(Measure *measure, Object *object); + ///@{ + std::vector GetTstampStaves(const Measure *measure, const Object *object) const; + std::vector GetTstampStaves(const Measure *measure, const Object *object); + ///@} /** * Return true if the interface owner is encoded in the measure of its start element diff --git a/src/timeinterface.cpp b/src/timeinterface.cpp index 3a8ed6e1abd..6ccc04ac1c1 100644 --- a/src/timeinterface.cpp +++ b/src/timeinterface.cpp @@ -108,17 +108,26 @@ bool TimePointInterface::IsOnStaff(int n) const return false; } -std::vector TimePointInterface::GetTstampStaves(Measure *measure, Object *object) +std::vector TimePointInterface::GetTstampStaves(const Measure *measure, const Object *object) +{ + std::vector staves = std::as_const(*this).GetTstampStaves(measure, object); + std::vector stavesCasted; + std::transform(staves.begin(), staves.end(), std::back_inserter(stavesCasted), + [](const Staff *staff) { return const_cast(staff); }); + return stavesCasted; +} + +std::vector TimePointInterface::GetTstampStaves(const Measure *measure, const Object *object) const { assert(measure); assert(object); - std::vector staves; + std::vector staves; std::vector staffList; // For within without @staff we try to get the @staff from the ancestor if (object->Is(FIGURE) && !this->HasStaff()) { - Harm *harm = vrv_cast(object->GetFirstAncestor(HARM)); + const Harm *harm = vrv_cast(object->GetFirstAncestor(HARM)); if (harm) { staffList = harm->GetStaff(); } @@ -127,7 +136,7 @@ std::vector TimePointInterface::GetTstampStaves(Measure *measure, Objec bool isInBetween = false; // limit between support to some elements? if (object->Is({ DYNAM, DIR, HAIRPIN, TEMPO })) { - AttPlacementRelStaff *att = dynamic_cast(object); + const AttPlacementRelStaff *att = dynamic_cast(object); assert(att); isInBetween = (att->GetPlace() == STAFFREL_between); } @@ -141,18 +150,18 @@ std::vector TimePointInterface::GetTstampStaves(Measure *measure, Objec } } else if (m_start && !m_start->Is({ BARLINE, TIMESTAMP_ATTR })) { - Staff *staff = m_start->GetAncestorStaff(); + const Staff *staff = m_start->GetAncestorStaff(); staffList.push_back(staff->GetN()); } else if (measure->GetChildCount(STAFF) == 1) { // If we have no @staff or startid but only one staff child assume it is the first one - Staff *staff = vrv_cast(measure->GetFirst(STAFF)); + const Staff *staff = vrv_cast(measure->GetFirst(STAFF)); staffList.push_back(staff->GetN()); } for (int staffN : staffList) { AttNIntegerComparison comparison(STAFF, staffN); - Staff *staff = vrv_cast(measure->FindDescendantByComparison(&comparison, 1)); + const Staff *staff = vrv_cast(measure->FindDescendantByComparison(&comparison, 1)); if (!staff) { // LogDebug("Staff with @n '%d' not found in measure '%s'", *iter, measure->GetID().c_str()); continue; From f7e0c3c5f7967c6ace054bc6403acb5c518872a4 Mon Sep 17 00:00:00 2001 From: David Bauer <63608463+brdvd@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:49:49 +0100 Subject: [PATCH 2/2] Update include/vrv/timeinterface.h Co-authored-by: Klaus Rettinghaus --- include/vrv/timeinterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vrv/timeinterface.h b/include/vrv/timeinterface.h index e569d1a6c03..d405044677b 100644 --- a/include/vrv/timeinterface.h +++ b/include/vrv/timeinterface.h @@ -85,7 +85,7 @@ class TimePointInterface : public Interface, public AttStaffIdent, public AttSta bool IsOnStaff(int n) const; /** - * Return a vector of staves looking at the @staff attribute or at the parent staff or the @startid + * Return a vector of staves looking at the @staff attribute or at the parent staff of the @startid */ ///@{ std::vector GetTstampStaves(const Measure *measure, const Object *object) const;