diff --git a/include/vrv/doc.h b/include/vrv/doc.h index 710d73c3ef0..d1cfdc7a7af 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 */ - void GenerateFooter(); + bool GenerateFooter(); /** * Generate a document pgHead from the MEI header if none is provided */ - void GenerateHeader(); + bool GenerateHeader(); /** * Generate measure numbers from measure attributes @@ -121,6 +121,11 @@ 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, @@ -136,31 +141,6 @@ 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 */ @@ -245,7 +225,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 Object *object, int staffIndex, data_STAFFREL staffPosition) const; + data_MEASUREMENTSIGNED GetStaffDistance(const ClassId classId, int staffIndex, data_STAFFREL staffPosition); /** * Prepare the timemap for MIDI and timemap file export. @@ -438,6 +418,19 @@ 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. */ @@ -484,11 +477,6 @@ class Doc : public Object { */ void PrepareMeasureIndices(); - /** - * Determine all visible scores - */ - void CollectVisibleScores(); - public: Page *m_selectionPreceding; Page *m_selectionFollowing; @@ -558,10 +546,12 @@ class Doc : public Object { Resources m_resources; /** - * The list of all visible scores - * Used in Doc::GetCorrespondingScore to quickly determine the score for an object + * @name Holds a pointer to the current score/scoreDef. + * Set by Doc::GetCurrentScoreDef or explicitly through Doc::SetCurrentScoreDef */ - std::list m_visibleScores; + ///@{ + Score *m_currentScore; + ///@} /** * 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 f6cd1f450a3..aaa9d9edcf3 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(const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox); + void CalcDrawingYRel(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 6b0d7800119..e162f386646 100644 --- a/include/vrv/iomei.h +++ b/include/vrv/iomei.h @@ -306,7 +306,7 @@ class MEIOutput : public Output { * Scoredef manipulation */ ///@{ - void WriteCustomScoreDef(ScoreDef *scoreDef); + void WriteCustomScoreDef(); void AdjustStaffDef(StaffDef *staffDef, Measure *measure); bool AdjustLabel(Label *label); ///@} diff --git a/include/vrv/object.h b/include/vrv/object.h index 1cb3f41ff41..8ab619368d9 100644 --- a/include/vrv/object.h +++ b/include/vrv/object.h @@ -692,6 +692,7 @@ 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 f1751100c99..7bab10d7ec7 100644 --- a/include/vrv/page.h +++ b/include/vrv/page.h @@ -48,6 +48,11 @@ 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 975909c70b9..de496139af5 100644 --- a/include/vrv/score.h +++ b/include/vrv/score.h @@ -56,6 +56,12 @@ 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 7bc8b01512d..ece6761c994 100644 --- a/src/adjustaccidxfunctor.cpp +++ b/src/adjustaccidxfunctor.cpp @@ -10,7 +10,6 @@ //---------------------------------------------------------------------------- #include "doc.h" -#include "score.h" //---------------------------------------------------------------------------- @@ -42,8 +41,7 @@ FunctorCode AdjustAccidXFunctor::VisitAlignmentReference(AlignmentReference *ali if (accids.empty()) return FUNCTOR_SIBLINGS; assert(m_doc); - ScoreDef *scoreDef = m_doc->GetCorrespondingScore(alignmentReference)->GetScoreDef(); - StaffDef *staffDef = scoreDef->GetStaffDef(alignmentReference->GetN()); + StaffDef *staffDef = m_doc->GetCurrentScoreDef()->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 1f930da9a88..63dc27b7a40 100644 --- a/src/adjustdotsfunctor.cpp +++ b/src/adjustdotsfunctor.cpp @@ -11,7 +11,6 @@ #include "doc.h" #include "elementpart.h" -#include "score.h" #include "staff.h" //---------------------------------------------------------------------------- @@ -126,7 +125,7 @@ FunctorCode AdjustDotsFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustDotsFunctor::VisitScore(Score *score) { - m_staffNs = score->GetScoreDef()->GetStaffNs(); + m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/adjustgracexposfunctor.cpp b/src/adjustgracexposfunctor.cpp index 85e4876cbb5..6d9ec49c51f 100644 --- a/src/adjustgracexposfunctor.cpp +++ b/src/adjustgracexposfunctor.cpp @@ -10,7 +10,6 @@ //---------------------------------------------------------------------------- #include "doc.h" -#include "score.h" //---------------------------------------------------------------------------- @@ -231,7 +230,7 @@ FunctorCode AdjustGraceXPosFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustGraceXPosFunctor::VisitScore(Score *score) { - m_staffNs = score->GetScoreDef()->GetStaffNs(); + m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/adjustlayersfunctor.cpp b/src/adjustlayersfunctor.cpp index 058120c970c..7b312d143a6 100644 --- a/src/adjustlayersfunctor.cpp +++ b/src/adjustlayersfunctor.cpp @@ -10,7 +10,6 @@ //---------------------------------------------------------------------------- #include "doc.h" -#include "score.h" #include "staff.h" //---------------------------------------------------------------------------- @@ -149,7 +148,7 @@ FunctorCode AdjustLayersFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustLayersFunctor::VisitScore(Score *score) { - m_staffNs = score->GetScoreDef()->GetStaffNs(); + m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/adjustxposfunctor.cpp b/src/adjustxposfunctor.cpp index 5436c605497..07b4117b196 100644 --- a/src/adjustxposfunctor.cpp +++ b/src/adjustxposfunctor.cpp @@ -12,7 +12,6 @@ #include "doc.h" #include "multirest.h" #include "rest.h" -#include "score.h" #include "staff.h" #include "system.h" @@ -299,7 +298,7 @@ FunctorCode AdjustXPosFunctor::VisitMeasure(Measure *measure) FunctorCode AdjustXPosFunctor::VisitScore(Score *score) { - m_staffNs = score->GetScoreDef()->GetStaffNs(); + m_staffNs = m_doc->GetCurrentScoreDef()->GetStaffNs(); return FUNCTOR_CONTINUE; } diff --git a/src/doc.cpp b/src/doc.cpp index b36a19f5b59..3fd5b393d28 100644 --- a/src/doc.cpp +++ b/src/doc.cpp @@ -125,6 +125,7 @@ void Doc::Reset() m_drawingPageMarginTop = 0; m_drawingPage = NULL; + m_currentScore = NULL; m_currentScoreDefDone = false; m_dataPreparationDone = false; m_timemapTempo = 0.0; @@ -190,8 +191,7 @@ bool Doc::GenerateDocumentScoreDef() return false; } - ScoreDef *scoreDef = this->GetFirstScoreDef(); - scoreDef->Reset(); + this->GetCurrentScoreDef()->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); } - scoreDef->AddChild(staffGrp); + this->GetCurrentScoreDef()->AddChild(staffGrp); LogInfo("ScoreDef generated"); return true; } -void Doc::GenerateFooter() +bool Doc::GenerateFooter() { - for (Score *score : this->GetVisibleScores()) { - ScoreDef *scoreDef = score->GetScoreDef(); - if (scoreDef->FindDescendantByType(PGFOOT)) continue; + 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"); - scoreDef->AddChild(pgFoot); + 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); - PgFoot *pgFoot2 = new PgFoot(); - pgFoot2->SetFunc(PGFUNC_all); - pgFoot2->IsGenerated(true); - pgFoot2->LoadFooter(this); - pgFoot2->SetType("autogenerated"); - scoreDef->AddChild(pgFoot2); - } + PgFoot *pgFoot2 = new PgFoot(); + pgFoot2->SetFunc(PGFUNC_all); + pgFoot2->IsGenerated(true); + pgFoot2->LoadFooter(this); + pgFoot2->SetType("autogenerated"); + this->GetCurrentScoreDef()->AddChild(pgFoot2); + + return true; } -void Doc::GenerateHeader() +bool Doc::GenerateHeader() { - for (Score *score : this->GetVisibleScores()) { - ScoreDef *scoreDef = score->GetScoreDef(); - if (scoreDef->FindDescendantByType(PGHEAD)) continue; + if (this->GetCurrentScoreDef()->FindDescendantByType(PGHEAD)) return false; - 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 *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 *pgHead2 = new PgHead(); - pgHead2->SetFunc(PGFUNC_all); - pgHead2->IsGenerated(true); - pgHead2->AddPageNum(HORIZONTALALIGNMENT_center, VERTICALALIGNMENT_top); - pgHead2->SetType("autogenerated"); - scoreDef->AddChild(pgHead2); - } + 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; } void Doc::PrepareMeasureIndices() @@ -345,12 +345,11 @@ void Doc::CalculateTimemap() double tempo = MIDI_TEMPO; // Set tempo - ScoreDef *scoreDef = this->GetFirstVisibleScore()->GetScoreDef(); - if (scoreDef->HasMidiBpm()) { - tempo = scoreDef->GetMidiBpm(); + if (this->GetCurrentScoreDef()->HasMidiBpm()) { + tempo = this->GetCurrentScoreDef()->GetMidiBpm(); } - else if (scoreDef->HasMm()) { - tempo = Tempo::CalcTempo(scoreDef); + else if (this->GetCurrentScoreDef()->HasMm()) { + tempo = Tempo::CalcTempo(this->GetCurrentScoreDef()); } // We first calculate the maximum duration of each measure @@ -373,6 +372,7 @@ void Doc::CalculateTimemap() void Doc::ExportMIDI(smf::MidiFile *midiFile) { + if (!this->HasTimemap()) { // generate MIDI timemap before progressing CalculateTimemap(); @@ -384,12 +384,11 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) double tempo = MIDI_TEMPO; // set MIDI tempo - ScoreDef *scoreDef = this->GetFirstVisibleScore()->GetScoreDef(); - if (scoreDef->HasMidiBpm()) { - tempo = scoreDef->GetMidiBpm(); + if (this->GetCurrentScoreDef()->HasMidiBpm()) { + tempo = this->GetCurrentScoreDef()->GetMidiBpm(); } - else if (scoreDef->HasMm()) { - tempo = Tempo::CalcTempo(scoreDef); + else if (this->GetCurrentScoreDef()->HasMm()) { + tempo = Tempo::CalcTempo(this->GetCurrentScoreDef()); } midiFile->addTempo(0, 0, tempo); @@ -418,8 +417,10 @@ 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 = scoreDef->GetStaffDef(staves->first)) { + if (StaffDef *staffDef = currentScoreDef->GetStaffDef(staves->first)) { // get the transposition (semi-tone) value for the staff if (staffDef->HasTransSemi()) transSemi = staffDef->GetTransSemi(); midiTrack = staffDef->GetN(); @@ -461,16 +462,16 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) } // set MIDI key signature KeySig *keySig = vrv_cast(staffDef->FindDescendantByType(KEYSIG)); - if (!keySig && (scoreDef->HasKeySigInfo())) { - keySig = vrv_cast(scoreDef->GetKeySig()); + if (!keySig && (currentScoreDef->HasKeySigInfo())) { + keySig = vrv_cast(currentScoreDef->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 && (scoreDef->HasMeterSigInfo())) { - meterSig = vrv_cast(scoreDef->GetMeterSig()); + if (!meterSig && (currentScoreDef->HasMeterSigInfo())) { + meterSig = vrv_cast(currentScoreDef->GetMeterSig()); } if (meterSig && meterSig->HasCount() && meterSig->HasUnit()) { midiFile->addTimeSignature(midiTrack, 0, meterSig->GetTotalCount(), meterSig->GetUnit()); @@ -481,7 +482,7 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) GenerateMIDIFunctor generateScoreDefMIDI(midiFile); generateScoreDefMIDI.SetChannel(midiChannel); generateScoreDefMIDI.SetTrack(midiTrack); - scoreDef->Process(generateScoreDefMIDI); + currentScoreDef->Process(generateScoreDefMIDI); for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) { filters.Clear(); @@ -573,10 +574,6 @@ void Doc::PrepareData() this->PrepareMeasureIndices(); - /************ Collect all visible scores ************/ - - this->CollectVisibleScores(); - /************ Store default durations ************/ PrepareDurationFunctor prepareDuration; @@ -861,10 +858,8 @@ void Doc::PrepareData() } } - for (Score *score : this->GetVisibleScores()) { - ScoreDefSetGrpSymFunctor scoreDefSetGrpSym; - score->GetScoreDef()->Process(scoreDefSetGrpSym); - } + ScoreDefSetGrpSymFunctor scoreDefSetGrpSym; + this->GetCurrentScoreDef()->Process(scoreDefSetGrpSym); // LogElapsedTimeEnd ("Preparing drawing"); @@ -883,7 +878,12 @@ 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,9 +904,10 @@ void Doc::ScoreDefOptimizeDoc() void Doc::ScoreDefSetGrpSymDoc() { - // Group symbols need to be resolved using scoreDef, since there might be @startid/@endid attributes that determine + // Group symbols need to be resolved using scoreDef, since there might be @starid/@endid attributes that determine // their positioning ScoreDefSetGrpSymFunctor scoreDefSetGrpSym; + // this->GetCurrentScoreDef()->Process(scoreDefSetGrpSym); this->Process(scoreDefSetGrpSym); } @@ -935,7 +936,7 @@ void Doc::CastOffDocBase(bool useSb, bool usePb, bool smart) return; } - std::list scores = this->GetVisibleScores(); + std::list scores = this->GetScores(); assert(!scores.empty()); this->ScoreDefSetCurrentDoc(); @@ -1092,7 +1093,7 @@ void Doc::CastOffEncodingDoc() this->ScoreDefSetCurrentDoc(true); // Optimize the doc if one of the score requires optimization - for (Score *score : this->GetVisibleScores()) { + for (Score *score : this->GetScores()) { if (score->ScoreDefNeedsOptimization(m_options->m_condense.GetValue())) { this->ScoreDefOptimizeDoc(); break; @@ -1445,6 +1446,18 @@ 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)); @@ -1461,72 +1474,6 @@ 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; @@ -1899,34 +1846,32 @@ double Doc::GetTopMargin(const ClassId classId) const return m_options->m_defaultTopMargin.GetValue(); } -data_MEASUREMENTSIGNED Doc::GetStaffDistance(const Object *object, int staffIndex, data_STAFFREL staffPosition) const +data_MEASUREMENTSIGNED Doc::GetStaffDistance(const ClassId classId, int staffIndex, data_STAFFREL staffPosition) { - const ScoreDef *scoreDef = this->GetCorrespondingScore(object)->GetScoreDef(); - data_MEASUREMENTSIGNED distance; if (staffPosition == STAFFREL_above || staffPosition == STAFFREL_below) { - if (object->Is(DIR)) { + if (classId == DIR) { // Inspect the scoreDef attribute - if (scoreDef->HasDirDist()) { - distance = scoreDef->GetDirDist(); + if (this->GetCurrentScoreDef()->HasDirDist()) { + distance = this->GetCurrentScoreDef()->GetDirDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); + const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasDirDist()) { distance = staffDef->GetDirDist(); } } - else if (object->Is(DYNAM)) { + else if (classId == DYNAM) { distance.SetVu(m_options->m_dynamDist.GetDefault()); // Inspect the scoreDef attribute - if (scoreDef->HasDynamDist()) { - distance = scoreDef->GetDynamDist(); + if (this->GetCurrentScoreDef()->HasDynamDist()) { + distance = this->GetCurrentScoreDef()->GetDynamDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); + const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasDynamDist()) { distance = staffDef->GetDynamDist(); } @@ -1936,16 +1881,16 @@ data_MEASUREMENTSIGNED Doc::GetStaffDistance(const Object *object, int staffInde distance.SetVu(m_options->m_dynamDist.GetValue()); } } - else if (object->Is(HARM)) { + else if (classId == HARM) { distance.SetVu(m_options->m_harmDist.GetDefault()); // Inspect the scoreDef attribute - if (scoreDef->HasHarmDist()) { - distance = scoreDef->GetHarmDist(); + if (this->GetCurrentScoreDef()->HasHarmDist()) { + distance = this->GetCurrentScoreDef()->GetHarmDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); + const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasHarmDist()) { distance = staffDef->GetHarmDist(); } @@ -1955,14 +1900,14 @@ data_MEASUREMENTSIGNED Doc::GetStaffDistance(const Object *object, int staffInde distance.SetVu(m_options->m_harmDist.GetValue()); } } - else if (object->Is(TEMPO)) { + else if (classId == TEMPO) { // Inspect the scoreDef attribute - if (scoreDef->HasTempoDist()) { - distance = scoreDef->GetTempoDist(); + if (this->GetCurrentScoreDef()->HasTempoDist()) { + distance = this->GetCurrentScoreDef()->GetTempoDist(); } // Inspect the staffDef attributes - const StaffDef *staffDef = scoreDef->GetStaffDef(staffIndex); + const StaffDef *staffDef = this->GetCurrentScoreDef()->GetStaffDef(staffIndex); if (staffDef != NULL && staffDef->HasTempoDist()) { distance = staffDef->GetTempoDist(); } @@ -2084,6 +2029,27 @@ 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 a572a89d6ac..f32481b091b 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -29,7 +29,6 @@ #include "neume.h" #include "page.h" #include "rend.h" -#include "score.h" #include "staff.h" #include "staffdef.h" #include "surface.h" @@ -786,8 +785,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->GetCorrespondingScore(parent)->GetScoreDef()->FindDescendantByType(STAFFDEF)); + newStaff->m_drawingStaffDef + = vrv_cast(m_doc->GetCurrentScoreDef()->FindDescendantByType(STAFFDEF)); newStaff->m_drawingNotationType = NOTATIONTYPE_neume; newStaff->m_drawingLines = 4; } diff --git a/src/floatingobject.cpp b/src/floatingobject.cpp index a2b126315f9..c6e46b59f62 100644 --- a/src/floatingobject.cpp +++ b/src/floatingobject.cpp @@ -445,7 +445,7 @@ int FloatingPositioner::GetAdmissibleHorizOverlapMargin(const BoundingBox *bbox, } void FloatingPositioner::CalcDrawingYRel( - const Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox) + Doc *doc, const StaffAlignment *staffAlignment, const BoundingBox *horizOverlappingBBox) { assert(doc); assert(staffAlignment); @@ -460,7 +460,8 @@ void FloatingPositioner::CalcDrawingYRel( int staffIndex = staffAlignment->GetStaff()->GetN(); int minStaffDistance = 0.0; - data_MEASUREMENTSIGNED minStaffDistanceMeasurement = doc->GetStaffDistance(m_object, staffIndex, m_place); + data_MEASUREMENTSIGNED minStaffDistanceMeasurement + = doc->GetStaffDistance(m_object->GetClassId(), staffIndex, m_place); if (minStaffDistanceMeasurement.HasValue()) { if (minStaffDistanceMeasurement.GetType() == MEASUREMENTTYPE_px) { diff --git a/src/ioabc.cpp b/src/ioabc.cpp index a7473bdae60..5ce7bdae43d 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->GetFirstScoreDef()->FindDescendantByType(METERSIG)); + MeterSig *meterSig = vrv_cast(m_doc->GetCurrentScoreDef()->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 debf3f3181a..36082e95284 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->GetFirstScoreDef()->AddChild(staffGrp); + m_doc->GetCurrentScoreDef()->AddChild(staffGrp); m_doc->ConvertToPageBasedDoc(); diff --git a/src/iohumdrum.cpp b/src/iohumdrum.cpp index 907caf7992c..801556e9b85 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->GetFirstScoreDef(), staffstarts[0], top, bot); + addMidiTempo(m_doc->GetCurrentScoreDef(), 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->GetFirstScoreDef()->AddChild(sg); + m_doc->GetCurrentScoreDef()->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->GetFirstScoreDef()->AddChild(sg); + m_doc->GetCurrentScoreDef()->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->GetFirstScoreDef(); + ScoreDef *sdf = m_doc->GetCurrentScoreDef(); 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->GetFirstScoreDef(); + ScoreDef *sdf = m_doc->GetCurrentScoreDef(); 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->GetFirstScoreDef()->AddChild(root); + m_doc->GetCurrentScoreDef()->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->GetFirstScoreDef()->AddChild(root); + m_doc->GetCurrentScoreDef()->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->GetFirstScoreDef()->AddChild(root); + m_doc->GetCurrentScoreDef()->AddChild(root); } std::vector spine; // kernstart index @@ -4271,7 +4271,7 @@ bool HumdrumInput::processStaffDecoration(const std::string &decoration) root->AddChild(sg); } else { - m_doc->GetFirstScoreDef()->AddChild(sg); + m_doc->GetCurrentScoreDef()->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->GetFirstScoreDef()->AddChild(sg); + m_doc->GetCurrentScoreDef()->AddChild(sg); } } @@ -4371,7 +4371,7 @@ bool HumdrumInput::processStaffDecoration(const std::string &decoration) } else { root_sg = new StaffGrp(); - m_doc->GetFirstScoreDef()->AddChild(root_sg); + m_doc->GetCurrentScoreDef()->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.GetFirstScoreDef()->FindDescendantByComparison(&comparison); + Object *pgfoot = tempdoc.GetCurrentScoreDef()->FindDescendantByComparison(&comparison); if (pgfoot == NULL) { return false; } @@ -4875,10 +4875,10 @@ bool HumdrumInput::prepareFooter( return false; } - m_doc->GetFirstScoreDef()->AddChild(pgfoot); + m_doc->GetCurrentScoreDef()->AddChild(pgfoot); AttFormeworkComparison comparison2(PGFOOT, PGFUNC_all); - Object *pgfoot2 = tempdoc.GetFirstScoreDef()->FindDescendantByComparison(&comparison2); + Object *pgfoot2 = tempdoc.GetCurrentScoreDef()->FindDescendantByComparison(&comparison2); if (pgfoot2 == NULL) { return true; } @@ -4896,7 +4896,7 @@ bool HumdrumInput::prepareFooter( return true; } - m_doc->GetFirstScoreDef()->AddChild(pgfoot2); + m_doc->GetCurrentScoreDef()->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.GetFirstScoreDef()->FindDescendantByType(ClassId::PGHEAD); + Object *pghead = tempdoc.GetCurrentScoreDef()->FindDescendantByType(ClassId::PGHEAD); if (pghead == NULL) { return false; } @@ -5050,7 +5050,7 @@ bool HumdrumInput::prepareHeader( return false; } - m_doc->GetFirstScoreDef()->AddChild(pghead); + m_doc->GetCurrentScoreDef()->AddChild(pghead); return true; } diff --git a/src/iomei.cpp b/src/iomei.cpp index e11544cc1c2..9f3e2b6c52f 100644 --- a/src/iomei.cpp +++ b/src/iomei.cpp @@ -914,13 +914,12 @@ 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(scoreDef); + this->WriteCustomScoreDef(); } else { // Save the main scoreDef - scoreDef->SaveObject(this, this->GetBasic()); + m_doc->GetCurrentScoreDef()->SaveObject(this, this->GetBasic()); } } @@ -1279,7 +1278,7 @@ void MEIOutput::WriteStackedObjectsEnd() [this](Object *object) { this->WriteObjectInternalEnd(object); }); } -void MEIOutput::WriteCustomScoreDef(ScoreDef *scoreDef) +void MEIOutput::WriteCustomScoreDef() { // Determine the first measure with respect to the first filter match Measure *measure = NULL; @@ -1306,8 +1305,8 @@ void MEIOutput::WriteCustomScoreDef(ScoreDef *scoreDef) if (measure && refScoreDef) { // Create a copy of the reference scoredef and adjust it to keep track of clef changes, key signature changes, // etc. - ScoreDef *customScoreDef = vrv_cast(refScoreDef->Clone()); - ListOfObjects staffDefs = customScoreDef->FindAllDescendantsByType(STAFFDEF); + ScoreDef *scoreDef = vrv_cast(refScoreDef->Clone()); + ListOfObjects staffDefs = scoreDef->FindAllDescendantsByType(STAFFDEF); for (Object *staffDef : staffDefs) { this->AdjustStaffDef(vrv_cast(staffDef), measure); } @@ -1320,7 +1319,7 @@ void MEIOutput::WriteCustomScoreDef(ScoreDef *scoreDef) } if (!drawLabels) { // If not, replace labels by abbreviation or delete them - ListOfObjects labels = customScoreDef->FindAllDescendantsByType(LABEL); + ListOfObjects labels = scoreDef->FindAllDescendantsByType(LABEL); for (Object *label : labels) { if (!this->AdjustLabel(vrv_cast