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

tonic.ts

v0.1.0

Published

Music theory and instrument models.

Downloads

5

Readme

Tonic.ts

Build Status Docs

Tonic.ts is a TypeScript library that provides APIs for music theory, drawing pitch constellation diagrams, and calculating guitar chord fingerings.

The API makes use of TypeScript enums, generics, and other TypeScript features. Although it can be used from straight JavaScript, there’s other alternatives (link TBD) for that.

Features

  • Music theory types: Note, Interval, Chord, Scale, PitchClass. See the API documentation.
  • Guitar chord calculator computes fingerings for guitar chords (and chords on other fretted instruments).
  • Graphics package draw chord diagrams and pitch constellations. You can see the latter at Fingerboard.

Examples

[The commented-out lines don't yet work.]

import { Chord, ChordQuality, Interval, Intervals, Key, Note, Scale } from 'tonic';
import { frettingFor } from 'tonic';

// Hemholtz and Scientific pitch notation
Note.fromString('C4') instanceof Note; // => true
Note.fromString('C♯4') instanceof Note; // => true
Note.fromString('C♭4') instanceof Note; // => true

// Unicode and ASCII sharps and flats
// Note.fromString('C#4') === Note.fromString('C♯4'); // => true
// Note.fromString('Cb4') === Note.fromString('C♭4'); // => true

// Enharmonic equivalents
Note.fromString('E♯4').midiNumber === Note.fromString('F4').midiNumber; // => true
Note.fromString('E4').midiNumber === Note.fromString('F♭4').midiNumber; // => true
Note.fromString('E♯4') === Note.fromString('F4'); // => false
Note.fromString('E4') === Note.fromString('F♭4'); // => false
Note.fromString('C4').octave; // => 4
Note.fromString('C4').midiNumber; // => 60
Note.fromMidiNumber(60); // ~> C4

// Intervals
Interval.fromString('M3');
Intervals.m3.semitones; // => 3
Intervals.M3.semitones; // => 4
Intervals.A3.semitones; // => 5
Intervals.d4.semitones; // => 4
Intervals.P4.semitones; // => 5
Intervals.A4.semitones; // => 6
Intervals.M3.number; // => 3
Intervals.M3.quality; // => 'M'

// Interval arithmetic
Intervals.M3.add(Intervals.m3); // ~> P5
Intervals.m3.add(Intervals.M3); // ~> P5
Intervals.m3.add(Intervals.m3); // ~> d5
Intervals.M3.add(Intervals.M3); // ~> A5

Note.fromString('C4').add(Intervals.M3); // ~> E4
Note.fromString('C4').add(Intervals.A3); // ~> E♯4
Note.fromString('C4').add(Intervals.d4); // ~> F♭4
Note.fromString('C4').add(Intervals.P4); // ~> F4

Interval.between(Note.fromString('C4'), Note.fromString('C4')); // ~> P1
Interval.between(Note.fromString('D4'), Note.fromString('C4')); // ~> M2
Interval.between(Note.fromString('E4'), Note.fromString('C4')); // ~> M3
// Interval.between(Note.fromString('E♯4'), Note.fromString('C4')); // ~> A3
// Interval.between(Note.fromString('F♭4'), Note.fromString('C4')); // ~> d4
Interval.between(Note.fromString('F4'), Note.fromString('C4')); // ~> P4

// Chords
Chord.fromString('E Major');
ChordQuality.fromString('Dominant 7th'); // ~> Dom 7th
ChordQuality.fromIntervals([Intervals.P1, Intervals.M3, Intervals.P5]); // ~> Major
ChordQuality.fromIntervals([Intervals.P1, Intervals.m3, Intervals.P5]); // ~> Minor
// ChordQuality.fromIntervals([
//   Intervals.P1,
//   Intervals.m3,
//   Intervals.P5,
//   Intervals.m7,
// ]); // => Min 7th

// Scales
const scale = Scale.fromString('Diatonic Major');
scale.intervals; // ~> [P1, M2, M3, P4, P5, M6, M7]
scale.modes; // ~> [Ionian, Dorian, Phrygian, Lydian, Mixolydian, Aeolian, Locrian]
// scale.modes.get('Dorian').intervals; // => [P1, M2, m3, P4, P5, M6, m7]

const key = scale.at(Note.fromString('E4'));
key.intervals; // ~> [P1, M2, M3, P4, P5, M6, M7]
key.pitchClasses; // ~> [0, 2, 4, 5, 7, 9, 11]

// Instruments and fret fingerings
frettingFor('E Major')?.ascii; // ~> 022100

Status

  • The API might change. In particular, FrettedChord might change back to Fingering.
  • The graphics functions haven’t been tested since being ported from CoffeeScript.

Other Languages

License

MIT