fix: allow multiple visuals for the same pattern
+ using .tag function instead of single .id
This commit is contained in:
parent
ab015ff48a
commit
b5720355f9
5 changed files with 15 additions and 11 deletions
|
|
@ -106,23 +106,23 @@ function getCanvasWidget(id, options = {}) {
|
||||||
|
|
||||||
registerWidget('_pianoroll', (id, options = {}, pat) => {
|
registerWidget('_pianoroll', (id, options = {}, pat) => {
|
||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
const ctx = getCanvasWidget(id, options).getContext('2d');
|
||||||
return pat.id(id).pianoroll({ fold: 1, ...options, ctx, id });
|
return pat.tag(id).pianoroll({ fold: 1, ...options, ctx, id });
|
||||||
});
|
});
|
||||||
|
|
||||||
registerWidget('_punchcard', (id, options = {}, pat) => {
|
registerWidget('_punchcard', (id, options = {}, pat) => {
|
||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
const ctx = getCanvasWidget(id, options).getContext('2d');
|
||||||
return pat.id(id).punchcard({ fold: 1, ...options, ctx, id });
|
return pat.tag(id).punchcard({ fold: 1, ...options, ctx, id });
|
||||||
});
|
});
|
||||||
|
|
||||||
registerWidget('_spiral', (id, options = {}, pat) => {
|
registerWidget('_spiral', (id, options = {}, pat) => {
|
||||||
let _size = options.size || 275;
|
let _size = options.size || 275;
|
||||||
options = { width: _size, height: _size, ...options, size: _size / 5 };
|
options = { width: _size, height: _size, ...options, size: _size / 5 };
|
||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
const ctx = getCanvasWidget(id, options).getContext('2d');
|
||||||
return pat.id(id).spiral({ ...options, ctx, id });
|
return pat.tag(id).spiral({ ...options, ctx, id });
|
||||||
});
|
});
|
||||||
|
|
||||||
registerWidget('_scope', (id, options = {}, pat) => {
|
registerWidget('_scope', (id, options = {}, pat) => {
|
||||||
options = { width: 500, height: 60, pos: 0.5, scale: 1, ...options };
|
options = { width: 500, height: 60, pos: 0.5, scale: 1, ...options };
|
||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
const ctx = getCanvasWidget(id, options).getContext('2d');
|
||||||
return pat.id(id).scope({ ...options, ctx, id });
|
return pat.tag(id).scope({ ...options, ctx, id });
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,10 @@ export class Hap {
|
||||||
return this.whole != undefined && this.whole.begin.equals(this.part.begin);
|
return this.whole != undefined && this.whole.begin.equals(this.part.begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasTag(tag) {
|
||||||
|
return this.context.tags?.includes(tag);
|
||||||
|
}
|
||||||
|
|
||||||
resolveState(state) {
|
resolveState(state) {
|
||||||
if (this.stateful && this.hasOnset()) {
|
if (this.stateful && this.hasOnset()) {
|
||||||
console.log('stateful');
|
console.log('stateful');
|
||||||
|
|
|
||||||
|
|
@ -2477,13 +2477,13 @@ export const hsl = register('hsl', (h, s, l, pat) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the id of the hap in, for filtering in the future.
|
* Tags each Hap with an identifier. Good for filtering. The function populates Hap.context.tags (Array).
|
||||||
* @name id
|
* @name tag
|
||||||
* @noAutocomplete
|
* @noAutocomplete
|
||||||
* @param {string} id anything unique
|
* @param {string} tag anything unique
|
||||||
*/
|
*/
|
||||||
Pattern.prototype.id = function (id) {
|
Pattern.prototype.tag = function (tag) {
|
||||||
return this.withContext((ctx) => ({ ...ctx, id }));
|
return this.withContext((ctx) => ({ ...ctx, tags: (ctx.tags || []).concat([tag]) }));
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export function pianoroll({
|
||||||
let to = cycles * (1 - playhead);
|
let to = cycles * (1 - playhead);
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
haps = haps.filter((hap) => hap.context.id === id);
|
haps = haps.filter((hap) => hap.hasTag(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeframeProp) {
|
if (timeframeProp) {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ function drawSpiral(options) {
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
haps = haps.filter((hap) => hap.context.id === id);
|
haps = haps.filter((hap) => hap.hasTag(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
const [w, h] = [ctx.canvas.width, ctx.canvas.height];
|
const [w, h] = [ctx.canvas.width, ctx.canvas.height];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue