Skip to content

Commit

Permalink
some i7 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
samba committed Jul 20, 2024
1 parent 81fe1c3 commit 3d8c31b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/lua/devices/integra7/_integra7.lua
Original file line number Diff line number Diff line change
@@ -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

59 changes: 59 additions & 0 deletions examples/lua/devices/integra7/i7parameter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- <command name="integra7" where="mod" using="lua/devices/integra7/integra7.lua">
-- A generic way to create integra7 parameter sysex messages
-- </command>
-- <param name="parameterId" optional="0" type="string">the parameter (node) id. As placeholder for the partId can `xxx` be used. For exampe `PRM-_PRF-_FPxxx-NEFP_OUT_ASGN`</param>
-- <param name="value" optional="0" type="number|string">the value</param>
-- <param name="partId" optional="1" type="0..15">specifies the part id. If not set, will be determined using its related instrument channel(s), assuming that the channel never changes.</param>


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

0 comments on commit 3d8c31b

Please sign in to comment.