@torbimusic/core
v1.0.29
Published
## Mision Provide a set of classes to solve many common needs for music theory programming.
Downloads
5
Readme
Torbimusic Core
Mision
Provide a set of classes to solve many common needs for music theory programming.
Quick Start
Install
npm install -s @torbimusic/core
Use
import { Chord, Interval, Note, MajorScale, MinorScale } from '@torbimusic/core'
let note = Note.parse('C')
let chord = Chord.parse('Eb')
let interval = Interval.parse('2M')
let intervalFromCtoEb = note.intervalOf(chord.base.note) // 3m
intervalFromCtoEb.traspose(note) // Eb
interval.traspose(note) // F
chord.traspose(interval.add(intervalFromCtoEb))
let scaleC = MajorScale.from(note) // C Major
scaleC.triads // [C, Dm, Em, F, G, A, B°]
scaleC.traspose(interval) // D Major
Core Objects in the Library
As a summary, the most important objects to use are:
- Interval.
- Note.
- Chord.
- Scale.
Intervals
Represents the distance between two notes.
You can read this table as a summary of what an Interval is.
| Interval | Aliases | Quality | Grades | Semitones | Notes | |--|--|--|--|--|--| | 1 | T | PERFECT | 1 | 0 | 0 | | 2m | | MINOR | 2 | 1 | 1 | | 2 | 2M | MAJOR | 2 | 2 | 1 | | 2aug | | AUGMENTED | 2 | 3 | 1 | | 3m | 3m | MINOR | 3 | 3 | 2 | | 3 | 3M | MAJOR | 3 | 4 | 2 | | 4J | 4 | PERFECT | 4 | 5 | 3 | | 4aug | 4+ 4# | AUGMENTED | 4 | 6 | 3 | | 5J | 5 | PERFECT | 5 | 7 | 4 | | 5aug | 5+ 5# | AUGMENTED | 5 | 8 | 4 | | 6m | | MINOR | 6 | 8 | 5 | | 6M | 6 | MAJOR | 6 | 9 | 5 | | 6aug | 6+ 6# | AUGMENTED | 6 | 10 | 5 | | 7dim | 7° | DIMINISHED | 7 | 9 | 6 | | 7m | | MINOR | 7 | 10 | 6 | | 7M | 7 | MAJOR | 7 | 11 | 6 | | 8 | | PERFECT | 8 | 12 | 7 | | 9m | | MINOR | 9 | 13 | 8 | | 9 | 9M | MAJOR | 9 | 14 | 8 | | 11 | 11J | PERFECT | 11 | 17 | 10 | | 11aug | 11+ 11# | AUGMENTED | 11 | 18 | 10 | | 13m | | MINOR | 13 | 20 | 12 | | 13 | 13M | MAJOR | 13 | 21 | 12 |
How to create an Interval
Use of
for create an Interval from the distance between two notes.
let a = Note.parse('A')
let c = Note.parse('C')
Interval.of(a, c) // 3M
The intervals can be represented as a difference of grades and semitones.
To obtain an Interval from this two things, you must use fromGradesAndSemitones
method.
let grades = 3
let semitones = 4
Interval.fromGradesAndSemitones(grades, semitones) // 3M
Another way to obtain an Interval is using parse
and providing a string representation of the Interval, using the table writed above.
Interval.parse('3M') // 3M
Another utility methods for Intervals
Use the traspose
just for traspose a note as the Interval value.
let note = Note.parse('C')
let interval = Interval.parse('3M')
interval.traspose(note) // 'E'
Use the add
method to compose two Intervals.
let _2M = Interval.parse('2M')
let _2m = Interval.parse('2m')
_2M.add(_2m) // 3m
Note
Represent a musical Note.
How to create an Note
Use fromNote
for create a Note from an American or SouthernEuropean note and a NoteAlteration.
Note.fromNote(AmericanNote.C, NoteAlteration.SHARP) // C#
Note.fromNote(SouthernEuropean.DO, NoteAlteration.SHARP) // C#
Use parse
to create a Note from a string. Can be an American or SouthernEuropean notation.
Note.parse('C') // C
Note.parse('DO') // C
Utility methods in Note
Use enharmonicToNoteAbove
and enharmonicToNoteBelow
to get the enharmonics of a note:
Note.parse('C#').enharmonicToNoteAbove() // Db
Note.parse('Eb').enharmonicToNoteBelow() // D#
Use intervalOf
to get the interval between the current note and the provided one:
let c = Note.parse('C')
let eb = Note.parse('Eb')
c.intervalOf(eb) // 3m