BasePlugin object

Every JSAP plugin inherits the BasePlugin object, getting all of its members. The BasePlugin is the interface between the host and the plugin architecture

...
    // This attaches the base plugin items to the Object
    BasePlugin.call(this, factory, owner);
...

The excerpt above shows the creation of the BasePlugin object. The BasePlugin handles anything common to all JSAP plugin instances, such as parameter interfaces, audio IO and events. The following section will show how these must be used in a JSAP plugin.

Inputs and Outputs

Every plugin requires inputs and outputs to operate. JSAP currently requires a plugin to have at least one input and one output defined, however these do not neccesarily need to be for audio, just accept audio streams (see IO section.

The BasePlugin handles the public input and output lists for adding, deleting and discovering the interfaces.

ParameterManager

Each plugin is given a ParameterManager which handles the plugins' public parameter interface. Any exposed plugin must be built via the Parameter Manager, as outlined in the Parameter Section. The ParameterManager exposes the following interface:

Shortcuts

Because the PluginManager is called parameter, normally to access the parameters inside the plugin, it would be necessary to type this.parameter.getParameterObject(). The BasePlugin provides a link to certain functions to shorten the steps taken, for instance the parameter object could also be accessed through this.getParameterObject().

Audio Events

Certain sessions will trigger events to pass to the plugins to indicate certain actions have occured, such as starting audio playback. The following functions are defined to aid the interaction with the plugin and the host.

Start playback

When audio playback is to begin, the host will trigger the plugin's start function. The BasePlugin object has this set to an empty function by default. To override this function, simply redeclare the function in the body of your object

The start playback will be triggered on plugins loaded whilst the audio stream is currently playing.

Stop playback

When the audio playback is to stop, the host will trigger the plugin's stop function. By default, this is set to an empty function. To override this function, simply redeclare the function in the body of your object

The next excerpt shows how to override the start and stop functions in the plugin.

// Empty Plugin
var Empty = function (factory, owner) {
    BasePlugin.call(this, factory, owner);
    /* USER MODIFIABLE BEGIN */
    this.start = function(e) {
        console.log("Audio Starting");
    }
    this.stop = function(e) {
        console.log("Audio Stopping");
    }
    /* USER MODIFIABLE END */
}
Empty.prototype = Object.constructor(BasePlugin);
Empty.prototype.constructor = Empty;
Empty.prototype.name = "Empty";

Onload and unload

A plugin constructor is called to create an instance of the plugin, however at this point the plugin is not owned included in any processing chain. If a plugin needs to know its location in a chain, track information or other specific information for it to function, these must only be requested once a plugin is loaded into a chain. The SubFactory calls on a plugins' onload and onunload functions to indicate when a plugin is inserted or removed from a chain. The onload indicates the plugin has been placed in a chain and unload indicates a plugin is removed and no longer processing audio.

// Empty Plugin
var Empty = function (factory, owner) {
    BasePlugin.call(this, factory, owner);
    /* USER MODIFIABLE BEGIN */
    this.onload = function(e) {
        console.log("Loaded into plugin chain");
    }
    this.stop = function(e) {
        console.log("Removed from plugin chain");
    }
    /* USER MODIFIABLE END */
}
Empty.prototype = Object.constructor(BasePlugin);
Empty.prototype.constructor = Empty;
Empty.prototype.name = "Empty";