# NRPNs Bits and Bytes

**URL:** <https://forum.electra.one/t/nrpns-bits-and-bytes/3319>\
**Category:** General discussion\
**Created:** [October 22, 2024, 8:01pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319 "2024-10-22T20:01:15Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 22, 2024, 8:01pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/1 "2024-10-22T20:01:15Z")

</div>

Hello. I’m a new user and very excited by what I have been able get set up in a very short time using the Electra One app. But I have run into my first snag. I am trying to set up a hardware synth module (Panda Audio’s Future Impact) that only responds to NRPNs. I have been able to set up most of the parameters successfully but a few of them use the same NRPN! Those ones make use of the bit information. For example, I have MSB 5, LSB 89 that controls both the keyboard trigger/gate switch and the portamento mode switch. It does this by assigning bit0:0 to gate, bit0:1 to trigger, bit1:0 to always glide, and bit1:1 to only glide when legato. Is there a way to program the Electra One to use the bit information? Hope my explanation makes sense to someone 🙂 Thanks in advance.  
John

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [October 22, 2024, 8:09pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/2 "2024-10-22T20:09:32Z")

</div>

Here’s an example 🙂

The first function I got from @oldgearguy . It’s a sendNrpn function, because the usual one is currently broken. So you better set it up yourself.

The second function is one I made for the Behringer UB-Xa. Same challenge as yours: I have 4 bits that together make 1 NRPN. So I gave all 4 controls the function bitMask007, which then serves to reconstruct the needed byte and send it off as NRPN.  
Of course you could have other combinations of the bits.

```auto
function sendNrpn(port, channel, parameter, value)
    local parameterMSB = (parameter >> 7) & 0x7F
    local parameterLSB = parameter & 0x7F
    local valueMSB = (value >> 7) & 0x7F
    local valueLSB = value & 0x7F
    local messages = {
        {channel = channel, type = CONTROL_CHANGE, controllerNumber = 99, value = parameterMSB},
        {channel = channel, type = CONTROL_CHANGE, controllerNumber = 98, value = parameterLSB},
        {channel = channel, type = CONTROL_CHANGE, controllerNumber = 6, value = valueMSB},
        {channel = channel, type = CONTROL_CHANGE, controllerNumber = 38, value = valueLSB}
    }
    for i, msg in ipairs(messages) do
        midi.sendMessage(port, msg)
    end
end

function bitMask007() -- NRPN 0/7 = 7 ControlPortamentoSettings 
-- Bitmask: Match (0001) Quantize (0010) Bend (0100) Exponential (1000)
  local result = parameterMap.get (1, PT_VIRTUAL, 54) * 2^0
   + parameterMap.get (1, PT_VIRTUAL, 60) * 2^1
   + parameterMap.get (1, PT_VIRTUAL, 59) * 2^2
   + parameterMap.get (1, PT_VIRTUAL, 65) * 2^3
  sendNrpn(currentPort, currentChannel, 7, result)
end

```

---

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 22, 2024, 9:33pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/3 "2024-10-22T21:33:34Z")

</div>

> [@NewIgnis](#):
>
> ```auto
> function sendNrpn(port, channel, parameter, value)
> local parameterMSB = (parameter >> 7) & 0x7F
> local parameterLSB = parameter & 0x7F
> local valueMSB = (value >> 7) & 0x7F
> local valueLSB = value & 0x7F
> local messages = {
> {channel = channel, type = CONTROL_CHANGE, controllerNumber = 99, value = parameterMSB},
> {channel = channel, type = CONTROL_CHANGE, controllerNumber = 98, value = parameterLSB},
> {channel = channel, type = CONTROL_CHANGE, controllerNumber = 6, value = valueMSB},
> {channel = channel, type = CONTROL_CHANGE, controllerNumber = 38, value = valueLSB}
> }
> for i, msg in ipairs(messages) do
> midi.sendMessage(port, msg)
> end
> end
> 
> ```

I can’t believe it. I managed to modify your examples to get it to do what I needed 🙂 Thank you! thank you! thank you!

---

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 24, 2024, 5:32pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/4 "2024-10-24T17:32:27Z")

</div>

@Newlgnis thanks again for posting the bitmask function. I got it to do what I needed, but without really understanding it. Moving on to a different case and I realize that my lack of understanding is a problem: I’m trying to unmask a NRPN where, according to the synth’s documentation, bit0: 0 1, bit1: 2 3, bit2: 0 1, and bit3: 0 1. Bits 1 and 2 control a parameter, bit 3 and bit 4 each control separate parameters. Any pointers on how to modify the function? Apologies for the high level of ignorance.

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [October 24, 2024, 6:39pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/5 "2024-10-24T18:39:45Z")

</div>

> [@kiwigrass](#):
>
> bit0: 0 1, bit1: 2 3, bit2: 0 1, and bit3: 0 1

Please be more specific. Absolutely no clue what the above means 🙂

---

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 24, 2024, 7:02pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/6 "2024-10-24T19:02:12Z")

</div>

🙂 Apologies. Part of my problem is the documentation has scant details. Let me give you what I have:

