Lets drop all the notes and midi, and just discuss the "abstract" problem.
Your last post asks if one action can have two actions:
B = digitalRead(pin) ;
if ( B == HIGH) {
digitalWrite(pinB,HIGH);
digitalWrite(pinC,HIGH);
}
No problem.
If you want to run a "loop", inside the other loop and NOT being a simple nested loop,, then you keep its counter seperate
int MyLoop ;
void loop() {
B = digitalRead(pin) ;
// count up loop if B is on
if ( B == HIGH ) {
MyLoop = MyLoop + 1;
if ( MyLoop > 1000 ) {
digitalWrite(pinB,HIGH) ;// do something here
MyLoop = 0 ; // reset the loop
}
}
To do two, just repeat the code with a My2ndLoop variable.
If the "B" can go low before the loop is finished, but you must have the loop run to the end, then use a boolean BSeenHigh.
if ( B == HIGH ) { becomes
if ( B == HIGH && BSeenHigh == false)
BSeenHigh = true ;
if (BSeenHigh ) {
and then you reset BSeenHigh when the loop is done.
NB to the smartasses out there - yes, the two long test lines can be rewritten in the more compact and cryptic
BSeenHigh=digitalRead(pin)==HIGH&&!BSeenHigh; (and the ==HIGH could be omitted, but it depends on the value of HIGH)