Hi folks,
I have a question regarding timestamps in midi messages.
I want to avoid a pb with a Midi keyboard that sends from time to time an unexpected Note ON to 127 followed by its Note OFF. They is due to a faulty key contact.
I tried to make a small Midi filter VST plugin to try to avoid that pb.
Here is what I did :
void NewProjectAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages)
{
buffer.clear();
juce::MidiBuffer processedMidi;
int time;
juce::MidiMessage m;
for (juce::MidiBuffer::Iterator i(midiMessages); i.getNextEvent(m, time);)
{
// test only duplicate on channel 1 to simplify
if (m.isNoteOn() && (m.getChannel()==1))
{
mNoteOnCounter[m.getNoteNumber()]++;
if (mNoteOnCounter[m.getNoteNumber()] == 2)
{
// Delete this note On because a duplicate note has been detected
mNoteOnCounter[m.getNoteNumber()]--;
continue;
}
if ((m.getVelocity() == 127))
{
DBG("Note ON with velocity 127");
if ((m.getTimeStamp() - mLastNoteOffTime[m.getNoteNumber()]) < 0.002)
{
DBG("Bad Note ON received -> Delete");
// Remove bad Note ON
mLastNoteOnDeleted[m.getNoteNumber()] = true;
continue;
}
}
}
else if (m.isNoteOff() && (m.getChannel() == 1))
{
mNoteOnCounter[m.getNoteNumber()]--;
if (mLastNoteOnDeleted[m.getNoteNumber()])
{
// Remove bad Note Off
mLastNoteOnDeleted[m.getNoteNumber()] = false;
continue;
}
else
{
mLastNoteOffTime[m.getNoteNumber()] = m.getTimeStamp();
}
}
processedMidi.addEvent(m, time);
}
midiMessages.swapWith(processedMidi);
}
This code is basically aimed to remove a Note ON of 127 that followed a Note OFF for less of 2 ms + its related Note OFF.
But it seems the Value returned by m.getTimeStamp() is not accurate enough.
Any ideas ?
Thanks in advance.
