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

@ng-web-apis/midi

v4.11.1

Published

An Observable based library for the use of Web MIDI API with Angular

Downloads

1,354

Readme

ng-web-apis logo Web MIDI API for Angular

npm version npm bundle size codecov

This library contains abstractions and helpful utils to use Web MIDI API idiomatically with Angular.

Install

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

Usage

To use Web MIDI API with your Angular application you can use tokens, RxJs operators and utils included with this package:

Tokens

  • MIDI_SUPPORTboolean value checking browser support
  • SYSEXboolean token responsible for system exclusive access, false by default
  • MIDI_ACCESS — a Promise with MIDIAccess object, depends on SYSEX token for access level
  • MIDI_INPUT — a Promise with MIDIInput. You would need to provide it yourself see utility functions below
  • MIDI_OUTPUT — a Promise with MIDIOutput. You would need to provide it yourself see utility functions below
  • MIDI_MESSAGES — an Observable of MIDIMessageEvent from all MIDIInputs, use rxjs function below to narrow and process the stream

Utility functions

  • You 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>) {}
}
  • You can convert MIDI note to frequency and back using toFrequency and toNote functions. They optionally accept second argument for tuning of middle A note using 440 as default value
  • You can use frequency pipe from FrequencyPipeModule to convert MIDI note to frequency directly in template

RxJs operators

Monotype operators

These 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 property
  • filterByName only lets through messages from particular MIDIInput identifying it by name property
  • notes only lets through played notes messages, normalizing noteOff messages to noteOn with 0 velocity
  • aftertouch only lets through aftertouch messages, same logic goes fow all functions below
  • modulationWheel
  • pan
  • pitchBend
  • polyphonicAftertouch
  • programChange
  • sustainPedal

If you believe other operators could be helpful, please file an issue explaining what would you like to be added and why.

Operators

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.

Keep 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).

Demo

You can try online demo here

See also

Other Web APIs for Angular by @ng-web-apis