Skip to content

Commit

Permalink
Add MeterSig::GetImplicitUnit and use it in MIDI
Browse files Browse the repository at this point in the history
* Closes #3808 and fixes #3807
* Test suite evaluate locally
  • Loading branch information
lpugin committed Oct 8, 2024
1 parent 5ffd814 commit e44ffcc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/vrv/metersig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/metersig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 4 additions & 0 deletions src/midifunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e44ffcc

Please sign in to comment.