-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIDI_MSC_SysEx.lua
153 lines (124 loc) · 4 KB
/
MIDI_MSC_SysEx.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
--[[
Made by: Ted Charles Brown
Version 1.0.1
HOW TO USE:
- Add a MIDI module to Control.
- Add a "NewModule" to Control.
- Right click in the "newModule" and select "add action" (or add a new action to the MIDI module to get around node counts).
- Name the module "mscIn(data)" - data is the variable name and must be included.
- Copy and paste this code into the code section of that new action.
- In the MIDI module, under Receive, SysEx, drag the output to the input of the new action.
- Edit the deviceID, cueList, and timelineName variables to match your setup.
NOTES:
- Currently does not support pause, resume, fader, or macro commands.
]]--
-- ----------------------------- USER VARIABLES ----------------------------- --
local deviceID = "00" --can be set to "all"
local cueList = "1" -- can be set to "0" for all cue lists
local timelineName = "all" -- can be set to "all"
-- ----------------------------- OTHER VARIABLES ---------------------------- --
-- --------------------------- DONT CHANGE THESE! --------------------------- --
local timeline = nil
if timelineName == "all" then
timeline = Pixera.Timelines.getTimelines()
else
timeline = Pixera.Timelines.getTimelineFromName(timelineName)
end
local commands = {
["01"] = "GO",
["02"] = "PAUSE",
["03"] = "RESUME",
["06"] = "FADER",
["07"] = "MACRO"
}
local sourceID = ""
local command = ""
local cueNumber = ""
local cueLength = 0
local sourceCueList = ""
-- ------------------------- CONFIRM AND STORE SYSEX ------------------------ --
sysex = {}
--parse the sysex message into an array
for byte in data:gmatch("..") do
--pixc.log(byte)
table.insert(sysex,byte)
end
--confirm it is sysex
if (sysex[1] == "f0" and sysex[2] == "7f") then
--pixc.log("Confirmed SysEx")
else
--pixc.log("Not SysEx")
return
end
-- ---------------------------- BEGIN SYSEX PARSE --------------------------- --
--remove first two sysex specific bytes
table.remove(sysex,1)
table.remove(sysex,1)
--remove last sysex specific byte
table.remove(sysex,#sysex)
--get and remove source device ID byte
sourceID = sysex[1]
table.remove(sysex,1)
--remove next two, MSC protocol bytes
table.remove(sysex,1)
table.remove(sysex,1)
--get and remove command byte
command = commands[sysex[1]]
table.remove(sysex,1)
-- ---------------------------- PARSE CUE NUMBER ---------------------------- --
for i, part in ipairs(sysex) do
if part ~= "00" and part ~= "2e" then -- IF PART IS NOT END OF INT OR DECIMAL DELIMITER
cueNumber = cueNumber .. part:gsub("^3", "")
cueLength = cueLength + 1
elseif part == "2e" then
cueNumber = cueNumber .. "."
cueLength = cueLength + 1
else
cueLength = cueLength + 1
break
end
end
-- Remove the processed parts
for i = 1, cueLength do
table.remove(sysex, 1)
end
-- ----------------------------- PARSE CUE LIST ----------------------------- --
for i, part in ipairs(sysex) do
sourceCueList = sourceCueList .. part:gsub("^3", "")
end
-- Print the parsed values
--pixc.log("Device ID:", sourceID)
--pixc.log("Command:", command)
--pixc.log("Cue List:", sourceCueList)
--pixc.log("Cue Number:", cueNumber)
-- ------------------------- HANDLE PIXERA CUE LIST ------------------------- --
--convert deviceID to hex if its not set to "all"
if (type(deviceID) == "number") then
deviceID = string.format("%02x", deviceID)
end
local pixeraCue = nil
local foundTimeline = nil
if timelineName == "all" then
for _, search in pairs(timeline) do
pixeraCue = search.getCueFromName(cueNumber)
if pixeraCue ~= nil then
timeline = search
break
end
end
end
pixeraCue = timeline.getCueFromName(cueNumber)
if (deviceID == sourceID or deviceID == "all" or sourceID == "7f") then
if (cueList == sourceCueList or tonumber(cueList) <= 0) then
if (command == "GO") then
if pixeraCue ~= nil then
pixc.log("GO CUE:", cueNumber)
pixeraCue.apply()
if(pixeraCue.getOperation()==2)
then
timeline.play()
end
end
end
end
end