-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
127 lines (101 loc) · 2.6 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
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
local livereload = require "livereload"
local state
local midiout
local midithread
local font
local draw
local blur = love.graphics.newShader[[
extern vec2 direction;
extern number radius;
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _) {
vec4 c = vec4(0.0);
for (float i = -radius; i <= radius; i += 1.0)
{
c += Texel(texture, tc + i * direction);
}
return c / (2.0 * radius + 1.0) * color;
}
]]
local canvas
local midiinput
function love.load()
love.window.setMode(666, 420, {
borderless = true,
centered = false,
x = 610,
y = 380,
highdpi = true,
msaa = 16
})
canvas = love.graphics.newCanvas(
love.graphics.getWidth(),
love.graphics.getHeight(),
{
msaa = 16
}
)
midiinput = love.thread.newChannel()
midiout = love.thread.newChannel()
state = {
midi = nil,
inputs = {},
ui = {}
}
midithread = love.thread.newThread("midiloader.lua")
midithread:start(midiout, midiinput)
draw = livereload "draw"
font = love.graphics.newFont("leaguespartan-bold.ttf", 10)
love.graphics.setFont(font)
end
function love.quit()
print("Quit")
if state.midi then
midiinput:push({ "quit" })
midithread:wait()
end
end
function love.keypressed( key, scancode, isrepeat )
table.insert(state.inputs, {"key", true, key, scancode, isrepeat})
end
function love.keyreleased( key, scancode )
table.insert(state.inputs, {"key", false, key, scancode})
end
function love.update_and_draw(dt)
local error = midithread:getError()
assert( not error, error )
local midi = midiout:peek()
if midi then
state.midi = midi
end
draw.run(state, dt, midiinput, blur, canvas)
end
function love.run()
if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
-- We don't want the first frame's dt to include time taken by love.load.
if love.timer then love.timer.step() end
local dt = 0
-- Main loop time.
return function()
-- Process events.
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
if name == "quit" then
if not love.quit or not love.quit() then
return a or 0
end
end
love.handlers[name](a,b,c,d,e,f)
end
end
-- Update dt, as we'll be passing it to update
if love.timer then dt = love.timer.step() end
if love.graphics and love.graphics.isActive() then
love.graphics.origin()
love.graphics.clear(love.graphics.getBackgroundColor())
if love.update_and_draw then love.update_and_draw(dt) end
love.graphics.present()
end
if love.timer then love.timer.sleep(0.033) end
end
end