Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIDI time signatures for "common" and "cut" meterSig #3808

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,13 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile)
if (!meterSig && (scoreDef->HasMeterSigInfo())) {
meterSig = vrv_cast<MeterSig *>(scoreDef->GetMeterSig());
}
if (meterSig && meterSig->HasCount() && meterSig->HasUnit()) {
midiFile->addTimeSignature(midiTrack, 0, meterSig->GetTotalCount(), meterSig->GetUnit());
if (meterSig) {
if (meterSig->HasSym() && meterSig->GetSym() != METERSIGN_open) {
lpugin marked this conversation as resolved.
Show resolved Hide resolved
midiFile->addTimeSignature(midiTrack, 0, meterSig->GetTotalCount(), meterSig->GetTotalCount());
}
else if (meterSig->HasCount() && meterSig->HasUnit()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think meter.count and meter.unit would overrule any written symbol, so it should be two simple if clauses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you want to have both added to the midi file? If not then the two conditions should be flipped.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not have both added, of course. I would say if you have an explicit count and unit, those should be used. If there is no count/unit, then it should be inferred from the symbol, with common-time being 4/4 and cut-time being 2/2.

I am wondering about this duplication:

meterSig->GetTotalCount(), meterSig->GetTotalCount());

the total count is the top number, and but this has nothing to do with the bottom number (the unit), so there seems to be an assumption here which is based on "4/4' and "2/2" having the same number on the top and the bottom. But the top is the count and the bottom is the unit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in the same way that, for common/cut sym, meterSig->HasCount() returns false but meterSig->GetTotalCount() stills gives a valid value (4 or 2), we should do the same for unit and return 4 or 2 when HasUnit() is false. But doing it on GetUnit() would look weird from the semantic point of view... maybe GetEffectiveUnit()? Or maybe GetTop()/GetBottom() / GetNum()/GetDem()

Copy link
Contributor

@lpugin lpugin Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply have

int countAndUnit = (meterSig->GetSym() == METERSIGN_common) ? 4 : 2;

And use this.

Don't forget to flip the clauses since the priority should be on explicit @unit and @count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my point here was to encapsulate the logic resolving common = 4/4 and cut = 2/2 inside the MeterSig class instead of resolving those details at the document level. Also the ternary operator here will add a 2/2 time signature for a MeterSig with "open" sym (or any other further supported symbol we might introduce).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. You can add a MeterSig::GetSymImplicitUnit()

midiFile->addTimeSignature(midiTrack, 0, meterSig->GetTotalCount(), meterSig->GetUnit());
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/midifunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,14 @@ FunctorCode GenerateMIDIFunctor::VisitScoreDef(const ScoreDef *scoreDef)
// set MIDI time signature
if (scoreDef->HasMeterSigInfo()) {
const MeterSig *meterSig = vrv_cast<const MeterSig *>(scoreDef->GetMeterSig());
if (meterSig && meterSig->HasCount() && meterSig->HasUnit()) {
m_midiFile->addTimeSignature(m_midiTrack, currentTick, meterSig->GetTotalCount(), meterSig->GetUnit());
if (meterSig) {
if (meterSig->HasSym() && meterSig->GetSym() != METERSIGN_open) {
m_midiFile->addTimeSignature(
m_midiTrack, currentTick, meterSig->GetTotalCount(), meterSig->GetTotalCount());
}
else if (meterSig->HasCount() && meterSig->HasUnit()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

m_midiFile->addTimeSignature(m_midiTrack, currentTick, meterSig->GetTotalCount(), meterSig->GetUnit());
}
}
}

Expand Down