Skip to content

Commit

Permalink
adding Get_Set_Mfx_Type_Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
samba committed Jul 20, 2024
1 parent 3d8c31b commit 492d0c4
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 14 deletions.
43 changes: 40 additions & 3 deletions examples/lua/devices/integra7/_integra7.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
require "_model"
require "_mfx"

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 function create_id(parameter_node_id_template, part_id)
return string.gsub(parameter_node_id_template, parameter_partId_placeholder, part_id)
end

function Create_Sysex_Message_For_Node(part_id, parameter_node_id_template, value, device_id)
local node_id = create_id(parameter_node_id_template, 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)
local sysex = Create_SysexMessage(nodeinfo, device_id)
return sysex
end

local function get_set_mfx_default_values_sysex(mfxType, part_id, mfx_id, device_id)
local prm = Mfx_Table[mfx_id + 1]
local payload = {}
local from = -1
local nodes = Mfx_Nodes[mfxType]
for i = 1, #nodes, 1 do
local node = nodes[i]
if node.pos == nil then goto continue end
if from < 0 then from = i end
local default_value_index = i - from + 1
if default_value_index <= #prm.leaf then
local default_value = prm.leaf[default_value_index].init
local bytesize = Get_Byte_Size(node.valueByteSizeType)
local bytes = Value_To_Bytes(default_value, bytesize)
payload = ConcatTable(payload, bytes)
end
::continue::
end
local idtemplate = Mfx_Ids[mfxType] .. "-" .. nodes[from].id
local id = create_id(idtemplate, part_id)
local addr = Get_Adress(id)
local sysex = Create_Sysex_Message_For_Payload(addr, payload, device_id)
return sysex
end

function Get_Set_Mfx_Type_Messages(mfxType, part_id, mfx_id, device_id)
local nodeid_template = Mfx_Type_Ids[mfxType]
return {
Create_Sysex_Message_For_Node(part_id, nodeid_template, mfx_id, device_id),
get_set_mfx_default_values_sysex(mfxType, part_id, mfx_id, device_id)
}
end
68 changes: 59 additions & 9 deletions examples/lua/devices/integra7/_model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3917,22 +3917,68 @@ local MODEL_ID_MAP =
["RESERVE_DUMMY"] = 0x0000
}


Mfx_Types = {
SNA = "SNA",
SNS = "SNS",
SND = "SND",
PCMS = "PCMS",
PCMD = "PCMD"
}

Mfx_Ids = {
SNA = "PRM-_FPARTxxx-_SNTONE-_SNTF",
SNS = "PRM-_FPARTxxx-_SHPAT-_SHPF",
SND = "PRM-_FPARTxxx-_KIT-_KF",
PCMS = "PRM-_FPARTxxx-_PAT-_PF",
PCMD = "PRM-_FPARTxxx-_RHY-_RF"
}

Mfx_Type_Ids = {
SNA = Mfx_Ids[Mfx_Types.SNA] .. "-_SNTF-SNTF_MFX_TYPE",
SNS = Mfx_Ids[Mfx_Types.SNS] .. "-_SHPF-SHPF_MFX_TYPE",
SND = Mfx_Ids[Mfx_Types.SND] .. "-_KF-SDKF_MFX_TYPE",
PCMS = Mfx_Ids[Mfx_Types.PCMS] .. "-RFPF_MFX_TYPE",
PCMD = Mfx_Ids[Mfx_Types.PCMD] .. "-RFRF_MFX_TYPE"
}

Mfx_Nodes = {
SNA = SNTF,
SNS = SHPF,
SND = KF,
PCMS = PF,
PCMD = RF
}

function Get_Adress(id)
local addr = 0
for splitted_id_part in string.gmatch(id, "([^-]+)") do
if splitted_id_part == "PRM" then
-- prm has no data representation
goto continue
end
addr = addr + MODEL_ID_MAP[splitted_id_part];
::continue::
end
return addr
end

function Get_Node(id)
local result = {
addr = 0,
node = nil
}
local nodes = I7ROOT_NODE
local node = nil
for part_id in string.gmatch(id, "([^-]+)") do
for splitted_id_part in string.gmatch(id, "([^-]+)") do
node = nil
if part_id == "PRM" then
if splitted_id_part == "PRM" then
-- prm has no data representation
goto continue
end
for _, n in pairs(nodes) do
if part_id == n.id then
result.addr = result.addr + MODEL_ID_MAP[part_id];
if splitted_id_part == n.id then
result.addr = result.addr + MODEL_ID_MAP[splitted_id_part];
node = n
nodes = node.children;
break
Expand Down Expand Up @@ -4003,16 +4049,13 @@ local function Checksum(values, begin_index, end_index)
return -result & 0x7F
end

