Spooky Invisible Midi Not Making Sound

Hello everyone. This is one of the strangest bugs I’ve ever encountered. For a few weeks I’ve been using the below demo code to create a midi sequencer VST. I have it hooked this up to a midi synth and then to an audio output using the Juce VSTHost. This has been working fine. All the sudden I noticed it was no longer making sound. I managed to reduce my processBlock code down to simply sending a note 60 on event once and never turning it off. Still there is no sound. I verified that I am sending the audio to the correct device and everything. What is odd is that I’ve loaded the plugin in reaper, and I can see the note being triggered, but I cannot hear it. In fact, when I record in reaper, it actually records all the notes properly for me to play back and hear, but they will not play while recording. Thank you for any insight.

void DoomTestAudioProcessor::addMessageToBuffer(const juce::MidiMessage& message, MidiBuffer& midiBuffer)
{
    auto timestamp = message.getTimeStamp();
    auto sampleNumber = (int)(timestamp * getSampleRate());
    midiBuffer.addEvent(message, sampleNumber);
}

void DoomTestAudioProcessor::setNoteNumber(int noteNumber, bool on, MidiBuffer& midiMessages)
{
    if (on) {
        auto message = juce::MidiMessage::noteOn(1, noteNumber, (juce::uint8)100);
        message.setTimeStamp(juce::Time::getMillisecondCounterHiRes() * 0.001);
        addMessageToBuffer(message, midiMessages);
    }
    else {
        auto message = juce::MidiMessage::noteOff(1, noteNumber, (juce::uint8)100);
        message.setTimeStamp(juce::Time::getMillisecondCounterHiRes() * 0.001);
        addMessageToBuffer(message, midiMessages);
    }
}

Two things to look for each event:

  • the channel. You are forcing events on channel 1. If your synth is expecting events on another channel, you won’t hear anything.
  • the timestamp: double check that the samplePosition of each event in the buffer is within the sample bounds. So if you have a buffer of N samples, the events in the buffer should have a samplePosition between 0 and N-1.