Trying to create a little "Sequencer" notes play but do not end

Hello there,

having big fun exploring Juce :wink:

I am trying to create a steady pulse of Midi notes. I used the arpeggiator example as a guide counting samples and stuff.

Still I am doing something wrong, as the notes do not stop. I can not tell if its a steady flow of notes or just one thats not ending…

Here is my code:
As the fomatting is party weird, its the process Block function in PluginProcessor, sorry for the hassle.

ScopedNoDenormals noDenormals;

int numSamples = buffer.getNumSamples();
midiMessages.clear();

if (isPlaying && !noteIsOn && (samplesTillNextNote<=0))
{
	samplesTillNoteOff = samplesPerQuarterNote / 4;
	samplesTillNextNote = samplesPerQuarterNote;
	midiMessages.addEvent(MidiMessage::noteOn(1, 64, uint8(100)), 1);
	noteIsOn = true;
}

if (isPlaying && noteIsOn && (samplesTillNoteOff==0))
{
		midiMessages.addEvent(MidiMessage::noteOff(1, 64, uint8(0)), 1);
		noteIsOn = false;
}

if (!isPlaying && noteIsOn)
{
	midiMessages.addEvent(MidiMessage::noteOff(1, 64, uint8(0)), 1);
	noteIsOn = false;
}
if (samplesTillNextNote >= numSamples)
	samplesTillNextNote -= numSamples;
else
	samplesTillNextNote = 0;

if (samplesTillNoteOff >= numSamples)
	samplesTillNoteOff -= numSamples;
else
	samplesTillNoteOff  = 0;

any ideas, suggestions? Am I completely on the wrong path?

Thank you,

Jens

if (samplesTillNoteOff >= numSamples)
	samplesTillNoteOff -= numSamples;
else
	samplesTillNextNote  = 0;

You have a type here meaning samplesTillNoteOff will never be set to 0.

Thanks,

I saw it when I posted it and corrected the code, still no change…

Forgot to correct it in the above post. Will do so now.

regards,

Jens

What is the value of samplesTillNoteOff and numSamples. If samplesTillNoteOff < numSamples then it’ll never get decremented.

Hahaha it works now.

Seems you can only use sample counting for timing as long as you have an audio bus…

How am I supposed to do timing on a plugin thats a midi effcet ? (which has no audio bus)