# NRPN Possible Bug

**URL:** <https://forum.electra.one/t/nrpn-possible-bug/2912>\
**Category:** Bug reports\
**Created:** [May 11, 2024, 8:01pm UTC](https://forum.electra.one/t/nrpn-possible-bug/2912 "2024-05-11T20:01:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobinC](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@RobinC](https://forum.electra.one/u/RobinC)\
**Post date:** [May 11, 2024, 8:01pm UTC](https://forum.electra.one/t/nrpn-possible-bug/2912/1 "2024-05-11T20:01:13Z")

</div>

Further to my post about issues I’m having with Bass Station 2 and NRPNs

I think I’ve found the cause and a possible bug

When sending NRPNs electra will send a pair of messages CC98 and CC99 to indicate which parameter is going to be adjusted

Electra then sends CC6 and a CC38 messages for values. However, it doesn’t appear to be setting these pair of messages correctly. According to [MIDI NRPN and RPN by Phil Rees](http://www.philrees.co.uk/nrpnq.htm) CC38 is an optional message for refinement of the main value which is sent in CC6.

So if I setup an NRPN which only has 4 possible values (0-3). Electra will always send CC6 as zero with the CC38 sent with a value of 0 - 3. This is irrespective of the MSB first / LSB first setting

In the case of the Bass Station 2. it is only monitoring the CC6 value which is always received as zero.

---

<div class="post-metadata">

**Author:** ![RobinC](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@RobinC](https://forum.electra.one/u/RobinC)\
**Post date:** [May 11, 2024, 9:24pm UTC](https://forum.electra.one/t/nrpn-possible-bug/2912/2 "2024-05-11T21:24:13Z")

</div>

Doing a bit more googling it seems that some manufacturers particularly Novation use NRPNs to give themselves more midi controllable parameters but when the value to be communicated is 7 bit they are omitting the CC38

---

<div class="post-metadata">

**Author:** ![RobinC](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@RobinC](https://forum.electra.one/u/RobinC)\
**Post date:** [May 12, 2024, 11:13am UTC](https://forum.electra.one/t/nrpn-possible-bug/2912/3 "2024-05-12T11:13:01Z")

</div>

I can work around this using Lua.

@NewIgnis has a suggested solution in the thread below using virtual controls

> [@NRPN messages with slower synths](https://forum.electra.one/t/nrpn-messages-with-slower-synths/913/12):
>
> I took a note but I do not want to promise I would work on that in coming weeks. From what was said here I assume that if there was an option to send the NRPN parameter change just once and then keep sending value changes it should be ok with the ESQ-1/SQ80. Right now, each NRPN includes the parameter identification and even the parameter reset messages.

This means that electra will send out the messages in the correct format for the Bass Station 2

I can then write code in a midi.OnControlChange event to direct messages from the Bass Station 2 back to the virtual controls

This gives me bidirectional control of the Bass Station 2 NRPNs

---

<div class="post-metadata">

**Author:** ![christianvogel](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@christianvogel](https://forum.electra.one/u/christianvogel)\
**Post date:** [May 28, 2024, 1:01pm UTC](https://forum.electra.one/t/nrpn-possible-bug/2912/4 "2024-05-28T13:01:45Z")

</div>

Hi @RobinC , how did you implement the Lua function? I tried this:

```auto
function sendNrpn(parameter, value)
    local parameterMSB = (parameter >> 7) & 0x7F
    local parameterLSB = parameter & 0x7F
    local valueMSB = (value >> 7) & 0x7F
    local valueLSB = value & 0x7F

    local messages = {
        {channel = 1, type = CONTROL_CHANGE, data1 = 99, data2 = parameterMSB},
        {channel = 1, type = CONTROL_CHANGE, data1 = 98, data2 = parameterLSB},
        {channel = 1, type = CONTROL_CHANGE, data1 = 6, data2 = valueMSB},
        {channel = 1, type = CONTROL_CHANGE, data1 = 38, data2 = valueLSB}
    }

    for i,msg in ipairs(messages) do
        midi.sendMessage(port, msg)
    end
end

```

But I keep getting this error:

`bad argument #1 to 'sendMessage' (number expected, got nil)`

However none of the parameters are actually nil (I checked by printing everything out before sending it, and I am kind of stumped.

---

<div class="post-metadata">

**Author:** ![christianvogel](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@christianvogel](https://forum.electra.one/u/christianvogel)\
**Post date:** [May 28, 2024, 1:14pm UTC](https://forum.electra.one/t/nrpn-possible-bug/2912/5 "2024-05-28T13:14:29Z")

</div>

Nevermind, I got it to work. Turns out I was using a bad value for the port… duh. In case someone else needs to send NRPN messages, here is the implementation in Lua:

```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

```

---

<div class="post-metadata">

**Author:** ![RobinC](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@RobinC](https://forum.electra.one/u/RobinC)\
**Post date:** [May 28, 2024, 4:53pm UTC](https://forum.electra.one/t/nrpn-possible-bug/2912/6 "2024-05-28T16:53:17Z")

</div>

glad you got it solved