function Create_SysexMessage(nodeinfo, device_id)
function Create_Sysex_Message_For_Payload(addr, payload, device_id)
local result = {table.unpack(ROLAND_DT1)}
local addr = nodeinfo.addr
table.insert(result, (addr >> 24) & 0xff)
table.insert(result, (addr >> 16) & 0xff)
table.insert(result, (addr >> 8) & 0xff)
table.insert(result, (addr & 0xff))
local bytesize = Get_Byte_Size(nodeinfo.node.valueByteSizeType)
local value_bytes = Value_To_Bytes(nodeinfo.node.value, bytesize)
result = ConcatTable(result, value_bytes)
result = ConcatTable(result, payload)
local checksum = Checksum(result, #ROLAND_DT1+1, #result)
table.insert(result, checksum)
table.insert(result, 0xF7)
Expand All @@ -4022,6 +4065,13 @@ function Create_SysexMessage(nodeinfo, device_id)
return result
end

function Create_SysexMessage(nodeinfo, device_id)
local addr = nodeinfo.addr
local bytesize = Get_Byte_Size(nodeinfo.node.valueByteSizeType)
local value_bytes = Value_To_Bytes(nodeinfo.node.value, bytesize)
return Create_Sysex_Message_For_Payload(addr, value_bytes, device_id)
end

function Bytes_To_String(bytes)
local chars = {}
for _, value in pairs(bytes) do
Expand Down
45 changes: 44 additions & 1 deletion examples/lua/devices/integra7/_tests.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "_model"
require "_integra7"

local nodeinfo = Get_Node("xxx")
assert(nodeinfo == nil)
Expand Down Expand Up @@ -53,4 +54,46 @@ assert(nodeinfo.node.desc == "PCM Tone Name");
nodeinfo.node:setvalue("012345")
sysex = Create_SysexMessage(nodeinfo)
sysexStr = Bytes_To_String(sysex)
assert(sysexStr == "f0 41 10 00 00 64 12 19 00 00 00 30 31 32 33 34 35 20 20 20 20 20 20 78 f7")
assert(sysexStr == "f0 41 10 00 00 64 12 19 00 00 00 30 31 32 33 34 35 20 20 20 20 20 20 78 f7")


local sysexMessages = Get_Set_Mfx_Type_Messages(Mfx_Types.SNA, 1, 14)
-- set mfx type
sysexStr = Bytes_To_String(sysexMessages[1])
assert(sysexStr == "f0 41 10 00 00 64 12 19 02 02 00 0e 55 f7")
-- set default values
sysexStr = Bytes_To_String(sysexMessages[2])
assert(sysexStr == "f0 41 10 00 00 64 12 19 02 02 0d 00 00 00 00 08 00 00 03 08 00 08 0c 08 00 05 00 08 00 07 0f 08 00 04 00 08 00 00 0f 08 00 00 0f 08 00 07 0f 2c f7")

sysexMessages = Get_Set_Mfx_Type_Messages(Mfx_Types.SNS, 2, 0)
-- set mfx type
sysexStr = Bytes_To_String(sysexMessages[1])
assert(sysexStr == "f0 41 10 00 00 64 12 19 21 02 00 00 44 f7")
-- set default values
sysexStr = Bytes_To_String(sysexMessages[2])
assert(sysexStr == "f0 41 10 00 00 64 12 19 21 02 0d 00 00 00 00 08 00 00 00 2f f7")

sysexMessages = Get_Set_Mfx_Type_Messages(Mfx_Types.SND, 3, 67)
-- set mfx type
sysexStr = Bytes_To_String(sysexMessages[1])
assert(sysexStr == "f0 41 10 00 00 64 12 19 43 02 00 43 5f f7")
-- set default values
sysexStr = Bytes_To_String(sysexMessages[2])
assert(sysexStr == "f0 41 10 00 00 64 12 19 43 02 0d 00 00 00 00 08 00 01 04 08 00 00 00 08 00 00 0a 08 00 01 02 08 00 01 0e 08 00 03 02 08 00 01 04 08 00 00 01 08 00 00 0a 08 00 01 02 08 00 02 08 08 00 04 0f 08 00 03 02 08 00 07 0f 34 f7")

sysexMessages = Get_Set_Mfx_Type_Messages(Mfx_Types.PCMS, 4, 16)
-- set mfx type
sysexStr = Bytes_To_String(sysexMessages[1])
assert(sysexStr == "f0 41 10 00 00 64 12 19 60 02 00 10 75 f7")
-- set default values
sysexStr = Bytes_To_String(sysexMessages[2])
assert(sysexStr == "f0 41 10 00 00 64 12 19 60 02 0d 00 00 00 00 08 00 00 00 08 00 00 01 08 00 05 00 08 00 00 09 08 00 06 00 08 00 00 0f 08 00 00 0f 08 00 07 0f 6f f7")


sysexMessages = Get_Set_Mfx_Type_Messages(Mfx_Types.PCMD, 5, 18)
-- set mfx type
sysexStr = Bytes_To_String(sysexMessages[1])
assert(sysexStr == "f0 41 10 00 00 64 12 1a 10 02 00 12 42 f7")
-- set default values
sysexStr = Bytes_To_String(sysexMessages[2])
assert(sysexStr == "f0 41 10 00 00 64 12 1a 10 02 0d 00 00 00 00 08 00 07 0f 08 00 00 00 08 00 01 0e 08 00 07 0f 08 00 07 0f 08 00 00 00 08 00 01 0e 08 00 00 00 08 00 07 0f 08 00 00 00 08 00 01 0e 08 00 07 0f 08 00 00 00 08 00 00 00 08 00 01 0e 08 00 00 00 08 00 00 01 08 00 00 0a 08 00 01 02 08 00 03 02 08 00 00 00 08 00 03 0c 08 00 00 00 08 00 00 00 08 00 07 0f 1d f7")
2 changes: 1 addition & 1 deletion examples/lua/devices/integra7/i7parameter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function execute(params, timeinfo, context)
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)
local sysex = Create_Sysex_Message_For_Node(part_id, node_id_template, value)
table.insert(messages, {
["type"] = "sysex",
["sysexData"] = sysex,
Expand Down

0 comments on commit 492d0c4

Please sign in to comment.