I downloaded the Midi program that plays 2 octaves when I connect the Arduino to a keyboard's MIDI in port. It works great. Changing the voice on the keyboard while the octaves are playing changes the sound of the keyboard keys when I press them but it doesn't change the sound of the 2 octaves coming in from the microprocessor. Is there a command that would let me change that voice programatically? I've got a Yamaha YPT-310.
The MIDI command for channel 1 voice change is 0xc0 followed by the voice information from 0 to 127
In MIDI the command you want is called Program Change or PC. It's well described in MIDI tutorial for programmers
Most keyboards respond to it but some consumer types seem to ignore it. I don't know about the Yamaha YPT-310.
Steve
Here you go... This one works very nicely for me!
void MidiSelectInstrument ( int nChannel, int nInstrument )
{
//
// Write the serial stuff to select a particular instrument on a particular channel
//
unsigned char chData[2] ;
// Instrument select cmd (top 4), channel (low 4)
chData[0] = 0b11000000 | ( nChannel | 0b00001111 ) ;
chData[1] = nInstrument & 0b01111111 ;
MIDISERIAL.write ( chData, sizeof ( chData ) ) ;
}
Thanks to all. I used Grumpy_Mike's answer and it worked. The only glitch was that the expected sound did not match the documentation for MY keyboard. There's not even a predictable offset (like +p or -p, where p is a patch number value from 0 to 127). Still, the "Serial.write(0xC0);" followed by "Serial.write(0xp)" did produce a program (patch) change.