Implementing fader curves/crossfades using LUA

Hello all,

I am looking for assistance with a custom LUA workaround to the lack of fader curves and equal power crossfades in certain software/hardware. I do not have a programming background but I have done some basic tutorials for Python, PHP, Perl, BASH scripting etc. I have a basic understanding of core programming concepts and I’ve read through some of the Grid documentation on the Intech site. My mathematics is pretty terrible though :|.

Specifically what I would like to achieve is:

  • Ability to choose a custom curve for faders (could apply to pots as well); linear, exponential, or logarithmic.
  • Ability to set one or more breakpoints; have a fixed value for a certain amount of fader travel before incrementing/decrementing of values over a segment. Segments should be able to be configured with a curve type.
  • Extending the above to setup crossfades between two or more values assigned to opposite ends of a controller range.

I can see some functions that I will need to call to get controller position and I’m aware that I will need to find suitable functions in the LUA ‘math’ section to deal with the curves. But, I wouldn’t even know where to begin. In plain English, to do the crossfader (which is of the most importance to me), I would need to:

  • Set start and end values for the full range of the controller.
  • Set the MIDI CC values for the top and bottom of the fader (this could be set to other supported data types as well I assume but I’m only needing to work with MIDI).
  • Set a breakpoint to determine when the value change should occur (this would be inverted/duplicated to represent both values at the top and bottom of the fader throw).
  • Set the curve type for the segment.
  • Send all of this as output from Grid.

Personally, I would only require two different CC values to crossfade in between but it would be quite powerful to assign multiple values to the top and bottom of the fader with their own breakpoints and curves. I assume that transmitting too much MIDI data would be problematic and users should be aware of this.

This is a representation of the fader curves on my Xone PX5 mixer. The middle crossfade is what I would like to achieve but ideally, a person could program any type of curve/crossfade:

Many thanks in advance!

Oh, I just received my EN16 and EF44 yesterday afternoon so I haven’t even had the chance to start looking at LUA scripting for this.


So I got the chance to look into this and I was able to set something up that does what I need. It could likely use some tweaks but, in use, it’s working. I setup a fader element with the following:

local num, val_1 = self:element_index(), self:potmeter_value()
local val_2 = 127 - self:potmeter_value()
local function cnst(min, value, max)
	return math.max(min, math.min(max, value))
local function ln(v)
	m = 8 * math.sqrt(v) + v;
	return m
v1 = cnst(0, math.floor(ln(val_1)), 127)
v2 = cnst(0, math.floor(ln(val_2)), 127)

midi_send(11, 176, 74, v1)
midi_send(11, 176, 73, v2)

It works well enough for what I need and was a good first scripting experience. It could likely use tweaks to the function that’s transforming things but so far, it’s enough.

EDIT: I had to ‘gorilla math’ the function together because I essentially have Grade 9 math skills. I didn’t get to trigonometry before I was done with school. It’s what I could cobble together with doing some searches.