Merge remote-tracking branch 'origin/main' into repl-package

This commit is contained in:
Felix Roos 2022-05-15 22:55:31 +02:00
commit 999251e137
3 changed files with 24 additions and 5 deletions

View File

@ -973,6 +973,10 @@ export class Pattern {
_velocity(velocity) { _velocity(velocity) {
return this._withContext((context) => ({ ...context, velocity: (context.velocity || 1) * velocity })); return this._withContext((context) => ({ ...context, velocity: (context.velocity || 1) * velocity }));
} }
_loopAt(factor,cps=1) {
return this.speed((1/factor)*cps).unit("c").slow(factor)
}
} }
// TODO - adopt value.mjs fully.. // TODO - adopt value.mjs fully..
@ -1396,6 +1400,10 @@ Pattern.prototype.chunkBack = function (...args) {
args = args.map(reify); args = args.map(reify);
return patternify2(Pattern.prototype._chunkBack)(...args, this); return patternify2(Pattern.prototype._chunkBack)(...args, this);
}; };
Pattern.prototype.loopAt = function (...args) {
args = args.map(reify);
return patternify2(Pattern.prototype._loopAt)(...args, this);
};
Pattern.prototype.zoom = function (...args) { Pattern.prototype.zoom = function (...args) {
args = args.map(reify); args = args.map(reify);
return patternify2(Pattern.prototype._zoom)(...args, this); return patternify2(Pattern.prototype._zoom)(...args, this);

View File

@ -10,15 +10,19 @@ import { Pattern } from '@strudel.cycles/core';
const comm = new OSC(); const comm = new OSC();
comm.open(); comm.open();
const latency = 0.1; const latency = 0.1;
let startedAt = -1;
Pattern.prototype.osc = function () { Pattern.prototype.osc = function () {
return this._withHap((hap) => { return this._withHap((hap) => {
const onTrigger = (time, hap, currentTime) => { const onTrigger = (time, hap, currentTime, cps, cycle, delta) => {
// time should be audio time of onset // time should be audio time of onset
// currentTime should be current time of audio context (slightly before time) // currentTime should be current time of audio context (slightly before time)
const keyvals = Object.entries(hap.value).flat(); if (startedAt < 0) {
const offset = (time - currentTime + latency) * 1000; startedAt = Date.now() - (currentTime * 1000);
const ts = Math.floor(Date.now() + offset); }
const controls = Object.assign({}, { cps: cps, cycle: cycle, delta: delta }, hap.value);
const keyvals = Object.entries(controls).flat();
const ts = Math.floor(startedAt + ((time + latency) * 1000));
const message = new OSC.Message('/dirt/play', ...keyvals); const message = new OSC.Message('/dirt/play', ...keyvals);
const bundle = new OSC.Bundle([message], ts); const bundle = new OSC.Bundle([message], ts);
bundle.timestamp(ts); // workaround for https://github.com/adzialocha/osc-js/issues/60 bundle.timestamp(ts); // workaround for https://github.com/adzialocha/osc-js/issues/60

View File

@ -57,7 +57,14 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawP
/* console.warn('no instrument chosen', event); /* console.warn('no instrument chosen', event);
throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */ throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */
} else { } else {
onTrigger(time, event, currentTime); onTrigger(
time,
event,
currentTime,
1 /* cps */,
event.wholeOrPart().begin.valueOf(),
event.duration.valueOf(),
);
} }
} catch (err) { } catch (err) {
console.warn(err); console.warn(err);