Example of the standalone BassoonTracker playback routine, playing a module file without the tracker interface.
Hit the "play" button above to start the playback.
Just include a single JS file and you're good to go.
The most simple example would be:
Please note that most modern browser disable audio playback until a user action, so you may need a "play" button to initiate playback.
Some useful methods:
BassoonTracker.play()
BassoonTracker.stop()
BassoonTracker.togglePlay()
BassoonTracker.isPlaying()
BassoonTracker.getSong()
(gets the current song)
BassoonTracker.getSong().title
BassoonTracker.getSong().length
(in patterns)
BassoonTracker.getSong().patterns
(array of patterns)
BassoonTracker.getSong().patternTable
(array of pattern positions in the song)
BassoonTracker.getSong().instruments
(array instruments/samples in the song)
BassoonTracker.setCurrentSongPosition(songPos)
BassoonTracker.audio
(pointer to the main audio object)
BassoonTracker.audio.playSample(sampleIndex,sampleRate)
The playback itself is scheduled in WebAudio and completely detached from the main JS thread.
Therefore there are no direct events to indicated playback progress.
If you want to display some UI with a progress indicator you will have to keep track of the start time of the song (Audio.context.currentTime)
and call
BassoonTracker.getStateAtTime(time)
periodically
(or
BassoonTracker.getTimeStates()
to get the complete list).
Note that the Tracker schedules audio ahead, so the last item in the BassoonTracker.getTimeStates() list will be in the future.
Refer
to this example with progress tracking for a demo.
If you want to adjust the volume, you can use
BassoonTracker.audio.masterVolume
which is a WebAudio GainNode.
Some more examples: