diff --git a/README.md b/README.md index f374424..d9b7cd4 100644 --- a/README.md +++ b/README.md @@ -20,25 +20,54 @@ All SuperCollider code is included in a [quark](http://doc.sccode.org/Guides/Usi * `SCReduxStore`: Class that implements the state store replica in SuperCollider. * `SCReduxTempoClockController`: A wrapper for TempoClock which will take a tempo from the Redux store. -## JavaScript Module -### Actions +## JavaScript Interface +### `reducer` +A reducer is provided to store the ready states of the SCReduxStore, sclang, and scsynth: -### Reducer +```javascript +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. + +```javascript +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](https://github.com/reduxjs/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. + +```javascript +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`. + -### Classes -* `SCLangController` - * Starts sclang - * Dispatches actions to store sclang and scsynth boot state - * Optionally takes a string for sclang to interpret when it is booted, helpful for initial setup or configuring audio devices before the server starts. -* `SCStoreController` - * Sends initial state to SuperCollider StateStore - * Forwards subsequent state changes to it - * Creates an `OSCActionListener` to listen for actions -* `OSCActionListener` - * Listens for actions on OSC port and dispatches to store - -## Use Cases +## Example Projects * [Transdimensional Audio Workstation](https://colin-sullivan.net/main/2016/transdimensional-audio-workstation/) * [Touch UI to Generative Music Sequencer in SuperCollider](https://colin-sullivan.net/main/2019/performance-environment/) diff --git a/src/lib/OSCActionListener.js b/src/lib/OSCActionListener.js index 9f91e39..8839505 100644 --- a/src/lib/OSCActionListener.js +++ b/src/lib/OSCActionListener.js @@ -25,6 +25,13 @@ function parse_payload_pairs(payloadPairs) { * to the state store. **/ class OSCActionListener { + /** + * @param {Store} params.store - The state store + * @param {String} params.clientId - A unique string to indicate the dispatch + * origin. + * @param {Number} params.localPort - A number of which port to listen on + * for incoming actions. + **/ constructor(params) { this.params = params; this.store = params.store; diff --git a/src/lib/SCLangController.js b/src/lib/SCLangController.js index 6268a96..f9d6bee 100644 --- a/src/lib/SCLangController.js +++ b/src/lib/SCLangController.js @@ -15,9 +15,9 @@ import { scLangInit, scLangReady, scLangQuit } from "./actions"; /** * @class SCLangController * - * @classdesc Start sclang using @supercollider/lang, dispatching sclang - * ready state to store and running initial sclang commands needed for - * supercollider-redux to work through the API quark. + * @classdesc Start sclang using @supercollider/lang, dispatch actions + * during init sequence, set up a dispatch to run within sclang once scsynth + * has started. **/ class SCLangController { /** diff --git a/src/lib/SCReduxController.js b/src/lib/SCReduxController.js index a41ef88..473713d 100644 --- a/src/lib/SCReduxController.js +++ b/src/lib/SCReduxController.js @@ -1,11 +1,26 @@ import SCStoreController from './SCStoreController'; import SCLangController from './SCLangController'; +/** + * @class SCReduxController + * + * @classdesc A top-level interface for launching SuperCollider and setting + * up the SCReduxStore. + * + * @param {Object} props - See SCLangController and SCStoreController for + * the possible options. + **/ class SCReduxController { constructor(store, props) { this.sclangController = new SCLangController(store, props); this.scStoreController = new SCStoreController(store, props); } + /** + * Start SuperCollider, initialize the replica state store, and set up a + * channels for sending state and receiving actions. + * + * @return {Promise} - Resolves when sclang has booted and store is ready. + **/ boot () { return new Promise((res, rej) => { this.sclangController.boot().then(() => { @@ -13,9 +28,17 @@ class SCReduxController { }).catch(rej); }); } + /** + * A helper method to get the `@supercolliderjs/lang` `SCLang` instance. + **/ getSCLang () { return this.sclangController.getSCLang(); } + /** + * Stop all interfaces and shutdown SuperCollider. + * + * @return {Promise} - Resolves when everything has shutdown. + **/ quit () { return new Promise((res, rej) => { this.scStoreController.quit();