Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ng-web-apis/midi

taiga-family2.8kApache-2.04.12.0TypeScript support: included

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

angular, ng, midi, audio, music, synth, keyboard

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

changelog

4.11.1 (2024-10-14)

🐞 Bug Fixes

  • screen-orientation: Viewport fix initial value (#952) (ab6d632)

4.11.0 (2024-10-14)

🚀 Features

  • screen-orientation: Viewport add new service (#951) (6781bf6)

4.10.2 (2024-10-11)

🐞 Bug Fixes

  • platform: invalid regexp for ios (#950) (34f3458)

4.10.1 (2024-10-10)

🐞 Bug Fixes

  • intersection-observer: fix wrong attributes aliasing (#948) (22a8cde)

4.10.0 (2024-10-10)

🐞 Bug Fixes

  • platform: correct behavior for isApple util (#946) (9a36f07)

4.9.0 (2024-10-10)

🚀 Features

  • platform: add WA_IS_TOUCH, WA_IS_WEBKIT, WA_IS_ANDROID, WA_IS_IOS, WA_IS_MOBILE (#944) (70543f1)

4.8.0 (2024-10-08)

🐞 Bug Fixes

  • typo platform package name (#943) (29b8dc7)

4.7.0 (2024-10-08)

🚀 Features

🐞 Bug Fixes

  • deps: update dependency @types/node to >=22.7.5 (#941) (35b605f)

Changelog

All notable changes to this project will be documented in this file. See conventional commits guidelines.

4.6.5 (2024-09-29)

4.6.4 (2024-09-25)

🐞 Bug Fixes

  • deps: update dependency @types/node to >=22.7.0 (#889) (afaa064)

4.6.3 (2024-09-23)

4.6.2 (2024-09-23)

4.6.1 (2024-09-23)

4.6.0 (2024-09-16)

4.5.0 (2024-09-13)

🚀 Features

🐞 Bug Fixes

4.4.0 (2024-09-12)

🚀 Features

🐞 Bug Fixes

  • coverage bandges (3916016)
  • compat for legacy modules (#559) (b720c40)
  • update peerDependencies (#556) (06f02d9)
  • speech, view-transition: add peer dependencies on appropriate types (#119) (a1ffd76)
  • view transition deploy (#118) (12efc9b)
  • universal: add secondary entry point for mocks (#112) (9e01f2d)

2.1.0 (2022-11-15)

🚀 Features

2.0.1 (2022-07-15)

🐞 Bug Fixes

  • page_visibility: share replay of page visibility (#45) (09b0956)

2.0.0 (2022-01-27)

🚀 Features

  • update to Angular 12 and Ivy (#31) (135f43c)

1.13.0 (2022-01-27)

🚀 Features

  • media_devices: added new token (#33) (2c05446)

1.12.1 (2021-10-15)

🐞 Bug Fixes

  • types: compatibility issues with modern TypeScript (#26) (1c43f38)

1.12.0 (2021-07-12)

🚀 Features

1.11.0 (2021-06-29)

🚀 Features

  • history: add new token (#23) (4ca7c33)
  • caches: add new token (#19) (b49a270)
  • page-visibility: document.hidden -> document.visibilityState (#18) (244ede0)

1.9.0 (2020-10-28)

🚀 Features

  • speech_recognition: add new token (#13) (ad0f627)

1.8.1 (2020-10-26)

🐞 Bug Fixes

1.8.0 (2020-10-26)

🚀 Features

1.7.0 (2020-09-02)

🚀 Features

  • network_information: add new token (492018e)

1.6.1 (2020-08-24)

🐞 Bug Fixes

1.6.0 (2020-08-10)

🚀 Features

  • session_storage: add new token (#10) (a4c39d9)

1.5.0 (2020-07-24)

🚀 Features

1.4.1 (2020-06-29)

🐞 Bug Fixes

1.4.0 (2020-04-30)

🚀 Features

  • css: inject mock object when CSS is not available, i.e. in IE or SSR (acea44c)

1.3.0 (2020-04-29)

🚀 Features

  • tokens: LOCAL_STORAGE, LOCATION, USER_AGENT add new tokens (07c7bda)

1.2.0 (2020-04-29)

🚀 Features

1.1.0 (2020-02-28)

🚀 Features

1.0.1 (2020-01-21)

🐞 Bug Fixes

1.0.0 (2020-01-21)