Hallo, I would like to invert the outcoming MIDI CC values of a fader or ADSR envelope, e.g. when the fader value is 0 I would like to output a CC value of 127 and vice versa with all the values in between.
How would that be possible?
Thank you!
I’m guessing you will need to do this as a lua script.
Outputvalue = 127 - value; There may be an easier way but it’s been awhile since I’ve programmed my Electra ones. (Sadly).
Thank you very much for your reply!
I really hope there is an easier way.
I heard that the Electra One is one of the most advanced MIDI controllers on the market.
But maybe at the expense of ergonomics…
This has been discussed and I think I posted an example.
Check this thread all the way through
Thank you very much! I will look into the thread and I might ask you questions. I hope that’s okay.
I hoped for an easy way, but well, I guess that’s not how this device is supposed to work. You must be a programmer. I’ll try to become a programmer then…
Happy new year ogg.
I agree that there’s a few things that you should be able to do from the basic web UI without needing Lua (reverse ranges is one of them). However, you don’t need to be a programmer to ask questions, look at examples, and either directly cut-n-paste into your preset or tweak as necessary.
The basic idea is that if you’re only caring about MIDI CC messages (and not storing/editing system exclusive data from a patch dump) then a very simple function pasted into the Lua code window plus adding the name of that function to your control from the main web UI is all that needs to be done.
Yamaha gear is notorious for having 0 = slowest, 127 = fastest for things like envelope attack, decay segments, so looking at Yamaha presets is usually a good starting point.
Thank you for that. Happy new year to you. 2025 is likely ushering in some changes for me, which will mean trimming down some gear and time spent working on new Electra presets, but also focusing on fully completing the current ones (for the most part) and taking full advantage of the 4.0 features when they become public and stable.
It may also give me more time to answer questions and post examples; we’ll see how it shapes up.
Happy new year too!
so it’s a 2 part solution.
Define the fader as a virtual instead of a CC.
Then, insert a function name in the formatter field.
in the lua code, have that function send the actual MIDI CC message.
You still set the parameter number to match the CC you want to send.
The Lua code assume MIDI channel 1 and using port 1 (first set of MIDI jacks) of the Electra.
The “re-reverse” fader in my example shows how to do this.
invert and more
Thank you very much! Going to check this as soon as I can!
As this is quite common thing I am considering two options to make it easier:
- allow users to enter minimum value that is greater than the maximum.
- extend Lua function (linked to a control value) so that when it returns a numeric value, that value would be set and send out as MIDI value.
Although, it may sound straightforward, both ways are not that easy to implement.
Often the simplest thing on the surface is very complex under the water.
My vote would be “user entering minimum greater than maximum”. That seems the most natural.
Would it help if you were able to identify the control as an inverted control type with a check box or special type?
Actually that was the first thing I tried when experimenting.
And I was surprised that this didn’t work.
Okay, with your example of the “re-reverse” fader, I have now managed to create 4 faders for Attack, Decay, Sustain, Release which all act like want.
I had to simply copy the faders and rename the FORMATTERs to altinvert1, altinvert2, altinvert3 and altinvert4 and copy and edit this in the LUA code.
Great!
The next challenge now would be to create one ADSR with inverted values, so I don’t need these 4 faders.
I’d have to look at things again, but if you set the parameter number for each fader to a different value, you should be able to just use 1 FORMATTER (altinvert) instead of 4 because the formatter code grabs the parameter number from the fader definition.
Not in front of any hardware for some hours, but I wonder what would happen if you used an ADSR control and a single FORMATTER function?
You might have to reject it for the sustain portion of the ADSR. I’ll take a quick look when I get home unless someone else experiments with it before I do.
I updated the example with a couple of ADSR envelopes.
Take a look at both the on screen values and the MIDI values being sent for both.
Thank you so much! You are really kind and helpful!
I have a question. I would like to have an ADSR with four pots assigned, one for Attack, like there already is, then one for Decay, one for Sustain and one for Release. How would I do this?
I have this code right now:
– might need to pay attention to pot touches for the MIDI patching section
events.subscribe(POTS | PAGES)
function parameterMap.onChange (valueObjects, origin, midiValue)
local pNum = valueObjects[1]:getMessage():getParameterNumber()
– print(string.format(“Sending value %d to parameter %d”, midiValue, pNum))
end
function dispInvert1(valueObject, value)
– my control range is 0-127, I want to invert what is sent
return math.floor(127 - value)
end
function altInvert1(valueObject, value)
local pNum = valueObject:getMessage():getParameterNumber()
midi.sendControlChange (PORT_1, 1, pNum, math.floor(127 - value))
– return math.floor(value)
end
function dispInvert2(valueObject, value)
– my control range is 0-127, I want to invert what is sent
return math.floor(127 - value)
end
function altInvert2(valueObject, value)
local pNum = valueObject:getMessage():getParameterNumber()
midi.sendControlChange (PORT_1, 1, pNum, math.floor(127 - value))
– return math.floor(value)
end
function dispInvert3(valueObject, value)
– my control range is 0-127, I want to invert what is sent
return math.floor(127 - value)
end
function altInvert3(valueObject, value)
local pNum = valueObject:getMessage():getParameterNumber()
midi.sendControlChange (PORT_1, 1, pNum, math.floor(127 - value))
– return math.floor(value)
end
function dispInvert4(valueObject, value)
– my control range is 0-127, I want to invert what is sent
return math.floor(127 - value)
end
function altInvert4(valueObject, value)
local pNum = valueObject:getMessage():getParameterNumber()
midi.sendControlChange (PORT_1, 1, pNum, math.floor(127 - value))
– return math.floor(value)
end
saveVal = -1
savedCtl = -1
mult = 1
changedMult = false
accelID = 9
function events.onPotTouch(potId, ctlId, touched)
print(string.format(“potId = %d, ctlId = %d”, potId, ctlId))
if (ctlId == accelID) then
local ctl = controls.get(ctlId)
curVal = ctl:getValue(“value”):getMessage():getValue()
if (touched == true) then
saveCtl = ctlId
saveVal = curVal
else
if (saveCtl == ctlId) and (saveVal == curVal) then
changedMult = true
mult = mult * 10
if (mult > 100) then
mult = 1
end
local grp = groups.get(10)
grp:setLabel(string.format("Mult = %d", mult))
end
end
end
end
preVal = 0
currentSum = 0
function accel(valueObject, value)
if (changedMult == false) then
local encMin = valueObject:getControl():getValue(“value”):getMin()
local encMax = valueObject:getControl():getValue(“value”):getMax()
local bucket = (value - preVal) * mult
preVal = value
currentSum = currentSum + bucket
if (currentSum < encMin) then
currentSum = encMin
elseif (currentSum > encMax) then
currentSum = encMax
end
else
changedMult = false
end
parameterMap.set(1, PT_CC14, accelID, currentSum)
return math.floor(currentSum)
end