Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esp_monitor.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
idf.py -C "./grid_esp" -b 2000000 -p $(ls /dev/ttyUSB1 | head -n 1) monitor
idf.py -C "./grid_esp" -b 2000000 -p $(ls /dev/ttyUSB0 | head -n 1) monitor
21 changes: 10 additions & 11 deletions grid_common/grid_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ uint8_t grid_decode_midi_to_ui(char* header, char* chunk) {

size_t idx = 0;

lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)chunk, INSTR));
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)header, BRC_SX));
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)header, BRC_SY));
lua_rawseti(L, -2, ++idx);

lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)chunk, CLASS_MIDI_CHANNEL));
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)chunk, CLASS_MIDI_COMMAND));
Expand All @@ -394,14 +401,6 @@ uint8_t grid_decode_midi_to_ui(char* header, char* chunk) {
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)chunk, CLASS_MIDI_PARAM2));
lua_rawseti(L, -2, ++idx);

lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)chunk, INSTR));
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)header, BRC_SX));
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, grid_msg_get_parameter_raw((uint8_t*)header, BRC_SY));
lua_rawseti(L, -2, ++idx);

lua_rawseti(L, -2, result_len + 1);

size_t order_len = lua_rawlen(L, -2);
Expand Down Expand Up @@ -465,16 +464,16 @@ uint8_t grid_decode_sysex_to_ui(char* header, char* chunk) {

size_t idx = 0;

lua_pushstring(L, sysex_string);
lua_rawseti(L, -2, ++idx);

lua_pushinteger(L, instr);
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, sx);
lua_rawseti(L, -2, ++idx);
lua_pushinteger(L, sy);
lua_rawseti(L, -2, ++idx);

lua_pushstring(L, sysex_string);
lua_rawseti(L, -2, ++idx);

lua_rawseti(L, -2, result_len + 1);

size_t order_len = lua_rawlen(L, -2);
Expand Down
4 changes: 2 additions & 2 deletions grid_common/lua_src/decode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ end

pass_midi = function(el, x)
if el.midirx_cb then
el:midirx_cb({ x[1], x[2], x[3], x[4] }, { x[5], x[6], x[7] })
el:midirx_cb({ x[1], x[2], x[3] }, { x[4], x[5], x[6], x[7] })
end
end

pass_sysex = function(el, x)
if el.sysexrx_cb then
el:sysexrx_cb(x[1], { x[2], x[3], x[4] })
el:sysexrx_cb({ x[1], x[2], x[3] }, x[4])
end
end

Expand Down
30 changes: 30 additions & 0 deletions grid_common/lua_src/lua_source_collection.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef LUA_SOURCE_COLLECTION_H_INCLUDED
#define LUA_SOURCE_COLLECTION_H_INCLUDED

// clang-format off

#include "decode.h"
#define GRID_LUA_FNC_G_DECODE_source grid_lua_src_decode_lua
#define GRID_LUA_FNC_G_DECODE_short "gdec"
Expand Down Expand Up @@ -45,9 +47,37 @@
#include "simplecolor.h"
#define GRID_LUA_FNC_G_SIMPLECOLOR_source grid_lua_src_simplecolor_lua

#define GRID_LUA_FNC_G_COLOR_CURVE_short "color_curve"
#define GRID_LUA_FNC_G_COLOR_CURVE_human "color_curve"
#define GRID_LUA_FNC_G_COLOR_CURVE_usage "color_curve(table color_array) Calculates three-point intensity response curve (min, mid, max) from color array. Processes -1 values as current LED colors. Returns three color tables. User overridable."

#define GRID_LUA_FNC_G_COLOR_AUTO_LAYER_short "color_auto_layer"
#define GRID_LUA_FNC_G_COLOR_AUTO_LAYER_human "color_auto_layer"
#define GRID_LUA_FNC_G_COLOR_AUTO_LAYER_usage "color_auto_layer(element self) Calculates LED layer based on current event type. Returns 1 for button/potentiometer events, 2 for encoder events, nil for others. User overridable."

