Trying to accomplish some basic stuff

Hi! New grid EN16 owner. I’m trying to accomplish the following:

1: Set up the first 8 encoders to output to CC 0, 2, 4, … 14. This is pretty easy to do with the midi action, but I’m hardcoding the chan and parameter 1. I find the ch and cc locals pretty confusing. What is module_position_y()?

2: Id like to make the lights go from black (off) to bright, but right now all lights are a dim blue when at the lowest value. Is there a way to make them darker?

3: When I store a new config, all my encoders are reset. Is there any way to at least setup a default value for each encoder so they don’t all reset to 0, (63 would be better). Preferably they would just remember the prior state during reset, is there a way to do that?

4: Similarly, I’d like to map a long press on one encoder to reset all the encoder values to the default state. Any suggestions on how to do that?

Generally I can’t find any meaningful documentation on the lua scripting api. I see various function auto-complete options in the editor, but no information about what arguments they accept.

Hey, another beginner here trying to help :slight_smile:

1: As far as I understand the values of the default locals ch an cc are determined with a calculation based on the physical positions of the modules and how they are snapped together.
So when you have various modules (e.g. 3 x EN16) snapped together, a practical distribution of the CC’s will be done by default and you are ready to go, no matter how the arrangement of your modules look like.
This is possible, because the functions module_position_x() and module_position_y() return values that indicate what the physical position of the related module is in your arrangement.
In your case you could go and delete the locals ch and cc.
It should make no difference for you, because you want to control specific CC’s on specific MIDI CH’s as far as I understand.
You could also replace the default value of the locals ch and cc and store the CH-and CC-value you need to them and then insert them in chan and parameter 1.

2: Go to the init - Event and take a look at the LED Color Action Block.
There you find a parameter switch called Beautify.
Switch it to off.
Now the LED should be completely turned off when you’re at the lowest value.

3 and 4: I don’t now exactly how encoders work on Grid but I am waiting for a module with encoders and It should arrive in the next days. When I’m familiar with them, I think I could help you out. :slight_smile:

br
Patrick

Thanks for your help!

1: interesting, yeah I hadn’t thought about multi-devices. Makes sense. I’ve been able to set up the encoders as needed for now.

2: good tip!

3: I’m just dealing with the encoders being reset as I modify the config. Once I got everything set up the values seem to persist.

4: haven’t tried this yet.

Overall documentation about the functions available to lua is lacking. However I found that when you merge actions, they’re converted to equivalent lua scripts, which reveals how many of the functions work. So, for example, I was able to figure out how to send midi messages in lua script just by merging and looking at the resulting midi code.

1 Like

For point 3): you can put self:encoder_value(63) in a code block on the init event. Init runs when a page is changed, the module is plugged in (page loads) or also after storing.

4.) You can write a code snippet like this to reset encoders to value 63 and trigger the encoder events to emit their freshly set values through the MIDI actions:

for i = 0, 15, 1 do
  element[i]:encoder_value(63)
  event_trigger(i, 2)
  --or use grid midi send
end;

The long press logic on a button can be made like this:

if self:button_state() > 0 then
  timer_start(num, 1100)
elseif self:button_state() == 0 and self:button_elapsed_time() < 1000 then
  timer_stop(num)
end

Here is an encoder preset link using the above configurations:
grid-editor://?config-link=xsANcJmOIySa11HuSGvd
(filter for name “Long press encoder button to reset all”)

This is helpful thanks!

How can I find the function defs for stuff like this?

Like what does 2 mean in this case?

I can find the lua function def here: https://github.com/intechstudio/grid-fw/blob/bea9c28543789a1b2eb7ebd523a0d7285ca0ac82/grid_common/grid_lua_api.h#L174

However I’m having some trouble figuring out what the parameters are.

Event codes:

"GRID_EVENT_INIT": "00",  
"GRID_EVENT_AC": "01",  #analog event (potentiometer)
"GRID_EVENT_EC": "02", #encoder event
"GRID_EVENT_BC": "03", #button event
"GRID_EVENT_MAP": "04", #utility button event
"GRID_EVENT_MIDIRX": "05",
"GRID_EVENT_TIMER": "06",

Sorry, event_trigger is rather undocumented in the docs.

1 Like

It’s actually completely documented under Code Block, under the Reference Manual Entries here: Code Block | Intech Studio Documentation.

I added it a few months ago iirc.

1 Like