Jazz-Soft.net
We make it sound!
Home » Documentation » JZZ.js » JZZ.gui.Player

JZZ.gui.Player

MIDI Player

MIDI Player GUI for browser.

Construction

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:

load()

player.load(smf) - load the MIDI data and enable the playback buttons.

smf is a JZZ.MIDI.SMF object.

play()

player.play() - start or resume playing if stopped or paused.

stop()

player.stop() - stop and skip to the beginning if playing or paused.

pause()

player.pause(value) - pause / resume.

value - if true - pause; if false - resume; if undefined - toggle between paused / resumed states.

loop()

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.

type()

player.type() - return the type of the MIDI file (0, 1 or 0).

tracks()

player.tracks() - return the number of MIDI tracks in the file.

duration()

player.duration() - return the MIDI file duration in MIDI ticks.

durationMS()

player.durationMS() - return the MIDI file duration in milliseconds.

position()

player.position() - return the current MIDI file position in MIDI ticks.

positionMS()

player.positionMS() - return the current MIDI file position in milliseconds.

jump()

player.jump(pos) - jump to the specified position in MIDI ticks.

pos - position in MIDI ticks.

jumpMS()

player.jumpMS(pos) - jump to the specified position in milliseconds.

pos - position in milliseconds.

tick2ms()

player.tick2ms(t) - convert the position in MIDI ticks into milliseconds.

t - position in MIDI ticks.

ms2tick()

player.ms2tick(t) - convert the position in milliseconds into MIDI ticks.

t - position in milliseconds.

connect()

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.

disconnect()

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.

destroy()

player.destroy() - destroy the player widget.

Example

<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>

User hooks

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.

Example

player.onLoad = function(smf) { player.play(); };

See also