This commit is contained in:
Felix Roos 2022-02-27 20:09:07 +01:00
parent 4f2f00ee62
commit 31319b4045

View File

@ -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);