JSMidi

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.

JSMidi
Properties
tracks (Object) : object to store instruments by name
events (Object) : MIDI event tracking object
io (JSMidiIO) : MIDI I/O controller via Web Midi API
loop (JSMidiLoop) : main loop
builder (JSMidiBuilder) : action builder
Instance Members
setup(midi, time)
addTrack(instrument)
removeTrack(instrument)
resetTracks()
schedule(position, time)
allOff()
fullReset()
reset()
scheduleEvent(event, time = 0)
_addEventListeners()

JSMidiLoop

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.

JSMidiLoop
Parameters
bars (Number?) number of bars
beats (Number?) number of beats
parts (Array?) an array of parts made of bars and beats
repeat (Boolean?) whether to start over at the end of the loop
offset (Number?) number of miliseconds to wait before starting the loop
maxRestarts (Number?) max number of restarts allowed
Properties
bar (Number) : current bar
beat (Number) : current beat
part (Number) : current part
position (String) : current position
playing (Boolean) : if the loop is "playing" or not
restarts (Number) : number of times the loop has restarted
form (JSMidiForm) : musical form of the loop/song
timer (NanoTimer) : used for setting timeouts
events (EventEmitter2) : used for emitting events
Instance Members
update(time = {})
start(time = 0)
stop()
restart()
enableRepeat()
disableRepeat()
focus(start, end)
reset()

JSMidiIO

JSMidiIO is the main midi I/O controller. It is esentially a wrapper for the Web MIDI API.

JSMidiIO
Properties
inputs (Array) : array of available inputs
outputs (Array) : array of available outputs
midi (Object) : Web MIDI API instance
time (Object) : window's performance time object
output (Object) : selected Web MIDI output
input (Object) : selected Web MIDI input
Instance Members
setup(midi, time)
setInput(idx = 0)
setOutput(idx = 0)
now()

JSMidiInstrument

JSMidiInstrument is how we define and interact with virtual instruments in Logic Pro, Ableton, Garage Band, etc.

JSMidiInstrument
Parameters
name (String) name of the instrument
opts (Object) options object
Name Description
opts.channel Number? MIDI channel of the instrument
opts.muted Boolean? instrument's muted state.
Properties
events (Object) : MIDI events by position
tracking (Object) : event tracking by position
rests (Object) : positions where the instrument should rest
Instance Members
play(position, props)
stop(position, props)
at(position, actions)
pattern(position, action, pattern, props)
sequence(position, actions)
noteOn(position, note, opts, options)
noteOff(position, note, opts, options)
sustainOn(position, opts, options)
sustainOff(position, opts, options)
notesOn(position, action)
notesOff(position, action)
rest(start, end)
shouldRest(position)
mute()
unmute()
reset()

JSMidiPosition

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.

JSMidiPosition
Parameters
position (String) loop position
Properties
bars (String) : expanded bars
beats (String) : expanded beats
parts (String) : parts as is

JSMidiAction

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.

JSMidiAction
Parameters
props ((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
Instance Members
getNotes()
getEventOptions()

JSMidiBuilder

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.

JSMidiBuilder
Parameters
action (Object) action object
Static Members
notes(notes)
chord(chord)
rest(hold)
sustain(hold)
Instance Members
hold(hold)
after(after)
velocity(velocity)

JSMidiEvent

JSMidiEvent represents MIDI event, like "noteon", with additional values like hold and after that affect timing.

JSMidiEvent
Parameters
type (String) type of MIDI event
channel (Number) MIDI channel
opts (Number) options object
Name Description
opts.data Number MIDI data value
opts.velocity Number? MIDI event velocity value
opts.after Number? how long to wait before executing the event
opts.hold Number? how long to hold the event
Instance Members
message()
offEvent()
calculateHold(loop)
calculateAfter(loop)
hasDuration()
isOnEvent()
isOffEvent()
trackingKey()
positionKey(pos)

JSMidiProject

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.

JSMidiProject
Parameters
midi (Object) Web MIDI API instance
time (Object) window's performance time
Instance Members
setup()

JSMidiForm

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.

JSMidiForm
Parameters
bars (Number?) number of bars
beats (Number?) number of beats
parts (Array?) array of parts made of bars and beats
Properties
bounds (Array) : upper and lower bounds of the form
Instance Members
update(opts)
reset()
updateBounds(start, end)
getFirstPosition()
getLastPosition()
getPart(part)
getFirstPart()
getLastPart()
hasParts()