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

Apply filters when processing pedals #3881

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
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 calle
lpugin marked this conversation as resolved.
Show resolved Hide resolved
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;
lpugin marked this conversation as resolved.
Show resolved Hide resolved
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
Loading