Kotlin implementation of the Midi Polyphonic Expression spec. Use in your Java, Kotlin, and JS projects to parse and generate MPE messages.
Example Usage
Parse
var MpeParser = MpeParser var midi = ; var parser = parser var input = ; // ... configure midi input, see https://www.npmjs.com/package/midi input; input;
Generate
var MpeSender = MpeSender var midi = ; var output = ; // ... configure midi output, see https://www.npmjs.com/package/midi output; var sender = sender var finger = sender // have fun with it finger finger finger finger
There are two main classes to use:
MpeParser
: feed your raw midi bytes, receive MPE-specific callbacks.
parse(bytes)
: send in raw midi bytes to be parsed.- This class acts as an EventEmitter,
and will emit the following events:
newNote
: emits aFingerInput
instance (see below) and the id of the MPE zone that it belongs to. This event indicates that a new midi "NoteOn" message has been received by that zone. In other words, a key has been pressed on the MPE instrument.zoneMessage
: emits the original midi byte array and the id of the MPE zone that it was sent to. In the future, this will likely be broken out into more specific events (such aszonePitchBend
)globalMessage
: emits the original midi byte array. In the future, this will likely be broken out into more specific events (such asprogramChange
)
MpeSender
: simulates an MPE controller. Use it's simple API, and register a callback to receive the raw midi messages that it generates. These can be piped directly into your MPE instrument.
sendNewNote(note, velocity)
: play a new note on your simulated controller. This will generate raw midi for a "NoteOn" event and will return aFingerOutput
instance (see below), which can be modulated and eventually released.- This class acts as an EventEmitter,
and will emit the following events:
data
: emits raw midi data in the form of a byte array that can be sent directly to your MPE instrument.
FingerInput
: represents a note being held on an MPE instrument.
- This class acts as an EventEmitter,
and will emit the following events:
pitchBend
: emits a 7 bit integer representing the new pitch bend for this specific "finger", as well as the current pitch bend range in +/- semitonestimbreChange
: emits a 7 bit integer representing the new timbre value for this specific "finger".pressureChange
: emits a 7 bit integer representing the new pressure value for this specific "finger".update
: emits all of the above as a single event, in the order:pitch, pressure, timbre, pitchRange
.end
: emits nothing; indicates that this "finger" has been released.
FingerOutput
: represents a note being held on your simulated MPE controller.
sendPitchBend(pitchBend)
: generates a midi pitch bend message for this specific "finger". That message will be emitted via the parentMidiSender
. The value forpitchBend
should be a 14 bit integer (8192 meaning no bend)sendPressureChange(pressure)
: generates a pressure change message for this specific "finger". That message will be emitted via the parentMidiSender
.
The value forpressure
should be a 7 bit integersendTimbreChange(timbre)
: generates a timbre change message for this specific "finger". That message will be emitted via the parentMidiSender
. This is really a midi control change message (CC74), but the MPE spec has given it special meaning. The value fortimbre
should be a 7 bit integer