Added 'end' event for groups. Fixes #69 #95
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #69 , I have added the 'end' event functionality for groups, just as it works for sounds. I've also included its correspondent test.
The 'end' event in Pizzicato is quite different from other events, since it's called by the Web Audio API itself, not by the user. Being so, only the sound receives the 'end' event from the API, using a callback to its node. I found 2 main ways to spread this event from the Pz.Sound itself through the Pizzicato library.
Modify the callback passed to the API to include other trigger calls aside from the one of Pz.Sound. I found this solution awful. No control/visibility at all on what your callback is doing if you modify it multiple times. Very hard to manage different groups needing each one a custom call to its trigger function. Also, this callback should be managed only by the sound itself, modifying it externally was just terrible.
Use the observer pattern to watch the last sound of a group, receiving the events it triggers as parameters. This way the group can easily watch its last element, when it triggers an 'end' event, the group also triggers its 'end' event. I found this to be the most pleasant way to do it. It doesn't modify or affect the current software architecture. The code is short, straightforward and easy to test/maintain. And finally, the observer pattern gives the sound 'class' capabilities that could be needed for other tasks.
Thanks for your time!