Git Product home page Git Product logo

piano's Introduction

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 MidiInput):

npm install --save tone 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({ note: 'C4', time: '+1' })

.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 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.

piano's People

Contributors

tambien avatar giladbarnea avatar teropa avatar dependabot[bot] avatar danigb avatar mrclay avatar abergs avatar zya avatar nunojesus avatar ichpuchtli avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.