Skip to content

Commit

Permalink
Merge pull request #3881 from rism-digital/develop-pedal-fix
Browse files Browse the repository at this point in the history
Apply filters when processing pedals
  • Loading branch information
ahankinson authored Dec 10, 2024
2 parents 7440209 + 1e80798 commit fd418ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/vrv/midifunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class GenerateMIDIFunctor : public ConstFunctor {
void SetTempoEventTicks(const std::set<int> &ticks) { m_tempoEventTicks = ticks; }
void SetTrack(int track) { m_midiTrack = track; }
void SetTransSemi(int transSemi) { m_transSemi = transSemi; }
void SetControlEvents(bool controlEvents) { m_controlEvents = controlEvents; }
///@}

/*
Expand Down Expand Up @@ -372,6 +373,8 @@ class GenerateMIDIFunctor : public ConstFunctor {
bool m_cueExclusion;
// Tablature held notes indexed by (course - 1)
std::vector<MIDIHeldNote> m_heldNotes;
// A flag indicating we want to process control events
bool m_controlEvents;
};

//----------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions src/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,11 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile)
GenerateMIDIFunctor generateScoreDefMIDI(midiFile);
generateScoreDefMIDI.SetChannel(midiChannel);
generateScoreDefMIDI.SetTrack(midiTrack);

scoreDef->Process(generateScoreDefMIDI);

bool controlEvents = true;

for (auto &layers : staves.second.child) {
filters.Clear();
// Create ad comparison object for each type / @n
Expand All @@ -543,11 +546,14 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile)
generateMIDI.SetCurrentTempo(tempo);
generateMIDI.SetDeferredNotes(initMIDI.GetDeferredNotes());
generateMIDI.SetCueExclusion(this->GetOptions()->m_midiNoCue.GetValue());
generateMIDI.SetControlEvents(controlEvents);

// LogDebug("Exporting track %d ----------------", midiTrack);
this->Process(generateMIDI);

tempoEventTicks = generateMIDI.GetTempoEventTicks();
// Process them only once per staff
controlEvents = false;
}
}
midiFile->sortTracks();
Expand Down
14 changes: 14 additions & 0 deletions src/midifunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ GenerateMIDIFunctor::GenerateMIDIFunctor(smf::MidiFile *midiFile) : ConstFunctor
m_lastNote = NULL;
m_accentedGraceNote = false;
m_cueExclusion = false;
m_controlEvents = false;
}

FunctorCode GenerateMIDIFunctor::VisitBeatRpt(const BeatRpt *beatRpt)
Expand Down Expand Up @@ -717,6 +718,19 @@ FunctorCode GenerateMIDIFunctor::VisitPedal(const Pedal *pedal)
{
if (!pedal->HasDir()) return FUNCTOR_CONTINUE;

// Check the functor flag - filters should always be there, but just in case we change how it is called
if (!m_controlEvents || !this->GetFilters()) return FUNCTOR_CONTINUE;

// Check if the pedal applies to the staff filtered
const Measure *measure = vrv_cast<const Measure *>(pedal->GetFirstAncestor(MEASURE));
assert(measure);
std::vector<const Staff *> staffList = pedal->GetTstampStaves(measure, pedal);
bool applies = false;
for (const Staff *staff : staffList) {
applies = (applies || this->GetFilters()->Apply(staff));
}
if (!applies) return FUNCTOR_CONTINUE;

double pedalTime = pedal->GetStart()->GetAlignment()->GetTime().ToDouble() * SCORE_TIME_UNIT;
double startTime = m_totalTime + pedalTime;
int tpq = m_midiFile->getTPQ();
Expand Down

0 comments on commit fd418ec

Please sign in to comment.