Newbie: MIDI note off

I have a newbie question:

I am trying to send a midi note on for a second and then off.
I am trying to achieve this in the most simple manner.

Something like this:
noteOn(0x90,60,0x45); //Note on channel 1 (0x90), note value (60), middle velocity (0x45):
delay(500);
noteOn(0x90,60,0); //Note on channel 1 decreases to 0

with
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}

doesn't seem to work

this is what I get using MIDI monitor on a Mac:

01:47:20.740 From USB Midi Note Off 1 C3 0
01:47:21.893 From USB Midi Note On 1 C3 69
01:47:21.894 From USB Midi Reset
01:47:22.392 From USB Midi Note Off 1 C3 0
01:47:24.318 From USB Midi Note On 1 C3 69
01:47:24.322 From USB Midi Reset
01:47:24.323 From USB Midi Reset
01:47:24.325 From USB Midi Reset
01:47:24.326 From USB Midi Reset
01:47:24.329 From USB Midi Reset
01:47:24.335 From USB Midi Reset
01:47:25.317 From USB Midi Note Off 1 C3 0
01:47:26.469 From USB Midi Note On 1 C3 69
01:47:26.471 From USB Midi Reset
01:47:26.476 From USB Midi Reset
01:47:26.969 From USB Midi Note Off 1 C3 0
01:47:28.895 From USB Midi Note On 1 C3 69
01:47:28.900 From USB Midi Reset
01:47:28.901 From USB Midi Reset

then the signal just interrupts. I am using a USB - MIDI cable. Is my programming wrong or is my hardware wrong?

MIDI runs on a non-standard baud rate. Have you correctly configured the serial device of the Arduino to run at that rate? Is that even possible?

Yes, I did declare the right baud I believe. This is the full sketch.

Any ideas?

/*

  • Code will output a user-defined pulse to operate a relay and then a solenoid valve.
  • This pulse to control the on/off of the solenoid is defined in terms of period and duty-cycle
  • That control happens through two analog inputs (2 potentiometers) on the prototype board
  • The solenoid valve thereby sends alternating pressure and vacuum to a air chamber
  • The current status of the valve (on/off) will be output via serial port to a MIDI device
    */

const int solenoidPin = 2;
const int periodPin = A0;
const int dutyPin = A1;

void setup()
{
pinMode(solenoidPin, OUTPUT);//initialize solenoid output (through transistor then relay)
pinMode(periodPin,INPUT); //initialize period control (future)
pinMode(dutyPin,INPUT); //initialize duty control (future)
Serial.begin(31250); //send an receive to computer MIDI note

}

void loop()
{

int periodPot;
int dutyPot;
int period;
int duty;
/* initializing periodPot and dutyPot values*/

periodPot = analogRead(periodPin); //receive the value of the potentiometer and save as periodPot
dutyPot = analogRead(dutyPin); //receive the value of the potentiometer and save as dutyPot
period = map(periodPot, 0, 1023, 500, 10000); //map the 0 to 1023 values from the potentiometer to appropriate frequency values of 500ms to 10000ms
duty = map(dutyPot, 0, 1023, 500, period); //map the 0 to 1023 values from the potentiometer to appropriate duty values of 500ms to period

digitalWrite(solenoidPin, HIGH);
noteOn(0x90,60,0x45); //Note on channel 1 (0x90), note value (60), middle velocity (0x45):
delay(500);
noteOn(0x90,60,0); //Note on channel 1 decreases to 0
delay(duty);

digitalWrite(solenoidPin, LOW);
noteOn(0x90,60,0x45); // note value (60)
delay(1000);
noteOn(0x90,60,0);//Note on channel 1 decreases to 0
delay(period - duty);
}

void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}