-
Notifications
You must be signed in to change notification settings - Fork 0
/
bach-loop-sub.js
86 lines (72 loc) · 1.5 KB
/
bach-loop-sub.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Yoshiaki Onishi
July 22, 2020
YO.bach-loop-sub
This takes a list of binary numbers, and does the following:
(1) 0 --> -1 (e.g. 0 0 1 0 --> -1 -1 1 -1)
(2) 1 stays as is
(3) each number is given a denominator 16 (for 16th-notes for bach.score to read)
(e.g. -1 -1 1 -1 --> -1/16 -1/16 1/16 -1/16)
(4) forms the time siguature, according the formula: [x-bit (of incoming binary numbers)]/16
(e.g. if the incoming binary number is 0 0 1 0, then 4/16)
Input: list (of binary numbers)
Outputs:
left: time signature (use "bach.wrap 1" before connecting to bach.score)
right: durations that bach.score reads (use "bach.collect @inwrap 1 @outwrap 1"
before connecting to bach.score)
*/
inlets = 1;
outlets = 2;
var l1 = [];
var len = 0;
var len2 = 0;
var cntr = 0;
var newlist = [];
var fractlist = [];
var rawfract = 0;
var timesig = [];
function list()
{
var l1 = arrayfromargs(messagename, arguments);
len = l1.length;
while (cntr < len)
if (l1[cntr] == 1)
{
newlist.push(1);
cntr++;
}
else if (l1[cntr] == 0)
{
newlist.push(-1);
cntr++;
}
divisifier();
}
function divisifier()
{
cntr = 0;
len2 = newlist.length;
while (cntr < len2)
if (newlist[cntr] == 1)
{
fractlist.push("1/"+16);
cntr++;
}
else if (newlist[cntr] == -1)
{
fractlist.push("-1/"+16);
cntr++;
}
timesig.push(len2, 16); // Creates time signature
outlet(1,fractlist);
outlet(0,timesig);
init();
}
function init()
{
l1 = [];
newlist = [];
fractlist = [];
cntr = 0;
timesig = [];
}