Buffer Size is Zero in processBlock() for Midi Effect in

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;
}

MIDI effect plug-ins aren’t really supported in JUCE’s VST3 wrapper at the moment, I’ll add it to our backlog.

You’ll need to enable the “Plugin MIDI Input” and “Plugin MIDI Output” settings in order to see the MIDI pins in the plug-in host. I’ve pushed a change to the Projucer here so that they are enabled by default when opening the ArpeggiatorPlugin demo.

Can you suggest a workaround? Or is writing a MIDI effect going to be too painful?

Thanks for the Projucer commit!

Just to clarify: This means we should not expect ArpeggiatorPlugin demo to work, at least not with Vst3 ? Is there a work around? (Manually setting numSamples does get the demo to work btw, but that is more of a kludge then a work around :grin:)

Same question. Am trying to work with ArpeggiatorPluginDemo as well. Any progress since this message was last updated?

2 Likes

Hi, perhaps a little late but I found a solution for this issue: storing in a variable the value of int SamplesPerBlock from the function argument of PrepareToPlay and using it in the processBlock.
At least it works for me on Windows