Octavian
Octavian is a little utility library for working with musical notes and their frequencies. Super cool, right?
Installation
First things, first: how do I install this thing?
npm install octavian
Maybe you even throw a --save
in there if you feel like keeping it around.
Usage
So, we've got Octavian installed, how do we use it?
var Octavian = ; var note = 'A4';
Or, if you're some kind of hipster…
var Note = Note; var note = 'A4';
The Basics
A Note
has a few properties that we can play around with.
var note = 'A#4'; noteletter; // 'A'notemodifier; // '#'noteoctave; // 4notesignature; // 'A#4'notepianoKey; // 50notefrequency; // 466.164
Normalization
But, what if we toss in some bogus note? Something like E#
, maybe? There is no E#
, right?
var note = 'E#5'; notesignature; // 'F5'
Intervals
Music is all about intervals. We can move up by a semitone or some other interval.
var note = 'C3'; note; // returns a new Note('E3');note; // returns a new Note('G3');note; // returns a new Note('C4');
You can do any of the following:
downOctave()
minorSecond()
majorSecond()
minorThird()
majorThird()
perfectFourth()
diminishedFifth()
perfectFifth()
minorSixth()
majorSixth()
minorSeventh()
majorSeventh()
perfectOctave()
There are also some extra methods that are aliased, if you'd prefer:
augmentedFourth()
third()
fifth()
Chords
You can create chords with Octavian.
const cMajorChord = 'C4' 'major'; cMajorChordnotes; // returns [ { letter: 'C', modifier: null, octave: 4 }, // { letter: 'E', modifier: null, octave: 4 }, // { letter: 'G', modifier: null, octave: 4 } ] cMajorChordsignatures; // returns [ 'C4', 'E4', 'G4' ]cMajorChordfrequencies; // returns [ 261.626, 329.628, 391.995 ]cMajorChordpianoKeys; // returns [ 40, 44, 47 ]
You can create the following chords:
major
majorSixth
majorSeventh
majorSeventhFlatFive
majorSeventhSharpFive
minor
minorSixth
minorSeventh
minorMajor
dominantSeventh
diminished
diminishedSeventh
halfDimished
You're also more than welcome to use the following aliases for any of the above:
maj
is an alias formajor
6
is an alias formajorSixth
maj6
is an alias formajorSixth
7
is an alias formajorSeventh
maj7
is an alias formajorSeventh
maj7b5
is an alias formajorSeventhFlatFive
maj7#5
is an alias formajorSeventhSharpFive
min
is an alias forminor
m
is an alias forminor
min6
is an alias forminorSixth
m6
is an alias forminorSixth
min7
is an alias forminorSeventh
m7
is an alias forminorSeventh
m#7
is an alias forminorMajor
min#7
is an alias forminorMajor
m(maj7)
is an alias forminorMajor
dom7
is an alias fordominantSeventh
dim
is an alias fordiminished
dim7
is an alias fordiminishedSeventh
m7b5
is an alias forhalfDiminshed
Adding Notes to a Chord
You can add notes to a chord manually, if that suits you:
const chord = 'C4'; chordsignatures; // returns ['C4'] chord;chordsignatures; // returns ['C4', 'E4'] chord;chordsignatures; // returns ['C4', 'E4', 'G4']
Turning a Note into a Chord
You can turn any note into the basis for a chord:
const note = 'C4';note; // returns a new chord with only C4 in it.note; // returns a new chord with C4, E4, and G4 in it