-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path08_midi.lua
More file actions
executable file
·59 lines (50 loc) · 1.39 KB
/
08_midi.lua
File metadata and controls
executable file
·59 lines (50 loc) · 1.39 KB
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
Midi = {}
Midi.__index = Midi
MidiInput = {}
MidiInput.__index = MidiInput
function Midi:Device(channel)
local midi = setmetatable({}, Midi)
midi.channel = channel
return midi
end
function Midi:note_on(note, velocity)
Cmd(string.format("SendMidi \"Note\" %d/%d %d", self.channel, note, velocity))
end
function sendMidiCmd(chan, note, velocity)
return Builder:new():noteOn(chan, noote, velocity)
end
function sendMidi(chan, note, velocity)
sendMidiCmd(chan, note, velocity):exec()
end
local function midiMapGet(chan, note)
local pool = Root().ShowData.Remotes.MIDIRemotes
last_index = 0
for i, remote in ipairs(pool) do
last_index = i
if remote.MidiChannel == chan and remote.MidiIndex == note
then
return remote
end
end
return nil
end
local function midiMapGetOrCreate(chan, note)
local mapping = midiMapGet(chan, note)
if mapping == nil then
local pool = Root().ShowData.Remotes.MIDIRemotes
mapping = pool:Acquire()
end
return mapping
end
function MidiInput:set(chan, note, target)
local midiRemote = midiMapGetOrCreate(chan, note)
midiRemote.Target = target.obj
midiRemote.MidiIndex = note
midiRemote.Key = "Go+"
end
function MidiInput:unset(chan, note)
local midiRemote = midiMapGet(chan, note)
if midiRemote ~= nil then
midiRemote.Target = nil
end
end