-
Notifications
You must be signed in to change notification settings - Fork 3
/
the big player.lsl
517 lines (423 loc) · 13 KB
/
the big player.lsl
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
integer DEBUG = FALSE;
string animName = "lute animation";
float INTERVAL = 3 ;
//float INTERVAL = llGetNotecardLine/( Name, pota );
float V = 6.0;
integer pota = 0;
integer CHAN = -81412;
integer ASSET = 9;
integer listener;
// integer trackCnt = 0;
// integer LINK_NUMBER = 0;
integer Curl = 0;
integer SoundID = 0;
integer songTrackCnt = 0;
integer lineNumber;
integer curSongOffset = 0;
integer totalSongs = 0;
integer curSongEnd = 8;
integer NotecardLine = 0;
integer numNotecardLines;
float totalTime;
string DirSound = "";
string Name = "";
string playing = "";
string NEXT_MSG = "Next >>";
string PREV_MSG = "<< Prev";
string STOP_MSG = "Stop";
list but = [];
list Names = [];
list Musicuuids = [];
key DataRequest = NULL_KEY;
key ncLineCountKey;
float nextQueueTime;
list styleDATA = ["Default!♥", "▱", "▰", "▻", "►", "◅", "◄"];
vector displayColourNormal = <1.0, 1.0, 1.0>;
vector displayColourLoading = <0.8, 1.0, 0.8>;
vector displayColourError = <1.0, 0.2, 0.2>;
integer priorityTag;
// ================
// Global functions
// ================
// Create a progress bar from percentage
string ProgressBar(float percent, integer length)
{
string tmp_str;
integer tmp_i;
// First apply bright icons
while(tmp_i < (integer)(percent * length)) {
tmp_str += llList2String(styleDATA, 2);
tmp_i++;
}
// Second apply dark icons
while(tmp_i < length) {
tmp_str += llList2String(styleDATA, 1);
tmp_i++;
}
return tmp_str;
}
string CalcTime(integer seconds)
{
string tmp_str;
integer tmp_timer_sec;
integer tmp_timer_min;
integer tmp_timer_hour;
// Calculate values
if(seconds >= 3600) { tmp_timer_hour = llFloor(seconds / 3600); seconds = seconds % 3600; }
if(seconds >= 60) { tmp_timer_min = llFloor(seconds / 60); seconds = seconds % 60; }
if(seconds > 0) { tmp_timer_sec = seconds; }
// Only include hours if applicable
if(tmp_timer_hour) { tmp_str = (string)tmp_timer_hour + ":"; }
// Include minutes
if(tmp_timer_min < 10) { tmp_str += "0"; }
tmp_str += (string)tmp_timer_min + ":";
// Include seconds
if(tmp_timer_sec < 10) { tmp_str += "0"; }
tmp_str += (string)tmp_timer_sec;
// Finished
return tmp_str;
}
RenderDisplay(string JSON)
{
// play status?
string type = llJsonGetValue(JSON, [ "type"]);
if(llJsonGetValue(JSON, ["type"]) == "playing")
{
// load & errors gets priority
if(priorityTag < llGetUnixTime())
{
// scale progress bar according to title
integer tmp_pb_length;
string tmp_title = llJsonGetValue(JSON, ["title"]);
if(llStringLength(tmp_title) < 12) {
tmp_pb_length = 6;
} else {
if(llStringLength(tmp_title) > 40) {
tmp_pb_length = 20;
tmp_title = llGetSubString(llJsonGetValue(JSON, ["title"]), 0, 40);
} else {
tmp_pb_length = (integer)(llStringLength(tmp_title) / 4) * 2;
}
}
// calc percentage
float tmp_percent = (float)llJsonGetValue(JSON, ["time"]) / (float)llJsonGetValue(JSON, ["totalTime"]);
// adjust icons accordingly
string tmp_str_ico_left;
string tmp_str_ico_right;
if(tmp_percent < 0.52) { tmp_str_ico_left = llList2String(styleDATA, 3); } else { tmp_str_ico_left = llList2String(styleDATA, 4); }
if(tmp_percent < 0.53) { tmp_str_ico_right = llList2String(styleDATA, 5); } else { tmp_str_ico_right = llList2String(styleDATA, 6); }
// build display
string tmp_str;
tmp_str = ProgressBar(tmp_percent, tmp_pb_length);
tmp_str = llInsertString(tmp_str, tmp_pb_length / 2, tmp_str_ico_left + " " + CalcTime((integer)llJsonGetValue(JSON, ["time"])) + " ⅼ " + CalcTime((integer)llJsonGetValue(JSON, ["totalTime"])) + " " + tmp_str_ico_right);
tmp_str = tmp_title + "\n" + tmp_str;
llSetText(tmp_str, displayColourNormal, 1.0);
}
}
// loading status?
if(llJsonGetValue(JSON, ["type"]) == "loading")
{
// reserve priority
priorityTag = llGetUnixTime(); // + 3;
// build display
float tmp_percent = (float)llJsonGetValue(JSON, ["current"]) / (float)llJsonGetValue(JSON, ["end"]);
string tmp_str = ProgressBar(tmp_percent, 10);
tmp_str = llInsertString(tmp_str, 5, (string)((integer)(tmp_percent * 100)) + "%");
tmp_str = llJsonGetValue(JSON, ["title"]) + "\n" + tmp_str;
llSetText(tmp_str, displayColourLoading, 1.0);
}
// error status?
if(llJsonGetValue(JSON, ["type"]) == "error")
{
// reserve priority
priorityTag = llGetUnixTime() + 10;
// build display
llSetText(llJsonGetValue(JSON, ["msg"]), displayColourError, 1.0);
}
}
ForceHoverText(string errorText)
{
list errorList = [ "target", "DISPLAY", "action", "display", "type", "error", "msg", errorText ];
string json = llList2Json(JSON_OBJECT, errorList);
llMessageLinked(LINK_THIS, 0, llList2Json(JSON_OBJECT, errorList), NULL_KEY);
}
SendPlayingList()
{
list playingList = [ "target", "DISPLAY", "action", "display", "type", "playing", "time", llGetTime(), "totalTime", totalTime, "title", Name ];
llMessageLinked(LINK_THIS, 0, llList2Json(JSON_OBJECT, playingList), NULL_KEY);
}
Initialize()
{
ForceHoverText("");
playing = "";
Curl = 1;
curSongEnd = 8;
curSongOffset = 0;
ReadSongListNotecards();
}
ReadSongListNotecards()
{
totalSongs = llGetInventoryNumber(INVENTORY_NOTECARD);
for (SoundID = 0; SoundID < totalSongs; ++SoundID)
{
Names += [ llGetInventoryName(INVENTORY_NOTECARD, SoundID) ];
}
}
curSongs()
{
if(curSongOffset > 0)
but = [PREV_MSG];
else
but = [" "];
if(curSongEnd < (totalSongs-1))
but += [STOP_MSG, NEXT_MSG];
else
but += [STOP_MSG, " "];
integer i;
DirSound = "\n \n";
if (curSongOffset >= totalSongs)
{
curSongOffset = 0;
curSongEnd = curSongOffset + (ASSET - 1);
}
if (curSongEnd >= totalSongs)
curSongEnd = totalSongs - 1;
for (i = curSongOffset; i <= curSongEnd; i++)
{
if (SoundID == i)
DirSound += "*";
else
DirSound += " ";
DirSound += (string) (i + 1) + ") ";
DirSound += llList2String(Names, i);
DirSound += "\n";
but += (string)(i + 1);
}
}
doNextSet()
{
curSongOffset += ASSET;
curSongEnd = curSongOffset + (ASSET - 1);
if (curSongOffset >= totalSongs)
{
curSongOffset = 0;
curSongEnd = curSongOffset + (ASSET - 1);
}
if (curSongEnd >= totalSongs)
curSongEnd = totalSongs - 1;
}
doPrevSet()
{
if (curSongOffset > 1 && ((curSongOffset - ASSET) < 1))
curSongOffset = 0;
else
curSongOffset -= ASSET;
curSongEnd = curSongOffset + (ASSET - 1);
if (curSongEnd >= totalSongs)
curSongEnd = totalSongs - 1;
if (curSongOffset < 0)
{
curSongEnd = totalSongs - 1;
curSongOffset = totalSongs - (ASSET - 1);
}
}
LoadSong()
{
Debug("LoadSong");
Debug( "Loading: "+ Name);
ncLineCountKey = llGetNumberOfNotecardLines(Name);
}
PlaySong()
{
Debug("PlaySong with INTERVAL=" + (string)INTERVAL);
playing = Name;
Curl = 0;
Debug("Playing: "+ Name);
llResetTime();
totalTime = INTERVAL * llGetListLength(Musicuuids);
SendPlayingList();
llPlaySound(llList2Key(Musicuuids, Curl++), V);
nextQueueTime = llGetTime() + INTERVAL - 1.0;
llSetTimerEvent(0.2);
}
StopSong()
{
Debug("StopSong");
llStopSound();
llSetTimerEvent(0.0);
StopAnimation(animName);
playing = "";
Musicuuids = [];
ForceHoverText("");
}
integer isUUID(string s)
{
integer result = TRUE;
if (llStringLength(s) != 36)
result = FALSE;
else
{
list temp = llParseStringKeepNulls(s, [ "-" ], []);
if (llGetListLength(temp) != 5)
result = FALSE;
}
return result;
}
StartAnimation(string anim)
{
integer invType = llGetInventoryType(anim);
if ((llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) && (invType == INVENTORY_ANIMATION))
llStartAnimation(anim);
}
StopAnimation(string anim)
{
integer invType = llGetInventoryType(anim);
if ((llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) && (invType == INVENTORY_ANIMATION))
llStopAnimation(anim);
}
ShowDialog(key avi)
{
llDialog(avi, DirSound, but, CHAN);
}
StartComms()
{
if (listener != 0)
llListenRemove(listener);
CHAN = llFloor(llFrand(1000000) - 100000);
listener = llListen(CHAN, "", NULL_KEY, "");
}
Debug(string msg)
{
if (DEBUG)
llOwnerSay(msg);
}
default
{
state_entry()
{
llSetSoundQueueing(TRUE);
llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
Initialize();
StartComms();
}
changed(integer change)
{
Debug("changed");
if (change & CHANGED_OWNER)
llResetScript();
else
{
if (change & CHANGED_INVENTORY)
ReadSongListNotecards();
if (change & (CHANGED_REGION | CHANGED_REGION_START))
StartComms();
}
}
on_rez(integer start_param)
{
llResetScript();
}
dataserver( key id, string data )
{
Debug("dataserver: "+(string)(lineNumber - 1)+" = "+data);
if (id == ncLineCountKey)
{
numNotecardLines = (integer)data;
INTERVAL = 0;
songTrackCnt = 0;
lineNumber = 0;
DataRequest = llGetNotecardLine(Name, lineNumber++);
ForceHoverText("");
}
else if (id == DataRequest)
{
if (data != EOF)
{
list loadingList = [ "target", "DISPLAY", "action", "display", "type", "loading", "current", lineNumber, "end", numNotecardLines, "title", Name ];
llMessageLinked(LINK_THIS, 0, llList2Json(JSON_OBJECT, loadingList), NULL_KEY);
if ((songTrackCnt == 0) && (INTERVAL <= 0.0))
INTERVAL = (float)llStringTrim(data, STRING_TRIM);
else
{
data = llStringTrim( data, STRING_TRIM );
list dataParts = llParseString2List(data, ["|"], [""]);
if (isUUID(llList2String(dataParts, 0)))
{
Musicuuids += llList2String(dataParts, 0);
songTrackCnt += 1;
}
}
DataRequest = llGetNotecardLine( Name, lineNumber++ );
}
else
PlaySong();
}
}
touch_start(integer touchNumber)
{
integer freeMem = llGetFreeMemory();
llOwnerSay("freeMem = " + (string)freeMem);
Debug("touch_start");
curSongs();
StartAnimation(animName);
ShowDialog(llDetectedKey(0));
}
listen(integer CHAN, string name, key id, string message)
{
Debug("listen: "+message);
list words = llParseString2List(message, ["="], []);
string testFind = llList2String(words, 0);
if (testFind == "Next >>")
{
doNextSet();
curSongs();
ShowDialog(id);
}
else if (testFind == "<< Prev")
{
doPrevSet();
curSongs();
ShowDialog(id);
}
else if (testFind == "Stop")
StopSong();
else if ((integer)message > 0 && (integer)message < 256)
{
SoundID = (integer)message - 1;
Name = llList2String(Names, SoundID);
StopSong();
LoadSong();
}
}
timer()
{
SendPlayingList();
if (nextQueueTime <= llGetTime())
{
nextQueueTime = llGetTime() + INTERVAL;
Debug("timer: start: playing = "+(string)playing+", curTrack="+(string)Curl+", songTrackCnt="+(string)songTrackCnt);
if ( Curl < songTrackCnt )
{
llPlaySound(llList2Key(Musicuuids, Curl), V);
if ( ++Curl < songTrackCnt )
llPreloadSound( llList2Key(Musicuuids, Curl) );
else
nextQueueTime = llGetTime() + INTERVAL + 1.0;
}
else
{
Debug("Finished: "+Name);
StopSong();
}
Debug("timer end: playing = "+playing+", Curl="+(string)Curl+", songTrackCnt="+(string)songTrackCnt);
}
}
link_message(integer sender, integer num, string msg, key id)
{
if(llJsonGetValue(msg, ["target"]) == "DISPLAY")
{
if(llJsonGetValue(msg, ["action"]) == "display")
RenderDisplay(msg);
}
}
}