working poc cyclist with cps change

This commit is contained in:
Felix Roos 2024-03-22 00:29:25 +01:00
parent 96a977990a
commit 8d8c843ccf

View File

@ -10,15 +10,50 @@ async function run() {
await loaded; await loaded;
const ctx = getAudioContext(); const ctx = getAudioContext();
let last = 0; let last = 0;
let cps = 0.6;
let num_ticks_since_cps_change = 0;
let num_cycles_at_cps_change = 0;
let seconds_at_cps_change;
let latency = 0.1;
function setCps(_cps) {
if (_cps === cps) {
return;
}
cps = _cps;
num_ticks_since_cps_change = 0;
}
const clock = createClock( const clock = createClock(
() => ctx.currentTime, () => ctx.currentTime,
(phase, duration, tick, t) => { (phase, duration, tick, t) => {
const [begin, end] = [last, (last = tick * duration)]; if (num_ticks_since_cps_change === 0) {
console.log('q', begin.toFixed(2), end.toFixed(2), phase.toFixed(2)); console.log('changed cps..!!', cps);
let haps = pat.queryArc(begin, end).filter((h) => h.hasOnset()); num_cycles_at_cps_change = last;
// console.log('phase', phase, haps.length); seconds_at_cps_change = phase;
haps.forEach((hap) => { }
superdough(hap.value, '=' + String(hap.whole.begin + 0.1)); num_ticks_since_cps_change++;
const seconds_since_cps_change = num_ticks_since_cps_change * duration;
const num_cycles_since_cps_change = seconds_since_cps_change * cps;
const [begin, end] = [last, (last = num_cycles_at_cps_change + num_cycles_since_cps_change)];
console.log(
'q',
begin.toFixed(2),
end.toFixed(2),
phase.toFixed(2),
'#',
(end - begin).toFixed(2),
duration.toFixed(2),
);
pat
.queryArc(begin, end, { _cps: cps })
.filter((h) => h.hasOnset())
.forEach((hap) => {
const deadline = (hap.whole.begin - num_cycles_at_cps_change) / cps + seconds_at_cps_change + latency;
superdough(hap.value, '=' + deadline);
}); });
}, },
0.025, // duration of each cycle 0.025, // duration of each cycle
@ -29,6 +64,13 @@ async function run() {
false, false,
); );
clock.start(); clock.start();
setTimeout(() => {
console.log('change cps!!!!!!!!!!!!!!!!!!!!');
setCps(1.2);
}, 6000);
setTimeout(() => {
clock.stop();
}, 12000);
} }
run(); run();