Can lookup table be shorter?

I don’t know if it’s possible to have a lookup table with 32 pairs, as having 16 pairs already consume a lot of the character limits.

My lookup table looks like this. I wish there’s a way to shorten this repetitive code that takes 156 characters.

num=glut(
  param1,
  cr(0),0,
  cr(1),1,
  cr(2),2,
  cr(3),3,
  cr(4),4,
  cr(5),5,
  cr(6),6,
  cr(7),7,
  cr(8),8,
  cr(9),9,
  cr(10),10,
  cr(11),11,
  cr(12),12,
  cr(13),13,
  cr(14),14,
  cr(15),15
)

When lookup tables take up too many characters, I usually try and create an algorithm that does the same thing the table does, but in a more efficient manner.

For example, if I have a lookup table that matches param1 CCs to LEDs on an encoder module like so:

num =
    lookup(
    param1,
    32,    0,
    33,    1,
    34,    2,
    35,    3,
    36,    4,
    37,    5,
    38,    6,
    39,    7,
    40,    8,
    41,    9,
    42,    10,
    43,    11,
    44,    12,
    45,    13,
    46,    14,
    47,    15
)

It would result in a lookup table that matches an EN16 module’s RX MIDI values in default operation to its LEDs when it’s the module in the (0,0) position.

Now, this can be done in a similar manner by doing the following:

num = 32-(module_position_x()*16)%128+param1

The above should achieve the same result, but it costs us a whole bunch less characters AND it’s more flexible than the code above.

Of course, this is not applicable to all cases, with semi-random co-relations between variables, but I hope it helps!

1 Like

I am not limited to use lookup() to assign the table to the variable?!
Now that sounds exciting! Thanks for the heads up!

1 Like