Track noteoffs
This commit is contained in:
parent
5ff31ae181
commit
27ceeb8e1a
2 changed files with 14 additions and 5 deletions
|
|
@ -33,6 +33,7 @@ void sfz::MidiState::noteOffEvent(int delay, int noteNumber, float velocity) noe
|
||||||
ASSERT(velocity >= 0.0 && velocity <= 1.0);
|
ASSERT(velocity >= 0.0 && velocity <= 1.0);
|
||||||
UNUSED(velocity);
|
UNUSED(velocity);
|
||||||
if (noteNumber >= 0 && noteNumber < 128) {
|
if (noteNumber >= 0 && noteNumber < 128) {
|
||||||
|
noteOffTimes[noteNumber] = internalClock + static_cast<unsigned>(delay);
|
||||||
if (activeNotes > 0)
|
if (activeNotes > 0)
|
||||||
activeNotes--;
|
activeNotes--;
|
||||||
}
|
}
|
||||||
|
|
@ -44,6 +45,7 @@ void sfz::MidiState::setSampleRate(float sampleRate) noexcept
|
||||||
this->sampleRate = sampleRate;
|
this->sampleRate = sampleRate;
|
||||||
internalClock = 0;
|
internalClock = 0;
|
||||||
absl::c_fill(noteOnTimes, 0);
|
absl::c_fill(noteOnTimes, 0);
|
||||||
|
absl::c_fill(noteOffTimes, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::MidiState::advanceTime(int numSamples) noexcept
|
void sfz::MidiState::advanceTime(int numSamples) noexcept
|
||||||
|
|
@ -59,13 +61,14 @@ void sfz::MidiState::setSamplesPerBlock(int samplesPerBlock) noexcept
|
||||||
float sfz::MidiState::getNoteDuration(int noteNumber, int delay) const
|
float sfz::MidiState::getNoteDuration(int noteNumber, int delay) const
|
||||||
{
|
{
|
||||||
ASSERT(noteNumber >= 0 && noteNumber < 128);
|
ASSERT(noteNumber >= 0 && noteNumber < 128);
|
||||||
|
if (noteNumber < 0 || noteNumber >= 128)
|
||||||
|
return 0.0f;
|
||||||
|
|
||||||
if (noteNumber >= 0 && noteNumber < 128) {
|
if (noteOnTimes[noteNumber] != 0 && noteOffTimes[noteNumber] != 0 && noteOnTimes[noteNumber] > noteOffTimes[noteNumber])
|
||||||
const unsigned timeInSamples = internalClock + static_cast<unsigned>(delay) - noteOnTimes[noteNumber];
|
return 0.0f;
|
||||||
return static_cast<float>(timeInSamples) / sampleRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0.0f;
|
const unsigned timeInSamples = internalClock + static_cast<unsigned>(delay) - noteOnTimes[noteNumber];
|
||||||
|
return static_cast<float>(timeInSamples) / sampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sfz::MidiState::getNoteVelocity(int noteNumber) const noexcept
|
float sfz::MidiState::getNoteVelocity(int noteNumber) const noexcept
|
||||||
|
|
@ -114,6 +117,7 @@ void sfz::MidiState::reset(int delay) noexcept
|
||||||
activeNotes = 0;
|
activeNotes = 0;
|
||||||
internalClock = 0;
|
internalClock = 0;
|
||||||
absl::c_fill(noteOnTimes, 0);
|
absl::c_fill(noteOnTimes, 0);
|
||||||
|
absl::c_fill(noteOffTimes, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::MidiState::resetAllControllers(int delay) noexcept
|
void sfz::MidiState::resetAllControllers(int delay) noexcept
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,11 @@ private:
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MidiNoteArray<unsigned> noteOnTimes {};
|
MidiNoteArray<unsigned> noteOnTimes {};
|
||||||
|
/**
|
||||||
|
* @brief Stores the note off times.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
MidiNoteArray<unsigned> noteOffTimes {};
|
||||||
/**
|
/**
|
||||||
* @brief Stores the velocity of the note ons for currently
|
* @brief Stores the velocity of the note ons for currently
|
||||||
* depressed notes.
|
* depressed notes.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue