replace from to with cycles / playhead
This commit is contained in:
parent
394e77c152
commit
ba5cf5ba83
1 changed files with 9 additions and 7 deletions
|
|
@ -9,8 +9,8 @@ import { Pattern } from '@strudel.cycles/core';
|
||||||
const scale = (normalized, min, max) => normalized * (max - min) + min;
|
const scale = (normalized, min, max) => normalized * (max - min) + min;
|
||||||
|
|
||||||
Pattern.prototype.pianoroll = function ({
|
Pattern.prototype.pianoroll = function ({
|
||||||
from = -2,
|
cycles = 4,
|
||||||
to = 2,
|
playhead = .5,
|
||||||
overscan = 1,
|
overscan = 1,
|
||||||
inactive = '#C9E597',
|
inactive = '#C9E597',
|
||||||
active = '#FFCA28',
|
active = '#FFCA28',
|
||||||
|
|
@ -26,6 +26,8 @@ Pattern.prototype.pianoroll = function ({
|
||||||
const ctx = getDrawContext();
|
const ctx = getDrawContext();
|
||||||
const w = ctx.canvas.width;
|
const w = ctx.canvas.width;
|
||||||
const h = ctx.canvas.height;
|
const h = ctx.canvas.height;
|
||||||
|
const from = -cycles * playhead;
|
||||||
|
const to = cycles * (1 - playhead);
|
||||||
|
|
||||||
if (timeframeProp) {
|
if (timeframeProp) {
|
||||||
console.warn('timeframe is deprecated! use from/to instead');
|
console.warn('timeframe is deprecated! use from/to instead');
|
||||||
|
|
@ -46,7 +48,7 @@ Pattern.prototype.pianoroll = function ({
|
||||||
let foldValues = [];
|
let foldValues = [];
|
||||||
|
|
||||||
// duration to px (on timeAxis)
|
// duration to px (on timeAxis)
|
||||||
const playhead = scale(-from / timeExtent, ...timeRange);
|
const playheadPosition = scale(-from / timeExtent, ...timeRange);
|
||||||
this.draw(
|
this.draw(
|
||||||
(ctx, events, t) => {
|
(ctx, events, t) => {
|
||||||
ctx.fillStyle = background;
|
ctx.fillStyle = background;
|
||||||
|
|
@ -60,11 +62,11 @@ Pattern.prototype.pianoroll = function ({
|
||||||
ctx.globalAlpha = event.context.velocity ?? 1;
|
ctx.globalAlpha = event.context.velocity ?? 1;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
ctx.moveTo(0, playhead);
|
ctx.moveTo(0, playheadPosition);
|
||||||
ctx.lineTo(valueAxis, playhead);
|
ctx.lineTo(valueAxis, playheadPosition);
|
||||||
} else {
|
} else {
|
||||||
ctx.moveTo(playhead, 0);
|
ctx.moveTo(playheadPosition, 0);
|
||||||
ctx.lineTo(playhead, valueAxis);
|
ctx.lineTo(playheadPosition, valueAxis);
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
const timePx = scale((event.whole.begin - from) / timeExtent, ...timeRange);
|
const timePx = scale((event.whole.begin - from) / timeExtent, ...timeRange);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue