Create a MIDI Sampler

I have a 9 button MIDI controller using the MIDI USB library where the keys connect using 6.35mm jacks. It has 5 switches to tell if each note is sharp or not for whatever the keys that need it, 9 other buttons to silence the note(basically to be able to have a beat) and it has a potentiometer to change octaves.

What I want to do is basically a way to store the value of the MIDI notes sent over a period of 5 seconds and continually send them until the user clears them. The user should be able to play any note they want with the tempo they choose. UI wise I was picturing 2 buttons, one of them to start the recording when pressed and stop it when released, then another one to clear it when pressed.

The way the library sends MIDI instructions is this:

if(buttonState[i] == HIGH) {
  noteOn(MIDIchannel,noteValue,speed);
  MidiUSB.flush();
}else{
  noteOff(MIDIchannel,noteValue,speed);
  MidiUSB.flush();
}

Is it possible? What method should I use to store the values?