object support for pianoroll

This commit is contained in:
Felix Roos 2022-06-21 22:38:05 +02:00
parent fd17377c18
commit 64f717f81b
2 changed files with 10 additions and 5 deletions

View File

@ -36,8 +36,7 @@ Pattern.prototype.draw = function (callback, { from, to, onQuery }) {
const begin = currentCycle + from;
const end = currentCycle + to;
setTimeout(() => {
events = this._asNumber(true) // true = silent error
.query(new State(new TimeSpan(begin, end)))
events = this.query(new State(new TimeSpan(begin, end))) //._asNumber(true) // true = silent error
.filter(Boolean)
.filter((event) => event.part.begin.equals(event.whole.begin));
onQuery?.(events);

View File

@ -7,6 +7,13 @@ This program is free software: you can redistribute it and/or modify it under th
import { Pattern } from '@strudel.cycles/core';
const scale = (normalized, min, max) => normalized * (max - min) + min;
const getValue = (e) => {
let value = typeof e.value === 'object' ? e.value.n : e.value;
if (typeof value === 'string') {
value = toMidi(value);
}
return value;
};
Pattern.prototype.pianoroll = function ({
cycles = 4,
@ -75,9 +82,9 @@ Pattern.prototype.pianoroll = function ({
ctx.stroke();
const timePx = scale((event.whole.begin - (flipTime ? to : from)) / timeExtent, ...timeRange);
let durationPx = scale(event.duration / timeExtent, 0, timeAxis);
const value = getValue(event);
const valuePx = scale(
fold ? foldValues.indexOf(event.value) / foldValues.length : (Number(event.value) - minMidi) / valueExtent,
fold ? foldValues.indexOf(value) / foldValues.length : (Number(value) - minMidi) / valueExtent,
...valueRange,
);
let margin = 0;
@ -105,7 +112,6 @@ Pattern.prototype.pianoroll = function ({
from: from - overscan,
to: to + overscan,
onQuery: (events) => {
const getValue = (e) => Number(e.value);
const { min, max, values } = events.reduce(
({ min, max, values }, e) => {
const v = getValue(e);