From 31319b40451ffbd4364a10a7a2fa42649c27eb75 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 27 Feb 2022 20:09:07 +0100 Subject: [PATCH] piano --- repl/src/tone.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/repl/src/tone.ts b/repl/src/tone.ts index ca459c87..37c96f76 100644 --- a/repl/src/tone.ts +++ b/repl/src/tone.ts @@ -18,6 +18,7 @@ import { Sampler, getDestination } from 'tone'; +import { Piano } from '@tonejs/piano'; // what about // https://www.charlie-roberts.com/gibberish/playground/ @@ -33,6 +34,9 @@ Pattern.prototype.tone = function (instrument) { instrument.triggerAttack(event.value, time); } else if (instrument.constructor.name === 'NoiseSynth') { instrument.triggerAttackRelease(event.duration, time); // noise has no value + } else if (instrument.constructor.name === 'Piano') { + instrument.keyDown({ note: event.value, time, velocity: 0.5 }); + instrument.keyUp({ note: event.value, time: time + event.duration }); } else { instrument.triggerAttackRelease(event.value, event.duration, time); } @@ -55,6 +59,11 @@ export const pluck = (options) => new PluckSynth(options); export const polysynth = (options) => new PolySynth(options); export const sampler = (options) => new Sampler(options); export const synth = (options) => new Synth(options); +export const piano = async (options = { velocities: 1 }) => { + const p = new Piano(options); + await p.load(); + return p; +}; // effect helpers export const vol = (v) => new Gain(v);