Question About MidiBuffer Class

Hello, everyone!

Recently I was planning to create a some filter plugin, which could set some filter frequency parameters from midi keyboard, so it could work like this: I am pressing the key, it will be converted into frequency (for example - A4, key 69 becomes 440 Hz), and thus, let’s say the cutoff frequency is set.

But honestly, I am really puzzled how I could extract the midi note frequency from MidiBuffer class in PluginProcessor::processBlock override method, I cannot see such a function for it in documentation for MidiBuffer class. However, I found getMidiNoteInHertz() and getNoteNumber() in MidiMessage class, which seems kinda what I really need, but so I have to convert somehow info from MidiBuffer to MidiMessage then…?

Should it look like this?

for (int midiEvent = 0; midiEvent < midiMessages.getNumEvents(); ++midiEvent)
{

    juce::MidiMessage msg = midiMessages.data[midiEvent]; <---- totally unsure for this line...
    auto mtof = msg.getMidiNoteInHertz(msg.getNoteNumber());
   other function stuff to do with mtof variable and processing....
}

I guess I don’t understand the topic properly here. I would be happy for any help or any hint:))

Wishing all the best in upcoming 2022 year!
Sincerely,
Katya

You can iterate through a midi buffer like this:

MidiBuffer midi;

for (const auto& meta : midi)
{
    // meta is an instance of MidiMessageMetadata

    const auto message = meta.getMessage();
    const auto timestamp = meta.samplePosition;
}

hope that helps!

Dear benvining,

Thank you so much for your help! Yes, it works great!

Happy Holidays once again!

1 Like