danigb / soundfont-player

Quick soundfont loader and player for browser
MIT License
455 stars 59 forks source link

Fix/typescript bindings #67

Closed jnpdx closed 4 years ago

jnpdx commented 5 years ago

Player definitely accepts number or string.

In my use, instrument was buggy to use at least in Safari without having it also accept AudioContext in addition to typeof AudioContext even though the two should be equivalent.

lujiwen commented 5 years ago

@jnpdx Would you please tell me how to use SoundFont.instrument after your modification. My typescript code looks like : const ac: AudioContext = new AudioContext() SoundFont.instrument(ac, 'marimba') .then((instrument) => { }).catch(function (err) { }) but the error message is :

argument type 'AudioContext' is not assignable to parameterof type '{new ():AudioContext; prototype:AudioContext;}' 

can you help me? I am a beginner of typescript, thank you so much!

jnpdx commented 5 years ago

In my case, here's how I had to get the AudioContext (unfortunately, this varies by browser at the moment):

function getAudioContext(): AudioContext { const win: any = window; if (win.AudioContext !== undefined) { return new win.AudioContext(); } else { return new win.webkitAudioContext(); } }

Then, I call Soundfont.instrument with the result of that call.

lujiwen commented 5 years ago

@jnpdx Thank you! It works!

danigb commented 4 years ago

Sorry @jnpdx . Thanks a lot for the PR and sorry for being soooooo late 🙏

I've updated AudioContext typescript bindings (in other PR).

I don't know why name could be a number... Please reopen if I'm wrong with it

sslotsky commented 4 years ago

don't know why name could be a number.

@danigb this is according to your docs!

  // Then you can play a note using names or midi numbers:
  clavinet.play('C4')
  clavinet.play(69)

The play function accepts a number as the first argument but the TypeScript definitions don't, so I think @jnpdx had it right!