Octavian is a little utility library for working with musical notes and their frequencies. Super cool, right?
First things, first: how do I install this thing?
npm install octavianMaybe you even throw a --save in there if you feel like keeping it around.
So, we've got Octavian installed, how do we use it?
var Octavian = require('octavian');
var note = new Octavian.Note('A4');Or, if you're some kind of hipster…
var Note = require('octavian').Note;
var note = new Note('A4');A Note has a few properties that we can play around with.
var note = new Note('A#4');
note.letter; // 'A'
note.modifier; // '#'
note.octave; // 4
note.signature; // 'A#4'
note.pianoKey; // 50
note.frequency; // 466.164But, what if we toss in some bogus note? Something like E#, maybe? There is no E#, right?
var note = new Note('E#5');
note.signature; // 'F5'Music is all about intervals. We can move up by a semitone or some other interval.
var note = new Note('C3');
note.majorThird(); // returns a new Note('E3');
note.perfectFifth(); // returns a new Note('G3');
note.perfectOctave(); // 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()
You can create chords with Octavian.
const cMajorChord = new Octavian.Chord('C4', 'major');
cMajorChord.notes; // returns [ { letter: 'C', modifier: null, octave: 4 },
// { letter: 'E', modifier: null, octave: 4 },
// { letter: 'G', modifier: null, octave: 4 } ]
cMajorChord.signatures; // returns [ 'C4', 'E4', 'G4' ]
cMajorChord.frequencies; // returns [ 261.626, 329.628, 391.995 ]
cMajorChord.pianoKeys; // returns [ 40, 44, 47 ]You can create the following chords:
majormajorSixthmajorSeventhmajorSeventhFlatFivemajorSeventhSharpFiveminorminorSixthminorSeventhminorMajordominantSeventhdiminisheddiminishedSeventhhalfDimished
You're also more than welcome to use the following aliases for any of the above:
majis an alias formajor6is an alias formajorSixthmaj6is an alias formajorSixth7is an alias formajorSeventhmaj7is an alias formajorSeventhmaj7b5is an alias formajorSeventhFlatFivemaj7#5is an alias formajorSeventhSharpFiveminis an alias forminormis an alias forminormin6is an alias forminorSixthm6is an alias forminorSixthmin7is an alias forminorSeventhm7is an alias forminorSeventhm#7is an alias forminorMajormin#7is an alias forminorMajorm(maj7)is an alias forminorMajordom7is an alias fordominantSeventhdimis an alias fordiminisheddim7is an alias fordiminishedSeventhm7b5is an alias forhalfDiminshed
You can add notes to a chord manually, if that suits you:
const chord = new Octavian.Chord('C4');
chord.signatures; // returns ['C4']
chord.addInterval('majorThird');
chord.signatures; // returns ['C4', 'E4']
chord.addInterval(7);
chord.signatures; // returns ['C4', 'E4', 'G4']You can turn any note into the basis for a chord:
const note = new Octavian.Note('C4');
note.toChord(); // returns a new chord with only C4 in it.
note.toChord('major'); // returns a new chord with C4, E4, and G4 in itYou can invert a chord. For a Triad, two inversions exist these can be created
by calling inversion(1) or inversion(2).
const cMajorChord = new Octavian.Chord('C4', 'major');
cMajorChord.signatures; // returns [ 'C4', 'E4', 'G4' ]
cMajorChord.inversion(2);
cMajorChord.signatures; // returns [ 'C5', 'E5', 'G4' ]It's also possible to have Octavian generate a random inversion:
const cMajorChord = new Octavian.Chord('C4', 'major');
cMajorChord.randomInversion();
cMajorChord.signatures; // returns any one of the following:
// [ 'C4', 'E3', 'G3' ]
// [ 'C4', 'E4', 'G3' ]
// [ 'C4', 'E4', 'G4' ]
// [ 'C5', 'E4', 'G4' ]
// [ 'C5', 'E5', 'G4' ]