-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
132 lines (114 loc) · 4.35 KB
/
index.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
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
let bpm, divisor, length, eval1, eval2, storeNote, wLoop = 0, noteNum, timeBetween, timeAt, audioID, startTime
let eval1s = []
let jumpNote = []
let spiralNote = []
var resObj = {result: 0}
for(let i = 0; i < 9; i++)
{
jumpNote[i] =[]
spiralNote[i] =[]
for (let g =0; g < 12; g++)
{
jumpNote[i][g] = null
spiralNote[i][g] = null
}
for(let g=12; g<15; g++)
{
jumpNote[i][g] = null
}
}
spiralNote = [ [1,3,1,3,1,3,1,3,1,3,1,3], [0,2,4,0,2,4,0,2,4,0,2,4], [1,5,1,5,1,5,1,5,1,5,1,5], [0,4,6,0,4,6,0,4,6,0,4,6], [1,3,5,7,1,3,5,7,1,3,5,7], [2,4,8,2,4,8,2,4,8,2,4,8], [3,7,3,7,3,7,3,7,3,7,3,7], [4,6,8,4,6,8,4,6,8,4,6,8], [5,7,5,7,5,7,5,7,5,7,5,7] ]
jumpNote = [[2,5,6,7,8,2,5,6,7,8,2,5,6,7,8],[6,7,8,6,7,8,6,7,8,6,7,8,6,7,8],[0,3,6,7,8,0,3,6,7,8,0,3,6,7,8],[2,5,8,2,5,8,2,5,8,2,5,8,2,5,8],[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[0,3,6,0,3,6,0,3,6,0,3,6,0,3,6],[0,1,2,5,8,0,1,2,5,8,0,1,2,5,8],[0,1,2,0,1,2,0,1,2,0,1,2,0,1,2],[0,1,2,3,6,0,1,2,3,6,0,1,2,3,6] ]
function randomSpiral( eval1, eval2, storeNote, wLoop, noteNum, timeBetween, timeAt, eval1s, spiralNote, resObj, startTime)
{
let centerCheck = [ 0,7,0,5,0,3,0,1,0 ];
while (wLoop < noteNum)
{
storeNote = spiralNote[eval1][eval2];
if (eval1s[wLoop - 1] == 4 && wLoop > 0)
{
storeNote = centerCheck[eval1s[wLoop - 2]];
}
while (storeNote == eval1s[wLoop - 2] && wLoop > 1)
{
eval2 = Math.floor((Math.random()*10000) % 12);
storeNote = spiralNote[eval1][eval2];
}
resObj.result = resObj.result + ","
dataConvert(storeNote, resObj);
timeAt = Math.trunc(Math.round(Number(startTime) + timeBetween * (wLoop)))
resObj.result = resObj.result + String(timeAt);
eval1s[wLoop] = storeNote;
eval1 = storeNote;
eval2 = Math.floor((Math.random()*10000) % 12);
wLoop++;
}
}
function randomJump(eval1, eval2, storeNote, wLoop, noteNum, timeBetween, timeAt, eval1s, jumpNote, resObj, startTime)
{
while (wLoop < noteNum)
{
storeNote = jumpNote[eval1][eval2];
while (storeNote == eval1s[wLoop - 2] && wLoop > 1)
{
eval2 = Math.floor((Math.random()*10000) % 15);
storeNote = jumpNote[eval1][eval2];
}
resObj.result = resObj.result + ","
dataConvert(storeNote, resObj);
timeAt = Math.trunc(Math.round(Number(startTime) + timeBetween * (wLoop)));
resObj.result = resObj.result + String(timeAt);
eval1s[wLoop] = storeNote;
eval1 = storeNote;
eval2 = Math.floor((Math.random()*10000)% 15);
wLoop++;
}
}
function randomPoo(storeNote, wLoop, noteNum, timeBetween, timeAt, resObj, startTime)
{
while (wLoop < noteNum)
{
storeNote = Math.floor(Math.random()*10000%9)
resObj.result = resObj.result + ","
dataConvert(storeNote, resObj);
timeAt = Math.trunc(Math.round(Number(startTime) + timeBetween * (wLoop)));
resObj.result = resObj.result + String(timeAt);
wLoop++;
}
}
function dataConvert(storeNote, result)
{
let data1 = [0,0,0,1,1,1,2,2,2]
let data2 = [0,1,2,0,1,2,0,1,2]
resObj.result = resObj.result + String(data1[storeNote]) + "|" + String(data2[storeNote]) + "|"
}
document.getElementById("myButton").onclick = function(){
bpm = document.getElementById("bpmValue").value
divisor = document.getElementById("divisorValue").value
length = document.getElementById("timeValue").value
startTime = document.getElementById("startValue").value
audioID = document.getElementById("audioValue").value
resObj.result = String(audioID)
noteNum = (bpm*divisor*length)/60
timeBetween = (length * 1000) / noteNum
eval1 = Math.floor((Math.random()*10000)%9)
while (eval1 == 4)
{
eval1 = Math.floor((Math.random()*10000)%9)
}
if (document.getElementById("jump").checked == true)
{
eval2 = Math.floor((Math.random()*10000)% 15)
randomJump(eval1, eval2, storeNote, wLoop, noteNum, timeBetween, timeAt, eval1s, jumpNote, resObj, startTime)
}
else if (document.getElementById("spiral").checked ==true)
{
eval2 = Math.floor((Math.random()*10000) % 12)
randomSpiral( eval1, eval2, storeNote, wLoop, noteNum, timeBetween, timeAt, eval1s, spiralNote, resObj, startTime)
}
else
{
randomPoo(storeNote, wLoop, noteNum, timeBetween, timeAt, resObj, startTime)
}
document.getElementById("resultText").innerHTML = resObj.result
}