Storing negative number in parameterMap

Beta OS 3.7.0f on a Mk II Electra One.

I’ve run into a situation where some parameters have either a bi-polar range or maybe a negative to 0 range and need to store a negative value from a parameter dump.
I can declare a control to be Virtual, Two’s-complement, 14 bit signed and formatting functions work perfectly. So a control will scroll from -127 to +127 just fine.

However, it appears I cannot store a valid representation of a single byte negative number in the parameterMap.

Example - I have a decibel range control, Values range from -6 dB to 0 dB.
The code generates an NRPN of 0x7f,0x7a (-6) through 0x7f,0x7f (-1), to 0x00,0x00 just fine.

However, there appears to be no way to store a -3 (0x7f,0x7d) as value from a sysex dump.

-3 is stored as 253 in the parameterMap since it is interpreting all values as MIDI in the range of 0 to 16383. Since 253 is outside the range of -6 to 0, at some point in time the Electra OS sets the stored value to 0.

It also looks like the Electra OS is performing range checks and limits on the parameterMap data some time in between patch.onResponse() and calling the formatting/display routines because inside my fmtDB(valueObject,value) formatter, the parameterMap value being passed in is 0 not 253, but at the very end of patch.onResponse(), the value is 253…

So, it appears that if I know ahead of time (i.e. during the patch.onResponse() parsing) and if I know through some comparison that the incoming value is supposed to be negative, I can adjust the value to fit by creating a 14 bit version of that number and storing that…

The trick is that in this case, the sysex is using a single byte to store a value with the range of -6 to 0. So looking at the raw data you cannot know if the single byte is representing a large positive value (253) or a small negative (-3) since the Electra OS does not know at that point how this data is going to be used and represented.

I guess the short term answer for me is to hard code a bunch of tests for these single byte parameters.

I will take a look at that. Do not spend time on making a workaround. It looks like an easy thing to correct (on my side).

Not sure what a good answer will be, but I’m interested to hear whatever you find out

1 Like