mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
add Pattern.id + use it for _punchcard and _spiral
This commit is contained in:
parent
2cc92a2b93
commit
2857e816d2
@ -106,19 +106,19 @@ 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.pianoroll({ fold: 1, ...options, ctx, id });
|
return pat.id(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.punchcard({ fold: 1, ...options, ctx, id });
|
return pat.id(id).punchcard({ fold: 1, ...options, ctx, id });
|
||||||
});
|
});
|
||||||
|
|
||||||
/* registerWidget('_spiral', (id, options = {}, pat) => {
|
registerWidget('_spiral', (id, options = {}, pat) => {
|
||||||
options = { width: 200, height: 200, size: 36, ...options };
|
options = { width: 200, height: 200, size: 36, ...options };
|
||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
const ctx = getCanvasWidget(id, options).getContext('2d');
|
||||||
return pat.spiral({ ...options, ctx, id });
|
return pat.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 };
|
||||||
|
|||||||
@ -2487,6 +2487,15 @@ export const { color, colour } = register(['color', 'colour'], function (color,
|
|||||||
return pat.withContext((context) => ({ ...context, color }));
|
return pat.withContext((context) => ({ ...context, color }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the id of the hap in, for filtering in the future.
|
||||||
|
* @name id
|
||||||
|
* @noAutocomplete
|
||||||
|
* @param {string} id anything unique
|
||||||
|
*/
|
||||||
|
Pattern.prototype.id = function (id) {
|
||||||
|
return this.withContext((ctx) => ({ ...ctx, id }));
|
||||||
|
};
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Control-related functions, i.e. ones that manipulate patterns of
|
// Control-related functions, i.e. ones that manipulate patterns of
|
||||||
// objects
|
// objects
|
||||||
|
|||||||
@ -129,12 +129,17 @@ export function pianoroll({
|
|||||||
colorizeInactive = 1,
|
colorizeInactive = 1,
|
||||||
fontFamily,
|
fontFamily,
|
||||||
ctx,
|
ctx,
|
||||||
|
id,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const w = ctx.canvas.width;
|
const w = ctx.canvas.width;
|
||||||
const h = ctx.canvas.height;
|
const h = ctx.canvas.height;
|
||||||
let from = -cycles * playhead;
|
let from = -cycles * playhead;
|
||||||
let to = cycles * (1 - playhead);
|
let to = cycles * (1 - playhead);
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
haps = haps.filter((hap) => hap.context.id === id);
|
||||||
|
}
|
||||||
|
|
||||||
if (timeframeProp) {
|
if (timeframeProp) {
|
||||||
console.warn('timeframe is deprecated! use from/to instead');
|
console.warn('timeframe is deprecated! use from/to instead');
|
||||||
from = 0;
|
from = 0;
|
||||||
|
|||||||
@ -50,13 +50,13 @@ function spiralSegment(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawSpiral(options) {
|
function drawSpiral(options) {
|
||||||
const {
|
let {
|
||||||
stretch = 1,
|
stretch = 1,
|
||||||
size = 80,
|
size = 80,
|
||||||
thickness = size / 2,
|
thickness = size / 2,
|
||||||
cap = 'butt', // round butt squar,
|
cap = 'butt', // round butt squar,
|
||||||
inset = 3, // start angl,
|
inset = 3, // start angl,
|
||||||
playheadColor = '#ffffff90',
|
playheadColor = '#ffffff',
|
||||||
playheadLength = 0.02,
|
playheadLength = 0.02,
|
||||||
playheadThickness = thickness,
|
playheadThickness = thickness,
|
||||||
padding = 0,
|
padding = 0,
|
||||||
@ -69,8 +69,13 @@ function drawSpiral(options) {
|
|||||||
time,
|
time,
|
||||||
haps,
|
haps,
|
||||||
drawTime,
|
drawTime,
|
||||||
|
id,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
haps = haps.filter((hap) => hap.context.id === id);
|
||||||
|
}
|
||||||
|
|
||||||
const [w, h] = [ctx.canvas.width, ctx.canvas.height];
|
const [w, h] = [ctx.canvas.width, ctx.canvas.height];
|
||||||
ctx.clearRect(0, 0, w * 2, h * 2);
|
ctx.clearRect(0, 0, w * 2, h * 2);
|
||||||
const [cx, cy] = [w / 2, h / 2];
|
const [cx, cy] = [w / 2, h / 2];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user