0.3.0 • Published 1 year ago
@ondas/piano v0.3.0
Piano
A self-container mono-sample piano
A sampled piano. By default is uses Steinway samples with 4 velocity layers from SplendidGrandPiano
import Piano from "@ondas/piano";
const piano = new Piano(new AudioContext());
await piano.ready();
piano.start("C4");
import Piano from "@ondas/piano";
const piano = new Piano(new AudioContext());
// Wait until the audio is loaded
await piano.ready();
// Start and stop
const stopNote = piano.start("C4");
stopNote();
// Schedule
piano.start({ name: "C4", time: audioContext.currentTime });
Install
npm i @ondas/piano
Usage
Start and stop notes
Start function accepts note name, midi number or object:
piano.start("C4");
piano.start(60);
piano.start({ note: "C4" });
piano.start({ midi: "C4" });
Start function returns a stop
function:
const stopNote = piano.start("C4");
stopNote();
You can stop all sounding notes at once:
["D4", "F4", "A4"].map(piano.start);
piano.stop();
Schedule
You can pass an optional time
to note object:
const now = context.currentTime;
piano.start({ note: "C4", time: now });
piano.start({ note: "E4", time: now + 0.5 });
piano.start({ note: "G4", time: now + 1 });