
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@ng-web-apis/midi
Advanced tools
An Observable based library for the use of Web MIDI API with Angular
This library contains abstractions and helpful utils to use Web MIDI API idiomatically with Angular.
If you do not have @ng-web-apis/common:
npm i @ng-web-apis/common
You would also need @types/webmidi package until it is included in TypeScript. Now install the package:
npm i @ng-web-apis/midi
To use Web MIDI API with your Angular application you can use tokens, RxJs operators and utils included with this package:
MIDI_SUPPORT — boolean value checking browser supportSYSEX — boolean token responsible for system exclusive access, false by defaultMIDI_ACCESS — a Promise
with MIDIAccess object, depends on SYSEX token for
access levelMIDI_INPUT — a Promise with
MIDIInput. You would need to provide it yourself see
utility functions belowMIDI_OUTPUT — a Promise
with MIDIOutput. You would need to provide it yourself
see utility functions belowMIDI_MESSAGES — an Observable of
MIDIMessageEvent from all
MIDIInputs, use rxjs function below to narrow and
process the streamYou can provide MIDI_INPUT and MIDI_OUTPUT tokens with following functions:
inputById, inputByName, outputById, outputByName:
import {Component, Inject} from '@angular/core';
import {inputById, MIDI_INPUT, MIDI_OUTPUT, outputByName} from '@ng-web-apis/midi';
@Component({
  selector: 'my-comp',
  template: '...',
  providers: [inputById('input-0'), outputByName('VirtualMIDISynth')],
})
export class Example {
  constructor(@Inject(MIDI_INPUT) input: Promise<MIDIInput>, @Inject(MIDI_OUTPUT) output: Promise<MIDIOutput>) {}
}
toFrequency and toNote functions. They optionally accept
second argument for tuning of middle A note using 440 as default valuefrequency pipe from FrequencyPipeModule to convert MIDI note to frequency directly in templateThese are filtering operators which you can use on MIDI_MESSAGES stream to narrow it to your needs. All of them are
applied like that:
messages$.pipe(filterByChannel(1), aftertouch());
filterByChannel only lets through messages from given channel (0 to 15)filterById only lets through messages from particular
MIDIInput identifying it by id propertyfilterByName only lets through messages from particular
MIDIInput identifying it by name propertynotes only lets through played notes messages, normalizing noteOff messages to noteOn with 0 velocityaftertouch only lets through aftertouch messages, same logic goes fow all functions belowmodulationWheelpanpitchBendpolyphonicAftertouchprogramChangesustainPedalIf you believe other operators could be helpful, please file an issue explaining what would you like to be added and why.
These are used to convert message to something necessary for you, since it turns MIDIMessageEvents to different objects, use it after all monotype operations from the list above have been applied.
toData — extracts data
Uint8Array from each
MIDIMessageEventtoTime — extracts receivedTime timestamp from each
MIDIMessageEventtoStatusByte — extracts first element from data
Uint8ArraytoDataByte — extracts second element from data
Uint8ArraytoValueByte — extracts third element from data
Uint8ArrayKeep in mind some messages might not contain third or even second byte so only use those extractions when you are sure (i.e. filtered the stream to compliant messages beforehand).
You can try online demo here
Other Web APIs for Angular by @ng-web-apis
FAQs
An Observable based library for the use of Web MIDI API with Angular
The npm package @ng-web-apis/midi receives a total of 395 weekly downloads. As such, @ng-web-apis/midi popularity was classified as not popular.
We found that @ng-web-apis/midi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.