Class WebAudioMidiOut

The WebAudioMidiOut class is a very simple synthesizer implementation, built on top of the Web Audio API. It is intended to primarily be a quick and dirty way to get some sound out through the web browser. For more advanced sound generation, use either the ToneJSMidiOut for in-browser sounds, or MidiOut for working with external instruments.

The WebAudioMidiOut class implements the IMidiOut interface, so that you can very easily swap out the WebAudioMidiOut for external devices as and when needed.

Hierarchy

  • WebAudioMidiOut

Implements

Constructors

  • Parameters

    • audioContext: AudioContext

      The AudioContext instance which the WebAudioMidiOut is operating within. Example: new shimi.WebAudioMidiOut(new AudioContext());

    Returns WebAudioMidiOut

Accessors

  • get audioContext(): AudioContext
  • The AudioContext instance which the WebAudioMidiOut is operating within.

    Returns AudioContext

  • get isFinished(): boolean
  • Returns true if the WebAudioMidiOut has been instructed to stop everything by the finish() method.

    Returns boolean

  • get notes(): Note[]
  • The notes collection consists of notes which have been started, but not ended yet.

    The WebAudioMidiOut will cycle through this collection on each update, checking to see if it needs to stop the playback of any notes.

    Returns Note[]

  • get ref(): string
  • Provides a way of identifying a WebAudioMidiOut so it can be easily retrieved later

    Returns string

  • set ref(value: string): void
  • Parameters

    • value: string

    Returns void

  • get typeName(): string
  • Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable.

    Returns string

Methods

  • Adds a new note to the WebAudioMidiOut's collection, returning the note that was added.

    If note.on == true, then the the WebAudioMidiOut immediately starts up new oscillators for it.

    Returns

    Parameters

    • note: Note

      The note to add to the WebAudioMidiOut.

    Returns Note

  • Calling this tells the WebAudioMidiOut to stop whatever it's doing and that it will no longer be used.

    Returns void

  • This method accepts an IMidiMessage object, which it interprets and performs the appropriate action. Currently this only supports Note On & Note Off messages.

    Returns

    Parameters

    • message: IMidiMessage

      The IMidiMessage object to be acted upon.

    Returns void

  • Receives a byte-array representation of a MIDI message. The method interprets the message into an IMidiMessage object, and calls the WebAudioMidiOut.sendMessage method with it.

    Parameters

    • data: number[]

      An array of the data to be sent to the synth.

    Returns void

  • Calls the stop() method of all notes which have been added to the WebAudioMidiOut that meet the passed in criteria.

    Parameters

    • Optional filter: ((note: Note) => boolean)

      The criteria for determining which notes need to be stopped. If no filter provided, then all notes are stopped.

        • (note: Note): boolean
        • Parameters

          Returns boolean

    Returns void

  • This method is intended to be called by a clock to provide regular updates. It should be called by consumers of the library.

    Returns

    Parameters

    • deltaMs: number

      How many milliseconds have passed since the last update cycle.

    Returns void

  • Define what sound to use for a specific MIDI channel number.

    Returns

    Returns the WebAudioMidiOut instance, to allow for chaining of operations.

    Parameters

    • channelNumber: number

      The channel being defined, valid values range from 0 - 15.

    • type: any

      The type of waveform being produced, valid values are: 'sine', 'square', 'triangle', or 'sawtooth'.

    • gain: number = 0.1

      The amount of gain to be applied to the waveform. Default value is 0.1.

    Returns WebAudioMidiOut

  • Automatically sets up all undefined channels with default sounds. It cycles through defining each channel with sine, square, sawtooth & triangle wave in turn, so that channels, 0, 4, 8 & 12 would be sine, 1, 5, 9 & 13 would be square, etc.

    Example usage: const synth = new shimi.WebAudioMidiOut(new AudioContext()).withDefaultChannels();

    Returns

    Returns the WebAudioMidiOut instance, to allow for chaining of operations.

    Returns WebAudioMidiOut

  • Provides a way for setting the ref through a chained function call. For example:

    clock.addChild(new WebAudioMidiOut(context).withDefaultChannels().withRef('output'));
    

    Returns

    The calling object.

    Parameters

    • ref: string

      The ref to set on the object.

    Returns IClockChild

Generated using TypeDoc