isNoteOn() always false




I work on a plugin which detects pitch of an audio and sends midi messages equivalent to this pitch. I have problem with sending noteOff messages. My noteOff function is inside isNoteOn() condition. Here is code:

void Soota1AudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer& midiMessages)
ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
dywapitchtracker pitchtracker;
MidiMessage midimsg;
MidiOutput midiOutput;
midiOutput = MidiOutput::openDevice(1);
int note;

for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear(i, 0, buffer.getNumSamples());

for (int channel = 0; channel < totalNumInputChannels; ++channel)
auto* channelData = buffer.getWritePointer(channel);
bufor = (double*)channelData;
pitch = 2 * (dywapitch_computepitch(&pitchtracker, bufor, 1, 2048));
volume = Decibels::gainToDecibels(buffer.getRMSLevel(channel, 0, buffer.getNumSamples()));
//note = Hz_to_note(pitch);

  if (volume > -20.0 && midimsg.isNoteOn() == false) {
  	if (Hz_to_note(pitch) >= 0 && Hz_to_note(pitch) <= 127) {
  		//auto message = MidiMessage::noteOn(1, Hz_to_note(pitch), (uint8)100);
  		//midiMessages.addEvent(MidiMessage::noteOn(1, Hz_to_note(pitch), (uint8)100), 0);
  		//midiOutput->sendBlockOfMessages(midiMessages, Time::getMillisecondCounter() + 1000, 44100);
  		midiOutput->sendMessageNow(MidiMessage::noteOn(1, Hz_to_note(pitch), 1.0f));

  if (volume < -19.0 && midimsg.isNoteOn() == true) {
  	//midiOutput->sendMessageNow(MidiMessage::noteOff(1, Hz_to_note(pitch), 0.0f));



So my vst sends midi message noteOn correctly when volume is more than -20 db but it can’t get into second condition (if (volume < -19.0 && midimsg.isNoteOn() == true)) which contains noteOff() function. If my volume value drops below -19 then i have no noteOff message (I cheked in debug mode that program never enters this “if”) so it is definitely caused by “midimsg.isNoteOn() == true”.

Does my problem results from using “sendMessageNow()” function? As you can see, I tried sending midi messages how it’s done in juce demo (with use of “addEvent”) but I couldn’t make it work.


I think you’ve got yourself a bit confused about how you can send and receive MIDI messages in a plug-in. Are you trying to communicate with an external MIDI device or just send MIDI within the host DAW?

Perhaps browsing the tutorials will clear things up a little:

Create a basic audio plug-in, part 1
Create a basic audio plug-in, part 2