Need lua help on tables arrays [Solved]

Hi, I want to build a generic modulation matrix, that would allow any to take a source X (velocity, aftertouch, modwheel) and control a CC parameter Y around its default setting.

The aim is to build to flexibly, and allow any number of slots. For it to work I was thinking of setting up a table or array, but my knowledge on these in lua is fairly basic, and you can do a lot with them.

I’m doubt if I shoud work with a 2D matrix (x,y) where the value is the depth. Or should I build 3 simple tables.
Table Source: key = slot, value = source
Table Destination: key = slot, value = destination
Table depth: key = slot, value = depth

My main concern here is speed: on any event such as aftertouch, I need to verify if there are slots with source Aftertouch, then I need, for all destinations found, to find if there are other sources modulating the same destination. Only then I can calculate the new temp value for that destination.

What is the fastest way to execute such algorithm?

I’d probably go with something like:

Slot table (ensures slots have at most a single modulation):

key slot => [source, destination, depth]

Lookup table:

key source => key destination => array of slot keys

1 Like

So using two tables with the same content but with different keys, right?

You’ll have to play around with different options.

That said it depends on how many routings because you can brute force this even with something like 16 slots in an array.

Personally I’d just get it going with something dumb that works and rejig it later once you have a better feel for what is needed.

1 Like

I’ve found a workable way, but it’s not yet a generic modulation matrix, where each slot can be set with source, depth and destination. Instead I’ve foreseen a set number of sources (velocity, aftertouch, modwheel etc…) and gave each two destination slots.

By definining a number for each source , I could make it work using 2 tables:

  • table modDest is one dimensional: i = the source, the value is the CC-value destination
  • table modDepth is two dimensional: i = the source, j = the destination, the value is the depth.

Whenever a certain combination is no longer in use, the nil is assigned to the component in those arrays. The number of variables is therefor kept at a minimum.

Thanks @adamc for getting me on my way

1 Like