1.0.0-beta.2 • Published 5 years ago

@lokua/midi-util v1.0.0-beta.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

midi-util

CommonJS constants for MIDI status types and some basic helper functions (mtof, ftom)

Install

npm i @lokua/midi-util --save

API

(SCREAMING_CONSTANTS)

NOTE_OFF = 128
NOTE_ON = 144
POLYPHONIC_AFTERTOUCH = 160
CONTROL_CHANGE = 176
PROGRAM_CHANGE = 192
CHANNEL_AFTERTOUCH = 208
PITCHBEND = 224
SYSEX = 240
TIME_CODE = 241
SONG_POSITION = 242
SONG_SELECT = 243
TUNE_REQUEST = 246
END_OF_SYSEX = 247
CLOCK = 248
START = 250
CONTINUE = 251
STOP = 252
ACTIVE_SENSING = 254
SYSTEM_RESET = 255

statusMap: Map<number|string, number|string>

lookup readable status string by status code or vis a versa

// status -> type
128 -> 'noteOff'
// etc...

// type -> status
'noteOff' -> 128
// ...

// screaming type -> status
'NOTE_OFF' -> 128
// ...

is***(statusOrMidiMessage: number | MidiMessage): boolean

Check if a status byte or MIDI message is a certain status type

  • isNoteOff
  • isNoteOn
  • isPolyphonicAftertouch
  • isControlChange
  • isProgramChange
  • isChannelAftertouch
  • isPitchBend
  • isSysex
  • isSongPosition
  • isSongSelect
  • isTuneRequest
  • isEndOfSysex
  • isClock
  • isStart
  • isContinue
  • isStop
  • isActiveSensing
  • isSystemReset

mtof(note: number): number

Convert MIDI note number to frequency

ftom(frequency: number): number

Convert frequency to MIDI note number

getChannel(statusOrMidiMessage: number | MidiMessage): number

Given a midi message status, returns the corresponding MIDI channel.

getType(statusOrMidiMessage: number | MidiMessage): string

Returns the message type (ie. noteOn, controlChange) for a given status

getPorts(): Promise<{ inputs: Array<MIDIInputPort>, outputs: Array<MIDIOutputPort> }>

Browser only. Converts the MIDIPortMap objects returned by navigator.requestMIDIAccess into a hash of inputs and outputs arrays.

findPortByName(test: RegExp|string, ports:MIDIPortMap|Array<MIDIPort>): ?MIDIPort

Find a port instance within an array of ports or a Map<any, { name: string }> structure by exact string or RegExp. (Actually, this is really a generic findObjectByName that works with arrays or maps, but, whatever).

Hint - use the i flag when using RegExp to make matching easier on yourself

This method also supports partial application so you can do the following:

const { getPorts, findPortByName } = require('@lokua/midi-util')

// this
const findMidiFighterTwister = findPortByName(/fighter\/twister/i)

const { inputs, outputs } = await getPorts()
const input = findMidiFighterTwister(inputs)
const output = findMidiFighterTwister(outputs)

License

MIT

1.0.0-beta.2

5 years ago

1.0.0-beta.1

5 years ago

1.0.0-beta.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

7 years ago

0.0.3

7 years ago