0.0.1
JSMidi is a singleton class that provides the shared state and interface we need to schedule MIDI events, manage tracks, control the loop and set musical form/structure.
(Object)
: object to store instruments by name
(Object)
: MIDI event tracking object
(JSMidiIO)
: MIDI I/O controller via Web Midi API
(JSMidiLoop)
: main loop
(JSMidiBuilder)
: action builder
Adds a JSMidiInstrument to the tracks object by name
(JSMidiInstrument)
Removes a JSMidiInstrument from the tracks object by name
(JSMidiInstrument)
Resets each instrument in the tracks object. This is required when live coding. We need to reset each instrument before we rebuild its events.
Schedule off messages for any outstanding notes or sustains in the scheduled events object. This is called when the loop stops.
Send off messages for all notes and sustains for each instrument/track.
TODO: need to test this!
Reset tracks, events and loop.
Schedule an individual MIDI event at time.
(JSMidiEvent)
event object
(Number?
= 0
)
performance time to execute the event
Adds event listeners for position scheduling and loop stop events.
JSMidiLoop is the musical time keeper and scheduler. The loop is broken down by position into parts, bars and beats based on the JSMidiForm. It works its way through the each position scheduling future MIDI events at each next position in the loop.
(Number?)
number of bars
(Number?)
number of beats
(Array?)
an array of parts made of bars and beats
(Boolean?)
whether to start over at the end of the loop
(Number?)
number of miliseconds to wait before starting the loop
(Number?)
max number of restarts allowed
(Number)
: current bar
(Number)
: current beat
(Number)
: current part
(String)
: current position
(Boolean)
: if the loop is "playing" or not
(Number)
: number of times the loop has restarted
(JSMidiForm)
: musical form of the loop/song
(NanoTimer)
: used for setting timeouts
(EventEmitter2)
: used for emitting events
Stops the loop, sends off messages for any open notes or sustains on each track and clears the timer.
Restarts the loop. Note that this is not the same as restartPlayback in the Atom plugin.
Turns repeat on.
Turns repeat off.
Resets the loop.
JSMidiIO is the main midi I/O controller. It is esentially a wrapper for the Web MIDI API.
(Array)
: array of available inputs
(Array)
: array of available outputs
(Object)
: Web MIDI API instance
(Object)
: window's performance time object
(Object)
: selected Web MIDI output
(Object)
: selected Web MIDI input
JSMidiInstrument is how we define and interact with virtual instruments in Logic Pro, Ableton, Garage Band, etc.
(String)
name of the instrument
(Object)
: MIDI events by position
(Object)
: event tracking by position
(Object)
: positions where the instrument should rest
Play any number of notes at position.
(String)
loop position
((JSMidiBuilder | Object))
action properties
Stop any number of notes at position.
(String)
loop position
((JSMidiBuilder | Object))
action properties
Sequences a pattern for a single note. Primarily used for making drum sequences easy. In the pattern values less than zero will be treated as a rest.
(String)
loop position
(any)
(Array)
pattern of holds and rests
((JSMidiBuilder | Object))
action properties
Adds an ordered sequence of events to the event queue. Each action requires a hold time so it can calculate when to take the next action in the sequence.
Adds "noteon" events for an action.
(String)
loop position
(JSMidiAction)
action object
Adds "noteoff" events for an action.
(String)
loop position
(JSMidiAction)
action object
Mutes the instrument.
Unmutes the instrument.
Resets the instrument to its inital state. When live coding, if changes are made to the Live file we need to reset the events and tracking so changes are reflected.
JSMidiPosition is a class to expand a position's bars and beats. Parts are not expanded since most songs will not have a ton of parts.
(String)
loop position
JSMidiAction is a class to describe instrumental actions like playing a chord, playing a series of notes or putting the sustain on. It accepts a plain object or a builder object with the action property set.
((Object | JSMidiBuilder)?)
action
Name | Description |
---|---|
props.type String?
|
action type |
props.chord String?
|
TonalJS chord name |
props.notes (String | Array)?
|
a single note or array of notes |
props.velocity Number?
|
action's velocity |
props.after Number?
|
how long to wait to execute an action |
props.hold Number?
|
how long to hold an action |
JSMidiBuilder is a class to build action objects that can be chained together for less verbose syntax. We only expose functions that can kick off a chain.
(Object)
action object
Sets the action's notes value.
JSMidiBuilder
:
Sets the action's chord value.
(String)
TonalJS chord name
JSMidiBuilder
:
Sets the action's rest value.
(Number)
how long to hold the rest
JSMidiBuilder
:
Sets the action's sustain value.
(Number)
how long to hold the sustain
JSMidiBuilder
:
Sets the action's hold value.
(Number)
hold value
JSMidiBuilder
:
Sets the action's after value.
(Number)
after value
JSMidiBuilder
:
Sets the action's velocity value.
(Number)
velocity value
JSMidiBuilder
:
JSMidiEvent represents MIDI event, like "noteon", with additional values like hold and after that affect timing.
Returns a MIDI message in Web Midi API send format.
Returns an off event for noteon and sustainon events.
Calculates in miliseconds how long to hold the event.
(JSMidiLoop)
Calculates in miliseconds how long to wait before sending the event.
(JSMidiLoop)
Determines if the event has a hold duration.
Determines if the event is an "on" event.
Determines if the event is an "off" event.
Builds a string key based on the channel, type and data properties for tracking if an event is already on or off.
Builds a string key based on a position, type and data properties for tracking if an event has already been added to the JSMidiInstrument events object.
(any)
JSMidiProject defines a project/song that is used to interface with JSMidi. It also initializes WebMidi passed from the JSMidi Atom Plugin and the Atom browser.
This is where the user sets up their project. Define the loop, instruments, tempo, etc.
JSMidiForm represents the musical form or structure of a song. The musical form is broken down into parts, bars and beats which determines the path of the loop.
(Number?)
number of bars
(Number?)
number of beats
(Array?)
array of parts made of bars and beats
(Array)
: upper and lower bounds of the form
Reset the form and reset the bounds.
Gets the first position.
Gets the last position.
Gets the first part.
Gets the last part.
Determines if the loop has parts or not.