Puck MIDI Note On

Posted on
  • Composer/Sound Designer/Musician here. First ever foray into this slightly daunting yet inspiring world of code and hardware!

    The ble_midi module is great and working as described - but is there any way for it to send a NoteOn or NoteOff message instead of a CC (controller) message?

    It’s looks like a no from the research I’ve done - but I know nothing about javascript, webmidi, etc. so I could be mistaken!

  • A Guess that you can try to see if it works.

    I don't have a Puck and not an expert but some poking around the web provides a guess.

    You might try:

    midi.send(0x9, 60, 100)
    

    A Note Off can be implemented by sending a Note ON with a velocity of 0.

    The Puck.js+MIDI page

    Puck.js+MIDI

    The send function as found in

    ble_midi.js

    exports.send = function(channel, controller, value) {
      NRF.updateServices({
        "03B80E5A-EDE8-4B33-A751-6CE34EC4C700": { // MIDI
          "7772E5DB-3868-4112-A1A9-F2669D106BF3": {
            value: [0x80, 0x80, 0xB0 + channel, controller, value],
            notify: true
          }
        }
      });
    

    The send command sends a 4 byte long MIDI message. The content of the 4 bytes determines the meaning of the 4 byte message and is defined in :

    From Section 4 of MIDI10.pdf

    MIDI10.pdf

    From Table 4.1 a Note On uses channel 0x9 and a Note Off uses channel 0x8.

    You might try:

    midi.send(0x9, 60, 100)
    

    A Note Off can be implemented by sending a Note ON with a velocity of 0.

  • Thanks so much for the suggestion! Really appreciate the help - for a total newbie to all of this.

    So I tried “0x9” as a channel data, and it comes out of my midi monitor as channel 10, but still a control message, rather than a note message.

    I read somewhere that any midi message has a ‘header’ which says whether it’s a control message or a note message. But I wonder if this isn’t represented in the ble_midi module yet?

    Wider context: Trying to use it as a trigger for Ableton, but I can’t map a static control change to anything in ableton (I think it needs a note, or a moving controller)...

    I mean, it might just be easier to use a keymap and then tell the Puck to be a HID keystroke, but I was really hoping it could send midi notes!

    Thanks again for the help

  • Here's a link that reveals a bit more about the MIDI message format
    NoteOnOff

    value: [0x80, 0x80, 0xB0 + channel, controller, value],
    

    If you change the 0xB0 to 0x90, it would send a NoteOn
    If you change the 0xB0 to 0x80, it would send a NoteOff

    If you configure a local projects in WebIDE and copy the module there, it will load that version of the module. Then you can try the changes. Look at the Gear-like Icon in the upper right of WebIDE. Select Project and define a location on your hard drive. Use you explorer to find that folder and a sub -folder called modules.
    Add a new function to the module:

    exports.noteOn = function(channel, controller, value) {
      NRF.updateServices({
        "03B80E5A-EDE8-4B33-A751-6CE34EC4C700": { // MIDI
          "7772E5DB-3868-4112-A1A9-F2669D106BF3": {
            value: [0x80, 0x80, 0x90 + channel, controller, value],
            notify: true
          }
        }
      });
    

    Similar function for noteOff.
    Worth a try.
    The channel is the channel number, controller is the Midi note, and value is the velocity.

  • You don't have to touch the module itself. Try:

    var midi = require("ble_midi");
    midi.init();
    
    midi.noteOn = function(channel, controller, value) {
      NRF.updateServices({
        "03B80E5A-EDE8-4B33-A751-6CE34EC4C700": { // MIDI
          "7772E5DB-3868-4112-A1A9-F2669D106BF3": {
            value: [0x80, 0x80, 0x90 + channel, controller, value],
            notify: true
          }
        }
      });
    
    setWatch(function() {
      // When a button is pressed...
      digitalPulse(LED,1,10);
    
    
      midi.noteOn(0, 60, 100);
    }, BTN, { repeat:true, edge:"rising", debounce:10 });
    

    If this works, let me know and I can add it to the module properly.

  • Yes, thanks so much:

    The Bx0 to 9x0 substitution seems to be the crucial change.

    (I couldn’t delve into the module, because the project-select-directory button in the IDE didn’t work for me (Mac?) but in Gordon’s non-module version it works a charm. Thank you!)

    I might tinker and see if I can get a NoteOff either from 0x80 or from a NoteOn with velocity of 0, and report back...

    Cheers

  • A better explanation of MIDI code:

    Midi Code

    Suggest that

    exports.send = function(channel, controller, value) 
    

    be changed to

    exports.send = function(cmd,channel, controller, value) 
    

    where cmd is the upper nibble and channel is the lower nibble of one byte.

  • I just added separate noteOn/noteOff commands for you, as well as a basic cmd. https://www.espruino.com/Puck.js+MIDI

    @ClearMemory041063 I've left .send the same so it doesn't break it for people already using the module

  • It works a charm, Gordon. NoteOn and NoteOff!

    With a bit of velocity randomisation in Ableton (which I imagine could be done on the Puck itself too, if one were inclined and more knowledgeable than I) you can get a reasonably musical performance with note randomisation on a given scale, different note lengths (thanks to noteOn and noteOff on rising and falling states of the BTN), and velocity changes.

    Thanks all for helping with this. It's been inspiring to receive your help and wisdom! I'm very grateful.

  • P.S. Have noticed on my midi monitor that:

    a channel value of "0" in the .send command uploaded to the puck, comes out as a MIDI channel of "1" when put into practice

    I then tested a channel value of "1" and it comes out as "2" in the MIDI message.

    Not necessarily something that needs "fixing", but a minor detail, useful to know if people are doing channel-specific work with it...

  • Thanks for the update! Yes, I guess the channels are zero-based - I'll update the docs.

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

Puck MIDI Note On

Posted by Avatar for CJA_Music @CJA_Music

Actions