-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
185 lines (184 loc) · 6.96 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
require("Zenitha")
ZENITHA.setAppName('ZMP')
ZENITHA.setFirstScene('player')
ZENITHA.setVersionText("v1.0")
ZENITHA.globalEvent.drawCursor=NULL
ZENITHA.globalEvent.clickFX=NULL
do
local waiting
local playing={}
local lastDropTime=-1
local masterObj={volume=1,lowgain=1,highgain=1}
local function reset()
for i=1,#playing do
playing[i].src:stop()
playing[i].src:release()
end
TABLE.clear(playing)
lastDropTime=love.timer.getTime()
masterObj.volume=1
masterObj.lowgain=1
masterObj.highgain=1
TABLE.clear(WIDGET.active)
local w
w=WIDGET.new{
type='slider',axis={0,1},pos={.5,1},
x=-300,y=-35,w=200,
lineWidth=1.5,
fontSize=15,
labelDistance=10,widthLimit=80,
disp=function() return masterObj.volume end,
code=function(v)
masterObj.volume=v
for i=1,#playing do
playing[i].volume=v
playing[i].src:setVolume(v)
end
end,
valueShow=function() return "" end,
} w:reset() table.insert(WIDGET.active,w)
w=WIDGET.new{
type='slider',axis={0,1},pos={.5,1},
x=-40,y=-35,w=160,
lineWidth=1.5,
disp=function() return masterObj.lowgain end,
code=function(v)
masterObj.lowgain=v
for _,obj in next,playing do
obj.lowgain=v
obj.src:setFilter{type='bandpass',lowgain=v,highgain=obj.highgain,volume=1}
end
end,
valueShow=function() return "" end,
} w:reset() table.insert(WIDGET.active,w)
w=WIDGET.new{
type='slider',axis={0,1},pos={.5,1},
x=180,y=-35,w=160,
lineWidth=1.5,
disp=function() return masterObj.highgain end,
code=function(v)
masterObj.highgain=v
for _,obj in next,playing do
obj.highgain=v
obj.src:setFilter{type='bandpass',lowgain=obj.lowgain,highgain=v,volume=1}
end
end,
valueShow=function() return "" end,
} w:reset() table.insert(WIDGET.active,w)
end
SCN.add('player',{
keyDown=function(key)
if key=='escape' then
if playing[1] then
reset()
elseif not TASK.lock('quit',1) then
love.event.quit()
else
MSG.new('info',"Press again to quit")
end
elseif key=='space' then
if playing[1] then
local m=playing[1].src:isPlaying()
for i=1,#playing do
if m then
playing[i].src:pause()
else
playing[i].src:play()
end
end
end
elseif key=='left' then
for i=1,#playing do
playing[i].src:seek(math.max(playing[i].src:tell()-5,0))
end
elseif key=='right' then
for i=1,#playing do
playing[i].src:seek(playing[i].src:tell()+5)
end
end
end,
fileDrop=function(file)
if love.timer.getTime()-lastDropTime>1 then reset() end
waiting=0
local suc,res=pcall(love.audio.newSource,file,'stream')
if suc then
local obj={
name=file:getFilename(),
shortname=file:getFilename():match(".+\\(.+)%.%w+$"),
src=res,volume=1,highgain=1,lowgain=1,
}
table.insert(playing,obj)
local w
w=WIDGET.new{
type='slider',axis={0,1},pos={.5,1},
x=-300,y=-35*(#playing+1),w=200,
lineWidth=1.5,
fontSize=15,
text=obj.shortname,
labelDistance=10,widthLimit=80,
disp=function() return obj.volume end,
code=function(v) obj.volume=v res:setVolume(v) end,
valueShow=function() return "" end,
} w:reset() table.insert(WIDGET.active,w)
w=WIDGET.new{
type='slider',axis={0,1},pos={.5,1},
x=-40,y=-35*(#playing+1),w=160,
lineWidth=1.5,
fontSize=25,
text="L",
labelDistance=5,
disp=function() return obj.lowgain end,
code=function(v) obj.lowgain=v res:setFilter{type='bandpass',lowgain=v,highgain=obj.highgain,volume=1} end,
valueShow=function() return "" end,
} w:reset() table.insert(WIDGET.active,w)
w=WIDGET.new{
type='slider',axis={0,1},pos={.5,1},
x=180,y=-35*(#playing+1),w=160,
lineWidth=1.5,
fontSize=25,
text="H",
labelDistance=5,
disp=function() return obj.highgain end,
code=function(v) obj.highgain=v res:setFilter{type='bandpass',lowgain=obj.lowgain,highgain=v,volume=1} end,
valueShow=function() return "" end,
} w:reset() table.insert(WIDGET.active,w)
else
local name=file:getFilename():reverse()
MSG.new('error',"Cannot load file "..name:sub(1,(name:find("[/\\]") or #name+1)-1):reverse())
end
end,
update=function(dt)
if waiting then
waiting=waiting+dt
if waiting>1 then
waiting=false
for i=1,#playing do
playing[i].src:setLooping(true)
playing[i].src:play()
end
end
end
end,
draw=function()
GC.clear(COLOR.lD)
GC.setColor(COLOR.L)
if playing[1] then
for i=1,#playing do
FONT.set(15)
GC.print(playing[i].name,20,20*i)
end
GC.setColor(COLOR.lG)
GC.rectangle('fill',0,5,800*playing[1].src:tell()/playing[1].src:getDuration(),8)
else
FONT.set(70)
GC.mStr("MrZ's Multitrack Player",400,200)
FONT.set(35)
GC.mStr("play multiple sound files together!",400,320)
FONT.set(30)
GC.mStr("Drag & drop files here",400,435-20*math.abs(math.sin(love.timer.getTime()*5)))
FONT.set(15)
GC.mStr("esc=clear space=pause/play left/right=adjust time",400,540)
end
end
})
end