Help wanted !!! Building a midi controller

Ok I have merged the functions of these two totally rubbish sketches:-

/*
* MIDI Drum Kit
* a demo code in how to read a multiplexed analogue input by Mike Cook
* while the code will work the result will be rubbish because it takes too long to get round all the sensors
* therefore some hits will be missed
* also holding on a hit sensor until it stops is a rubbish way of doing things but that was in the origional sketch
*/

// what midi channel we're sending on
// ranges from 0-15
#define drumchan 1  // note the drum set is normally on channel 9 or 10
// general midi drum notes
// analog threshold for piezo sensing
#define PIEZOTHRESHOLD 100

//==============================================================

//==============================================================

void setup()
{

//4051Mux A B C digital control pins // Mux A Part//

pinMode(8, OUTPUT); // s0
pinMode(9, OUTPUT); // s1
pinMode(10, OUTPUT); // s2
pinMode(13, OUTPUT);
Serial.begin(31250); // set MIDI baud rate
}

void loop()
{
//Read Value of 4051 analog-in 0 by setting the values of s0,s1 and s2
int readValue, t, noteToPlay = 30;
for(int i = 0; i<4; i++) { // this loop will read each of the four analogue inputs 0 to 3
for (int j= 0; j<7; j++){  // this loop will read 8 inputs from one analogue input
noteToPlay++;                  // increment the note to play this will be used if we find a hit
digitalWrite(8, j & 1);       // output the binary number j to the three pins 8, 9 & 10 
digitalWrite(9, (j >>1)& 1);
digitalWrite(10, (j >>2)& 1);
readValue = analogRead(i); // read the input pin
// everything above this point is the second sketch - everything below is the first sketch
if( readValue >= PIEZOTHRESHOLD ) {  // we have found a hit sensor
  t=0;
  while(analogRead(i) >= PIEZOTHRESHOLD/2) {  // hold until the hit drops off
  t++;                                        // and count how many times round the loop we go
 }
 noteOn(drumchan,noteToPlay, t*2); // note on - use the number of times round the loop as a velocity and note length
 delay(t);
 noteOff(drumchan,noteToPlay, 0);  // note off
   } // end of we have found a hit
  } // end of j loop
 } // end of i loop
} // end of loop()

// Send a MIDI note-on message. Like pressing a piano key
// channel ranges from 0-15
void noteOn(byte channel, byte note, byte velocity) {
midiMsg( (0x90 | channel), note, velocity);
}

// Send a MIDI note-off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
midiMsg( (0x80 | channel), note, velocity);
}

// Send a general MIDI message

void midiMsg(byte cmd, byte data1, byte data2) {
digitalWrite(13,HIGH); // indicate we're sending MIDI data
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
digitalWrite(13,LOW);
}