I have created a MIDI effect from Projuicer. I am debugging it in Xcode, using the JUCE AudioPluginHost.
I have taken processBlock() from the Arpeggiator example. But buffer.getNumSamples() returns zero. Should this work, or is there a new method for calculating timing in a MIDI plugin?
// the audio buffer in a midi effect will have zero channels!
jassert (buffer.getNumChannels() == 0);
// however we use the buffer to get timing information
auto numSamples = buffer.getNumSamples();
I do get arpeggios if I manually set numSamples.
Note: I am doing this from scratch because the Arpeggiator example doesn’t show any MIDI connection pins in the JUCE test host. Would love to know how to get those pins to appear.
Here is the entire routine:
void processBlock (AudioBuffer& buffer, MidiBuffer& midi) override
{
// the audio buffer in a midi effect will have zero channels!
jassert (buffer.getNumChannels() == 0);
// however we use the buffer to get timing information
auto numSamples = buffer.getNumSamples();
// get note duration
auto noteDuration = static_cast<int> (std::ceil (rate * 0.25f * (0.1f + (1.0f - (*speed)))));
MidiMessage msg;
int ignore;
for (MidiBuffer::Iterator it (midi); it.getNextEvent (msg, ignore);)
{
if (msg.isNoteOn()) notes.add (msg.getNoteNumber());
else if (msg.isNoteOff()) notes.removeValue (msg.getNoteNumber());
}
midi.clear();
if ((time + numSamples) >= noteDuration)
{
auto offset = jmax (0, jmin ((int) (noteDuration - time), numSamples - 1));
if (lastNoteValue > 0)
{
midi.addEvent (MidiMessage::noteOff (1, lastNoteValue), offset);
lastNoteValue = -1;
}
if (notes.size() > 0)
{
currentNote = (currentNote + 1) % notes.size();
lastNoteValue = notes[currentNote];
midi.addEvent (MidiMessage::noteOn (1, lastNoteValue, (uint8) 127), offset);
}
}
time = (time + numSamples) % noteDuration;
}

)