-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathawbwnd_music.lua
325 lines (271 loc) · 8.06 KB
/
awbwnd_music.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
--
-- Basic audio-player with a playlist
-- and some audio visualization
--
local global_aplayer = nil;
local shader_seqn = 0;
local last_audshader = nil;
--
-- Usually there's little point in having many music players running
-- (same can not be said for video however) so we track the one that
-- is running and add to the playlist if one already exists
--
function awbwnd_globalmedia(newmedia)
return global_aplayer;
end
local function filterpop(wnd, icn)
local opts = glob_resource("shaders/audio/*.fShader");
if (opts == nil or #opts == 0) then
return;
end
local labels = {};
for i=1,#opts do
table.insert(labels, string.sub(opts[i], 1, string.len(opts[i]) - 8));
end
local vid, lines = desktoplbl(table.concat(labels, "\\n\\r"));
awbwman_popup(vid, lines, function(ind)
last_audshader = "shaders/audio/" .. labels[ind] .. ".fShader";
local shid = load_shader(nil, last_audshader, "aud_" .. wnd.wndid);
if (shid) then
image_shader(wnd.canvas.vid, shid);
end
end, {ref = icn.vid});
end
local function playlistwnd(wnd)
local x, y = mouse_xy();
local props = image_surface_properties(wnd.anchor);
local speed = awbwman_cfg().animspeed;
if (wnd.playlistwnd) then
if (wnd.playlistwnd.minimized) then
awbwman_restore(wnd.playlistwnd);
else
move_image(wnd.playlistwnd.anchor, x, y, speed);
wnd.playlistwnd:focus();
end
return;
end
local nwin = awbwman_listwnd(menulbl("Playlist"),
deffont_sz, linespace, {1.0}, wnd.playlist_full,
desktoplbl);
if (nwin == nil) then
return;
end
wnd.playlistwnd = nwin;
nwin.name = "Playlist";
local bar = nwin:add_bar("tt", wnd.dir.tt.activeimg, wnd.dir.tt.activeimg,
wnd.dir.t.rsize, wnd.dir.t.bsize);
local cfg = awbwman_cfg();
bar.hoverlut[
(bar:add_icon("sortaz", "l", cfg.bordericns["sortaz"],
function()
table.sort(wnd.playlist, function(a, b)
return string.lower(a) < string.lower(b);
end);
table.sort(wnd.playlist_full, function(a, b)
return string.lower(a.name) < string.lower(b.name);
end);
nwin:force_update();
end
)).vid] = MESSAGE["HOVER_SORTAZ"];
bar.hoverlut[
(bar:add_icon("sortza", "l", cfg.bordericns["sortza"],
function()
table.sort(wnd.playlist, function(a, b)
return string.lower(a) > string.lower(b);
end);
table.sort(wnd.playlist_full, function(a, b)
return string.lower(a.name) > string.lower(b.name);
end);
nwin:force_update();
end
)).vid] = MESSAGE["HOVER_SORTZA"];
bar.hoverlut[
(bar:add_icon("shuffle", "l", cfg.bordericns["shuffle"],
function()
local newlist_wnd = {};
local newlist_full = {};
while #wnd.playlist_full > 0 do
local ind = math.random(1, #wnd.playlist_full);
local entry = table.remove(wnd.playlist_full, ind);
table.insert(newlist_full, entry);
entry = table.remove(wnd.playlist, ind);
table.insert(newlist_wnd, entry);
end
wnd.playlist_full = newlist_full;
nwin.tbl = newlist_full;
wnd.playlist = newlist_wnd;
wnd.playlist_ofs = 1;
nwin:force_update();
end)).vid] = MESSAGE["HOVER_SHUFFLE"];
nwin:add_handler("on_destroy", function(self)
wnd.playlistwnd = nil;
warning("playlist destroyed");
end
);
nwin.input = function(self, iotbl)
if (iotbl.active == false) then
return;
end
if (iotbl.lutsym == "DELETE" and #wnd.playlist > 1 and
nwin.selline ~= nil) then
table.remove(wnd.playlist_full, nwin.selline);
table.remove(wnd.playlist, nwin.selline);
nwin:force_update();
if (nwin.selline == wnd.playlist_ofs) then
wnd.playlist_ofs = wnd.playlist_ofs > 1
and wnd.playlist_ofs - 1 or 1;
wnd.callback(wnd.recv, {kind = "terminated"});
elseif (nwin.selline < wnd.playlist_ofs) then
wnd.playlist_ofs = wnd.playlist_ofs - 1;
end
nwin:update_cursor();
end
end
local sel = color_surface(1, 1, 40, 128, 40);
nwin.activesel = sel;
link_image(sel, nwin.anchor);
-- need one cursor to indicate currently playing
link_image(sel, nwin.canvas.vid);
image_inherit_order(sel, true);
order_image(sel, 1);
blend_image(sel, 0.4);
image_clip_on(sel, CLIP_SHALLOW);
image_mask_set(sel, MASK_UNPICKABLE);
nwin.update_cursor = function()
-- find y
local ind = wnd.playlist_ofs - (nwin.ofs - 1);
if (ind < 1 or ind > nwin.capacity) then
hide_image(sel);
return;
end
blend_image(sel, 0.4);
move_image(sel, 0, nwin.line_heights[ind]);
resize_image(sel, nwin.canvasw, nwin.lineh + nwin.linespace);
end
nwin.on_resize = nwin.update_cursor;
nwin:force_update();
wnd:add_cascade(nwin);
end
--
-- Mapped to frameserver events,
-- includes chaining/spawning new frameservers when
-- the previous one died.
--
local function awnd_callback(pwin, source, status)
if (pwin.alive == false) then
return;
end
if (pwin.controlid == nil) then
pwin.controlid = source;
end
-- update_canvas will delete this one
if (status.kind == "terminated") then
pwin.playlist_ofs = pwin.playlist_ofs + 1;
pwin.playlist_ofs = pwin.playlist_ofs > #pwin.playlist and 1 or
pwin.playlist_ofs;
if (pwin.playlistwnd and pwin.playlistwnd.update_cursor) then
pwin.playlistwnd:update_cursor();
end
pwin.recv = nil;
pwin.controlid = load_movie(pwin.playlist_full[pwin.playlist_ofs].name,
FRAMESERVER_NOLOOP, pwin.callback, 1, "novideo=true");
pwin:update_canvas(pwin.controlid);
end
if (status.kind == "resized") then
pwin.name = pwin.playlist[pwin.playlist_ofs];
pwin:update_canvas(source);
pwin.recv = status.source_audio;
pwin:set_mvol(pwin.mediavol);
if (pwin.shid == nil) then
pwin.shid = load_shader(nil,
last_audshader, "aud_" .. pwin.wndid);
end
image_shader(pwin.canvas.vid, pwin.shid);
image_texfilter(pwin.canvas.vid, FILTER_NONE, FILTER_NONE);
elseif (status.kind == "streamstatus") then
awbmedia_update_streamstats(pwin, status);
end
end
local function awnd_setup(pwin, bar)
pwin.callback = function(source, status)
awnd_callback(pwin, source, status);
end
pwin.on_fullscreen = function(self, dstvid, active)
if (pwin.shid and active) then
image_shader(dstvid, pwin.shid);
end
end
local canvash = {
name = "musicplayer" .. "_canvash",
own = function(self, vid)
return vid == pwin.canvas.vid;
end,
click = function() pwin:focus(); end
};
mouse_addlistener(canvash, {"click"});
table.insert(pwin.handlers, canvash);
--
-- keep them separate so we can reuse for listwindow
--
pwin.playlist = {};
pwin.playlist_full = {};
pwin.playtrig = function(self)
for i,v in ipairs(pwin.playlist_full) do
if (self.name == v.name) then
pwin.playlist_ofs = i - 1;
pwin.callback(pwin.recv, {kind = "terminated"});
end
end
end
pwin.add_playitem = function(self, caption, item)
table.insert(pwin.playlist, caption);
local ind = #pwin.playlist;
-- this will be used for the playlist window as well, hence the formatting.
table.insert(pwin.playlist_full, {
name = item,
cols = {caption},
trigger = pwin.playtrig
});
-- if not playing, launch a new session
if (pwin.recv == nil) then
pwin.playlist_ofs = 1;
local vid =
load_movie(item, FRAMESERVER_NOLOOP, pwin.callback, 1, "novideo=true");
pwin:update_canvas(vid);
end
if (pwin.playlistwnd) then
pwin.playlistwnd:force_update();
end
end
local cfg = awbwman_cfg();
bar.hoverlut[
(bar:add_icon("playlist", "r", cfg.bordericns["list"],
function() playlistwnd(pwin); end)).vid
] = MESSAGE["HOVER_PLAYLIST"];
pwin.canvas_iprops = function(self)
local ar = VRESW / VRESH;
local w = math.floor(0.3 * VRESW);
local h = math.floor( w / ar );
return {
width = w,
height = h
};
end
pwin:add_handler("on_destroy", function() global_aplayer = nil; end);
global_aplayer = pwin;
local cfg = awbwman_cfg();
bar.hoverlut[
(bar:add_icon("filters", "r", cfg.bordericns["filter"],
function(self) filterpop(pwin, self); end)).vid] =
MESSAGE["HOVER_AUDIOFILTER"];
-- shared with video windows etc.
awbmedia_add_fsrvctrl(pwin, bar);
pwin.helpmsg = MESSAGE["HELP_AMEDIA"];
end
function awbwnd_aplayer(pwin, source, options)
local bar = pwin:add_bar("tt", pwin.ttbar_bg, pwin.ttbar_bg,
pwin.dir.t.rsize, pwin.dir.t.bsize);
bar.name = "amedia_ttbarh";
awnd_setup(pwin, bar);
return pwin;
end