reactive-sequencer
v0.1.9
Published
A powerful sequencer that can be used to sequence anything in the browser or node although it has a strong focus on musical sequencing. Streams allow controlling any parameter efficiently in real time, as well as reacting to any sequencer events. The API
Downloads
11
Readme
reactive-sequencer
🧪
A powerful sequencer that can be used to sequence anything in the browser or node although it has a strong focus on musical sequencing. Streams allow controlling any parameter efficiently in real time, as well as reacting to any sequencer events. The API is modular and designed to be used with external instruments and effects (WebAudio libraries, DAWs, hardware). Basic audio support is included in order to play simple sounds right out of the box.
Get started
Install
yarn add reactive-sequencer
# or
npm install --save reactive-sequencer
Use
import { sequencer } from 'reactive-sequencer'
import { pipe, map, forEach, interval } from 'reactive-fns'
import { randomInteger } from 'random-fns'
import { playSound } from './synth'
const { play, tempo$, setTempo, output$ } = sequencer() // create the sequencer
play() // emit a 'play' event
pipe(
output$,
forEach(playSound)
)
pipe(
tempo$, // streams are always named with a $
map(tempo => `bpm: ${tempo}`)
forEach(console.log) // perform side effects when tempo$ updates
)
pipe(
interval(1000), // emits every second
forEach(() => {
setTempo(randomInteger(110, 130)) // randomize tempo
})
)
Here we see a use of the sequencer
function. It is the most high level function exported from this library. It is composed of other functions with a similar shape to it: they receive (optional) input streams, and output streams along with useful handlers. The sequencer wires them up once and starts reacting to incoming data. This gives full control for altering parameters any time after initialization. The object that is returned by sequencer
contains streams that send note and events data that can be reacted to. It's also possible to use the output streams of data, manipulate and wire back to control the input parameters.
🤯
This approach is very similar to how modular synthesizers work. The user plugs the cables and controls parameters while the machine does the rest. With that in mind, there's 2 things to consider:
- You're working with data streams rather than high frequency audio signal streams.
- The lack of precision in javascript timers requires scheduling instead of directly using the data as it arrives. This library abstracts that so you can focus on other things.
API
Sequencer
Initializing a new sequencer. Use the output streams to react to events, and input streams to change parameters.
You can learn more about the internal workings of the sequencer and the rest of the API here.
☞ functions:
sequencer
☞ types:
SequencerProps
SequencerInputStreams
- run$ - tells the sequencer to play or resume when it emits.
- stop$ - tells the sequencer to stop when it emits.
- pause$ - tells the sequencer to pause when it emits.
SequencerOutputstreams
- run$ - tells the player to play or resume when it emits.
- stop$ - tells the player to stop when it emits.
- pause$ - tells the player to pause when it emits.
PlaybackOutputstreams
- playbackStatus$ - emits
'playing' | 'stopped' | 'paused' | 'resumed'
representing its playback status. - isRunning$ - emits
true
when its status is'playing' | 'resumed'
,false
when it's not. - isPlaying$ - emits
true
when its status is'playing'
,false
when it's not. - isStopped$ - emits
true
when its status is'stopped'
,false
when it's not. - isPaused$ - emits
true
when its status is'paused'
,false
when it's not. - isResumed$ - emits
true
when its status is'resumed'
,false
when it's not. - onRun$ - emits
null
when the sequencer either plays or resumes. - onPlay$ - emits
null
when the sequencer plays. - onStop$ - emits
null
when the sequencer stops. - onPause$ - emits
null
when the sequencer pauses. - onResume$ - emits
null
when the sequencer resumes.
- playbackStatus$ - emits