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

@rharel/music-note-utils

v1.0.1

Published

Compact utility library for modeling and manipulating individual musical notes.

Downloads

4

Readme

Build Status Coverage

Musical Note Utilities

...is a little JavaScript library aiming to help you model and manipulate musical notes.

Installation

Either require('@rharel/music-note-utils') or include in the browser with <script src="music_note_utils.js"></script>.

Usage

var MusicNoteUtilities = require('@rharel/music-note-utils');

or if in-browser:

window.MusicNoteUtilities;

Tuning

By default, the library operates with the assumption that the frequency of A4 is 440Hz, but this can be changed:

MusicNoteUtilities.A4_frequency = 442;  // default is 440

Pitch classes

The PitchClass enumeration provides useful information about each pitch class A-G, and is also a property of the Note object.

var PitchClass = MusicNoteUtilities.PitchClass;

// The class' index (0-6, corresponding to A-G).
PitchClass.A.index;  // 0

// The class' index as a key in an octave
// (an octave has 12 keys).
PitchClass.A.index_in_octave;  // 9

// The class' letter symbol
PitchClass.A.letter;  // "A"

// Gets the class with the specified index.
var A = PitchClass.with_index(0);  // PitchClass.A

Accidentals

The Accidental enumeration provides useful information about possible accidental modifications of a note, and is also a property of the Note object.

var Accidental = MusicNoteUtilities.Accidental;

// The accidental's implied semi-tone shift.
Accidental.None.shift;  // 0
Accidental.Sharp.shift;  // 1
Accidental.Flat.shift;  // -1

// The accidental's symbol.
Accidental.None.symbol;  // ""
Accidental.Sharp.symbol;  // "#"
Accidental.Flat.symbol;  // "b"

Notes

Construction

Note objects can be created by multiple ways:

var Note = MusicNoteUtilities.Note;

// From strings:
var As5 = Note.from_string("A#5");

// From frequencies:
var A4 = Note.from_frequency(440);

// From indices relative to A4:
var A3 = Note.from_index(-12);

// From MIDI numbers:
var A4 = Note.from_midi_number(69);

// Explicitly:
var Cb5 = Note.C(Accidental.Flat, 5);

// Even more explicitly:
var Db5 = new Note(PitchClass.D, Accidental.Flat, 5);

Query and manipulation

The following properties and methods are available on a Note object:

var Ab4 = Note.from_string("Ab4");
var Ab5 = Note.from_string("Ab5");

// Descriptors:
Ab4.pitch_class;  // PitchClass.A
Ab4.accidental;  // Accidental.Flat
Ab4.octave;  // 4
Ab4.is_accidental();  // true
Ab4.is_natural();  // false
Ab4.index();  // -1
Ab4.C4_index();  // 8 (relative to C4 instead of A4)
Ab4.midi_number();  // 68
Ab4.frequency();  // ~415 (in Hz)

// As a string:
Ab4.to_string();  // "Ab4"

// Cloning:
var Ab4_clone = Ab4.clone();  // a separate note object

// Equality
Ab4.equals(Ab4);  // true
Ab4.equals(Ab5);  // false

// Transposition:
Ab4.transpose(12).equals(Ab5);  // true

// Variants:
var A4 = Ab4.natural();
var As4 = Ab4.sharp();
Ab4.equals(As4.flat());  // true

License

This software is licensed under the MIT License. See the license file for more information.