Hey Raul,
thanks for your efforts writing this tool. I was looking into your source to find something which could be used for a Keylab/Minilab MK3 tool… Sadly the code structure seems to be somewhat chaotic. Did you somehow run your code thru a obfusciator or simplifying tool or something?
If not, I would highly recommend to you to read/think about “mapping”, “multidimensional objects”, like for example, you can of course use tables within tables. Instead numeric indices, you can use words. Instead putting all tooltips into a single table, you could put the tooltip into the “fader description” table instead.
You can also map functions within a table. No need for doing long if else clauses here.
Just a loose example for a better data / config structure:
faders = {
awesomeFader1 = {
label = "Fade away",
toStringConverter = function () ... end,
toNumberConverter = function () ... end,
tooltip = "What a nice tooltip",
mappedMidiSysex = { 0xff, 0xfe, 0x01, 0x02 }
},
extremePowerFader2 = {
label = "Fade in",
toStringConverter = function () ... end,
toNumberConverter = function () ... end,
tooltip = "extreme Powerfader tooltip",
mappedMidiSysex = { 0xff, 0xfe, 0x01, 0x03 }
},
...
}
Then you could simply iterate over this structure in nested loops and build it up, like so, or similar:
for faderKey, values in pairs(faders) do
print(faderKey, values.label);
local stringConvertedValue = values.toStringConverter(42 or whatever[faderKey])
...
end
Please think about this… I believe this would help you a lot with coding. And also help others who want to contribute, reuse or extend…
Also keep in mind that you also can pass a whole method to another method as parameter, which commonly is then called a “callback method”. Like so:
function renderFader(id, callbackFunction)
...
local tooltipText = faders[id].tooltip
callbackFunction(tooltipText)
end
renderFader("awesomeFader1", function (tooltipText) showTooltip(tooltipText) end)
This is just an example. I think by knowing these two patterns, you could highly improve and shrink your code, also make it more maintainable and way more human readable (for yourself, too, assuming you are human).
Thanks for consideration and greetings!