-
Notifications
You must be signed in to change notification settings - Fork 0
/
midiloader.lua
62 lines (43 loc) · 1.14 KB
/
midiloader.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
local timer = require "love.timer"
-- local lfs = require "lfs"
local livereload = require "livereload"
local modules = livereload "modules"
-- Receive values sent via thread:start
local midiout, midiinput = ...
local state = {}
local function setChannel(channel, value)
channel:clear()
channel:push(value)
end
local time = nil
local module = livereload "rack"
local running = true
local perf_state = {}
local last_update_time = timer.getTime()
while running do
local inputs = {}
while true do
local input = midiinput:pop()
if input then
table.insert(inputs, input)
else
break
end
end
local newtime = timer.getTime()
local dt = newtime - (time or newtime)
time = newtime
local result = module.update(state, dt, inputs)
local start_time = timer.getTime()
if result == "quit" then
running = false
else
if time - last_update_time > 0.01 then
last_update_time = time
midiout:performAtomic(setChannel, result)
end
end
local perf = modules.perf(perf_state, timer.getTime() - start_time)
-- print(string.format("%06.3f", perf.average * 1000))
timer.sleep(0.002)
end