#define GRID_LUA_FNC_G_COLOR_AUTO_VALUE_short "color_auto_value"
#define GRID_LUA_FNC_G_COLOR_AUTO_VALUE_human "color_auto_value"
#define GRID_LUA_FNC_G_COLOR_AUTO_VALUE_usage "color_auto_value(element self, int segment_index) Calculates LED intensity value based on element type and state. For endless encoders, returns segment-specific value. For other elements, returns mapped value 0-255. User overridable."

#include "simplemidi.h"
#define GRID_LUA_FNC_G_SIMPLEMIDI_source grid_lua_src_simplemidi_lua

#define GRID_LUA_FNC_G_MIDI_AUTO_CH_short "midi_auto_ch"
#define GRID_LUA_FNC_G_MIDI_AUTO_CH_human "midi_auto_ch"
#define GRID_LUA_FNC_G_MIDI_AUTO_CH_usage "midi_auto_ch(element self) Calculates default MIDI channel from grid position. Returns channel 0-15 based on module Y position and page number. User overridable."

#define GRID_LUA_FNC_G_MIDI_AUTO_CMD_short "midi_auto_cmd"
#define GRID_LUA_FNC_G_MIDI_AUTO_CMD_human "midi_auto_cmd"
#define GRID_LUA_FNC_G_MIDI_AUTO_CMD_usage "midi_auto_cmd(element self) Calculates default MIDI command type. Returns 144 (Note On) for button events, 176 (Control Change) for others. User overridable."

#define GRID_LUA_FNC_G_MIDI_AUTO_P1_short "midi_auto_p1"
#define GRID_LUA_FNC_G_MIDI_AUTO_P1_human "midi_auto_p1"
#define GRID_LUA_FNC_G_MIDI_AUTO_P1_usage "midi_auto_p1(element self) Calculates default MIDI parameter 1 (note/CC number) from grid position. Returns 0-127 based on module X position and element index. User overridable."

#define GRID_LUA_FNC_G_MIDI_AUTO_P2_short "midi_auto_p2"
#define GRID_LUA_FNC_G_MIDI_AUTO_P2_human "midi_auto_p2"
#define GRID_LUA_FNC_G_MIDI_AUTO_P2_usage "midi_auto_p2(element self) Calculates default MIDI parameter 2 (value) from element state. Returns value based on event type (button, encoder, potentiometer). User overridable."

#include "autovalue.h"
#define GRID_LUA_FNC_G_AUTOVALUE_source grid_lua_src_autovalue_lua

Expand Down
97 changes: 30 additions & 67 deletions grid_common/lua_src/simplecolor.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function cp(c)
color_curve = function(c)
for i = 1, #c do
if c[i][1] == -1 then
c[i][1] = glr()
Expand Down Expand Up @@ -50,74 +50,43 @@ event_handler_to_layer = {
["ld"] = nil,
}

init_endless_color = function(self)
self.glp = function(self, l, v)
if l == -1 then
l = event_handler_to_layer[event_function_name()]
if l == nil then
return
end
end
for i = 0, 4, 1 do
local int = 0
if l == 1 then
-- button
if v == nil or v == -1 then
int = gmaps(self:bva(), self:bmi(), self:bma(), 0, 255) // 1
else
int = v
end
else
-- rotation
if v == nil or v == -1 then
int = gsc(i, self:epva(), self:epmi(), self:epma())
else
int = gsc(i, v, 0, 255)
end
end
local lix = glag(self:ind(), i)
glp(lix, l, int)
end
end
color_auto_layer = function(self)
return event_handler_to_layer[event_function_name()]
end

self.glc = function(self, l, c)
local up = table.unpack
local x, y, z = cp(c)
if l == -1 then
l = event_handler_to_layer[event_function_name()]
if l == nil then
return
end
color_auto_value = function(self, i)
local l = color_auto_layer(self)
if self.type == "endless" then
if l == 1 then
return gmaps(self:bva(), self:bmi(), self:bma(), 0, 255) // 1
else
return gsc(i, self:epva(), self:epmi(), self:epma())
end
for i = 0, 4, 1 do
local lix = glag(self:ind(), i)
gln(lix, l, up(x))
gld(lix, l, up(y))
glx(lix, l, up(z))
else
if event_function_name() == "bc" then
return gmaps(self:bva(), self:bmi(), self:bma(), 0, 255) // 1
elseif event_function_name() == "pc" then
return gmaps(self:pva(), self:pmi(), self:pma(), 0, 255) // 1
elseif event_function_name() == "ec" then
return gmaps(self:eva(), self:emi(), self:ema(), 0, 255) // 1
end
end
end

