MIDI Player GUI for browser.
JZZ.gui.Player(parent) or JZZ.gui.Player(x, y) or JZZ.gui.Player(options) - create a new MIDI Player widget; works with or without the new keyword.
parent - parent; can be a DOM object itself, or its id as string.
x, y - coordinates of the top-left corner; if parent is not found or undefined, the widget is created moveable and floating at the specified position.
options - the object with the following keys:
player.load(smf) - load the MIDI data and enable the playback buttons.
smf is a JZZ.MIDI.SMF object.
player.play() - start or resume playing if stopped or paused.
player.stop() - stop and skip to the beginning if playing or paused.
player.pause(value) - pause / resume.
value - if true - pause; if false - resume; if undefined - toggle between paused / resumed states.
player.loop(value) - set / unset the loop.
value - if integer - set the loop to value; if true - set the loop to infinity; if false - unset the loop; if undefined - toggle between infinity / unset loop.
player.type() - return the type of the MIDI file (0, 1 or 0).
player.tracks() - return the number of MIDI tracks in the file.
player.duration() - return the MIDI file duration in MIDI ticks.
player.durationMS() - return the MIDI file duration in milliseconds.
player.position() - return the current MIDI file position in MIDI ticks.
player.positionMS() - return the current MIDI file position in milliseconds.
player.jump(pos) - jump to the specified position in MIDI ticks.
pos - position in MIDI ticks.
player.jumpMS(pos) - jump to the specified position in milliseconds.
pos - position in milliseconds.
player.tick2ms(t) - convert the position in MIDI ticks into milliseconds.
t - position in MIDI ticks.
player.ms2tick(t) - convert the position in milliseconds into MIDI ticks.
t - position in milliseconds.
player.connect(out) - connect an output port or handler that will receive the playback.
out - an output port or a handler function; see MidiIn.connect().
If out is the player itself, it connects to its own MIDI selector and enables the MIDI Setup button.
player.disconnect(out) - disconnect an output port or handler.
out - an output port or a handler function; see MidiIn.disconnect().
If out is the player itself, it disconnects its own MIDI selector and disables the MIDI Setup button.
player.destroy() - destroy the player widget.
player.setUrl(url, name) - set the link button URL and file name.
url URL; normally, a download link for the MIDI file; can be a data URL.
name (optional) download file name if the url is a data URL, otherwise, ignored.
<script src="JZZ.js"></script> <script src="JZZ.gui.Player.js"></script> <script src="JZZ.midi.SMF.js"></script> <div id=player></div> <script><!-- var player = new JZZ.gui.Player('player'); var data = ... // load the MIDI file as string player.load(new JZZ.MIDI.SMF(data)); player.loop(5); player.play(); --></script>
The following functions allow user to set hooks on special events. By default, they do nothing.
player.onLoad(smf) - called when the MIDI data is successfully loaded; smf is an instance of the JZZ.MIDI.SMF class.
player.onSelect(name) - called when the MIDI Output port is successfully selected; name is the port name.
player.onPlay() - called when the playback is started (either by the button click or by calling play()).
player.onStop() - called when the playback is stopped (either by the button click or by calling stop()).
player.onPause() - called when the playback is paused (either by the button click or by calling pause()).
player.onResume() - called when the playback is resumed (either by the button click or by calling pause()).
player.onJump(t) - called when the playback position is changed (either by dragging the knob or by calling jump()/jumpMS()); t is the new position in MIDI ticks.
player.onEnd() - called when the end of the MIDI file is reached; if the plyback is looped, called in the end of each loop.
player.onClose() - called when the widget is closed.
player.onLoad = function(smf) { player.play(); };