New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Midi CC receive #1
Comments
I don't think this would be difficult to do. I think you'd need to extend the ble_midi code (copy/paste?) in order to add your own http://www.espruino.com/Reference#l_NRF_setServices Your implementation would need to decode the CC event data, which I expect to be an array of 5 bytes, similar to the CC bytes that are sent. Some onWrite code here, FWIW: https://www.espruino.com/BLE+Communications |
thanks! |
I am fairly new to this and still struggle to understand it ::) |
The relevant specs are: https://www.midi.org/specifications-old/item/table-1-summary-of-midi-message The first spec defines the transport: a header and timestamp byte followed by data bytes, possibly with some intervening timestamps. The second table defines the data bytes. In the simplest case you'll receive 5 bytes:
|
thank you! I gonna try my best and get back to you if I get anything interesting! |
I didnt went too far for now but in parallel I am trying to add a function to be able to rename the device, using midi.setName("PUCKIO"); ( where the name is always 6 letters to keep it easy with the first byte (length of the name+1) "0x07" my code doesn't throw error but the device isnt showing up as a midi device anymore, any idea what could be the problem? thank you! /// Sets the name of the MIDI device }; |
setAdvertising needs a flat array of bytes, not a nested array:
Maybe you can assign these bytes to an array variable and then overwrite the name chars at indices 5..10 before calling setAdvertising. With BLE, by the way, you'll often need to clear the on-device cache in order to see changes. So, for example, on an Android, you'd turn off Bluetooth and forget the old device to clear the cache. |
"flat array of bytes, not a nested array" That's what I thought but I have no idea how to do that, actually I thought it was already what I was doing 😅 |
for the receiveCC that's where I am at but still no luck: onWrite: function (evt) { |
/// Receives MIDI events
function recv(evt) {
var data = evt.data;
var cmd = data[2] & 0xF0; // command
var chn = data[2] & 0x0F; // channel
var num = data[3]; // note or controller number
var val = data[4]; // velocity or controller value
switch(cmd) {
case 0x80: // noteOff
case 0x90: // noteOn
if (val) LED1.set(); else LED1.reset();
break;
case 0xB0: // CC
if (val) LED2.set(); else LED2.reset();
break;
default:
if (val) LED3.set(); else LED3.reset();
}
}
/// Turns the device into a MIDI controller
function init(name) {
NRF.setServices({
"03B80E5A-EDE8-4B33-A751-6CE34EC4C700": { // MIDI
"7772E5DB-3868-4112-A1A9-F2669D106BF3": {
readable: true,
writable: true,
notify: true,
value: [0x80, 0x80, 0x00, 0x00, 0x00],
onWrite: recv
}
}
});
NRF.setAdvertising([
// Flags: LE Limited Discoverable Mode, BR/EDR Not Supported
0x02, 0x01, 0x05,
// Complete Local Name: PuckCC
0x07, 0x09,
name.charCodeAt(0),
name.charCodeAt(1),
name.charCodeAt(2),
name.charCodeAt(3),
name.charCodeAt(4),
name.charCodeAt(5),
// MIDI
0x11, 0x06, 0x00, 0xC7, 0xC4, 0x4E, 0xE3, 0x6C, 0x51,
0xA7, 0x33, 0x4B, 0xE8, 0xED, 0x5A, 0x0E, 0xB8, 0x03
]);
}
init("PuckCC"); |
::) effortless ! |
The weird latency is likely due to low power mode kicking in and lowering the connection interval. Try calling the following and see if that helps:
|
Would it be possible to add a function to receive midi CC also ? (to control led, servos etc )
thanks!
The text was updated successfully, but these errors were encountered: