npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lokua/midi-util

v1.0.0-beta.2

Published

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

Downloads

12

Readme

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