Mixin: SourceMixin

SourceMixin

Interface added to `LfoCore to implement source

Source have some responsability on graph as they mostly control its whole lifecycle. They must implement the start and stop method in order to make sure the graph is initialized and set started to true. A source should never accept and propagate incomming frames until started is set to true.

Source:

Example

class MySource extends SourceMixin(BaseLfo) {}

Members

init

Initialize the graph by calling initModule. When the returned Promise fulfills, the graph can be considered as initialized and start can be called safely. If start is called whithout explicit init, init is made internally, actual start of the graph is then not garanteed to be synchronous.

Source:
Example
// safe initialization and start
source.init().then(() => source.start())
// safe initialization and start
source.start();

processFrame

The implementation should never allow incomming frames if this.started is not true.

Source:
Example
// basic `processFrame` implementation
processFrame(frame) {
  if (this.started === true) {
    this.prepareFrame();
    this.processFunction(frame);
    this.propagateFrame();
  }
}

start

Interface method to implement that starts the graph.

The method main purpose is to make sure take verify initialization step and set started to true when done. Should behave synchronously when called inside init().then() and async if called without init step.

Source:
Example
// basic `start` implementation
start() {
  if (this.initialized === false) {
    if (this.initPromise === null) // init has not yet been called
      this.initPromise = this.init();

    this.initPromise.then(this.start);
    return;
  }

  this.started = true;
}

stop

Interface method to implement that stops the graph.

Source:
Example
// basic `stop` implementation
stop() {
  this.started = false;
}