forked from echonest/GirlTalkInABox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo.html
More file actions
1312 lines (1110 loc) · 33.1 KB
/
go.html
File metadata and controls
1312 lines (1110 loc) · 33.1 KB
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html>
<head>
<script src="js/raphael-min.js" type="text/javascript" charset="utf-8"></script>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="styles.css" type="text/css" media="screen">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script src="js/underscore-min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="jremix.js"></script>
<title> MaKey Music Remix</title>
</head>
<body>
<div id="wrap" class="navbar navbar-inverse">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a id='show-search' class="brand">MaKey Music Remix</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><a id='show-main' href="index.html">Main</a></li>
<li><a id='show-gallery' href="gallery.html" >Gallery of songs</a></li>
<li><a id='show-loader' href="loader.html">Upload a song</a></li>
<li><a id='show-help' href="help.html">Help</a></li>
<li><a id='show-about' href="about.html">About</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id='info-div'>
<span id='info'> </span>
<span id='tweet-span'>
<a href="https://twitter.com/share" id='tweet' class="twitter-share-button" data-lang="en" data-count='none'>Tweet</a>
<script>!function(d,s,id){var
js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</span>
</div>
<div id='error'> </div>
<div id="hero">
<div id='tiles'></div>
<div id="stats">
<!-- <button class="btn btn-small" title="sort tiles by loudness" onclick='sortTiles("loudness_max", false)'> Loudness
Sort</button>
<button class="btn btn-small" title="sort tiles by similarity to most recently clicked tile" onclick='sortTiles("seg_distance", false)'> Similar Sort</button>
<button class="btn btn-small" title="sort tiles in reverse order" onclick='reverseTiles()'> Reverse
Sort</button>
<button class="btn btn-small" title="sort tiles in chronological order" onclick='sortTiles("which", false)'> Normal
Sort</button> -->
<button class="btn btn-small" id='reset'>Reset</button>
<button class="btn btn-small" id='play'>Play</button>
<span id="numbers">
Tile: <span class='nval' id='tile'> 1 </span>
Period: <span class='nval' id='speed'> 100 </span>
Incr: <span class='nval' id='incr'>1</span>
<span class='nval' id='bmode'>bars</span>
</span>
</div>
</div>
<div id="help" class="hero-unit">
<div class="container">
<h2> MaKey Music Remix</h2>
<p>
Puts you in control of your favorite song.
<p>
<hr>
<img src="images.jpeg" align="left" Hspace="30">
Read more about our research at the intersection of music, education and computing at <a href="http://experiencingaudio.org">Experiencing Audio</a> and <a href="http://performamatics.org">Performamatics</a>.
<br>Learn more about Music Education @ NYU on our Facebook page & follow us on Twitter.
</p>
<hr>
Controls:
<ul>
<li> mouse click - start playing from the clicked beat
<li> space - start and stop playing the song
<li> arrows - control song cursor velocity
<li> w/a/s/d - move the song cursor
<li> < > ? - controls the beat period
<li> b - toggle between beats and tatums
<li> n - set to segments
<li> g - set to bars
<li> m - set to sections
<li> shift+key - bookmark a beat
<li> [/] - set loop points
</ul>
See 'help' for more info
<p>
</div>
</div>
</body>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3675615-27']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type =
'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
var remixer;
var player;
var driver;
var track;
var effects;
var paper;
var tiles = [];
var selectedTile;
var mouseOverTile;
var tatumMode = false;
var bMode = 'beats'; // initialize to beat display
var shifted = false;
var controlled = false;
var chartReady;
var draggedOver = null;
// From Crockford, Douglas (2008-12-17). JavaScript: The Good Parts (Kindle Locations 734-736). Yahoo Press.
if (typeof Object.create !== 'function') {
Object.create = function (o) {
var F = function () {};
F.prototype = o;
return new F();
};
}
function info(s) {
$("#info").text(s);
}
function error(s) {
if (s.length == 0) {
$("#error").hide();
} else {
$("#error").text(s);
$("#error").show();
}
}
function goBars() {
bMode = 'bars';
createTilePanel(bMode);
}
function goBeats() {
bMode = 'beats';
createTilePanel(bMode);
}
function goTatums() {
bMode = 'tatums';
createTilePanel(bMode);
}
function goSegments() {
bMode = 'segments';
createTilePanel(bMode);
}
function goSections() {
bMode = 'sections';
createTilePanel(bMode);
}
function stop() {
player.stop();
player = remixer.getPlayer();
}
function createTiles(qtype) {
var tiles = [];
var qlist = track.analysis[qtype];
for (var i = 0; i < qlist.length; i++) {
tiles.push(createTile(i, qlist[i]));
}
return tiles;
}
function extractTitle(url) {
var lastSlash = url.lastIndexOf('/');
if (lastSlash >= 0 && lastSlash < url.length - 1) {
var res = url.substring(lastSlash + 1, url.length - 4);
return res;
} else {
return url;
}
}
function getTitle(title, artist, url) {
if (title == undefined || title.length == 0 || title === '(unknown title)' || title == 'undefined') {
if (url) {
title = extractTitle(url);
} else {
title = null;
}
} else {
if (artist !== '(unknown artist)') {
title = title + ' by ' + artist;
}
}
return title;
}
function loadTrack(trid) {
fetchAnalysis(trid);
}
function setDisplayMode(playMode) {
if (playMode) {
//$("#help").hide();
$("#hero").show();
$("#play").show();
$("#tweet-span").show();
} else {
//$("#help").show();
$("#hero").hide();
$("#play").hide();
$("#tweet-span").hide();
}
}
function showTrackTitle(t) {
info(t.title + ' by ' + t.artist);
}
function trackReady(t) {
t.fixedTitle = getTitle(t.title, t.artist, t.info.url);
document.title = 'MaKey MaKey Remix for ' + t.fixedTitle;
// $("#song-title").text(t.fixedTitle);
}
function readyToPlay(t) {
if (t.status === 'ok') {
trackReady(t);
setDisplayMode(true);
info("ready!");
normalizeColor();
createTilePanel(bMode);
showTrackTitle(t);
tweetSetup(t);
} else {
info(t.status);
}
}
function rearrange(insertBefore, tile, anchor) {
var firstIndex = _.indexOf(tiles, tile);
tiles.splice(firstIndex, 1);
var newIndex = _.indexOf(tiles, anchor);
if (!insertBefore) {
newIndex += 1;
}
tiles.splice(newIndex, 0, tile);
}
function insert(insertBefore, tile, anchor) {
var newIndex = _.indexOf(tiles, anchor);
if (!insertBefore) {
newIndex += 1;
}
tiles.splice(newIndex, 0, tile);
}
function gotTheAnalysis(profile) {
var status = get_status(profile);
if (status == 'complete') {
info("Loading track ...");
remixer.remixTrack(profile.response.track, function(state, t, percent) {
track = t;
if (state == 1) {
info("Here we go ...");
setTimeout( function() { readyToPlay(t); }, 10);
} else if (state == 0) {
if (percent >= 99) {
info("Here we go ...");
} else {
info( percent + "% of track loaded ");
}
} else {
info('Trouble ' + t.status);
}
});
} else if (status == 'error') {
info("Sorry, couldn't analyze that track");
}
}
function fetchAnalysis(trid) {
var url = 'http://static.echonest.com/infinite_jukebox_data/' + trid + '.json';
info('Fetching the analysis');
// showPlotPage(trid);
$.getJSON(url, function(data) { gotTheAnalysis(data); } )
.error( function() {
info("Sorry, can't find info for that track");
});
}
function get_status(data) {
if (data.response.status.code == 0) {
return data.response.track.status;
} else {
return 'error';
}
}
var tilePrototype = {
normalColor:"#5f9",
move: function(x,y) {
this.rect.attr( { x:x, y:y});
this.x = x;
this.y = y;
},
amove: function(x,y, time, delay, easing) {
this.x = x;
this.y = y;
if (time === undefined) {
time = 500;
}
if (delay === undefined) {
delay = 0;
}
if (easing === undefined) {
easing = 'linear';
}
var anim = Raphael.animation({cx: 10, cy: 20}, 800);
var ranimator = Raphael.animation({ x:x, y: y}, time, easing);
this.rect.animate(ranimator.delay(delay));
},
play:function(force) {
if (force || shifted) {
this.playStyle();
player.play(this.q);
} else if (controlled) {
this.queueStyle();
player.queue(this.q);
} else {
this.selectStyle();
}
if (force) {
info("Selected tile " + this.q.which);
selectedTile = this;
}
},
pos: function() {
return {
x: this.x,
y: this.y
}
},
selectStyle: function() {
this.rect.attr("fill", "#C9a");
},
queueStyle: function() {
this.rect.attr("fill", "#aFF");
},
playStyle: function() {
this.rect.attr("fill", "#FF9");
},
normal: function() {
this.rect.attr("fill", this.normalColor);
},
highlight: function() {
this.rect.attr("fill", "#FFFFFF");
},
unplay: function() {
this.normal();
if (shifted) {
player.stop(this.q);
}
},
init:function() {
var that = this;
//this.rect.mouseover(function(event) { event.preventDefault(), mouseOverTile = that; that.play(); });
this.rect.mousedown(function(event) {
event.preventDefault();
driver.setNextTile(that);
selectedTile = that;
if (!driver.isRunning()) {
//player.playNow(that.q);
//driver.setIncr(1);
driver.start();
}
if (shifted) {
driver.setIncr(1);
}
if (controlled) {
driver.setIncr(0);
}
});
this.rect.drag(
// on move
function(dx, dy, x, y) {
that.move(startPos.x + dx, startPos.y + dy);
//this.connectedSet.transform('T' + (startPos.x + dx) + "," + (startPos.y + dy));
},
// on start
function() {
startPos = that.pos();
that.rect.toFront();
},
// on end
function(ctx) {
//iplayer.clear();
if (draggedOver) {
var tp = that.pos();
var op = draggedOver.pos();
var insertBefore = tp.x < op.x;
rearrange(insertBefore, that, draggedOver);
refreshLayout(true);
draggedOver.normal();
draggedOver = null;
} else {
var pos = that.pos();
that.amove(pos.x, pos.y);
}
}
);
this.rect.onDragOver(
function(over) {
if (draggedOver) {
draggedOver.normal();
}
draggedOver = over.tile;
draggedOver.highlight();
}
);
//this.rect.mouseout(function() { mouseOverTile = null; that.unplay(); } );
}
}
function getQuantumColor(q) {
if (isSegment(q)) {
return getSegmentColor(q);
} else {
q = getQuantumSegment(q);
if (q != null) {
return getSegmentColor(q);
} else {
return "#000"; // default is #7Fa
}
}
}
function getQuantumSegment(q) {
while (! isSegment(q) ) {
if ('children' in q && q.children.length > 0) {
q = q.children[0]
} else {
break;
}
}
if (isSegment(q)) {
return q;
} else {
return null;
}
}
function isSegment(q) {
return 'pitches' in q; // color of tiles mapped to pitch
}
//function isSegment(q) {
// return 'timbre' in q; // color of tiles mapped to timbre
//}
function getSegmentColor(seg) {
return getColor(seg);
}
function tw() {
return 19; //default was 19
}
function createTile(which, q) {
var labeled = false;
var tile = Object.create(tilePrototype);
tile.which = which;
tile.width = 16; //Equal beat size
//tile.width = Math.round(40 * q.duration); // tile width as a function of duration
tile.height = 16;
tile.normalColor = getQuantumColor(q);
tile.rect = paper.rect(0, 0, tile.width, tile.height);
tile.rect.attr("stroke", "#349");
tile.rect.tile = tile;
tile.normal();
tile.q = q;
tile.init();
return tile;
}
function copyTile(tile) {
var ntile = Object.create(tilePrototype);
ntile.which = tile.which;
ntile.width = tile.width;
ntile.height = tile.height;
ntile.normalColor = tile.normalColor;
ntile.rect = paper.rect(0, 0, ntile.width, ntile.height);
ntile.rect.attr("stroke", "#349");
ntile.rect.tile = ntile;
ntile.normal();
ntile.q = tile.q;
ntile.init();
return ntile;
}
function sortTiles(sort, reverse) {
if (sort === 'timbre') {
if (selectedTile) {
info("Sorting based on timbral similarity to segment " + selectedTile.q.which);
calculateSegmentDistance(selectedTile, 'timbre', true);
sort = 'seg_distance';
} else {
info("No selected tile");
}
} else if (sort === 'pitch') {
if (selectedTile) {
info("Sorting based on pitch similarity to segment " + selectedTile.q.which);
calculateSegmentDistance(selectedTile, 'pitches', false);
sort = 'seg_distance';
} else {
info("No selected tile");
}
} else if (sort === 'segment') {
if (selectedTile) {
info("Sorting based on overall segment similarity " + selectedTile.q.which);
calculateOverallSegmentDistance(selectedTile);
sort = 'seg_distance';
} else {
info("No selected tile");
}
}
tiles.sort(tile_sorter(sort, reverse));
refreshLayout(true);
}
function tile_sorter(qfield, reverse) {
return function(a,b) {
if (reverse) {
var tmp = b;
b = a;
a = tmp;
}
return a.q.overlappingSegments[0][qfield] - b.q.overlappingSegments[0][qfield];
};
}
function extendTiles(newTiles) {
for (var i = 0; i < newTiles.length; i++) {
tiles.push(newTiles[i]);
}
}
function renumberTiles() {
for (var i = 0; i < tiles.length; i++) {
tiles[i].which = i;
}
}
function createTilePanel(which) {
$("#bmode").text(which);
removeAllTiles();
var newTiles = createTiles(which);
extendTiles(newTiles);
refreshLayout(false);
}
function normalizeColor() {
cmin = [100,100,100];
cmax = [-100,-100,-100];
var qlist = track.analysis.segments;
for (var i = 0; i < qlist.length; i++) {
for (var j = 0; j < 3; j++) {
var t = qlist[i].timbre[j];
if (t < cmin[j]) {
cmin[j] = t;
}
if (t > cmax[j]) {
cmax[j] = t;
}
}
}
}
function getColor(seg) {
var results = []
for (var i = 0; i < 3; i++) {
var t = seg.timbre[i];
var norm = (t - cmin[i]) / (cmax[i] - cmin[i]);
results[i] = norm * 255;
}
return to_rgb(results[0], results[1], results[2]);
}
function convert(value) {
var integer = Math.round(value);
var str = Number(integer).toString(16);
return str.length == 1 ? "0" + str : str;
};
function to_rgb(r, g, b) {
return "#" + convert(r) + convert(g) + convert(b);
}
function removeAllTiles() {
for (var i =0; i < tiles.length; i++) {
tiles[i].rect.remove();
}
tiles = [];
}
function playall() {
for (var i =0; i < tiles.length; i++) {
player.queue(tiles[i].q);
}
}
function reverseTiles() {
rtiles = []
for (var i = tiles.length - 1; i >= 0; i--) {
rtiles.push(tiles[i]);
}
tiles = rtiles;
refreshLayout(true);
}
mapper = {}
function keydown(evt) {
if (evt.which == 39) { // right arrow
var inc = driver.getIncr();
driver.setIncr(inc + 1);
evt.preventDefault();
}
if (evt.which == 37) { // left arrow
evt.preventDefault();
var inc = driver.getIncr();
driver.setIncr(inc - 1);
}
if (evt.which ==38 ) { // up arrow
driver.setIncr(1);
evt.preventDefault();
}
if (evt.which == 40 ) { // down arrow
driver.setIncr(0);
evt.preventDefault();
}
if (evt.which == 219 ) { // [
driver.setLoopStart();
evt.preventDefault();
}
if (evt.which == 221 ) { // ]
driver.setLoopEnd();
evt.preventDefault();
}
if (evt.which == 220 ) { // /
driver.loopCancel();
}
if (evt.which == 190 ) { // , slower
var factor = player.getSpeedFactor() + .01;
setSpeedFactor(factor)
evt.preventDefault();
}
if (evt.which == 188 ) { // . faster
var factor = player.getSpeedFactor() - .01;
if (factor < 0) {
factor = 0;
}
setSpeedFactor(factor)
evt.preventDefault();
}
if (evt.which == 191 ) { // / reset
setSpeedFactor(1)
evt.preventDefault();
}
if (evt.which == 65 ) { // a
var ct = driver.getCurTile();
if (ct !== null) {
var nextIndex = ct.which - 1;
driver.setIncr(0);
if (nextIndex >= 0) {
var nextTile = tiles[nextIndex];
driver.setNextTile(nextTile);
}
}
evt.preventDefault();
}
if (evt.which == 83 ) { // s
driver.setIncr(0);
var ct = driver.getCurTile();
var delta = tilesPerRow;
if (ct !== null) {
var nextIndex = ct.which + delta;
if (nextIndex < tiles.length -1 && nextIndex >= 0) {
var nextTile = tiles[nextIndex];
driver.setNextTile(nextTile);
}
}
evt.preventDefault();
}
if (evt.which == 87 ) { // w
driver.setIncr(0);
var ct = driver.getCurTile();
var delta = tilesPerRow;
if (ct !== null) {
var nextIndex = ct.which - delta;
if (nextIndex < tiles.length -1 && nextIndex >= 0) {
var nextTile = tiles[nextIndex];
driver.setNextTile(nextTile);
}
}
evt.preventDefault();
}
if (evt.which == 68 ) { // d
driver.setIncr(0);
var ct = driver.getCurTile();
if (ct !== null) {
var nextIndex = ct.which + 1;
if (nextIndex < tiles.length -1) {
var nextTile = tiles[nextIndex];
driver.setNextTile(nextTile);
}
}
evt.preventDefault();
}
if (evt.which === 66 ) { // b
driver.toggleBeatsTatums();
evt.preventDefault();
}
if (controlled && evt.which === 67 ) { // c
if (selectedTile) {
copiedTile = copyTile(selectedTile);
insert(false, copiedTile, selectedTile);
refreshLayout(true);
}
evt.preventDefault();
}
if (evt.which === 71 ) { // g displays by Bars
goBars();
evt.preventDefault();
}
if (evt.which === 78 ) { // n displays by Segments
goSegments();
evt.preventDefault();
}
if (evt.which === 77 ) { // m displays by Sections
goSections();
evt.preventDefault();
}
if (evt.which == 17) { // tests for control key for copying tiles.
controlled = true;
}
if (evt.which == 16) { // tests for shift key - keybinding
shifted = true;
}
if (evt.which == 32) { // tests for spacebar, start & stop playback
evt.preventDefault();
if (driver.isRunning()) {
driver.stop();
} else {
driver.start();
}
}
if (shifted && isDigit(evt.keyCode)) { // maps number keys only to tiles
mapper[evt.keyCode] = driver.getCurTile();
} else {
if (evt.keyCode in mapper) {
var tile = mapper[evt.keyCode];
if (tile != null) {
driver.setNextTile(tile);
}
}
}
}
function isDigit(key) {
return key >= 48 && key <= 57;
}
function keyup(evt) {
if (evt.which == 17) {
controlled = false;
}
if (evt.which == 16) {
shifted = false;
}
if (evt.keyCode in mapper) {
var tile = mapper[evt.keyCode];
if (tile != null) {
tile.normal();
}
}
}
function urldecode(str) {
return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}
function init() {
jQuery.ajaxSettings.traditional = true;
setDisplayMode(false);
window.oncontextmenu = function(event) {
event.preventDefault();
event.stopPropagation();
return false;
};
document.ondblclick = function DoubleClick(event) {
event.preventDefault();
event.stopPropagation();
return false;
}
$("#error").hide();
$("#play").click(
function() {
if (driver.isRunning()) {
driver.stop();
} else {
driver.start();
}
}
);
$("#reset").click(
function() {
driver.setIncr(1);
setSpeedFactor(1);
driver.stop();
goBeats();
setURL();
}
);
paper = Raphael("tiles", 6, 4);
$(document).keydown(keydown);
$(document).keyup(keyup);
if (window.webkitAudioContext === undefined) {
error("Sorry, this app needs advanced web audio. Your browser doesn't"
+ " support it. Try the latest version of Chrome or Safari");
hideAll();
} else {
var context = new webkitAudioContext();
remixer = createJRemixer(context, $);
player = remixer.getPlayer();
driver = Driver(player)
processParams();
}
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
};
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
}
// smartresize
jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
})(jQuery,'smartresize');
// usage:
$(window).smartresize(function(){
refreshLayout(true);
});
}
var margin = 10;
var top = 100;
var tilesPerGroup = 4; // 4 is default
var tspace = 3; // Space between tiles - 3 is default
var tilesPerRow = 0; // 0 is default
function refreshLayout(animated) {
var nt = tiles.length;
renumberTiles();
if (nt > 0) {
var w = $(window).width();
var h = $(window).height() - top;
var rw = w - margin * 2;
var rh = h - margin * 2;