From e44ffcc16e5c8f14532475e73ebd7f6e9fee5ac6 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Tue, 8 Oct 2024 12:34:25 +0200 Subject: [PATCH] Add MeterSig::GetImplicitUnit and use it in MIDI * Closes #3808 and fixes #3807 * Test suite evaluate locally --- include/vrv/metersig.h | 3 +++ src/doc.cpp | 3 +++ src/metersig.cpp | 12 +++++++++++- src/midifunctor.cpp | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/vrv/metersig.h b/include/vrv/metersig.h index 4e3363e4863..ae5304a7138 100644 --- a/include/vrv/metersig.h +++ b/include/vrv/metersig.h @@ -54,6 +54,9 @@ class MeterSig : public LayerElement, /** Evaluate additive meter counts */ int GetTotalCount() const; + /** Return the implicit unit according to the sym (if any, return 0 otherwise) */ + int GetSymImplicitUnit() const; + /** * Return the unit (int) as data_DURATION (up to 32). * Return DURATION_4 if no match. diff --git a/src/doc.cpp b/src/doc.cpp index b123741b1cf..8d1f276e609 100644 --- a/src/doc.cpp +++ b/src/doc.cpp @@ -503,6 +503,9 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile) if (meterSig && meterSig->HasCount() && meterSig->HasUnit()) { midiFile->addTimeSignature(midiTrack, 0, meterSig->GetTotalCount(), meterSig->GetUnit()); } + else if (meterSig && meterSig->HasSym()) { + midiFile->addTimeSignature(midiTrack, 0, meterSig->GetTotalCount(), meterSig->GetSymImplicitUnit()); + } } // Set initial scoreDef values for tuning diff --git a/src/metersig.cpp b/src/metersig.cpp index 8ff16ecf702..43a4c9228ca 100644 --- a/src/metersig.cpp +++ b/src/metersig.cpp @@ -70,7 +70,7 @@ int MeterSig::GetTotalCount() const // If @count is empty, look at the sym to return a resonable value if (counts.empty()) { if (this->HasSym()) { - return (this->GetSym() == METERSIGN_common) ? 4 : 2; + return (this->GetSym() == METERSIGN_cut) ? 2 : 4; } else { return 0; @@ -108,6 +108,16 @@ int MeterSig::GetTotalCount() const return counts.front(); } +int MeterSig::GetSymImplicitUnit() const +{ + if (this->HasSym()) { + return (this->GetSym() == METERSIGN_cut) ? 2 : 4; + } + else { + return 0; + } +} + data_DURATION MeterSig::GetUnitAsDur() const { switch (this->GetUnit()) { diff --git a/src/midifunctor.cpp b/src/midifunctor.cpp index c05965ae93a..1677485613d 100644 --- a/src/midifunctor.cpp +++ b/src/midifunctor.cpp @@ -776,6 +776,10 @@ FunctorCode GenerateMIDIFunctor::VisitScoreDef(const ScoreDef *scoreDef) if (meterSig && meterSig->HasCount() && meterSig->HasUnit()) { m_midiFile->addTimeSignature(m_midiTrack, currentTick, meterSig->GetTotalCount(), meterSig->GetUnit()); } + else if (meterSig && meterSig->HasUnit()) { + m_midiFile->addTimeSignature( + m_midiTrack, currentTick, meterSig->GetTotalCount(), meterSig->GetSymImplicitUnit()); + } } return FUNCTOR_CONTINUE;