supercollider-redux
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-alpha.3 • Public • Published

supercollider-redux

Build Status Coverage Status

A library for state synchronization between SuperCollider and Node.js using the Flux design pattern. State flows from a primary state store in Node.js to a replica in SuperCollider which can dispatch actions back to the Node.js store.

How it works

Intended for use with a primary state store in Node.js implemented with Redux. Provides StateStore, a replica state store in SuperCollider which leverages supercolliderjs and the API quark to receive state changes.

The Node.js class SCStoreController forwards state updates to a replica running in sclang and receives actions dispatched from it using a separate OSC channel.

Basic state flow

When actions are dispatched from sclang to the replica StateStore instance, they are passed up to the primary Node.js store via OSC, any reducers written in Node.js can update the state which will then be forwarded back to the replica. The primary / replica design promotes all state changes written as reducers in Redux, centralizing the state in the Node.js process.

SuperCollider API

All SuperCollider code is included in a quark inside the quarks/supercollider-redux directory.

SCReduxStore

Implements the state store replica in SuperCollider. Usage:

var store = SCReduxStore.getInstance();

// Subscribing to state changes
store.subscribe({
    var state = store.getState();

    // This method is called whenever state changes.
});


// Dispatching a message to the Node.js store
store.dispatch((
    type: MyActionTypes['HELLO_WORLD'],
    payload: (
        hello: "world"
    )
));

Other classes:

  • SCRedux: Used as a namespace for storing constants like actionTypes.
  • SCReduxTempoClockController: A wrapper for TempoClock which will take a tempo from the Redux store.

Node.js API

reducer

A reducer is provided to store the ready states of the SCReduxStore, sclang, and scsynth:

import SCRedux from 'supercollider-redux';

const rootReducer = combineReducers({
  [SCRedux.DEFAULT_MOUNT_POINT]: SCRedux.reducer,
  ...
});

SCReduxController

A controller class that starts sclang and initializes the SCReduxStore.

import SCRedux from 'supercollider-redux';

const scReduxController = new SCRedux.SCReduxController(store);

scReduxController.boot().then(() => {
    ...
}).catch((err) => {
    ...
});

Parameters may be passed:

  • scStateSelector: An optional selector (intended use with reselect) to control which portion of the state tree is passed to SCReduxStore in SuperCollider. This will be an important performance consideration in any application.
  • interpretOnLangBoot: A string containing SuperCollider code for sclang to interpret immediately on boot. This is important to, for example, indicate which audio device to use.
const controller = new SCReduxController(store, {
    interpretOnLangBoot: `
s.options.inDevice = "JackRouter";
s.options.outDevice = "JackRouter";
    `,
    scStateSelector: mySCStateSelector
});

Constants

READY_STATES

An enum with the possible values for the ready states of scStoreReadyState, scLangReadyState, scSynthReadyState.

Browser API

The browser API exposes the subset of the functionality of supercollider-redux that may be relevant to a browser UI, the actions, reducers, and constants. As a browser cannot spawn a SuperCollider process, the controller class is not exposed.

Example Projects

Package Sidebar

Install

npm i supercollider-redux

Weekly Downloads

3

Version

1.0.0-alpha.3

License

MIT

Unpacked Size

103 kB

Total Files

58

Last publish

Collaborators

  • colinsullivan