-
Notifications
You must be signed in to change notification settings - Fork 1
/
liveConnect.lua
79 lines (68 loc) · 2.13 KB
/
liveConnect.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
-- define helper functions
local print = Printf
local function Error(m)
local options = {
title = "Error",
message = m,
commands = {{
value = 0,
name = "OKAY"
}}
}
local r = MessageBox(options)
end
-- load HTTP package
local http = require("http")
-- cache responses
local lastResponse
local last = {}
-- define main function
function Main()
-- get sequence number by user input
local seqNo = TextInput("Enter sequence number", 1)
if (not seqNo or not tonumber(seqNo)) then
Error("Invalid sequence number")
return
end
-- validate user input for sequence number
local seq = Root().ShowData.DataPools.Default.Sequences[tonumber(seqNo)]
if (not seq.no) then
Error("Sequence does not exist")
return
end
-- get timecode number by user input
local codeNo = TextInput("Enter timecode number", 1)
if (not codeNo or not tonumber(codeNo)) then
Error("Invalid timecode number")
return
end
-- validate user input for timecode number
local code = Root().ShowData.DataPools.Default.Sequences[tonumber(codeNo)]
if (not code.no) then
Error("Timecode does not exist")
return
end
-- define loop for continuous sychronisation with reaper
while true do
-- get marker response from reaper
local response = http.request('http://localhost:18080/_/MARKER')
-- pasrse response and tell MA3 about changes
for name, i, time, color in response:gmatch('MARKER\t([^\t]*)\t([^\t]+)\t([^\t]+)\t([^\t]+)\n') do
local cueRef = "Sequence " .. seqNo .. " Cue " .. i
if (last[i] ~= time) then
print("Marker %s at %s: %s", i, time, name)
if (seq.name == "Sequence " .. seq.no) then
Cmd('Set Timecode ' .. code.no .. '.*."<Sequence ' .. seq.no .. '>".*.*.' .. i .. ' Property Time ' .. time)
else
Cmd('Set Timecode ' .. code.no .. '.*."' .. seq.name .. '".*.*.' .. i .. ' Property Time ' .. time)
end
end
last[i] = time
end
lastResponse = response
-- let other processes continue their job for 3 seconds till checking back with reaper agian
coroutine.yield(3)
end
end
-- run main funtion
return Main