From 3d8c31b577acecf9b32deec788b14ae252acd856 Mon Sep 17 00:00:00 2001 From: samba Date: Sat, 20 Jul 2024 17:10:32 +0200 Subject: [PATCH] some i7 refactoring --- examples/lua/devices/integra7/_integra7.lua | 15 +++++ examples/lua/devices/integra7/i7parameter.lua | 59 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 examples/lua/devices/integra7/_integra7.lua create mode 100644 examples/lua/devices/integra7/i7parameter.lua diff --git a/examples/lua/devices/integra7/_integra7.lua b/examples/lua/devices/integra7/_integra7.lua new file mode 100644 index 00000000..18000dc5 --- /dev/null +++ b/examples/lua/devices/integra7/_integra7.lua @@ -0,0 +1,15 @@ +require "_model" + +local parameter_partId_placeholder = "xxx" + +function Create_Sysex_Message_For(part_id, parameter_node_id_template, value) + local node_id = string.gsub(parameter_node_id_template, parameter_partId_placeholder, part_id) + local nodeinfo = Get_Node(node_id) + if nodeinfo == nil then + error("no node found for id:" .. node_id) + end + nodeinfo.node:setvalue(value) + local sysex = Create_SysexMessage(nodeinfo) + return sysex +end + diff --git a/examples/lua/devices/integra7/i7parameter.lua b/examples/lua/devices/integra7/i7parameter.lua new file mode 100644 index 00000000..8b7fa9ae --- /dev/null +++ b/examples/lua/devices/integra7/i7parameter.lua @@ -0,0 +1,59 @@ +-- +-- A generic way to create integra7 parameter sysex messages +-- +-- the parameter (node) id. As placeholder for the partId can `xxx` be used. For exampe `PRM-_PRF-_FPxxx-NEFP_OUT_ASGN` +-- the value +-- specifies the part id. If not set, will be determined using its related instrument channel(s), assuming that the channel never changes. + + +require "lua/com/com" +require "_integra7" + +parameters = { + { name="parameterId"}, + { name="value"}, + { name="partId", default=-1 }, +} + +local function get_partids(params, context) + if isnumber(params.partId) then + return { tonumber(params.partId) } + end + local part_ids = {} + local function get_id_from_instrument(instrument) + if instrument.children ~= nil then + for _, child in pairs(instrument.children) do + get_id_from_instrument(child) + end + return + end + table.insert(part_ids, instrument.midiChannel + 1) + end + local instrument = context:getCurrentInstrument() + get_id_from_instrument(instrument) + return part_ids +end + + +function execute(params, timeinfo, context) + local part_ids = get_partids(params, context) + local messages = {} + local value = tonumber(params.value) + local node_id_template = params.parameterId + for _, part_id in pairs(part_ids) do + local sysex = Create_Sysex_Message_For(part_id, node_id_template, value) + table.insert(messages, { + ["type"] = "sysex", + ["sysexData"] = sysex, + }) + end + return messages +end + +function perform(events, params, timeinfo, context) + local messages = execute(params, timeinfo, context) + for _, message in pairs(messages) do + table.insert(events, message) + end + return events +end \ No newline at end of file