NRPN 624 contains 4 midi sync options, turns osc2 hard sync off/on, and turns delay off/on. The values for the NRPN are 0,1,2,3,4,5,6,7. It then says  
bit 0: 0: midi sync off, 1: midi sync lfo4,  
bit 1: 2: midi sync delay1, 3: midi sync delay1+2  
bit 2: 0: OSC2 sync off, 1: OSC2 sync on  
bit 3: 0: Delay off, 1: Delay on

I created this monstrosity trying to extend your logic:

function bitMask764() – NRPN 5/124 = 764 Sync&PrioritySettings  
– Bitmask: Sync off (000) LFO4 (001) Delay 1 (010) Delay1+2 (011) OscSync off (100) OscSync on (101) Delay off (110) Delay on (111)  
local result = parameterMap.get (1, PT\_VIRTUAL, 54) \* 2^0  
+ parameterMap.get (1, PT\_VIRTUAL, 60) \* 2^1  
+ parameterMap.get (1, PT\_VIRTUAL, 59) \* 2^2  
+ parameterMap.get (1, PT\_VIRTUAL, 65) \* 2^3  
+ parameterMap.get (1, PT\_VIRTUAL, 64) \* 2^4  
+ parameterMap.get (1, PT\_VIRTUAL, 70) \* 2^5  
+ parameterMap.get (1, PT\_VIRTUAL, 69) \* 2^6  
+ parameterMap.get (1, PT\_VIRTUAL, 75) \* 2^7  
sendNrpn(currentPort, currentChannel, 764, result)  
end

My interest is really in control of the hard sync function and I found that choosing values 0 and 5 turned osc2 sync off and on, respectively. I could just leave it at that and have a beer. But I want to know what it is I’m actually doing or should be doing 🙂

Does that help? Cheers  
John

---

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 24, 2024, 7:22pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/7 "2024-10-24T19:22:20Z")

</div>

Not sure if this is relevant, but FYI I have to select “LSB first” in the preset editor for any of my NRPNs to work. Here is the link to the preset [Electra One App](https://app.electra.one/preset/TE4vO8yC4pVv0FlKN5SU)

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [October 24, 2024, 7:41pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/8 "2024-10-24T19:41:41Z")

</div>

It helps … a bit… but I think I got it.

There are contradictions however in the info: If a NRPN uses 4 bits, it should have at least one value above 7, but no values above 15. In your case it state the values are 0 to 7, which implies it only uses 3 bits.  
That’s a contradiction you need to figure out. I believe in reality the NRPN will have values 0 to 15 and thus need 4 bits.

The bitmask will be as follows:

- Midi Sync: off (00xx) LFO4 (10xx) Delay 1 (10xx) Delay1+2 (11xx)
- OscSync off/on (xx0x)/(xx1x)
- Delay off /on (xxx0)/(xxx1)

You then need one control “Midi Sync” with 4 options, and twon switches. The first control however will control 2 bits and therefor should be able to set values 0-3:

```auto
local result = parameterMap.get (1, PT_VIRTUAL, 1) * 2^0
+ parameterMap.get (1, PT_VIRTUAL, 2) * 2^2
+ parameterMap.get (1, PT_VIRTUAL, 3) * 2^3

```

Be aware control 2 is thus not multiplied by **2^1** but by **2^2** in order to set the third instead of the second bit.  
If it all sounds too gibberish to you, familiarize yoursvelf with transforming bits and bytes into values and a new world will open up to you 😃

---

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 24, 2024, 8:50pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/9 "2024-10-24T20:50:47Z")

</div>

Your explanation helps a lot. Thanks! I followed your logic. I had assumed it was 3 bits since 2^3=8 options. But your logic makes sense if an NRPN is 4 bits. Interestingly, when I implemented your code I found the following for OSC sync (which really the only parameter I’m interested in). Values 0-3 were off, values 4-7 were on, values 8-11 were off, and 12-15 were on. But that doesn’t seem to fit with the logic. I will take your advice and do some reading.

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [October 24, 2024, 9:35pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/10 "2024-10-24T21:35:09Z")

</div>

The behaviour for osc sync is correct…

---

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 24, 2024, 9:46pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/11 "2024-10-24T21:46:40Z")

</div>

You’re right. I did some reading. I see now that the parameters are  
0=(0000), 1=(0001), 2=(0010), 3=(0011),  
4=(0100), 5=(0101), 6=(0110), 7=(0111)

But the bit mask (or whatever it should be called) is this:  
Sync off: (xxx0), LFO4: (xxx1), Delay 1 (xx0x) Delay1+2 (xx1x)  
OscSync off: (x0xx) OscSync on: (x1xx) Delay off: (0xxx) Delay on: 1=(1xxx)

So, OscSync is off for parameter values 0-3, and on for 4-7, etc.

New world opened. 🙂

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [October 24, 2024, 9:49pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/12 "2024-10-24T21:49:16Z")

</div>

Yes, I just realised I’ve set my bitmask in the wrong order . Sorry to create confusion, and splendid you worked it out 😁

---

<div class="post-metadata">

**Author:** ![kiwigrass](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/kiwigrass/32/4983_2.png) [@kiwigrass](https://forum.electra.one/u/kiwigrass)\
**Post date:** [October 24, 2024, 9:52pm UTC](https://forum.electra.one/t/nrpns-bits-and-bytes/3319/13 "2024-10-24T21:52:47Z")

</div>

Wrong order? [Edit: NM. I see what you did.]
