kevinsqi / piano-utils

Utilities for building piano components in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

piano-utils

build status

A set of functional utilities to help you build piano UI components in javascript. Extracted from react-piano.

Installation

Install with npm/yarn:

yarn add piano-utils

Usage: MidiNumbers

Import it:

import { MidiNumbers } from 'piano-utils';

Converting note names to midi numbers:

MidiNumbers.fromNote('C#0'); // => 13
MidiNumbers.fromNote('C3'); // => 48
MidiNumbers.fromNote('Eb5'); // => 75

Getting attributes of a midi number:

const attrs = MidiNumbers.getAttributes(51);

// {
//   note: 'Eb3',
//   pitchName: 'Eb',
//   octave: 3,
//   isAccidental: true,
//   midiNumber: 51,
// }

Usage: KeyboardShortcuts

Import it:

import { KeyboardShortcuts } from 'piano-utils';

Building an array of keyboard shortcuts mapping key names to midi numbers:

const shortcuts = KeyboardShortcuts.create({
  firstNote: 48,
  lastNote: 60,
  keyboardConfig: KeyboardShortcuts.HOME_ROW,
});

// {
//   key: 'a',
//   midiNumber: 48,
// },
// {
//   key: 'w',
//   midiNumber: 49,
// },
// {
//   key: 's',
//   midiNumber: 50,
// },
// {
//   key: 'e',
//   midiNumber: 51,
// },
// {
//   key: 'd',
//   midiNumber: 52,
// },

Developing

This library was built with tsdx.

Make changes and keep typescript compiling with:

yarn start

Run tests with:

yarn test

About

Utilities for building piano components in javascript

License:MIT License


Languages

Language:TypeScript 100.0%