media/MidiAudioPlayer. MidiAudioPlayer

A simple MIDI player based on MidiPlayerJS
https://github.com/grimmdude/MidiPlayerJS
See also: http://www.midijs.net (https://github.com/babelsberg/babelsberg-js/tree/master/midijs)

Constructor

new MidiAudioPlayer(data, optionsopt)

MidiAudioPlayer constructor

Parameters:
NameTypeAttributesDefaultDescription
dataexternal:ArrayBuffer

The MIDI file content, in ArrayBuffer format

optionsobject<optional>
{}

Optional params related to the type of soundfont used. Valid options inside this object are:

  • MIDISoundFontObject: An object containing the full soundfont data. When this param is provided, no other one will be used.
  • MIDISoundFontBase: The URL used as base for the current collection of MIDI soundfonts. Defaults to https://clic.xtec.cat/dist/jclic.js/soundfonts/MusyngKite
  • MIDISoundFontName: The MIDI instrument name. Defaults to acoustic_grand_piano. See MIDI.js Soundfonts for full lists of MIDI instrument names.
  • MIDISoundFontExtension: An extension to be added to MIDISoundFontName in order to build the full file name of the soundfont JS file. Defaults to -mp3.js

Members

currentTime

Gets the current time

currentTime

Sets the current time of this player (in milliseconds)

data :external:ArrayBuffer

The MIDI file data used by this MIDI player

Type:
  • external:ArrayBuffer

ended

Checks if the current player has ended or is already playing

mainVolume :number

Main volume of this track (set with a MIDI message of type Controller Change #7)

Type:
  • number

paused

Gets the ' paused' state of the current player

playTo :number

When >0, time position at which the music must end

Type:
  • number

player :external:MidiPlayerJS

The grimmdude's MidiPlayer used by this player

startedNotes :Array.<function()>

This array is used when processing 'Note off' events to stop notes that are currently playing.
It contains a collection of 'instrument.play' instances, one for each active note

Type:
  • Array.<function()>

(static) MIDISoundFontBase :string

The URL used as base for the current collection of MIDI soundfonts.
This value can be overwritten by the global parameter MIDISoundFontBase

Type:
  • string

(static) MIDISoundFontExtension :string

An extension to be added to MIDISoundFontName in order to build the full file name of the soundfont JS file.
Current valid options are -mp3.js and -ogg.js
This value can be overwritten by the global parameter MIDISoundFontExtension

Type:
  • string

(static) MIDISoundFontName :string

The MIDI instrument name.
This value can be overwritten by the global parameter MIDISoundFontName
See MIDI.js Soundfonts for full lists of MIDI instrument names.

Type:
  • string

(static) MIDISoundFontObject :object

An object containing the full soundfont data used by instrument
When this member is set, no other settings related to the sounfFont will be used.
This value can be overwritten by the global parameter MIDISoundFontObject

Type:
  • object

(static) audioContext :external:AudioContext

The external:AudioContext used by this MIDI player.

(static) instrument :external:Instrument

The "Instrument" object used by this MIDI player.
See: https://github.com/danigb/soundfont-player

(static) loadingInstrument :boolean

A flag used to avoid re-entrant calls to prepareInstrument

Type:
  • boolean

Methods

pause()

Pauses the player

play()

Starts or resumes playing

playEvent(ev)

Plays a MIDI event

Parameters:
NameTypeDescription
evobject

The event data. See http://grimmdude.com/MidiPlayerJS/docs/index.html for details

(static) prepareInstrument(options, audioContext)

Initializes the soundfont instrument, loading data from GitHub
NOTE: This will not work when off-line!
TODO: Provided a basic, simple, static soundfont

Parameters:
NameTypeDescription
optionsobject

Optional param with options related to the MIDI soundfont. See details in constructor description.

audioContextexternal:AudioContext

The AudioContext object (see: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext)