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.
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.
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.
All SuperCollider code is included in a quark inside the quarks/supercollider-redux
directory.
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.
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,
...
});
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 toSCReduxStore
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
});
An enum with the possible values for the ready states of scStoreReadyState
, scLangReadyState
, scSynthReadyState
.
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.