Giter Club home page Giter Club logo

tonic.ts's Introduction

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

tonic.ts's People

Contributors

osteele avatar roshbhatia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tonic.ts's Issues

support for Add9 Add2 chord qualities

this is a brilliant library for creating / getting fingering for chords.

is there a reason why Add9 / Add2 are not supported? I tried adding them in the map in chordClassArray i.e.

{ name: 'Add9', abbrs: ['add9'], intervals: 'P1 M3 P5 M9' },

which seemed ok but the resultant chord is undefined.

Can't run yarn install

It seems like the dependencies specified in yarn.lock are out of date or incompatible with each other. Perhaps the event-stream package needs to be updated? Thanks!

yarn
yarn install v1.13.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/event-stream/-/event-stream-3.3.6.tgz: Request failed \"404 Not Found\"".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.