Skip to content

Commit

Permalink
comments and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
colinsullivan committed Nov 16, 2019
1 parent 65bfcdd commit 9e24704
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 19 deletions.
61 changes: 45 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
7 changes: 7 additions & 0 deletions src/lib/OSCActionListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/SCLangController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
23 changes: 23 additions & 0 deletions src/lib/SCReduxController.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
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(() => {
this.scStoreController.init().then(res).catch(rej);
}).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();
Expand Down

0 comments on commit 9e24704

Please sign in to comment.