-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.lua
executable file
·95 lines (78 loc) · 2.03 KB
/
main.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
local l = require('lume')
local controls = require('controls')
local selector = require('selector')
local recorder = require('recorder')
local mock = require('mock')
local time = 0
local sw, sh, dpi
patch = selector
local stream = {}
function love.resize()
sw, sh = love.graphics.getDimensions()
dpi = love.window.getDPIScale()
end
function love.load()
love.resize() -- force layout re-configuration
require('toolset') -- import module only after love.draw is defined
controls.load()
selector.load('patches')
recorder.addTape()
mock.load()
love.audio.setPosition(0, 0, 0)
love.audio.setVolume(1)
love.graphics.translate(sw / 2, sh / 2)
end
local function transform()
-- use same set of transformations in both draw() and update() functions
-- it's extracted here because if they diverge, it takes time to detect and debug
-- set (0,0) to screen center and 1 unit to half-screen height
love.graphics.translate(sw / 2, sh / 2)
love.graphics.scale(sh / 2, sh / 2)
end
function love.update(dt)
love.graphics.origin()
transform()
time = time + dt
--stream is created
stream = {
dt = dt,
time = time,
width = sw,
height = sh,
dpi = dpi,
}
controls.process(stream)
if love.system.getOS() ~= 'Android' then
mock.process(stream)
end
recorder.interpret(stream, patch == selector)
patch:process(stream)
recorder.process(stream)
love.timer.sleep(0.007)
--stream is garbage collected
end
function love.draw()
love.graphics.origin()
transform()
patch:draw(stream)
recorder.draw(patch == selector)
love.graphics.origin()
--mock.draw(stream)
--drawTable(stream)
--track('fps %2.1f', love.timer.getFPS())
end
function loadPatch(newPatch)
time = 0 -- back to big bang
patch = newPatch.load()
recorder.patchChanged(newPatch)
end
function love.keypressed(key)
if key == 'escape' then
if patch ~= selector then
loadPatch(selector)
love.audio.stop()
end
elseif key == 'menu' or key == 'f' then
controls.frozen = not controls.frozen
end
end