init_endless_nosegment_color = function(self)
init_endless_color = function(self)
self.glp = function(self, l, v)
if l == -1 then
l = event_handler_to_layer[event_function_name()]
l = color_auto_layer(self)
if l == nil then
return
end
end
for i = 0, 4, 1 do
local int = v
if l == 1 then
-- button
if v == nil or v == -1 then
int = gmaps(self:bva(), self:bmi(), self:bma(), 0, 255) // 1
end
local int = 0
if v == nil or v == -1 then
int = color_auto_value(self, i)
else
-- rotation
if v == nil or v == -1 then
int = gmaps(self:epva(), self:epmi(), self:epma(), 0, 255) // 1
end
int = v
end
local lix = glag(self:ind(), i)
glp(lix, l, int)
Expand All @@ -126,9 +95,9 @@ init_endless_nosegment_color = function(self)

self.glc = function(self, l, c)
local up = table.unpack
local x, y, z = cp(c)
local x, y, z = color_curve(c)
if l == -1 then
l = event_handler_to_layer[event_function_name()]
l = color_auto_layer(self)
if l == nil then
return
end
Expand All @@ -145,32 +114,26 @@ end
init_element_color = function(self)
self.glp = function(self, l, v)
if l == -1 then
l = event_handler_to_layer[event_function_name()]
l = color_auto_layer(self)
if l == nil then
return
end
end
local lix = glag(self:ind(), 0)
local int = v
if v == nil or v == -1 then
if event_function_name() == "bc" then
int = gmaps(self:bva(), self:bmi(), self:bma(), 0, 255) // 1
elseif event_function_name() == "pc" then
int = gmaps(self:pva(), self:pmi(), self:pma(), 0, 255) // 1
elseif event_function_name() == "ec" then
int = gmaps(self:eva(), self:emi(), self:ema(), 0, 255) // 1
end
int = color_auto_value(self, 0)
end

glp(lix, l, int)
end

self.glc = function(self, l, c)
local up = table.unpack
local x, y, z = cp(c)
local x, y, z = color_curve(c)

if l == -1 then
l = event_handler_to_layer[event_function_name()]
l = color_auto_layer(self)
if l == nil then
return
end
Expand Down
57 changes: 35 additions & 22 deletions grid_common/lua_src/simplemidi.lua
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
midi_auto_ch = function(self)
return (gmy() * 4 + gpc()) % 16
end

midi_auto_cmd = function(self)
if event_function_name() == "bc" then
return 144
else
return 176
end
end

midi_auto_p1 = function(self)
return (32 + gmx() * 16 + self:ind()) % 128
end

midi_auto_p2 = function(self)
local event = event_function_name()
if event == "bc" then
return self:bva()
elseif event == "ec" then
return self:eva()
elseif event == "epc" then
return self:epva()
elseif event == "pc" then
return self:pva()
else
return 0
end
end

init_element_midi = function(self)
self.gms = function(self, ch, cmd, p1, p2)
if cmd == -1 then
if event_function_name() == "bc" then
cmd = 144
else
cmd = 176
end
cmd = midi_auto_cmd(self)
end

if ch == -1 then
-- ch = (module_position_y()*4+page_current())%16
ch = (gmy() * 4 + gpc()) % 16
ch = midi_auto_ch(self)
end

if p1 == -1 then
-- note = (32+module_position_x()*16+self:element_index())%128
p1 = (32 + gmx() * 16 + self:ind()) % 128
p1 = midi_auto_p1(self)
end

if p2 == -1 then
local event = event_function_name()
if event == "bc" then
p2 = self:bva()
elseif event == "ec" then
p2 = self:eva()
elseif event == "epc" then
p2 = self:epva()
elseif event == "pc" then
p2 = self:pva()
else
-- system element, lcd element etc
p2 = 0
end
p2 = midi_auto_p2(self)
end

gms(ch, cmd, p1, p2)
Expand Down