Add midi control to audio-plug in


Hello guys , I wonder how can I implement midi control to my project so in every note that I hit plays the loaded file thank you very much.

this is my code so far :

And I have an issue when I load another file something is not working.


Here’s a basic on how to play a sample when a MIDI note comes in. - Juce Project

The algorithm is basically

  1. for each new midi note on message
    • Find position in buffer (beginning @ 0 ? middle? end ?
    • add new note to CurrentNotes (index = array + sampleLength (number of samples int)

Then, you cycle through your ‘current notes’ and add the sample to the output:

For each (n = 0 -> CurrentNotes.size())
    For each ( i = 0 - > sampleCount in audio buffer)
        if CurrentNote.index  < sampleLength
                 if(CurrentNote[n].index >= 0)
                      int getSample = sampleLength - CurrentNote[n].index
                      output[i] += sampleData[getSample];
        CurrentNote[n].index -= 1

As far as loading samples, I’m not sure how to help you there.


Hmm, that’s a pretty bad example algorithm for anyone to try to follow, I’m afraid!

Best plan to just play some samples would be to use the juce Synthesiser/SamplerSound/SamplerVoice classes. See the big juce demo’s synthesiser example, where it plays some sampled cello sounds.