Iterator depreciated (Part 2: Coding your plug-in)

Hello,

I’m at at the end of Part 2 of Coding your plugin JUCE: Tutorial: Create a basic Audio/MIDI plugin, Part 2: Coding your plug-in when I get an error saying Iterator is depreciated. Reading the documentation I find that this has been done in favor of MidiBufferIterator. Can anyone give me ideas on how to rewrite this last bit of code using MidiBufferIterator? Thanks in advance for your time and effort.

I didn’t test it, but it should be something like that :

void TutorialPluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
    buffer.clear();
 
    juce::MidiBuffer processedMidi;

 
    for (const MidiMessageMetadata metadata : midiMessages)
    {
        auto m = metadata.getMessage();
	    auto time = metadata.samplePosition;

        if (m.isNoteOn())
        {
            uint8 newVel = (uint8) noteOnVel;
            m = juce::MidiMessage::noteOn (m.getChannel(), m.getNoteNumber(), newVel);
        }
        else if (m.isNoteOff())
        {
        }
        else if (m.isAftertouch())
        {
        }
        else if (m.isPitchWheel())
        {
        }
 
        processedMidi.addEvent (m, time);
    }
 
    midiMessages.swapWith (processedMidi);
}

We’ve updated this tutorial and the new version is on the website. The updated processBlock() code is as follows:

void TutorialPluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
    buffer.clear();

    juce::MidiBuffer processedMidi;

    for (const auto metadata : midiMessages)
    {
        auto message = metadata.getMessage();
        const auto time = metadata.samplePosition;

        if (message.isNoteOn())
        {
            message = juce::MidiMessage::noteOn (message.getChannel(),
                                                 message.getNoteNumber(),
                                                 (juce::uint8) noteOnVel);
        }
        
        processedMidi.addEvent (message, time);
    }

    midiMessages.swapWith (processedMidi);
}
1 Like

Correct me if i’m wrong, but it seems that in the old function all messages were going through whereas in the the new one only the NoteOn messages are kept, isn’t it?

1 Like

Yes, good spot thanks! I’ve edited my post above, and the tutorial will be updated shortly.

1 Like

Thanks about that. Would it be also possible to add somewhere on each tutorial page when they have been last updated? It’s not clear if they’re up to date or not and sometimes it could help to know it when getting issues at the one reported in this post. Thanks!

3 Likes