Need help with MIDI.h code.

I am building a MIDI player using photocells. I have come up with this code so far. For changing light situation I came up with this “THRESHOLD1 = val+5”, so next change will trigger the note. It kind of works OK, but may not trigger noteOff always. Maybe there is a better way so feel free to correct if it looks weird.
But if I want to play sequence of notes instead of one. Somehow I can not find the way. :’(

#include <MIDI.h>
byte note = 0;
int AnalogValue = 0;
byte val = 0;
int statePin = LOW;
int THRESHOLD1 = val+5;

void setup() {

MIDI.begin(1);
MIDI.sendProgramChange (12,1);
}

void loop() {

val = analogRead(AnalogValue);
if (val <= THRESHOLD1) {
MIDI.sendNoteOn(44,127,1);
delay(1000);
if (val >= THRESHOLD1) {
MIDI.sendNoteOff(44,127,1);
}
}
}

You need a septate on threshold and an off threshold for each note you want to generate. Then you just go through the list of all thresholds turning notes on or off each time though the loop.

However, that will keep on triggering notes each time round the loop so you want another variable that tells you if a note is playing. Then you only trigger a note (and set the variable to playing) when the note is off and you only turn a note off (and set the variable to not playing) when the note is on. Use a boolean variable for this.

It will be even more efficient if you use an array to store these.

Thanks! So for the sequence I use the same value to trigger lets say 3 notes with different delays to get these to play one after another and note off's. I forgot to say I am on my first steps with arduino and writing the code so at this point an example of using variables would help me a lot.