isNoteOn() always false

midi

#1

Hello,

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);
//midiOutput->startBackgroundThread();
double
bufor;
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;
dywapitch_inittracking(&pitchtracker);
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));
  	midiOutput->sendMessageNow(MidiMessage::allNotesOff(1));

  }

}
}

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.


#2

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


#3

Thank you for reply. Sorry for so long absence, but I didn’t have time to code my plugin.
So to make some change in audio we need to iterate through audio buffer and to make changes in midi we need to iterate through midi buffer. But is it possible to somehow make change in midi messages while using audio buffer? Basic example: Plugin which put some midi note (midiOn) only if there is audio louder than -20 dB and cut the note (midiOff) if audio is less than -20 dB?