• Hi all,
    I am trying to implement 2 functions to this module. One to receive CC messages and one to rename the device. I am pretty limited in my knowledge when it comes to this subject.
    If anyone can help it will be greatly appreciated!

    thank you!

    this is where I am at, and both function doesn't work for now ๐Ÿ˜Ž:

    /* Copyright (c) 2017 Gordon Williams, George Mandis, Joe Bowbeer, Pur3 Ltd. See the file LICENSE for copying permission. */
    /* usage:
    var midi = require("ble_midi");
    midi.init();
    
    midi.send(channel, controller, value);
    */
    
    /// Turns the device into a MIDI controller
    exports.init = function () {
      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: function (evt) {
              if (
                evt.data.length == 6 &&
                evt.data[0] == 0x80 &&
                evt.data[1] == 0x80 &&
                (evt.data[2] & 0xf0) == 0xb0
              ) {
                var timestamp = ((evt.data[0] & 0x3f) << 7) | (evt.data[1] & 0x7f);
                var channel = evt.data[2] & 0x0f;
                var controller = evt.data[3];
                var value = evt.data[4];
                exports.onCC(timestamp, channel, controller, value);
              }
            }
          }
        }
      });
    
      NRF.setAdvertising([
        // Flags: LE Limited Discoverable Mode, BR/EDR Not Supported
        0x02, 0x01, 0x05,
        // Complete Local Name: PuckCC
        0x07, 0x09, 0x50, 0x75, 0x63, 0x6b, 0x43, 0x43,
        // MIDI
        0x11, 0x06, 0x00, 0xc7, 0xc4, 0x4e, 0xe3, 0x6c, 0x51, 0xa7, 0x33, 0x4b,
        0xe8, 0xed, 0x5a, 0x0e, 0xb8, 0x03,
      ]);
    };
    
    /// Sends a raw MIDI command
    exports.cmd = function (cmd, d1, d2) {
      NRF.updateServices({
        "03B80E5A-EDE8-4B33-A751-6CE34EC4C700": {
          "7772E5DB-3868-4112-A1A9-F2669D106BF3": {
            value: [0x80, 0x80, cmd, d1, d2],
            notify: true,
          },
        },
      });
    };
    
    /// Send a 'control change' (0xB0) MIDI command
    exports.send = function (channel, controller, value) {
      this.cmd(0xb0 + channel, controller, value);
    };
    /// Send a 'note on' (0x90) MIDI command
    exports.noteOn = function (channel, note, velocity) {
      this.cmd(0x90 + channel, note, velocity);
    };
    /// Send a 'note off' (0x80) MIDI command
    exports.noteOff = function (channel, note, velocity) {
      this.cmd(0x80 + channel, note, velocity);
    };
    
    /// Sets the name of the MIDI device
    exports.setName = function (name) {
      var nameBytes = [];
      for (var i = 0; i < name.length; ++i) nameBytes.push(name.charCodeAt(i));
      NRF.setAdvertising([
        // Flags: LE Limited Discoverable Mode, BR/EDR Not Supported
        0x02,
        0x01,
        0x05,
        // Complete Local Name
        0x07,
        0x09,
        nameBytes,
        // MIDI
        0x11,
        0x06,
        0x00,
        0xc7,
        0xc4,
        0x4e,
        0xe3,
        0x6c,
        0x51,
        0xa7,
        0x33,
        0x4b,
        0xe8,
        0xed,
        0x5a,
        0x0e,
        0xb8,
        0x03,
      ]);
    };
    
  • Hi - did you close this because you figured it out?

    Or is this another bit of code from ChatGPT? :)

  • ๐Ÿ˜‚
    ahaha no!
    resolved with the help of Joe Bowbeer <3

    full discussion and solution:
    https://github.com/joebowbeer/PuckCC/issยญues/1#issuecomment-1524715536

  • Great! Actually Joe dropped me an email (I'll get back to you soon Joe!) so maybe we can get it built into a module

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ble_midi module need help implementing new functions

Posted by Avatar for user155285 @user155285

Actions