Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ piano.load().then(() => {
Once the samples are loaded, it exposes 4 methods for playing the notes:


### `.keyDown({ note: string, time?: Time, velocity?: number })`
### `.keyDown({ note: string|number, 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.

Expand All @@ -72,9 +72,12 @@ The velocity is a value between 0-1.
```javascript
//play a 'C4' 1 second from now
piano.keyDown({ note: 'C4', time: '+1' })

//play a 'C4' via MIDI code
piano.keyDown({ note: 60, time: '+1' })
```

### `.keyUp({ note: string, time?: Time })`
### `.keyUp({ note: string|number, time?: Time })`

Release a note at the given time.

Expand Down
4 changes: 1 addition & 3 deletions src/piano/Piano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ export class Piano extends ToneAudioNode<PianoOptions> {

time = this.toSeconds(time)

if (isString(note)) {
midi = Math.round(Midi(note).toMidi())
}
midi = isString(note) ? Math.round(Midi(note).toMidi()) : note

if (!this._heldNotes.has(midi)) {
// record the start time and velocity
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Piano', async () => {
await piano.load()
piano.keyDown('C4')
piano.pedalDown('+0.2')
piano.keyUp('C4', '+0.5')
piano.keyUp(60, '+0.5')
piano.keyDown('D4', '+0.4')
piano.pedalUp('+3')
})
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('Piano', async () => {
})
await piano.load()
piano.keyDown('C4')
piano.keyDown('E4')
piano.keyDown(64)
piano.keyDown('G4')
piano.pedalDown()
await new Promise(done => setTimeout(done, 100))
Expand Down