-
Hi folks, In my Korg Kross 2 many parameters that can be assigned to a potentiometer use 2 SysEx arrays, a SysEx array on negative values and another SysEx array on positive values. -99 = {0xf0, 0x42, 0x30, 0x00, 0x01, 0x49, 0x41, 0x00, 0x00, 0x09, 0x00, 0x34, 0x0f, 0x7f, 0x7f, 0x7f, 0x1d, 0xf7}; -01 = {0xf0, 0x42, 0x30, 0x00, 0x01, 0x49, 0x41, 0x00, 0x00, 0x09, 0x00, 0x34, 0x0f, 0x7f, 0x7f, 0x7f, 0x7f, 0xf7}; +00 = {0xf0, 0x42, 0x30, 0x00, 0x01, 0x49, 0x41, 0x00, 0x00, 0x09, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7}; +99 = {0xf0, 0x42, 0x30, 0x00, 0x01, 0x49, 0x41, 0x00, 0x00, 0x09, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x63, 0xf7}; Does anyone know how to implement this in the sketch? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
From what I can see, the only thing that changes in those messages is the last 5 bytes of data (ignoring the last 0xf7 byte that marks the end of the SysEx message). Those 5 bytes represent the value, and there is actually only one message: negative values in binary are represented using two's complement. Now in the case of SysEx, there's a little extra trick: all data bytes have to be between 0x00 and 0x7f. That's because values with a most significant bit (MSB) of 1 (0x80 to 0xff) represent status codes and other control commands in the MIDI protocol. From what we can see in the encoding of the -1 value (0x0f 0x7f 0x7f 0x7f 0x7f), we have 32 bits of data: that's a four byte value, spread out on four blocks of 7 bits (0x7f), plus one block of 4 bits (0x0f):
This is confirmed with the -99 value:
So, how can we convert a potentiometer value into valid SysEx data? The ADCs in Arduino have 10 bits of resolution (0 to 1023). It's more resolution than we need in this case (-99 to 99, plus zero, makes 199 values). We can use the If we store this -99 to 99 value directly on a signed 32 bit variable*, we can then perform our bit arithmetic to turn that into SysEx-compatible data: const long rangedValue = map(analogRead(potPin), 0, 1023, -99, 99);
const byte sysExValueData[5] = {
(rangedValue >> 28) & 0x0f, // First 4 bits
(rangedValue >> 21) & 0x7f, // Next 7 bits
(rangedValue >> 14) & 0x7f, // etc..
(rangedValue >> 7) & 0x7f, // until
rangedValue & 0x7f // the last 7 bits
};
const byte sysExMessage[16] = {
0x42,
0x30,
0x00,
0x01,
0x49,
0x41,
0x00,
0x00,
0x09,
0x00,
0x34,
sysExValueData[0],
sysExValueData[1],
sysExValueData[2],
sysExValueData[3],
sysExValueData[4],
};
MIDI.sendSysEx(16, sysExMessage); // The library sends start/end bytes by default * Note: using an |
Beta Was this translation helpful? Give feedback.
From what I can see, the only thing that changes in those messages is the last 5 bytes of data (ignoring the last 0xf7 byte that marks the end of the SysEx message).
Those 5 bytes represent the value, and there is actually only one message: negative values in binary are represented using two's complement.
Now in the case of SysEx, there's a little extra trick: all data bytes have to be between 0x00 and 0x7f. That's because values with a most significant bit (MSB) of 1 (0x80 to 0xff) represent status codes and other control commands in the MIDI protocol.
From what we can see in the encoding of the -1 value (0x0f 0x7f 0x7f 0x7f 0x7f), we have 32 bits of data: that's a four byte value, sprea…