1111-- via a context document typed to the specific element subclass.
1212-- =============================================================================
1313
14+ -- =============================================================================
15+ -- 1. SHARED TYPES & ALIASES
16+ -- Put all dropdown menus and custom types here at the very top!
17+ -- =============================================================================
18+
19+ --- @alias Auto integer
20+ --- | -1 # Auto (use the configured element value / min-max)
21+
22+ --- @alias Layer integer
23+ --- | -1 # Auto (use the active/configured layer)
24+ --- | 1 # Layer 1 (Button and Potmeter)
25+ --- | 2 # Layer 2 (Encoder and Endless)
26+
1427-- =============================================================================
1528-- Element (base class)
1629--
1730-- Common methods available on all element types.
1831-- Do not use this type directly in user code — use the specific subclass.
1932-- =============================================================================
2033
34+ --- **THE "self" VARIABLE**
35+ --- In Grid Lua, `self` always refers to the specific physical control (button, encoder, fader)
36+ --- that you are currently interacting with.
37+ ---
38+ --- When you use a function with `self:` (like `self:midi_send()`), you are
39+ --- telling the Grid to apply that action specifically to **this exact element**.
40+ ---
2141--- @class Element
2242--- Called after element initialization. Triggers the init event handler.
2343--- @field post_init_cb ? fun ( self : Element )
@@ -55,20 +75,61 @@ function Element:timer_stop() end
5575--- @param event_type integer Event type index
5676function Element :event_trigger (event_type ) end
5777
58- --- Sets the LED color for this element.
59- --- @param layer integer LED layer index (-1 for all layers )
60- --- @param colors table Color data table
78+ --- Sets the LED color and its value-based transition for this element.
79+ ---
80+ --- This function creates smooth color fades based on the element's current value (min to max).
81+ --- You must provide a list of colors, where each color is `{red, green, blue, alpha}`.
82+ --- * **RGB** values are `0-255`. You can also use `-1` for any RGB channel to use the element's auto-configured (factory) color.
83+ --- * **Alpha** (brightness/opacity) is `0.0 - 1.0`.
84+ ---
85+ --- **The transition changes based on how many colors you provide:**
86+ --- * **1 Color:** `{{-1, -1, -1, 1}}`
87+ --- Sets the color for the MAX value (using the auto color in this example). The MIN value defaults to transparent (0 alpha).
88+ --- * **2 Colors:** `{{0, 0, 255, 0.5}, {255, 0, 0, 1}}`
89+ --- 1st color is MIN value, 2nd color is MAX value.
90+ --- * **3 Colors:** `{{0, 255, 0, 1}, {255, 255, 0, 1}, {255, 0, 0, 1}}`
91+ --- 1st color is MIN, 2nd color is MIDDLE, 3rd color is MAX value.
92+ ---
93+ --- @param layer Layer integer The LED layer to target (use ` -1` for all /active layers ).
94+ --- @param colors number[][] Array of color tables. Don ' t forget the double braces! Example: `{{-1, -1, -1, 1}}`
6195function Element :led_color (layer , colors ) end
6296
63- --- Sends a MIDI message from this element.
64- --- Pass -1 for any parameter to use the auto-configured value.
65- --- @param channel MIDI_Channel MIDI channel (0 –15 , or -1 for auto )
66- --- @param command MIDI_Command MIDI command (e.g. 144 =NoteOn , 176=CC , or -1 for auto )
67- --- @param param1 MIDI_Param First parameter (0 –127 , or -1 for auto )
68- --- @param param2 MIDI_Param Second parameter (0 –127 , or -1 for auto )
69- function Element :midi_send (channel , command , param1 , param2 ) end
7097
71- --- Sends a MIDI SysEx message from this element.
98+
99+ --- Sets or gets the LED light intensity (brightness/phase) for this element.
100+ ---
101+ --- When parameters are provided, it sets the intensity. The `-1` value is very common and tells the Grid to use the auto-configured setting.
102+ ---
103+ --- @param layer Layer integer The LED layer to target (` 1` , ` 2`, or ` -1` for auto ).
104+ --- @param value integer The intensity level (` 0-255` , or ` -1` for auto ).
105+ --- @return integer | nil current_value Returns the current value if called without parameters , otherwise nothing.
106+ function Element :led_value (layer , value ) end
107+
108+ --- Sends a MIDI message from this specific element.
109+ --- Pass -1 for any parameter to use the element's auto-configured value.
110+ ---
111+ ---
112+ --- @param channel integer MIDI channel (0-15 ). Note : Your DAW translates this as channels 1-16 ! (0 = Channel 1 , or -1 for auto ).
113+ --- @param command integer MIDI command type (e.g. , 144 = Note On , 176=CC or -1 for auto ).
114+ --- @param param1 integer Value (0-127 ). For Notes : Pitch (e.g. , 60 = Middle C ). For CC : Controller Number (e.g. , 7 = Volume ). (-1 for auto ).
115+ --- @param param2 integer use -1 (Auto ) for the element ' s min-max range. or provide a specific value.
116+ --- @param resolution ? integer Optional MIDI resolution mode (0 =Standard 7-bit , 1=14-bit , 2=NRPN , 3=14-bit NRPN ). Defaults to 0.
117+ function Element :midi_send (channel , command , param1 , param2 , resolution ) end
118+
119+ --- Registers a MIDI receive (RX) listener for this element.
120+ --- This allows the element to automatically update its internal value or LED state
121+ --- when the specified MIDI message is received from the host (DAW).
122+ ---
123+ --- @param element_index integer Target element index (use ` -1` for this specific element ).
124+ --- @param channel integer MIDI channel (0-15 , or -1 for auto ).
125+ --- @param command integer MIDI command type (e.g. , 144 = Note On , 176=CC or -1 for auto ).
126+ --- @param param1 integer Note pitch or CC number (0-127 , or -1 for auto ).
127+ --- @param sync_config { value_sync : boolean , led_sync : boolean } Synchronization settings. Example : `{ value_sync = true , led_sync = true }` .
128+ --- @param resolution integer resolution mode (0 =Standard 7-bit , 1=14-bit , 2=NRPN , 3=14-bit NRPN ).
129+ function Element :midirx_register (element_index , channel , command , param1 , sync_config , resolution ) end
130+
131+ --- Sends a MIDI SysEx message from this element.
132+ --- Send 8bit SysEx data bytes (0-255) as separate arguments. eg: (0xF0, 0x41, 0x10, 0xF7)
72133--- @param ... integer SysEx data bytes
73134function Element :midi_sysex_send (...) end
74135
@@ -492,48 +553,18 @@ local SystemElement = {}
492553-- Global functions — MIDI
493554-- =============================================================================
494555
495- --- Returns the short code of the currently executing event handler.
496- --- Possible values: "ini", "ec", "bc", "pc", "tim", "map", "mrx", "epc", "ld".
497- --- @return string event_name Event handler short code
498- function event_function_name () end
499-
500- --- @alias MIDI_Channel
501- --- | -1 # auto
502- --- | 0 # Channel 1
503- --- | 1 # Channel 2
504- --- | 2 # Channel 3
505- --- | 3 # Channel 4
506- --- | 4 # Channel 5
507- --- | 5 # Channel 6
508- --- | 6 # Channel 7
509- --- | 7 # Channel 8
510- --- | 8 # Channel 9
511- --- | 9 # Channel 10
512- --- | 10 # Channel 11
513- --- | 11 # Channel 12
514- --- | 12 # Channel 13
515- --- | 13 # Channel 14
516- --- | 14 # Channel 15
517- --- | 15 # Channel 16
518-
519- --- @alias MIDI_Command
520- --- | -1 # auto
521- --- | 176 # Control change
522- --- | 144 # Note on
523- --- | 128 # Note off
524-
525- --- @alias MIDI_Param
526- --- | -1 # auto
527-
528- --- Sends a MIDI message.
529- --- Pass -1 for any parameter to use the auto-configured value.
530- --- @param channel MIDI_Channel MIDI channel (0 –15 , or -1 for auto )
531- --- @param command MIDI_Command MIDI command (e.g. 144 =NoteOn , 176=CC , or -1 for auto )
532- --- @param param1 MIDI_Param First parameter (0 –127 , or -1 for auto )
533- --- @param param2 MIDI_Param Second parameter (0 –127 , or -1 for auto )
556+ --- Sends a standard 7-bit MIDI message.
557+ --- (Note: Use `self:midi_send()` to send the MIDI messages from an Element).
558+ ---
559+ ---
560+ --- @param channel integer MIDI channel (0-15 ). Note : Your DAW translates this as channels 1-16 ! (0 = Channel 1 ).
561+ --- @param command integer MIDI command type (e.g. , 144 = Note On ).
562+ --- @param param1 integer Value (0-127 ). For Notes : Pitch (e.g. , 60 = Middle C ). For CC : Controller Number (e.g. , 7 = Volume ).
563+ --- @param param2 integer Value (0-127 ). For Notes : Velocity (hit strength ). For CC : Control Value (CV ).
534564function midi_send (channel , command , param1 , param2 ) end
535565
536- --- Sends a MIDI SysEx message.
566+ --- Sends a MIDI SysEx message.
567+ --- Send 8bit SysEx data bytes (0-255) as separate arguments. eg: (0xF0, 0x41, 0x10, 0xF7)
537568--- @param ... integer SysEx data bytes
538569function midi_sysex_send (...) end
539570
@@ -543,15 +574,15 @@ function midi_sysex_send(...) end
543574
544575--- Sets LED color by layer for a specific element LED.
545576--- @param led_index integer Hardware LED index (use led_address_get to resolve )
546- --- @param layer integer LED layer
577+ --- @param layer Layer integer LED layer
547578--- @param red integer Red component (0 –255 )
548579--- @param green integer Green component (0 –255 )
549580--- @param blue integer Blue component (0 –255 )
550581function led_color (led_index , layer , red , green , blue ) end
551582
552583--- Sets the LED phase/intensity value for a specific LED and layer.
553584--- @param led_index integer Hardware LED index
554- --- @param layer integer LED layer
585+ --- @param layer Layer integer LED layer
555586--- @param value integer Phase /intensity value (0 –255 )
556587function led_value (led_index , layer , value ) end
557588
@@ -572,13 +603,13 @@ function led_default_blue(value) end
572603
573604--- Sets the LED animation rate for a specific LED and layer.
574605--- @param led_index integer Hardware LED index
575- --- @param layer integer LED layer
606+ --- @param layer Layer integer LED layer
576607--- @param value integer Animation rate
577608function led_animation_rate (led_index , layer , value ) end
578609
579610--- Sets the LED animation type/shape for a specific LED and layer.
580611--- @param led_index integer Hardware LED index
581- --- @param layer integer LED layer
612+ --- @param layer Layer integer LED layer
582613--- @param value integer Animation type
583614function led_animation_type (led_index , layer , value ) end
584615
@@ -637,6 +668,11 @@ function timer_stop(element_index) end
637668-- Global functions — Events
638669-- =============================================================================
639670
671+ --- Returns the short code of the currently executing event handler.
672+ --- Possible values: "ini" (init), "ec" (encoder), "bc" (button), "pc" (potmeter), "tim" (timer), "map", "mrx" , "epc" (endless), "ld".
673+ --- @return string event_name Event handler short code
674+ function event_function_name () end
675+
640676--- Triggers an event on a specific element.
641677--- @param element_index integer Element index
642678--- @param event_type integer Event type
@@ -708,7 +744,8 @@ function package_send(message) end
708744--- @param message string Message to send
709745function websocket_send (message ) end
710746
711- --- Sends Lua code for immediate execution on a remote module.
747+ --- Sends Lua code for immediate execution on a remote module.
748+ --- Example: https://docs.intech.studio/wiki/more/immediate-send-explainer/
712749--- @param x integer Target module X coordinate
713750--- @param y integer Target module Y coordinate
714751--- @param lua_code string Lua code to execute
@@ -731,3 +768,102 @@ function element_name_get(element_index) end
731768--- Sends an element name update notification.
732769--- @param element_index integer Element index
733770function element_name_send (element_index ) end
771+
772+ -- =============================================================================
773+ -- Global functions — Auto values
774+ -- =============================================================================
775+
776+ --- Overrideable MIDI channel provider.
777+ --- Called by the system for every MIDI event.
778+ ---
779+ --- You can override it like:
780+ --- ```lua
781+ --- midi_auto_ch = function(self)
782+ --- return 0
783+ --- end
784+ --- ```
785+ --- more info: https://docs.intech.studio/wiki/more/midi-auto-value
786+ --- @param self table Context of the current MIDI event
787+ --- @return MIDI_Channel channel 0 –15
788+ function midi_auto_ch (self ) end
789+
790+ --- Overrideable MIDI command provider.
791+ --- Example override:
792+ --- ```lua
793+ --- midi_auto_cmd = function(self)
794+ --- return 144
795+ --- end
796+ --- ```
797+ --- more info: https://docs.intech.studio/wiki/more/midi-auto-value
798+ --- @param self table Context of the current MIDI event
799+ --- @return MIDI_Command command
800+ function midi_auto_cmd (self ) end
801+
802+ --- Overrideable MIDI parameter 1 provider (note/CC number).
803+ --- Example override:
804+ --- ```lua
805+ --- midi_auto_p1 = function(self)
806+ --- return 60
807+ --- end
808+ --- ```
809+ --- more info: https://docs.intech.studio/wiki/more/midi-auto-value
810+ --- @param self table Context of the current MIDI event
811+ --- @return integer value
812+ function midi_auto_p1 (self ) end
813+
814+ --- Overrideable MIDI parameter 2 provider (velocity/value).
815+ --- Example override:
816+ --- ```lua
817+ --- midi_auto_p2 = function(self)
818+ --- return 127
819+ --- end
820+ --- ```
821+ --- more info: https://docs.intech.studio/wiki/more/midi-auto-value
822+ --- @param self table Context of the current MIDI event
823+ --- @return integer value
824+ function midi_auto_p2 (self ) end
825+
826+ -- =============================================================================
827+ -- MIDI RX Mode configuration
828+ -- =============================================================================
829+
830+ --- Configures which input sources are enabled for a specific MIDI message type.
831+ ---
832+ --- This function controls the RX Mode routing programmatically.
833+ ---
834+ --- ### Types:
835+ ---- `0` = MIDI Voice
836+ ---- `1` = MIDI SysEx
837+ ---- `2` = MIDI RTM
838+ ---- `3` = Event View
839+ ---
840+ --- ### Sources:
841+ ---- `0` = Disabled
842+ ---- `1` = USB
843+ ---- `2` = External (Ext)
844+ ---- `3` = USB + Ext
845+ ---- `4` = Internal (Int)
846+ ---- `5` = USB + Int
847+ ---- `6` = Ext + Int
848+ ---- `7` = USB + Ext + Int
849+ ---
850+ --- @param type integer MIDI message type (0 –3 )
851+ --- @param source integer Input source mask (0 –7 )
852+ function rx_mode (type , source ) end
853+
854+ -- =============================================================================
855+ -- ERROR CATCHING STUBS (Do not use these functions globally!)
856+ -- These are helper definitions to warn beginners who forget to use "self:"
857+ -- =============================================================================
858+
859+ --- @deprecated ❌ Incorrect usage! Did you forget "self:"? Use: self:button_value()
860+ function button_value (value ) end
861+
862+ --- @deprecated ❌ Incorrect usage! Did you forget "self:"? Use: self:encoder_value()
863+ function encoder_value (value ) end
864+
865+ --- @deprecated ❌ Incorrect usage! Did you forget "self:"? Use: self:potmeter_value()
866+ function potmeter_value (value ) end
867+
868+ --- @deprecated ❌ Incorrect usage! Did you forget "self:"? Use: self:endless_value()
869+ function endless_value (value ) end
0 commit comments