Closed jnpdx closed 4 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!
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.
@jnpdx Thank you! It works!
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
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!
Player
definitely acceptsnumber
orstring
.In my use,
instrument
was buggy to use at least in Safari without having it also acceptAudioContext
in addition totypeof AudioContext
even though the two should be equivalent.