JS API Reference BaseDevice class

BaseDevice class

RNBO BaseDevice class.

Remarks

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the BaseDevice class.

Signature

export declare abstract class BaseDevice 

Events

invalidateEvent

read-only

Type: EventSubject<void>

The EventSubject for invalidation of a RNBO Device. This event is triggered when a call to createDevice() is called with this device passed as its second argument.

Example

device.invalidateEvent.subscribe(() => {
  // Handle the invalidation
});

messageEvent

read-only

Type: EventSubject<RNBOMessageEvent>

The EventSubject for going out of the RNBO Device

Example

device.messageEvent.subscribe((e: MessageEvent) => {
  // handle the message event
});

midiEvent

read-only

Type: EventSubject<RNBOMIDIEvent>

The EventSubject for MIDIEvents going out of the RNBO Device

Example

device.midiEvent.subscribe((e: MIDIEvent) => {
  // Handle the MIDIEvent
});

parameterChangeEvent

read-only

Type: EventSubject<Parameter>

The EventSubject for Parameter changes of the RNBO Device

Example

device.parameterChangeEvent.subscribe((param: Parameter) => {
  // Code to execute when the parameter assigned to param has changed
});

presetTouchedEvent

read-only

Type: EventSubject<void>

The EventSubject notification when a Preset-relevant value (e.g. parameter) is changed

Example

device.presetTouchedEvent.subscribe(() => {
  // Code to execute when a preset-relevant value has been changed
});

Properties

context

Type: AudioContext

The AudioContext used for creating the Device. For more information, visit the guide on Working with Web Audio Contexts

dataBufferDescriptions

Type: ExternalDataInfo[]

Retrieve a list of descriptions for data buffer sources within the patch. These contain not only the IDs that can be used to set and retrieve DataBuffers, but also information about the files the patcher requests to be loaded and the type of the files (currently only 32 bit audio buffers supported)

from a Device using BaseDevice.setDataBuffer()

dataBufferIds

Type: ExternalDataId[]

Warning: This API is deprecated.

use dataBufferDescriptions instead

Retrieve a list of ids for data buffer sources within the patch. These ids can be used to set and retrieve DataBuffers from a Device using BaseDevice.setDataBuffer()

inports

Type: MessageInfo[]

Get info describing the device's inports

isInvalid

Type: boolean

Property indicating whether the device is invalid. A Device will be invalidated when passed to createDevice() as the second argument.

isValid

Type: boolean

Property indicating whether the device is valid. A Device will be invalidated when passed to createDevice() as the second argument.

messages

Type: MessageInfo[]

node

Type: AudioNode

Access the AudioNode of the device. Use this to integrate the Device into your WebAudio graph

Example

const context = new AudioContext();
device.node.connect(context.destination);

numInputChannels

Type: number

Number of input channels supported by the Device and available on its BaseDevice.node.

numMIDIInputPorts

Type: number

Number of MIDI Input ports on the device. If no MIDI Input is enabled the number is zero

numMIDIOutputPorts

Type: number

Number of MIDI Output ports on the device. If no MIDI Output is present the number is zero

numOutputChannels

Type: number

Number of output channels supported by the Device and available on its BaseDevice.node.

numParameters

Type: number

Parameter count describing the amount of parameters the device has. Refer to BaseDevice.parameters on how to access the parameters.

outports

Type: MessageInfo[]

Get info describing the device's outports

parameterNotificationSetting

Type: ParameterNotificationSetting

Get or Set how the Device should emit ParameterChangeEvents. See ParameterNotificationSetting for the available options and details.

parameters

Type: Parameter[]

Access the Device parameters as an array. The length of the array equals BaseDevice.numParameters

parametersById

Type: Map<string, Parameter>

Helper property to get the Device parameters as a Map sorted by their unique id.

sourceType

Type: IPatcherSrc["type"]

type

Type: DeviceType

