Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 3.52 KB

midi.md

File metadata and controls

46 lines (34 loc) · 3.52 KB

Sharp11 Midi Module

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.

Exported Functions

create .create(settings)

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 is 1.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.

noteLength .noteLength(duration, settings)

Given a Duration and a settings object, returns the number of ticks for that note (assuming 96 ticks per beat).

makeVLQ .makeVLQ(num)

Given a number, returns a Buffer with that number represented as a MIDI-compatible Variable-Length Quantity (VLQ).

noteValue .noteValue(note)

Given a Note object, return its MIDI number.

Midi Object

Midi objects are used to create MIDI representations of Sharp11 objects. Supported objects will expose a .midi() method to assemble the corresponding Midi object.

settings .settings

The settings that yielded the MIDI output.

addChordTrack .addChordTrack(chordList)

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.

addMelodyTrack .addMelodyTrack(noteList)

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.

data .data()

Returns a Buffer containing the raw MIDI data.

write .write(filename, callback)

Asynchronously writes the MIDI output to a file. Server-side only.

writeSync .writeSync(filename)

Synchronously writes the MIDI output to a file. Server-side only.