can now have multiple triggers
+ Pattern.log now makes sense
This commit is contained in:
parent
27fb2d2d5b
commit
ff5d14fb63
9 changed files with 32 additions and 22 deletions
|
|
@ -55,7 +55,8 @@ Fraction.prototype.min = function (other) {
|
|||
return this.lt(other) ? this : other;
|
||||
};
|
||||
|
||||
Fraction.prototype.show = function () {
|
||||
Fraction.prototype.show = function (/* excludeWhole = false */) {
|
||||
// return this.toFraction(excludeWhole);
|
||||
return this.s * this.n + '/' + this.d;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -85,9 +85,13 @@ export class Hap {
|
|||
);
|
||||
}
|
||||
|
||||
showWhole() {
|
||||
showWhole(compact = false) {
|
||||
return `${this.whole == undefined ? '~' : this.whole.show()}: ${
|
||||
typeof this.value === 'object' ? JSON.stringify(this.value) : this.value
|
||||
typeof this.value === 'object'
|
||||
? compact
|
||||
? JSON.stringify(this.value).slice(1, -1).replaceAll('"', '').replaceAll(',', ' ')
|
||||
: JSON.stringify(this.value)
|
||||
: this.value
|
||||
}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import { unionWithObj } from './value.mjs';
|
|||
|
||||
import { compose, removeUndefineds, flatten, id, listRange, curry, mod, numeralArgs, parseNumeral } from './util.mjs';
|
||||
import drawLine from './drawLine.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
|
||||
let stringParser;
|
||||
// parser is expected to turn a string into a pattern
|
||||
|
|
@ -1328,22 +1329,25 @@ export class Pattern {
|
|||
.unit('c')
|
||||
.slow(factor);
|
||||
}
|
||||
onTrigger(onTrigger) {
|
||||
return this._withHap((hap) => hap.setContext({ ...hap.context, onTrigger }));
|
||||
}
|
||||
log(func = id) {
|
||||
onTrigger(onTrigger, dominant = true) {
|
||||
return this._withHap((hap) =>
|
||||
hap.setContext({
|
||||
...hap.context,
|
||||
onTrigger: (...args) => {
|
||||
if (hap.context.onTrigger) {
|
||||
if (!dominant && hap.context.onTrigger) {
|
||||
hap.context.onTrigger(...args);
|
||||
}
|
||||
console.log(func(...args));
|
||||
onTrigger(...args);
|
||||
},
|
||||
// we need this to know later if the default trigger should still fire
|
||||
dominantTrigger: dominant,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
log(func = (_, hap) => `[hap] ${hap.showWhole(true)}`) {
|
||||
return this.onTrigger((...args) => logger(func(...args)), false);
|
||||
}
|
||||
logValues(func = id) {
|
||||
return this.log((_, hap) => func(hap.value));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ export function repl({
|
|||
interval,
|
||||
onTrigger: async (hap, deadline, duration) => {
|
||||
try {
|
||||
if (!hap.context.onTrigger) {
|
||||
return await defaultOutput(hap, deadline, duration);
|
||||
if (!hap.context.onTrigger || !hap.context.dominantTrigger) {
|
||||
await defaultOutput(hap, deadline, duration);
|
||||
}
|
||||
if (hap.context.onTrigger) {
|
||||
const cps = 1;
|
||||
// call signature of output / onTrigger is different...
|
||||
await hap.context.onTrigger(getTime() + deadline, hap, getTime(), cps);
|
||||
}
|
||||
const cps = 1; // TODO: fix
|
||||
// call signature of output / onTrigger is different...
|
||||
return await hap.context.onTrigger(getTime() + deadline, hap, getTime(), cps);
|
||||
} catch (err) {
|
||||
logger(`[cyclist] error: ${err.message}`, 'error');
|
||||
}
|
||||
|
|
|
|||
2
packages/react/dist/index.cjs.js
vendored
2
packages/react/dist/index.cjs.js
vendored
File diff suppressed because one or more lines are too long
5
packages/react/dist/index.es.js
vendored
5
packages/react/dist/index.es.js
vendored
|
|
@ -303,10 +303,7 @@ function eu({
|
|||
interval: e,
|
||||
onTrigger: async (E, C, x) => {
|
||||
try {
|
||||
if (!E.context.onTrigger)
|
||||
return await t(E, C, x);
|
||||
const I = 1;
|
||||
return await E.context.onTrigger(a() + C, E, a(), I);
|
||||
(!E.context.onTrigger || !E.context.dominantTrigger) && await t(E, C, x), E.context.onTrigger && await E.context.onTrigger(a() + C, E, a(), 1);
|
||||
} catch (I) {
|
||||
Le(`[cyclist] error: ${I.message}`, "error");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ function useHighlighting({ view, pattern, active, getTime }) {
|
|||
highlights.current = highlights.current.concat(haps); // add potential new onsets
|
||||
view.dispatch({ effects: setHighlights.of(highlights.current) }); // highlight all still active + new active haps
|
||||
} catch (err) {
|
||||
// console.log('error in updateHighlights', err);
|
||||
view.dispatch({ effects: setHighlights.of([]) });
|
||||
}
|
||||
frame = requestAnimationFrame(updateHighlights);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue