danigb / smplr

A web audio sampler instrument
https://danigb.github.io/smplr/
183 stars 19 forks source link

feat: piano loads subset of audio notes in layers #53

Closed georgecartridge closed 10 months ago

georgecartridge commented 10 months ago

Summary: I've introduced the ability for the Splended Grand Piano component to load a subset of its audio files in the configuration object.

Why: This allows you to reduce the amount of audio files downloaded by the user by specifying the notes and a velocity range that the user will play when setting the piano component up.

Changes:

[Additional Note + Example]: notesToLoad.velocityRange will include the notes given in notesToLoad.notes for all velocity layers in that velocity range.

So if a user wants to load audio files for the note C4 for all velocity layers, they can pass a notesToLoad object with this data. The resulting component would look like this

import { SplendidGrandPiano } from "smplr";

const context = new AudioContext();
const piano = new SplendidGrandPiano(context, { 
     notesToLoad:  {
          notes: [60],
          velocityRange: [1, 127],
     }
});

piano.start({ note: "C4" });
danigb commented 10 months ago

Thanks!

danigb commented 10 months ago

BTW, published v0.12.0

georgecartridge commented 10 months ago

BTW, published v0.12.0

I just tried updating my smplr version but the feature changes don't seem to have been published in the package. The updated README file is there, just not the code in the merged commit.