Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SoundFontPlayer

A NoteSequence player based on Tone.js that uses SoundFont samples. The loadSamples method may be called before start so that the samples necessary for playing the sequence will be loaded and playing will begin immediately upon start.

Example (explicitly loading samples):

player.loadSamples(seq).then(() => { player.start(seq) })

Explicitly loads samples, so that playing starts immediately when start is called.

Example (implicitly loading samples):

player.start(seq)

If the samples for seq have not already been loaded, playing will only start after all necessary samples have been loaded.

Hierarchy

Index

Constructors

constructor

  • new SoundFontPlayer(soundFontURL: string, output?: any, programOutputs?: Map<number, any>, drumOutputs?: Map<number, any>, callbackObject?: BasePlayerCallback): SoundFontPlayer

Properties

Protected callbackObject

callbackObject: BasePlayerCallback

Protected currentPart

currentPart: any

Protected desiredQPM

desiredQPM: number

Protected playClick

playClick: boolean

Protected scheduledStop

scheduledStop: number

Methods

getAudioNodeOutput

  • getAudioNodeOutput(note: INote): any

getPlayState

  • getPlayState(): any

isPlaying

  • isPlaying(): boolean
  • Returns false iff the player is completely stopped. This will only be false after creating the player or after calling stop(), and will be true after calling start(), pause() or resume().

    Returns boolean

loadAllSamples

  • loadAllSamples(program?: number, isDrum?: boolean): Promise<void>
  • Loads the audio samples for all valid midi pitches, for a specific program. Note: this method is rather slow; only use it if you're sure that you need to load all possible samples (for example, you're playing a stream of live notes from the user) -- otherwise, if you already have the NoteSequence you have to play, use loadSamples instead.

    If you do end up using loadAllSamples, make sure you're calling it asynchronously, as to not block other main thread work (like UI interactions) while waiting for it to finish.

    Parameters

    • Default value program: number = 0

      (optional) Program number to use for instrument lookup. Default is 0.

    • Default value isDrum: boolean = false

      (optional) True if the drum status should be used for instrument lookup. Default is false.

    Returns Promise<void>

loadSamples

  • loadSamples(seq: INoteSequence): Promise<void>
  • Loads the audio samples required to play a NoteSequence.

    Parameters

    • seq: INoteSequence

      The NoteSequence to be played.

    Returns Promise<void>

pause

  • pause(): void
  • Pause playing the currently playing sequence right away. Call resume() to resume.

    throws

    {Error} If the player is stopped.

    Returns void

Protected playNote

  • playNote(time: number, note: INote): void

playNoteDown

  • playNoteDown(note: INote): void

playNoteUp

  • playNoteUp(note: INote): void

resume

  • resume(): void

resumeContext

  • resumeContext(): void
  • Resumes the Audio context. Due to autoplay restrictions, you must call this function in a click handler (i.e. as a result of a user action) before you can start playing audio with a player. This is already done in start(), but you might have to call it yourself if you have any deferred/async calls.

    Returns void

seekTo

  • seekTo(seconds: number): void
  • Seek to a number of seconds in the NoteSequence.

    throws

    {Error} If the player is stopped.

    Parameters

    • seconds: number

    Returns void

setTempo

  • setTempo(qpm: number): void

start

  • start(seq: INoteSequence, qpm?: number, offset?: number): Promise<void>

stop

  • stop(): void

Generated using TypeDoc