MIDI note creation seems to "double up"

midi

#1

Hi there,

my names is Jens and I am just starting with Juce and audio development.

First of all thanks for such an amazing tool and the super detailled documentation and tutorials !

I am currently working on a simple chord generator. Basically you press a note and it adds a major third and a minor third above, which gives a major chord.

I loop over the MIDI Buffer like in the examples and if I find a note-on message I take the getNoteNumer(), add 4 for the major third and 7 for the minor third above, which gives a major chord and create two additional note-on messages. I do the same for note-off. Here is the loop:

for (MidiBuffer::Iterator it (midiMessages); it.getNextEvent(msg, ignore); )                          
{

	if (msg.isNoteOn())
	{
		myBuffer.addEvent(MidiMessage::noteOn(1, msg.getNoteNumber() + 4, msg.getVelocity()), 1);
		myBuffer.addEvent(MidiMessage::noteOn(1, msg.getNoteNumber() + 7, msg.getVelocity()), 2);

	}
	else if	(msg.isNoteOff())
	{
		myBuffer.addEvent(MidiMessage::noteOff(1, msg.getNoteNumber() + 4, uint8(0)), 1);
		myBuffer.addEvent(MidiMessage::noteOff(1, msg.getNoteNumber() + 7, uint8(0)), 2);
	}

	midiMessages.clear();
	midiMessages.addEvents(myBuffer, 1 ,- 1, numSamples - 1);
	myBuffer.clear();
}

For a C this should produce C E G and it kind of does BUT
it produces an additional note, which is seven halfsteps above the G, but it does not do that for the E. (trusting my hearing) If I just produce the major third, it all works, no additional notes.

I have the feeling, somehow the 2nd note (in this case the G) is again interpreted as a new MIDI event, how can hat be, I deleted the buffer and added my own?

My 2nd question was kind of answered by some forum posts, but just to make sure: I also want to build a scale note filter. (You play a note thats not in the selected scale and it is not played) As I read, I can not manipulate the notes that go to another plugin, so does this mean, I cannot delete them ?

Many thanks in advance,

Jens


#2

It looks like you are adding the notes that you have created back into the original buffer whilst you are still iterating over that buffer with this line:

midiMessages.addEvents(myBuffer, 1 ,- 1, numSamples - 1);

So the messages you are creating are getting interpreted as input notes. I suspect you want to move that step outside of the for loop like so:

for (MidiBuffer::Iterator it (midiMessages); it.getNextEvent(msg, ignore); )                          
{

	if (msg.isNoteOn())
	{
		myBuffer.addEvent(MidiMessage::noteOn(1, msg.getNoteNumber() + 4, msg.getVelocity()), 1);
		myBuffer.addEvent(MidiMessage::noteOn(1, msg.getNoteNumber() + 7, msg.getVelocity()), 2);

	}
	else if	(msg.isNoteOff())
	{
		myBuffer.addEvent(MidiMessage::noteOff(1, msg.getNoteNumber() + 4, uint8(0)), 1);
		myBuffer.addEvent(MidiMessage::noteOff(1, msg.getNoteNumber() + 7, uint8(0)), 2);
	}

}

midiMessages.clear();
midiMessages.addEvents(myBuffer, 0, numSamples, 0);
myBuffer.clear();

#3

How could I not see this ? So many trees but no forest :wink:

works like a charm now…

Thank you so much!