The DeviceType of the Device. An invalid Device will return DeviceType.Invalid.

Methods

bufferDescriptionHasRemoteURL

Determines if buffer info has a remote URL part. For this to be true, it must either have a "url" key, or else the "file" key must point to a url with an http or https scheme.

Parameters

ParameterTypeDescription
infoExternalDataInfoThe buffer info to test

Returns:

boolean

fetchAudioData

Fetch data from a url and decode it into an AudioBuffer

Parameters

ParameterTypeDescription
urlstringThe URL to load the data from
contextAudioContextThe AudioContext to use

Returns:

Promise<AudioBuffer>

getPreset

Get a IPreset from the enclosed RNBO patcher, based on its current state.

Parameters

None.

Returns:

Promise<IRNBOPreset>

loadDataBufferDependencies

Load dependencies for data references. For example, if the patch contained something like [buffer~ anton @url http://fileplace.org/anton.aif], retrieve the data at that URL and load it into the appropriate data buffer.

Parameters

ParameterTypeDescription
dependenciesExternalDataInfo[]an array of ExternalDataInfo containing buffer ids and resource locations

Returns:

Promise<DependencyLoadDescription[]>

Example 1

// Get dependencies from the device. Note that file dependencies
// stored in the device may not have the correct path.
let bufferDescriptions = device.dataBufferDescriptions;

// (optional) Filter out file dependencies
bufferDescriptions = bufferDescriptions.filter(BaseDevice.bufferDescriptionHasRemoteURL)

// load them
device.loadDataBufferDependencies(bufferDescriptions);

Example 2

// Load the exported dependencies.json file
let dependencies = await fetch("dependencies.json");
dependencies = await dependencies.json();

// Load the dependencies into the device
device.loadDataBufferDependencies(dependencies)

releaseDataBuffer

Releases (resets) the contents of a DataBuffer within the Device and returns its contents as a DataBuffer

Parameters

ParameterTypeDescription
idExternalDataIdThe id of the DataBuffer to release

Returns:

Promise<RNBODataBuffer>

scheduleEvent

Schedule Events on the device. Refer to Event for possible events.

Parameters

ParameterTypeDescription
evtRNBOPublicEventThe event to schedule

Returns:

void

setDataBuffer

Sets the contents of the DataBuffer referenced by the given id to the content of the given AudioBuffer. Note that a RNBO Device copies the buffer content in order to keep the original buffer fully intact.

Parameters

ParameterTypeDescription
idExternalDataIdThe id of the DataBuffer to set
dataAudioBufferThe AudioBuffer to use

Returns:

Promise<void>

setDataBuffer

Sets the contents of the DataBuffer referenced by the given id to the content of the given ArrayBuffer. The RNBO Device will interpret the data as an Float32Array. Note that a RNBO Device copies the buffer content in order to keep the original buffer fully intact and considers the data to be given in an interleaved format while considering the provided channel count and sample rate.

Parameters

ParameterTypeDescription
idExternalDataIdThe id of the DataBuffer to set
dataArrayBufferThe ArrayBuffer to use
channelCountnumber
sampleRatenumber

Returns:

Promise<void>

setDataBuffer

Sets the contents of the DataBuffer referenced by the given id to the content of the ArrayBuffer of the provided Float32Array. Note that a RNBO Device copies the buffer content in order to keep the original buffer fully intact and considers the data to be given in an interleaved format while considering the provided channel count and sample rate.

Parameters

ParameterTypeDescription
idExternalDataIdThe id of the DataBuffer to set
dataFloat32ArrayThe Float32Array to use
channelCountnumber
sampleRatenumber

Returns:

Promise<void>

setPreset

Set the state of enclosed RNBO patcher using a IPreset.

Parameters

ParameterTypeDescription
presetIRNBOPreset

Returns:

void

Example

const preset = await device.getPreset();
device.parametersById("gain").value = -70;
device.setPreset(preset); // return to the previous value