[color=#7E7E7E]/* Demo of sending MIDI Non-Registered Parameter Number (NRPN)[/color]
[color=#7E7E7E] Allows high resolution 14-bit or normal resolution 7-bit values for up[/color]
[color=#7E7E7E] to 2^14 numbered controllers. Controller numbers are implementation [/color]
[color=#7E7E7E] specific (make up your own).[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] Documentation:[/color]
[color=#7E7E7E] http://www.midi.org/techspecs/midimessages.php[/color]
[color=#7E7E7E] http://www.philrees.co.uk/nrpnq.htm[/color]
[color=#7E7E7E] http://home.roadrunner.com/~jgglatt/tutr/rpn.htm[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] Chris Lilley 2013[/color]
[color=#7E7E7E] This example code is in the public domain.[/color]
[color=#7E7E7E] */[/color]
[color=#7E7E7E]// Fixed values, for demonstration[/color]
[color=#CC6600]uint32_t[/color] channel = 1; [color=#7E7E7E]// channels are 1 to 16[/color]
[color=#CC6600]uint32_t[/color] param = 123456; [color=#7E7E7E]// your parameter number here, 0 to 16k[/color]
[color=#CC6600]uint32_t[/color] val = 54321; [color=#7E7E7E]// your value here, 0 to 16k[/color]
[color=#7E7E7E]// in actual use this would come from some physical controller like an analog value[/color]
[color=#7E7E7E]// or be computed by monitoring an encoder[/color]
[color=#CC6600]void[/color] sendNRPN([color=#CC6600]uint32_t[/color] parameter, [color=#CC6600]uint32_t[/color] value, [color=#CC6600]uint32_t[/color] channel) {
[color=#7E7E7E]// Send an arbitrary 7-bit value to an arbitrary 14-bit non-registered parameter[/color]
[color=#7E7E7E]// Note that param MSB and LSB are shared between RPN and NRPN, so set both at once[/color]
[color=#7E7E7E]// Also, null out the RPN (and NRPN) active parameter (best practice) after data is sent (as it persists)[/color]
[color=#7E7E7E]// Control change 99 for NRPN, MSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((99 & 0x7F) << 16) | ((parameter & 0x7F) << 24));
[color=#7E7E7E]// Control change 98 for NRPN, LSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((98 & 0x7F) << 16) | (((parameter >>7) & 0x7F) << 24));
[color=#7E7E7E]// Control change 6 for Data Entry MSB of value[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((6 & 0x7F) << 16) | ((value & 0x7F) << 24));
[color=#7E7E7E]// Now null out active parameter by sending null (127, 0x7F) as MSB and LSB[/color]
[color=#7E7E7E]// Control change 101 for RPN, MSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((101 & 0x7F) << 16) | (0x7F << 24));
[color=#7E7E7E]// Control change 100 for NRPN, LSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((100 & 0x7F) << 16) | (0x7F << 24));
}
[color=#CC6600]void[/color] sendNRPNHR([color=#CC6600]uint32_t[/color] parameter, [color=#CC6600]uint32_t[/color] value, [color=#CC6600]uint32_t[/color] channel) {
[color=#7E7E7E]// Send an arbitrary 14-bit value to an arbitrary 14-bit non-registered parameter[/color]
[color=#7E7E7E]// Note that param MSB and LSB are shared between RPN and NRPN, so set both at once[/color]
[color=#7E7E7E]// Also, null out the RPN (and NRPN) active parameter (best practice) after data is sent (as it persists)[/color]
[color=#7E7E7E]// Control change 99 for NRPN, MSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((99 & 0x7F) << 16) | ((parameter & 0x7F) << 24));
[color=#7E7E7E]// Control change 98 for NRPN, LSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((98 & 0x7F) << 16) | (((parameter >>7) & 0x7F) << 24));
[color=#7E7E7E]// Control change 6 for Data Entry MSB of value[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((6 & 0x7F) << 16) | ((value & 0x7F) << 24));
[color=#7E7E7E]// Control change 38 for Data Entry LSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((38 & 0x7F) << 16) | (((value >>7) & 0x7F) << 24));
[color=#7E7E7E]// Now null out active parameter by sending null (127, 0x7F) as MSB and LSB[/color]
[color=#7E7E7E]// Control change 101 for RPN, MSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((101 & 0x7F) << 16) | (0x7F << 24));
[color=#7E7E7E]// Control change 100 for NRPN, LSB of param[/color]
usb_midi_write_packed(0xB00B | (((channel - 1) & 0x0F) << 8) | ((100 & 0x7F) << 16) | (0x7F << 24));
}
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {
[color=#CC6600]delay[/color] (5000); [color=#7E7E7E]// start up your MIDI monitoring now[/color]
sendNRPNHR(param, val, 1); [color=#7E7E7E]// channel 1[/color]
}
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {
[color=#CC6600]delay[/color] (3000); [color=#7E7E7E]// slowly, for testing[/color]
sendNRPNHR(param, val, 1); [color=#7E7E7E]// channel 1[/color]
}