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

music-notation

v1.0.1

Published

Parse alterations, notes, intervals and other musical elements with differents notations

Downloads

607

Readme

music-notation npm version

tonal

music-notation is a collection of javascript functions to parse alterations, notes, intervals and other pitched elements using different notations.

Install via npm : npm install --save music-notation

This is part of tonal

Features

  • Parse notes in scientific notation
  • Parse notes in helmholtz notation
  • Parse intervals in short hand notation
  • Parse roman numerals
  • Parse pitched elements (scales, chords, keys)
  • Convert accidentals to alterations and back

Notations

Fifths-octaves-duration array notation

The array notation a format to represent pitches and intervals using fifths, octaves and duration encoded as an array. It's largely based on coord notation by teoria

The array notation is the primary format in this module. All the parse functions (note/parse, interval/parse, ...) converts from string to array format. All the str functions (note/str, interval/str, ...) converts from array notation to string.

A pitch in array notation is an array with different length depending what it stores:

  • 1 length array: pitch classes. It stores the number of fifths from C to the pitch class. For example: 'C' is [ 0 ], 'D' is [ 2 ], 'E' is [ 4 ], and so on.
  • 2 length array: intervals. It stores the number of fifths from unison as first element, and the number of octaves up or down from that fifths. For example, [ 2, 0 ] its '9M' (major ninth) since two fifths span more than a octave, so '2M' (major second) its [ 2, -1 ]
  • 3 length arrays: notes. It's the interval from C0 to the note pitch with an additional value of the duration. For example: 'C2' with no duration would be [0, 2, null].

The purpose of this design is to provide a uniform way to represent pitches (including notes, pitch classes and intervals) so lot of code can be shared, but be able to differentiate them easily.

Note scientific notation

The note scientific notation is a string with the form <letter><alteration><octave>/<duration> where only the letter is mandatory.

You can parse notes in scientific notation with note/parse:

var parse = require('music-notation/note/parse')
parse('C2') // => [0, 2, null]
parse('c2') // => [0, 2, null]

Note helmholtz notation

You can parse and build notes with strings containing note helmholtz notation

Interval shorthand notation

The interval shorthand notation is a way to encode intervals using strings. In tonal the cannonical form is <number><quality> in which the components are reversed from the standard interval shorthand notation. The reason for this is to cleary differenciate between A4 (the note) and 4A (the interval).

The interval shorthand notation parser is capable to understand the reversed and the direct interval notation as well as intervals with the form <number><alteration>:

var parse = require('music-notation/interval/parse')
parse('2M') // => [2, -1] // reverse shorthand notation (tonal's default)
parse('M2') // => [2, -1] // standard shorthand notation
parse('2') // => [2, -1] // number-alteration notation

Roman notation

The roman notation allows to express pitch classes using string with roman numerals. The cannonical form is <alteration><roman> but the parser is capable to understand the <roman><alteration> format:

var parse = require('music-notation/roman/parse')
parse('bII') // => [ -5 ] <= same as `Db`
parse('bii') // => [ -5 ] <= case is ignored
parse('IIb') // => [ -5 ] <= reversed components allowed

Accidentals

You have functions to convert accidentals string to alterations integers (### => 3, for example) and vice versa.

Usage

Read the API documentation to see all the available functions.

License

MIT License