-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathwebsynth_sequencer.js
59 lines (53 loc) · 1.49 KB
/
websynth_sequencer.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
/*
* websynth_sequencer.js
*
* This program is licensed under the MIT License.
* Copyright 2012, aike (@aike1000)
*
*/
$(function() {
var n8 = 200;
// J.S.Bach - Suite No 1 in G major BWV 1007 Prelude
var sequence_note = [
2, 9, 18, 16, 18, 9, 18, 9,
2, 9, 18, 16, 18, 9, 18, 9,
2, 11, 19, 18, 19, 11, 19, 11,
2, 11, 19, 18, 19, 11, 19, 11,
2, 13, 19, 18, 19, 13, 19, 13,
2, 13, 19, 18, 19, 13, 19, 13,
2, 14, 18, 16, 18, 14, 18, 14,
2, 14, 18, 16, 18, 14, 18, 14
];
var sequence_duration = [
n8, n8, n8, n8, n8, n8, n8, n8,
n8, n8, n8, n8, n8, n8, n8, n8,
n8, n8, n8, n8, n8, n8, n8, n8,
n8, n8, n8, n8, n8, n8, n8, n8,
n8, n8, n8, n8, n8, n8, n8, n8,
n8, n8, n8, n8, n8, n8, n8, n8,
n8, n8, n8, n8, n8, n8, n8, n8,
n8, n8, n8, n8, n8, n8, n8, n8
];
$('<img />').switch({
id: 'play_button', image: 'images/play_button.png',
left: 350, top: 500, width: 36, height: 36, value: 0,
click: (function() { seq(0);} )
}).appendTo('#draw');
function seq_note_on(note) {
p.play(note);
$('#key_' + note).keypad("value", 1);
};
function seq_note_off(note) {
p.stop(note);
$('#key_' + note).keypad("value", 0);
};
function seq(pos) {
if (pos >= sequence_note.length) {
seq(0);
} else if ($('#play_button').switch("value") == 1) {
seq_note_on(sequence_note[pos]);
setTimeout(function() {seq_note_off(sequence_note[pos]);}, sequence_duration[pos] - 10);
setTimeout(function() {seq(pos + 1);}, sequence_duration[pos]);
}
};
});