diff --git a/include/vrv/doc.h b/include/vrv/doc.h index d1cfdc7a7af..710d73c3ef0 100644 --- a/include/vrv/doc.h +++ b/include/vrv/doc.h @@ -90,12 +90,12 @@ class Doc : public Object { /** * Generate a document pgFoot if none is provided */ - bool GenerateFooter(); + void GenerateFooter(); /** * Generate a document pgHead from the MEI header if none is provided */ - bool GenerateHeader(); + void GenerateHeader(); /** * Generate measure numbers from measure attributes @@ -121,11 +121,6 @@ class Doc : public Object { */ bool HasPage(int pageIdx) const; - /** - * Get all the Score in the visible Mdiv. - */ - std::list GetScores(); - /** * Get the Pages in the visible Mdiv. * Will find it only when having read a pages-based MEI file, @@ -141,6 +136,31 @@ class Doc : public Object { */ int GetPageCount() const; + /** + * Get the first scoreDef + */ + ///@{ + ScoreDef *GetFirstScoreDef(); + const ScoreDef *GetFirstScoreDef() const; + ///@} + + /** + * Get all visible scores / the first visible score + * Lazily updates the visible scores, hence not const + */ + ///@{ + std::list GetVisibleScores(); + Score *GetFirstVisibleScore(); + ///@} + + /** + * Get the corresponding score for a node + */ + ///@{ + Score *GetCorrespondingScore(const Object *object); + const Score *GetCorrespondingScore(const Object *object) const; + ///@} + /** * Return true if the MIDI generation is already done */ @@ -225,7 +245,7 @@ class Doc : public Object { * Get the default distance from the staff for the object * The distance is given in x * MEI UNIT */ - data_MEASUREMENTSIGNED GetStaffDistance(const ClassId classId, int staffIndex, data_STAFFREL staffPosition); + data_MEASUREMENTSIGNED GetStaffDistance(const Object *object, int staffIndex, data_STAFFREL staffPosition) const; /** * Prepare the timemap for MIDI and timemap file export. @@ -418,19 +438,6 @@ class Doc : public Object { bool HasFacsimile() const { return m_facsimile != NULL; } ///@} - /** - * @name Setter and getter for the current Score/ScoreDef. - * If not set, then looks for the first Score in the Document and use that. - * The currentScoreDef is also changed by the Object::Process whenever as Score is reached. - * When processing backward, the ScoreDef is changed when reaching the corresponding PageMilestoneEnd - */ - ///@{ - Score *GetCurrentScore(); - ScoreDef *GetCurrentScoreDef(); - void SetCurrentScore(Score *score); - bool HasCurrentScore() const { return m_currentScore != NULL; } - ///@} - /** * Return true if the document has been cast off already. */ @@ -477,6 +484,11 @@ class Doc : public Object { */ void PrepareMeasureIndices(); + /** + * Determine all visible scores + */ + void CollectVisibleScores(); + public: Page *m_selectionPreceding; Page *m_selectionFollowing; @@ -546,12 +558,10 @@ class Doc : public Object { Resources m_resources; /** - * @name Holds a pointer to the current score/scoreDef. - * Set by Doc::GetCurrentScoreDef or explicitly through Doc::SetCurrentScoreDef + * The list of all visible scores + * Used in Doc::GetCorrespondingScore to quickly determine the score for an object */ - ///@{ - Score *m_currentScore; - ///@} + std::list m_visibleScores; /** * A flag indicating if the document has been cast off or not. diff --git a/include/vrv/floatingobject.h b/include/vrv/floatingobject.h index aaa9d9edcf3..f6cd1f450a3 100644 --- a/include/vrv/floatingobject.h +++ b/include/vrv/floatingobject.h @@ -251,7 +251,7 @@ class FloatingPositioner : public BoundingBox { /** * Update the Y drawing relative position based on collision detection with the overlapping bounding box */ - void CalcDrawingYRel(Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox); + void CalcDrawingYRel(const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox); /** * Align extender elements across systems diff --git a/include/vrv/iomei.h b/include/vrv/iomei.h index e162f386646..6b0d7800119 100644 --- a/include/vrv/iomei.h +++ b/include/vrv/iomei.h @@ -306,7 +306,7 @@ class MEIOutput : public Output { * Scoredef manipulation */ ///@{ - void WriteCustomScoreDef(); + void WriteCustomScoreDef(ScoreDef *scoreDef); void AdjustStaffDef(StaffDef *staffDef, Measure *measure); bool AdjustLabel(Label *label); ///@} diff --git a/include/vrv/object.h b/include/vrv/object.h index 8ab619368d9..1cb3f41ff41 100644 --- a/include/vrv/object.h +++ b/include/vrv/object.h @@ -692,7 +692,6 @@ class Object : public BoundingBox { * Helper methods for functor processing */ ///@{ - void UpdateDocumentScore(bool direction); bool SkipChildren(bool visibleOnly) const; bool FiltersApply(const Filters *filters, Object *object) const; ///@} diff --git a/include/vrv/page.h b/include/vrv/page.h index 7bab10d7ec7..f1751100c99 100644 --- a/include/vrv/page.h +++ b/include/vrv/page.h @@ -48,11 +48,6 @@ class Page : public Object { bool IsSupportedChild(Object *object) override; ///@} - /** - * Return the number of system (children are System object only) - */ - int GetSystemCount() const { return (int)GetChildren().size(); } - /** * @name Get and set the pixel per unit factor. */ diff --git a/include/vrv/score.h b/include/vrv/score.h index de496139af5..975909c70b9 100644 --- a/include/vrv/score.h +++ b/include/vrv/score.h @@ -56,12 +56,6 @@ class Score : public PageElement, public PageMilestoneInterface, public AttLabel const ScoreDef *GetScoreDef() const { return &m_scoreDef; } ///@} - /** - * Helper looking at the parent Doc and set its scoreDef as current one. - * Called from Object::Process - */ - void SetAsCurrent(); - /** * Calculate the height of the pgHead/pgHead2 and pgFoot/pgFoot2 (if any) * Requires the Doc to have an empty Pages object because it adds temporary pages diff --git a/src/adjustaccidxfunctor.cpp b/src/adjustaccidxfunctor.cpp index ece6761c994..7bc8b01512d 100644 --- a/src/adjustaccidxfunctor.cpp +++ b/src/adjustaccidxfunctor.cpp @@ -10,6 +10,7 @@ //---------------------------------------------------------------------------- #include "doc.h" +#include "score.h" //---------------------------------------------------------------------------- @@ -41,7 +42,8 @@ FunctorCode AdjustAccidXFunctor::VisitAlignmentReference(AlignmentReference *ali if (accids.empty()) return FUNCTOR_SIBLINGS; assert(m_doc); - StaffDef *staffDef = m_doc->GetCurrentScoreDef()->GetStaffDef(alignmentReference->GetN()); + ScoreDef *scoreDef = m_doc->GetCorrespondingScore(alignmentReference)->GetScoreDef(); + StaffDef *staffDef = scoreDef->GetStaffDef(alignmentReference->GetN()); int staffSize = (staffDef && staffDef->HasScale()) ? staffDef->GetScale() : 100; std::sort(accids.begin(), accids.end(), AccidSpaceSort()); diff --git a/src/adjustdotsfunctor.cpp b/src/adjustdotsfunctor.cpp index 63dc27b7a40..1f930da9a88 100644 --- a/src/adjustdotsfunctor.cpp +++ b/src/adjustdotsfunctor.cpp @@ -11,6 +11,7 @@ #include "doc.h" #include "elementpart.h" +#include "score.h" #include "staff.h" //---------------------------------------------------------------------------- @@ -125,7 +126,7 @@ FunctorCode AdjustDotsFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustDotsFunctor::VisitScore(Score *score) { - m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); + m_staffNs = score->GetScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/adjustgracexposfunctor.cpp b/src/adjustgracexposfunctor.cpp index 6d9ec49c51f..85e4876cbb5 100644 --- a/src/adjustgracexposfunctor.cpp +++ b/src/adjustgracexposfunctor.cpp @@ -10,6 +10,7 @@ //---------------------------------------------------------------------------- #include "doc.h" +#include "score.h" //---------------------------------------------------------------------------- @@ -230,7 +231,7 @@ FunctorCode AdjustGraceXPosFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustGraceXPosFunctor::VisitScore(Score *score) { - m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); + m_staffNs = score->GetScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/adjustlayersfunctor.cpp b/src/adjustlayersfunctor.cpp index 7b312d143a6..058120c970c 100644 --- a/src/adjustlayersfunctor.cpp +++ b/src/adjustlayersfunctor.cpp @@ -10,6 +10,7 @@ //---------------------------------------------------------------------------- #include "doc.h" +#include "score.h" #include "staff.h" //---------------------------------------------------------------------------- @@ -148,7 +149,7 @@ FunctorCode AdjustLayersFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustLayersFunctor::VisitScore(Score *score) { - m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); + m_staffNs = score->GetScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/adjustxposfunctor.cpp b/src/adjustxposfunctor.cpp index 07b4117b196..5436c605497 100644 --- a/src/adjustxposfunctor.cpp +++ b/src/adjustxposfunctor.cpp @@ -12,6 +12,7 @@ #include "doc.h" #include "multirest.h" #include "rest.h" +#include "score.h" #include "staff.h" #include "system.h" @@ -298,7 +299,7 @@ FunctorCode AdjustXPosFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustXPosFunctor::VisitScore(Score *score) { - m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); + m_staffNs = score->GetScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/doc.cpp b/src/doc.cpp index 3fd5b393d28..b36a19f5b59 100644 --- a/src/doc.cpp +++ b/src/doc.cpp @@ -125,7 +125,6 @@ void Doc::Reset() m_drawingPageMarginTop = 0; m_drawingPage = NULL; - m_currentScore = NULL; m_currentScoreDefDone = false; m_dataPreparationDone = false; m_timemapTempo = 0.0; @@ -191,7 +190,8 @@ bool Doc::GenerateDocumentScoreDef() return false; } - this->GetCurrentScoreDef()->Reset(); + ScoreDef *scoreDef = this->GetFirstScoreDef(); + scoreDef->Reset(); StaffGrp *staffGrp = new StaffGrp(); for (Object *object : staves) { Staff *staff = vrv_cast(object); @@ -202,57 +202,57 @@ bool Doc::GenerateDocumentScoreDef() if (!measure->IsMeasuredMusic()) staffDef->SetNotationtype(NOTATIONTYPE_mensural); staffGrp->AddChild(staffDef); } - this->GetCurrentScoreDef()->AddChild(staffGrp); + scoreDef->AddChild(staffGrp); LogInfo("ScoreDef generated"); return true; } -bool Doc::GenerateFooter() +void Doc::GenerateFooter() { - if (this->GetCurrentScoreDef()->FindDescendantByType(PGFOOT)) { - return false; - } - - PgFoot *pgFoot = new PgFoot(); - pgFoot->SetFunc(PGFUNC_first); - // We mark it as generated for not having it written in the output - pgFoot->IsGenerated(true); - pgFoot->LoadFooter(this); - pgFoot->SetType("autogenerated"); - this->GetCurrentScoreDef()->AddChild(pgFoot); + for (Score *score : this->GetVisibleScores()) { + ScoreDef *scoreDef = score->GetScoreDef(); + if (scoreDef->FindDescendantByType(PGFOOT)) continue; - PgFoot *pgFoot2 = new PgFoot(); - pgFoot2->SetFunc(PGFUNC_all); - pgFoot2->IsGenerated(true); - pgFoot2->LoadFooter(this); - pgFoot2->SetType("autogenerated"); - this->GetCurrentScoreDef()->AddChild(pgFoot2); + PgFoot *pgFoot = new PgFoot(); + pgFoot->SetFunc(PGFUNC_first); + // We mark it as generated for not having it written in the output + pgFoot->IsGenerated(true); + pgFoot->LoadFooter(this); + pgFoot->SetType("autogenerated"); + scoreDef->AddChild(pgFoot); - return true; + PgFoot *pgFoot2 = new PgFoot(); + pgFoot2->SetFunc(PGFUNC_all); + pgFoot2->IsGenerated(true); + pgFoot2->LoadFooter(this); + pgFoot2->SetType("autogenerated"); + scoreDef->AddChild(pgFoot2); + } } -bool Doc::GenerateHeader() +void Doc::GenerateHeader() { - if (this->GetCurrentScoreDef()->FindDescendantByType(PGHEAD)) return false; + for (Score *score : this->GetVisibleScores()) { + ScoreDef *scoreDef = score->GetScoreDef(); + if (scoreDef->FindDescendantByType(PGHEAD)) continue; - PgHead *pgHead = new PgHead(); - pgHead->SetFunc(PGFUNC_first); - // We mark it as generated for not having it written in the output - pgHead->IsGenerated(true); - pgHead->GenerateFromMEIHeader(m_header); - pgHead->SetType("autogenerated"); - this->GetCurrentScoreDef()->AddChild(pgHead); + PgHead *pgHead = new PgHead(); + pgHead->SetFunc(PGFUNC_first); + // We mark it as generated for not having it written in the output + pgHead->IsGenerated(true); + pgHead->GenerateFromMEIHeader(m_header); + pgHead->SetType("autogenerated"); + scoreDef->AddChild(pgHead); - PgHead *pgHead2 = new PgHead(); - pgHead2->SetFunc(PGFUNC_all); - pgHead2->IsGenerated(true); - pgHead2->AddPageNum(HORIZONTALALIGNMENT_center, VERTICALALIGNMENT_top); - pgHead2->SetType("autogenerated"); - this->GetCurrentScoreDef()->AddChild(pgHead2); - - return true; + PgHead *pgHead2 = new PgHead(); + pgHead2->SetFunc(PGFUNC_all); + pgHead2->IsGenerated(true); + pgHead2->AddPageNum(HORIZONTALALIGNMENT_center, VERTICALALIGNMENT_top); + pgHead2->SetType("autogenerated"); + scoreDef->AddChild(pgHead2); + } } void Doc::PrepareMeasureIndices() @@ -345,11 +345,12 @@ void Doc::CalculateTimemap() double tempo = MIDI_TEMPO; // Set tempo - if (this->GetCurrentScoreDef()->HasMidiBpm()) { - tempo = this->GetCurrentScoreDef()->GetMidiBpm(); + ScoreDef *scoreDef = this->GetFirstVisibleScore()->GetScoreDef(); + if (scoreDef->HasMidiBpm()) { + tempo = scoreDef->GetMidiBpm(); } - else if (this->GetCurrentScoreDef()->HasMm()) { - tempo = Tempo::CalcTempo(this->GetCurrentScoreDef()); + else if (scoreDef->HasMm()) { + tempo = Tempo::CalcTempo(scoreDef); } // We first calculate the maximum duration of each measure @@ -372,7 +373,6 @@ void Doc::CalculateTimemap() void Doc::ExportMIDI(smf::MidiFile *midiFile) { - if (!this->HasTimemap()) { // generate MIDI timemap before progressing CalculateTimemap(); @@ -384,11 +384,12 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) double tempo = MIDI_TEMPO; // set MIDI tempo - if (this->GetCurrentScoreDef()->HasMidiBpm()) { - tempo = this->GetCurrentScoreDef()->GetMidiBpm(); + ScoreDef *scoreDef = this->GetFirstVisibleScore()->GetScoreDef(); + if (scoreDef->HasMidiBpm()) { + tempo = scoreDef->GetMidiBpm(); } - else if (this->GetCurrentScoreDef()->HasMm()) { - tempo = Tempo::CalcTempo(this->GetCurrentScoreDef()); + else if (scoreDef->HasMm()) { + tempo = Tempo::CalcTempo(scoreDef); } midiFile->addTempo(0, 0, tempo); @@ -417,10 +418,8 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) int midiTrack = 1; Filters filters; for (staves = layerTree.child.begin(); staves != layerTree.child.end(); ++staves) { - - ScoreDef *currentScoreDef = this->GetCurrentScoreDef(); int transSemi = 0; - if (StaffDef *staffDef = currentScoreDef->GetStaffDef(staves->first)) { + if (StaffDef *staffDef = scoreDef->GetStaffDef(staves->first)) { // get the transposition (semi-tone) value for the staff if (staffDef->HasTransSemi()) transSemi = staffDef->GetTransSemi(); midiTrack = staffDef->GetN(); @@ -462,16 +461,16 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) } // set MIDI key signature KeySig *keySig = vrv_cast(staffDef->FindDescendantByType(KEYSIG)); - if (!keySig && (currentScoreDef->HasKeySigInfo())) { - keySig = vrv_cast(currentScoreDef->GetKeySig()); + if (!keySig && (scoreDef->HasKeySigInfo())) { + keySig = vrv_cast(scoreDef->GetKeySig()); } if (keySig && keySig->HasSig()) { midiFile->addKeySignature(midiTrack, 0, keySig->GetFifthsInt(), (keySig->GetMode() == MODE_minor)); } // set MIDI time signature MeterSig *meterSig = vrv_cast(staffDef->FindDescendantByType(METERSIG)); - if (!meterSig && (currentScoreDef->HasMeterSigInfo())) { - meterSig = vrv_cast(currentScoreDef->GetMeterSig()); + if (!meterSig && (scoreDef->HasMeterSigInfo())) { + meterSig = vrv_cast(scoreDef->GetMeterSig()); } if (meterSig && meterSig->HasCount() && meterSig->HasUnit()) { midiFile->addTimeSignature(midiTrack, 0, meterSig->GetTotalCount(), meterSig->GetUnit()); @@ -482,7 +481,7 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) GenerateMIDIFunctor generateScoreDefMIDI(midiFile); generateScoreDefMIDI.SetChannel(midiChannel); generateScoreDefMIDI.SetTrack(midiTrack); - currentScoreDef->Process(generateScoreDefMIDI); + scoreDef->Process(generateScoreDefMIDI); for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) { filters.Clear(); @@ -574,6 +573,10 @@ void Doc::PrepareData() this->PrepareMeasureIndices(); + /************ Collect all visible scores ************/ + + this->CollectVisibleScores(); + /************ Store default durations ************/ PrepareDurationFunctor prepareDuration; @@ -858,8 +861,10 @@ void Doc::PrepareData() } } - ScoreDefSetGrpSymFunctor scoreDefSetGrpSym; - this->GetCurrentScoreDef()->Process(scoreDefSetGrpSym); + for (Score *score : this->GetVisibleScores()) { + ScoreDefSetGrpSymFunctor scoreDefSetGrpSym; + score->GetScoreDef()->Process(scoreDefSetGrpSym); + } // LogElapsedTimeEnd ("Preparing drawing"); @@ -878,12 +883,7 @@ void Doc::ScoreDefSetCurrentDoc(bool force) } // First we need to set Page::m_score and Page::m_scoreEnd - // We do it by going BACKWARD, with a depth limit of 3 (we want to hit the Score elements) ScoreDefSetCurrentPageFunctor scoreDefSetCurrentPage(this); - scoreDefSetCurrentPage.SetDirection(BACKWARD); - this->Process(scoreDefSetCurrentPage, 3); - // Do it again FORWARD to set Page::m_scoreEnd - relies on Page::m_score not being NULL - scoreDefSetCurrentPage.SetDirection(FORWARD); this->Process(scoreDefSetCurrentPage, 3); ScoreDefSetCurrentFunctor scoreDefSetCurrent(this); @@ -904,10 +904,9 @@ void Doc::ScoreDefOptimizeDoc() void Doc::ScoreDefSetGrpSymDoc() { - // Group symbols need to be resolved using scoreDef, since there might be @starid/@endid attributes that determine + // Group symbols need to be resolved using scoreDef, since there might be @startid/@endid attributes that determine // their positioning ScoreDefSetGrpSymFunctor scoreDefSetGrpSym; - // this->GetCurrentScoreDef()->Process(scoreDefSetGrpSym); this->Process(scoreDefSetGrpSym); } @@ -936,7 +935,7 @@ void Doc::CastOffDocBase(bool useSb, bool usePb, bool smart) return; } - std::list scores = this->GetScores(); + std::list scores = this->GetVisibleScores(); assert(!scores.empty()); this->ScoreDefSetCurrentDoc(); @@ -1093,7 +1092,7 @@ void Doc::CastOffEncodingDoc() this->ScoreDefSetCurrentDoc(true); // Optimize the doc if one of the score requires optimization - for (Score *score : this->GetScores()) { + for (Score *score : this->GetVisibleScores()) { if (score->ScoreDefNeedsOptimization(m_options->m_condense.GetValue())) { this->ScoreDefOptimizeDoc(); break; @@ -1446,18 +1445,6 @@ bool Doc::HasPage(int pageIdx) const return ((pageIdx >= 0) && (pageIdx < pages->GetChildCount())); } -std::list Doc::GetScores() -{ - std::list scores; - ListOfObjects objects = this->FindAllDescendantsByType(SCORE, false, 3); - for (const auto object : objects) { - Score *score = vrv_cast(object); - assert(score); - scores.push_back(score); - } - return scores; -} - Pages *Doc::GetPages() { return vrv_cast(this->FindDescendantByType(PAGES)); @@ -1474,6 +1461,72 @@ int Doc::GetPageCount() const return ((pages) ? pages->GetChildCount() : 0); } +ScoreDef *Doc::GetFirstScoreDef() +{ + return const_cast(std::as_const(*this).GetFirstScoreDef()); +} + +const ScoreDef *Doc::GetFirstScoreDef() const +{ + const Score *score = vrv_cast(this->FindDescendantByType(SCORE, 3)); + + return score ? score->GetScoreDef() : NULL; +} + +std::list Doc::GetVisibleScores() +{ + if (m_visibleScores.empty()) { + this->CollectVisibleScores(); + + assert(!m_visibleScores.empty()); + } + + return m_visibleScores; +} + +Score *Doc::GetFirstVisibleScore() +{ + if (m_visibleScores.empty()) { + this->CollectVisibleScores(); + + assert(!m_visibleScores.empty()); + } + + return m_visibleScores.front(); +} + +Score *Doc::GetCorrespondingScore(const Object *object) +{ + return const_cast(std::as_const(*this).GetCorrespondingScore(object)); +} + +const Score *Doc::GetCorrespondingScore(const Object *object) const +{ + assert(!m_visibleScores.empty()); + + const Score *correspondingScore = m_visibleScores.front(); + for (Score *score : m_visibleScores) { + if ((score == object) || Object::IsPreOrdered(score, object)) { + correspondingScore = score; + } + } + return correspondingScore; +} + +void Doc::CollectVisibleScores() +{ + m_visibleScores.clear(); + ListOfObjects objects = this->FindAllDescendantsByType(SCORE, false, 3); + for (Object *object : objects) { + Score *score = vrv_cast(object); + assert(score); + // Visible scores have milestone end + if (score->GetMilestoneEnd()) { + m_visibleScores.push_back(score); + } + } +} + int Doc::GetGlyphHeight(char32_t code, int staffSize, bool graceSize) const { int x, y, w, h; @@ -1846,32 +1899,34 @@ double Doc::GetTopMargin(const ClassId classId) const return m_options->m_defaultTopMargin.GetValue(); } -data_MEASUREMENTSIGNED Doc::GetStaffDistance(const ClassId classId, int staffIndex, data_STAFFREL staffPosition) +data_MEASUREMENTSIGNED Doc::GetStaffDistance(const Object *object, int staffIndex, data_STAFFREL staffPosition) const { + const ScoreDef *scoreDef = this->GetCorrespondingScore(object)->GetScoreDef(); + data_MEASUREMENTSIGNED distance; if (staffPosition == STAFFREL_above || staffPosition == STAFFREL_below) { - if (classId == DIR) { + if (object->Is(DIR)) { // Inspect the scoreDef attribute - if (this->GetCurrentScoreDef()->HasDirDist()) { - distance = this->GetCurrentScoreDef()->GetDirDist(); + if (scoreDef->HasDirDist()) { + distance = scoreDef->GetDirDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); + const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasDirDist()) { distance = staffDef->GetDirDist(); } } - else if (classId == DYNAM) { + else if (object->Is(DYNAM)) { distance.SetVu(m_options->m_dynamDist.GetDefault()); // Inspect the scoreDef attribute - if (this->GetCurrentScoreDef()->HasDynamDist()) { - distance = this->GetCurrentScoreDef()->GetDynamDist(); + if (scoreDef->HasDynamDist()) { + distance = scoreDef->GetDynamDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); + const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasDynamDist()) { distance = staffDef->GetDynamDist(); } @@ -1881,16 +1936,16 @@ data_MEASUREMENTSIGNED Doc::GetStaffDistance(const ClassId classId, int staffInd distance.SetVu(m_options->m_dynamDist.GetValue()); } } - else if (classId == HARM) { + else if (object->Is(HARM)) { distance.SetVu(m_options->m_harmDist.GetDefault()); // Inspect the scoreDef attribute - if (this->GetCurrentScoreDef()->HasHarmDist()) { - distance = this->GetCurrentScoreDef()->GetHarmDist(); + if (scoreDef->HasHarmDist()) { + distance = scoreDef->GetHarmDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); + const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasHarmDist()) { distance = staffDef->GetHarmDist(); } @@ -1900,14 +1955,14 @@ data_MEASUREMENTSIGNED Doc::GetStaffDistance(const ClassId classId, int staffInd distance.SetVu(m_options->m_harmDist.GetValue()); } } - else if (classId == TEMPO) { + else if (object->Is(TEMPO)) { // Inspect the scoreDef attribute - if (this->GetCurrentScoreDef()->HasTempoDist()) { - distance = this->GetCurrentScoreDef()->GetTempoDist(); + if (scoreDef->HasTempoDist()) { + distance = scoreDef->GetTempoDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); + const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasTempoDist()) { distance = staffDef->GetTempoDist(); } @@ -2029,27 +2084,6 @@ int Doc::GetAdjustedDrawingPageWidth() const return (contentWidth + m_drawingPageMarginLeft + m_drawingPageMarginRight) / DEFINITION_FACTOR; } -Score *Doc::GetCurrentScore() -{ - if (!m_currentScore) { - m_currentScore = vrv_cast(this->FindDescendantByType(SCORE)); - assert(m_currentScore); - } - return m_currentScore; -} - -ScoreDef *Doc::GetCurrentScoreDef() -{ - if (!m_currentScore) this->GetCurrentScore(); - - return m_currentScore->GetScoreDef(); -} - -void Doc::SetCurrentScore(Score *score) -{ - m_currentScore = score; -} - //---------------------------------------------------------------------------- // Doc functors methods //---------------------------------------------------------------------------- diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index f32481b091b..a572a89d6ac 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -29,6 +29,7 @@ #include "neume.h" #include "page.h" #include "rend.h" +#include "score.h" #include "staff.h" #include "staffdef.h" #include "surface.h" @@ -785,8 +786,8 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in parent = m_doc->GetDrawingPage()->FindDescendantByType(MEASURE); assert(parent); newStaff = new Staff(1); - newStaff->m_drawingStaffDef - = vrv_cast(m_doc->GetCurrentScoreDef()->FindDescendantByType(STAFFDEF)); + newStaff->m_drawingStaffDef = vrv_cast( + m_doc->GetCorrespondingScore(parent)->GetScoreDef()->FindDescendantByType(STAFFDEF)); newStaff->m_drawingNotationType = NOTATIONTYPE_neume; newStaff->m_drawingLines = 4; } diff --git a/src/floatingobject.cpp b/src/floatingobject.cpp index c6e46b59f62..a2b126315f9 100644 --- a/src/floatingobject.cpp +++ b/src/floatingobject.cpp @@ -445,7 +445,7 @@ int FloatingPositioner::GetAdmissibleHorizOverlapMargin(const BoundingBox *bbox, } void FloatingPositioner::CalcDrawingYRel( - Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox) + const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox) { assert(doc); assert(staffAlignment); @@ -460,8 +460,7 @@ void FloatingPositioner::CalcDrawingYRel( int staffIndex = staffAlignment->GetStaff()->GetN(); int minStaffDistance = 0.0; - data_MEASUREMENTSIGNED minStaffDistanceMeasurement - = doc->GetStaffDistance(m_object->GetClassId(), staffIndex, m_place); + data_MEASUREMENTSIGNED minStaffDistanceMeasurement = doc->GetStaffDistance(m_object, staffIndex, m_place); if (minStaffDistanceMeasurement.HasValue()) { if (minStaffDistanceMeasurement.GetType() == MEASUREMENTTYPE_px) { diff --git a/src/ioabc.cpp b/src/ioabc.cpp index 5ce7bdae43d..a7473bdae60 100644 --- a/src/ioabc.cpp +++ b/src/ioabc.cpp @@ -224,7 +224,7 @@ int ABCInput::SetBarLine(const std::string &musicCode, int i) void ABCInput::CalcUnitNoteLength() { - MeterSig *meterSig = vrv_cast(m_doc->GetCurrentScoreDef()->FindDescendantByType(METERSIG)); + MeterSig *meterSig = vrv_cast(m_doc->GetFirstScoreDef()->FindDescendantByType(METERSIG)); if (!meterSig || !meterSig->HasUnit() || double(meterSig->GetTotalCount()) / double(meterSig->GetUnit()) >= 0.75) { m_unitDur = 8; m_durDefault = DURATION_8; diff --git a/src/iodarms.cpp b/src/iodarms.cpp index 36082e95284..debf3f3181a 100644 --- a/src/iodarms.cpp +++ b/src/iodarms.cpp @@ -521,7 +521,7 @@ bool DarmsInput::Import(const std::string &data_str) StaffDef *staffDef = new StaffDef(); staffDef->SetN(1); staffGrp->AddChild(staffDef); - m_doc->GetCurrentScoreDef()->AddChild(staffGrp); + m_doc->GetFirstScoreDef()->AddChild(staffGrp); m_doc->ConvertToPageBasedDoc(); diff --git a/src/iohumdrum.cpp b/src/iohumdrum.cpp index 801556e9b85..907caf7992c 100644 --- a/src/iohumdrum.cpp +++ b/src/iohumdrum.cpp @@ -3411,7 +3411,7 @@ void HumdrumInput::prepareStaffGroups(int top, int bot) const std::vector &staffstarts = m_staffstarts; if (staffstarts.size() > 0) { - addMidiTempo(m_doc->GetCurrentScoreDef(), staffstarts[0], top, bot); + addMidiTempo(m_doc->GetFirstScoreDef(), staffstarts[0], top, bot); } hum::HumRegex hre; for (int i = 0; i < (int)staffstarts.size(); ++i) { @@ -3445,7 +3445,7 @@ void HumdrumInput::prepareStaffGroups(int top, int bot) // If there is one staff, then no extra decoration. else if (staffstarts.size() == 1) { StaffGrp *sg = new StaffGrp(); - m_doc->GetCurrentScoreDef()->AddChild(sg); + m_doc->GetFirstScoreDef()->AddChild(sg); sg->AddChild(m_staffdef[0]); } // do something if there is no staff in the score? @@ -3454,7 +3454,7 @@ void HumdrumInput::prepareStaffGroups(int top, int bot) bool status = processStaffDecoration(decoration); if (!status) { StaffGrp *sg = new StaffGrp(); - m_doc->GetCurrentScoreDef()->AddChild(sg); + m_doc->GetFirstScoreDef()->AddChild(sg); sg->SetBarThru(BOOLEAN_false); // setGroupSymbol(sg, staffGroupingSym_SYMBOL_bracket); for (int i = 0; i < (int)m_staffdef.size(); ++i) { @@ -3481,7 +3481,7 @@ void HumdrumInput::prepareStaffGroups(int top, int bot) void HumdrumInput::promoteInstrumentNamesToGroup() { - ScoreDef *sdf = m_doc->GetCurrentScoreDef(); + ScoreDef *sdf = m_doc->GetFirstScoreDef(); int count = sdf->GetChildCount(); for (int i = 0; i < count; ++i) { Object *obj = sdf->GetChild(i); @@ -3555,7 +3555,7 @@ void HumdrumInput::promoteInstrumentsForStaffGroup(StaffGrp *group) void HumdrumInput::promoteInstrumentAbbreviationsToGroup() { - ScoreDef *sdf = m_doc->GetCurrentScoreDef(); + ScoreDef *sdf = m_doc->GetFirstScoreDef(); int count = sdf->GetChildCount(); for (int i = 0; i < count; ++i) { @@ -4007,14 +4007,14 @@ bool HumdrumInput::processStaffDecoration(const std::string &decoration) // There is no barline across the staves in this case. root = new StaffGrp(); root->SetBarThru(BOOLEAN_false); - m_doc->GetCurrentScoreDef()->AddChild(root); + m_doc->GetFirstScoreDef()->AddChild(root); } else if (d[0] == '(') { // The outer group is not bracketed, but bar goes all of // the way through system. root = new StaffGrp(); root->SetBarThru(BOOLEAN_true); - m_doc->GetCurrentScoreDef()->AddChild(root); + m_doc->GetFirstScoreDef()->AddChild(root); } else if (pairing.back() == 0) { skipfirst = true; @@ -4030,7 +4030,7 @@ bool HumdrumInput::processStaffDecoration(const std::string &decoration) else if (d[0] == '[') { setGroupSymbol(root, staffGroupingSym_SYMBOL_bracket); } - m_doc->GetCurrentScoreDef()->AddChild(root); + m_doc->GetFirstScoreDef()->AddChild(root); } std::vector spine; // kernstart index @@ -4271,7 +4271,7 @@ bool HumdrumInput::processStaffDecoration(const std::string &decoration) root->AddChild(sg); } else { - m_doc->GetCurrentScoreDef()->AddChild(sg); + m_doc->GetFirstScoreDef()->AddChild(sg); } for (int i = 0; i < (int)m_staffdef.size(); ++i) { sg->AddChild(m_staffdef[i]); @@ -4294,7 +4294,7 @@ bool HumdrumInput::processStaffDecoration(const std::string &decoration) root->AddChild(sg); } else { - m_doc->GetCurrentScoreDef()->AddChild(sg); + m_doc->GetFirstScoreDef()->AddChild(sg); } } @@ -4371,7 +4371,7 @@ bool HumdrumInput::processStaffDecoration(const std::string &decoration) } else { root_sg = new StaffGrp(); - m_doc->GetCurrentScoreDef()->AddChild(root_sg); + m_doc->GetFirstScoreDef()->AddChild(root_sg); root_sg->SetBarThru(BOOLEAN_false); } for (int i = 0; i < (int)newgroups.size(); ++i) { @@ -4857,7 +4857,7 @@ bool HumdrumInput::prepareFooter( // std::cout << "MEI CONTENT " << meicontent << std::endl; AttFormeworkComparison comparison(PGFOOT, PGFUNC_first); - Object *pgfoot = tempdoc.GetCurrentScoreDef()->FindDescendantByComparison(&comparison); + Object *pgfoot = tempdoc.GetFirstScoreDef()->FindDescendantByComparison(&comparison); if (pgfoot == NULL) { return false; } @@ -4875,10 +4875,10 @@ bool HumdrumInput::prepareFooter( return false; } - m_doc->GetCurrentScoreDef()->AddChild(pgfoot); + m_doc->GetFirstScoreDef()->AddChild(pgfoot); AttFormeworkComparison comparison2(PGFOOT, PGFUNC_all); - Object *pgfoot2 = tempdoc.GetCurrentScoreDef()->FindDescendantByComparison(&comparison2); + Object *pgfoot2 = tempdoc.GetFirstScoreDef()->FindDescendantByComparison(&comparison2); if (pgfoot2 == NULL) { return true; } @@ -4896,7 +4896,7 @@ bool HumdrumInput::prepareFooter( return true; } - m_doc->GetCurrentScoreDef()->AddChild(pgfoot2); + m_doc->GetFirstScoreDef()->AddChild(pgfoot2); return true; } @@ -5032,7 +5032,7 @@ bool HumdrumInput::prepareHeader( // std::string meicontent = meioutput.GetOutput(); // std::cout << "MEI CONTENT " << meicontent << std::endl; - Object *pghead = tempdoc.GetCurrentScoreDef()->FindDescendantByType(ClassId::PGHEAD); + Object *pghead = tempdoc.GetFirstScoreDef()->FindDescendantByType(ClassId::PGHEAD); if (pghead == NULL) { return false; } @@ -5050,7 +5050,7 @@ bool HumdrumInput::prepareHeader( return false; } - m_doc->GetCurrentScoreDef()->AddChild(pghead); + m_doc->GetFirstScoreDef()->AddChild(pghead); return true; } diff --git a/src/iomei.cpp b/src/iomei.cpp index 9f3e2b6c52f..e11544cc1c2 100644 --- a/src/iomei.cpp +++ b/src/iomei.cpp @@ -914,12 +914,13 @@ bool MEIOutput::WriteObjectInternal(Object *object, bool useCustomScoreDef) if (this->IsTreeObject(object)) m_nodeStack.push_back(m_currentNode); if (object->Is(SCORE)) { + ScoreDef *scoreDef = vrv_cast(object)->GetScoreDef(); if (useCustomScoreDef) { - this->WriteCustomScoreDef(); + this->WriteCustomScoreDef(scoreDef); } else { // Save the main scoreDef - m_doc->GetCurrentScoreDef()->SaveObject(this, this->GetBasic()); + scoreDef->SaveObject(this, this->GetBasic()); } } @@ -1278,7 +1279,7 @@ void MEIOutput::WriteStackedObjectsEnd() [this](Object *object) { this->WriteObjectInternalEnd(object); }); } -void MEIOutput::WriteCustomScoreDef() +void MEIOutput::WriteCustomScoreDef(ScoreDef *scoreDef) { // Determine the first measure with respect to the first filter match Measure *measure = NULL; @@ -1305,8 +1306,8 @@ void MEIOutput::WriteCustomScoreDef() if (measure && refScoreDef) { // Create a copy of the reference scoredef and adjust it to keep track of clef changes, key signature changes, // etc. - ScoreDef *scoreDef = vrv_cast(refScoreDef->Clone()); - ListOfObjects staffDefs = scoreDef->FindAllDescendantsByType(STAFFDEF); + ScoreDef *customScoreDef = vrv_cast(refScoreDef->Clone()); + ListOfObjects staffDefs = customScoreDef->FindAllDescendantsByType(STAFFDEF); for (Object *staffDef : staffDefs) { this->AdjustStaffDef(vrv_cast(staffDef), measure); } @@ -1319,7 +1320,7 @@ void MEIOutput::WriteCustomScoreDef() } if (!drawLabels) { // If not, replace labels by abbreviation or delete them - ListOfObjects labels = scoreDef->FindAllDescendantsByType(LABEL); + ListOfObjects labels = customScoreDef->FindAllDescendantsByType(LABEL); for (Object *label : labels) { if (!this->AdjustLabel(vrv_cast