Handling NRPNs with Javascript

    Mar 29 2010 | 12:27 am
    In writing M4L devices to control the Tetra and Mopho I created a couple javascripts to handling converting CCs to NRPNs and back again. This should allow you to assembly incoming CCs into 14 bit NRPN Index + Value lists and send 14 bit Index + Values as 4 separate CCs to trigger an NRPN change. I haven't troubleshot everything quite yet but it's working great for the Mopho Keyboard here. Hopefully I'll get a device set up pretty soon, still need to figure out how to tunnel sysex over... bleh.
    NRPNs Part 1: The Basics - The first blog post goes over what NRPNs are and how MIDI handles them since I've gotten a lot of questions around that topic.NRPNs Part 2: Filtering NRPNs in Ableton with M4L - Describes how to use Javascript to filter NRPN values from an incoming MIDI stream and assemble them into NRPN# and value for using in M4LNRPNs Part 3: Sending with Ableton and M4L - Covers some bitwise operations used to convert values into MSB and LSB and the actual repackaging into 4 CC packets
    I've attached the Javascripts here, figure there are those of you who just want the code and to go at it. I figured javascript was the best way to get it going quick until I can putz around with the SDK and rewrite it as a C module. Let me know if anything looks wrong or if there are any bugs. Hope it helps!

    • Apr 01 2010 | 9:39 am
      Hi there, Very interesting indeed - I've been chipping away at doing this for my Electribes and have it working fine. Your blog made me realise I don't think Electribes are even 14bit since I haven't needed to use the LSB - 38. They must only use NRPNs because of the amount of controllers used.
      Do you think your js will work if my device does not use the LSB data? If I understand right you said in the code you assumed - "the LSB of the data will change every time we get an NRPN change."
      Anyway - I'll at least try it when I get a chance. Very interested to see if it speeds up transmission to my Korgs - which unfortunately don't have USB.
    • Apr 02 2010 | 9:44 pm
      That's a really hard question to answer...
      If you don't have USB MIDI then you're limited to normal MIDI rates. That means you really don't want to send more than one MIDI packet (3 bytes) per msec. If you're sending faster than this it adds a bit of latency to the changes in the hardware and if it overloads the hardware buffer you'll start losing data packets and possibly cause some weird behavior. I've found that usually means 3-4 high resolution CC changes. So just be careful when you do high resolution changes with this method, it'll probably break.
      The receive script will work as long as you are getting a CC#38 change from the device. If the Electribe really isn't putting out that value you may have to change the script slightly. Check to see what sort of data the Electribe sends on an NRPN change and change the script accordingly. I'd be surprised if it just wasn't sending all 4 packets but I wouldn't put it past them.
      You'll probably want to edit the script a little bit to prevent unneeded data from being sent. If you don't need to send CC#6, comment that part out in the translation layer script so it just sends 3 CC packets instead of 4.
    • Nov 11 2014 | 11:27 am
      Hello, I have been trying to connect a A&H Qu-16 mixer using I&O nrpn MIDI messages to sync Live faders with the mixer faders. It works but only with MaxMSP. I cannot have it working in M4L. Do you know of any simple solution, without going to uni and become a developper ?
      Here is my nrpn patch, far from being perfect but working.
      Best regards Roland