require('sharp11').midi
Contains a Midi object, which can be created with midi.create()
, and some helpful functions for dealing with MIDI data that are used internally. Methods of the Midi object do not mutate it, they return a new object.
Returns a Midi object given an optional settings object, which can contain any of the following properties:
tempo
- The tempo in beats per minute. Default value is 120.swingRatio
- A number (1 to 3) representing the ratio of the first note to the second note for swing eighth notes.1
yields straight eighth notes.1.5
yields a swing feel.2
yields a triplet feel.3
yields a dotted feel. Default value is1.5
.melodyPatch
- A number (1 to 128) representing the midi patch of the melody instrument. Default value is 57 (Trumpet).chordPatch
- A number (1 to 128) representing the midi patch of the chord instrument. Default value is 1 (Acoustic Grand Piano).noteVelocity
- A number (1 to 127) representing the velocity with which melody notes are played. Default value is 80.chordVelocity
- A number (1 to 127) representing the velocity with which chords are played. Default value is 60.chordOctave
- A number (1 to 6) representing the octave in which chords should be played. Default value is 4.
Given a Duration and a settings
object, returns the number of ticks for that note (assuming 96 ticks per beat).
Given a number, returns a Buffer with that number represented as a MIDI-compatible Variable-Length Quantity (VLQ).
Given a Note object, return its MIDI number.
Midi
objects are used to create MIDI representations of Sharp11 objects. Supported objects will expose a .midi()
method to assemble the corresponding Midi
object.
The settings
that yielded the MIDI output.
Adds a track of chords specified by an array of objects, each with a key chord
that corresponds to a Chord object, and a key duration
that corresponds to a Duration object.
Adds a track of notes specified by an array of objects, each with a key note
that corresponds to a Note object or null
for a rest, and a key duration
that corresponds to a Duration object.
Returns a Buffer containing the raw MIDI data.
Asynchronously writes the MIDI output to a file. Server-side only.
Synchronously writes the MIDI output to a file. Server-side only.