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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tonejs/piano

v0.2.1

Published

Web Audio instrument using Salamander Grand Piano samples

Downloads

2,647

Readme

Piano Logo with keyboard and knobs

@tonejs/piano

Tone Piano is a Web Audio instrument which uses high-quality multi-sampled piano sounds provided by Salamander Grand Piano

It has up to 16 velocity levels across 88 keys (sampled every third note) of a Yamaha C5.

Install

Install the npm package:

npm install --save @tonejs/piano

Tone Piano requires Tone.js as a peer dependency (and webmidi to use MidiKeyboard):

npm install --save tone
# optional
npm install --save webmidi

Usage

Import

Using CommonJS:

const Piano = require('@tonejs/piano');

Using ES6 modules:

import { Piano } from '@tonejs/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()

All of the samples are loaded with the load() method which returns a promise

piano.load().then(() => {
	console.log('loaded!')
})

API reference

Once the samples are loaded, it exposes 4 methods for playing the notes:

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

Press a note down on the piano. Optionally give it a time using Tone.js time notation or seconds relative to the AudioContext clock.

The velocity is a value between 0-1.

//play a 'C4' 1 second from now
piano.keyDown('C4', '+1')

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

Release a note at the given time.

//release the pressed 'C4' immediately
piano.keyUp('C4')

.pedalDown(time?: Time)

Press and hold the pedal starting at the given time. While the pedal is down, notes scheduled after the time will be sustained and released once the pedal is lifted.

.pedalUp(time?: Time)

Release the pedal and also dampen any notes which are currently sustained.