-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpatatap-looper.js
71 lines (65 loc) · 1.94 KB
/
patatap-looper.js
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
(function(exports, $container){
var SL = {
beatsPerLoop: 16,
beatsPerMinute: 200,
_loops: {},
_stop: false,
add: function(name, beats) {
this._loops[name] = beats.split(' ');
return this;
},
remove: function(name, beats) {
delete this._loops[name];
},
list: function() {
var count = 0;
for (key in this._loops) {
console.log(key + ': ' + this._loops[key].join(' '));
count++;
}
console.log(count + ' loop(s)');
},
clear: function() {
this._loops = {};
},
stop: function() {
this._stop = true;
},
start: function() {
this._stop = false
superloop(0, this.beatsPerLoop, this.beatsPerMinute);
}
}
function playBeat(loop, beat) {
if(loop[beat] !== '-'){
var e = jQuery.Event("keydown");
try {
e.which = loop[beat].toUpperCase().charCodeAt(0);
} catch(error) {
console.warn('Typo at beat ' + beat + '');
}
$("input").val(String.fromCharCode(e.which));
$("html").trigger(e);
}
}
function superloop(beat, bpl, bpm) {
_.each(SL._loops, function(loop) {
playBeat(loop, beat);
});
if (SL._stop)
return
setTimeout(function(){
var nextBeat = (beat+1)%bpl;
superloop(nextBeat, bpl, bpm);
}, (1000 * 60) / bpm);
}
superloop(0, SL.beatsPerLoop, SL.beatsPerMinute);
exports.superloops = SL;
if ($container) {
$container.append('<div style="position:fixed; top: 10px; left: 10px;font-family:helvetica; font-size: 30px;color: white; padding: 20px;background-color: rgba(0,0,0,0.2);border: 5px solid black;">github.com/reimertz/patatap-looper</div>');
}
console.clear()
})(window, $("html"));
superloops.add('base', 'e - - - e - - - e - - - e - - -')
.add('snare', '- - o - - - o - - - o - - - o -')
.add('love', '- p - h - e - a - r - t - m - -');