-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
166 lines (163 loc) · 4.96 KB
/
script.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
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
var TimePulse = /** @class */ (function () {
function TimePulse() {
this.time = 0;
this.rate = 1; // 1 pulse for every 1 second
}
TimePulse.prototype.onReset = function () {
// To be implemented
// eslint-disable-next-line @typescript-eslint/no-empty-function
};
TimePulse.prototype.updateTime = function (dt) {
this.time += dt * this.rate;
if (this.time > 1) {
var diff = this.time % 1;
this.time = diff;
this.onReset();
}
};
return TimePulse;
}());
var TimeStream = /** @class */ (function () {
function TimeStream() {
this.rate = 1;
this.lastTimeUniformValue = undefined;
this._time = undefined;
}
TimeStream.prototype.updateTime = function (timeUniformValue, dt) {
if (this.lastTimeUniformValue === undefined) {
this.lastTimeUniformValue = timeUniformValue;
}
var diff = timeUniformValue - this.lastTimeUniformValue;
if (diff < 0) {
this.lastTimeUniformValue = timeUniformValue;
this._time = timeUniformValue;
return;
}
if (this._time === undefined) {
return;
}
this.lastTimeUniformValue = timeUniformValue;
// dt must be >= diff
// if diff === dt then we have 100% progression rate
// If diff === 0 then we have 0% progression rate
var progressionRate = diff / dt;
this._time += diff * (progressionRate * this.rate);
};
Object.defineProperty(TimeStream.prototype, "time", {
get: function () {
return this._time || 0;
},
enumerable: false,
configurable: true
});
return TimeStream;
}());
var setTimeoutIds = [];
var setTimeouts = {};
var nextSetTimeoutId = 0;
function setTimeout(cb, duration) {
var id = nextSetTimeoutId++;
setTimeouts[id] = {
id: id,
cb: cb,
durationLeft: duration,
};
setTimeoutIds.push(id);
return id;
}
function clearTimeout(id) {
delete setTimeouts[id];
// Remove id from IDs array
var index = setTimeoutIds.indexOf(id);
if (index !== -1) {
setTimeoutIds.splice(index, 1);
}
}
var setIntervalIds = [];
var setIntervals = {};
var nextSetIntervalId = 0;
function setInterval(cb, duration) {
var id = nextSetIntervalId++;
setIntervals[id] = {
id: id,
cb: cb,
durationLeft: duration,
duration: duration,
};
setIntervalIds.push(id);
return id;
}
function clearInterval(id) {
delete setIntervals[id];
// Remove id from IDs array
var index = setIntervalIds.indexOf(id);
if (index !== -1) {
setIntervalIds.splice(index, 1);
}
}
function updateTimeoutsAndIntervals(dtMs) {
setTimeoutIds.forEach(function (id) {
var timeout = setTimeouts[id];
if (timeout) {
timeout.durationLeft -= dtMs;
if (timeout.durationLeft <= 0) {
try {
timeout.cb();
}
catch (e) {
console.error(e);
}
clearTimeout(id);
}
}
});
setIntervalIds.forEach(function (id) {
var interval = setIntervals[id];
if (interval) {
interval.durationLeft -= dtMs;
if (interval.durationLeft <= 0) {
try {
interval.cb();
}
catch (e) {
console.error(e);
}
interval.durationLeft = interval.duration;
}
}
});
}
function waterWave(angle) {
return -(Math.abs(Math.sin(angle)) - 1);
}
var timePulse = new TimePulse();
var midHighTimeStream = new TimeStream();
timePulse.onReset = function () {
if (inputs.limit !== curLimit) {
curLimit = inputs.limit;
}
};
var curLimit = inputs.limit;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function update(dt) {
updateTimeoutsAndIntervals(dt * 1000);
timePulse.rate = inputs.bpm / 60;
timePulse.updateTime(dt);
uniforms.pulse = waterWave((timePulse.time - 0.5) * Math.PI);
uniforms.scriptLimit = curLimit;
midHighTimeStream.rate = inputs.uMusicEnabled * inputs.uRotationMultiplier;
midHighTimeStream.updateTime(syn_MidHighTime, dt);
uniforms.scriptSyn_BPMConfidence = inputs.uMusicEnabled * syn_BPMConfidence;
uniforms.scriptSyn_OnBeat = inputs.uMusicEnabled * syn_OnBeat;
uniforms.scriptSyn_BassLevel = inputs.uMusicEnabled * syn_BassLevel;
uniforms.scriptSyn_MidHighTime = midHighTimeStream.time;
uniforms.scriptGreen = 0.0;
}
setInterval(function () {
console.log("syn_MidHighitme: ".concat(syn_MidHighTime));
console.log("uniforms.scriptSyn_MidHighTime: ".concat(uniforms.scriptSyn_MidHighTime));
}, 1000);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function transition() {
// eslint-disable-next-line @typescript-eslint/no-empty-function
}