npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

d-piano

v1.0.2

Published

Web Audio instrument using Salamander Grand Piano samples

Readme

d-piano

A web audio piano instrument

About

This is a fork of @tonejs/piano by Yotam Mann with performance optimizations and more active maintaince. Built on high-quality samples from Salamander Grand Piano.

Features

  • High-quality samples - Up to 16 velocity levels across 88 keys (Yamaha C5)
  • Complete instrument - Includes pedal sounds and string harmonics
  • Buffer caching - Audio buffers are cached and shared across multiple piano instances

Install

Install the npm package:

npm install --save d-piano

d-piano requires Tone.js as a peer dependency:

npm install --save tone

Usage

Import

import { Piano } from 'd-piano'

Create and load samples

// create the piano and load 5 velocity steps
const piano = new Piano({
	velocities: 5
})

// connect it to the speaker output
piano.toDestination()

// load all samples (returns a promise)
piano.load().then(() => {
	console.log('Piano loaded!')
})

Multiple Piano Instances (Optimized)

The enhanced caching system makes creating multiple pianos efficient:

// Create multiple piano instances - audio buffers are shared automatically
const piano1 = new Piano({ velocities: 3 })
const piano2 = new Piano({ velocities: 5 })
const piano3 = new Piano({ velocities: 1 })

// Load all pianos - samples are fetched only once and shared
Promise.all([
	piano1.load(),
	piano2.load(), 
	piano3.load()
]).then(() => {
	console.log('All pianos loaded with optimized caching!')
})

API Reference

Piano Options

interface PianoOptions {
	velocities: number;    // Number of velocity steps to load (default: 1, max: 16)
	minNote: number;       // Lowest MIDI note to load (default: 21)
	maxNote: number;       // Highest MIDI note to load (default: 108)
	release: boolean;      // Include release sounds (default: false)
	pedal: boolean;        // Include pedal sounds (default: true)
	url: string;           // Custom sample URL (optional)
	maxPolyphony: number;  // Max simultaneous notes (default: 32)
	volume: {              // Component volume levels in dB (default: 0)
		pedal: number;
		strings: number;
		keybed: number;
		harmonics: number;
	}
}

Methods

.keyDown({ note: string, time?: Time, velocity?: number })

Press a note down on the piano.

// Play a 'C4' immediately
piano.keyDown({ note: 'C4' })

// Play a 'C4' 1 second from now with velocity 0.8
piano.keyDown({ note: 'C4', time: '+1', velocity: 0.8 })

.keyUp({ note: string, time?: Time })

Release a note at the given time.

// Release the pressed 'C4' immediately
piano.keyUp({ note: 'C4' })

.pedalDown({ time?: Time })

Press and hold the sustain pedal. Notes played while the pedal is down will be sustained until the pedal is released.

.pedalUp({ time?: Time })

Release the sustain pedal and dampen any sustained notes.

.load(): Promise<void>

Load all audio samples. Returns a promise that resolves when loading is complete.

.dispose()

Clean up the piano instance and free resources.

Development

Building

npm run build

Testing

npm test

Linting

npm run lint

Credits

This project builds upon the great work of:

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.