spessasus / SpessaSynth

MIDI SoundFont/DLS synthesizer library written in JavaScript.
https://spessasus.github.io/SpessaSynth/
Other
96 stars 12 forks source link

How to monitor the end of mid play? #25

Closed lihongyao closed 3 months ago

lihongyao commented 3 months ago

I use it in react, I don't know how to monitor the end of mid play, can you tell me how to achieve it? Thank you!

spessasus commented 3 months ago

Hi @LiHongyao,

I think the easiest way for detecting when the song has ended (assuming the loop is disabled) is by checking if the currentTime property of the sequencer is equal or larger than the duration property.

Although I can add a new event to the sequencer called addOnSogEndEvent if you'd like!

lihongyao commented 3 months ago

Hi @LiHongyao,

I think the easiest way for detecting when the song has ended (assuming the loop is disabled) is by checking if the currentTime property of the sequencer is equal or larger than the duration property.

Although I can add a new event to the sequencer called addOnSogEndEvent if you'd like!

Thank you very much for your suggestion. If possible, I think adding addOnSogEndEvent is a very meaningful thing. Looking forward to your update, thank you again!

spessasus commented 3 months ago

I've added the onSongEnded event! I hope this helps.

Also, spessasynth_lib is now available as an npm package!. This can be helpful since you use react.