• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utilities for reasoning about musical notes, frequencies, and intervals

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 = 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');

The Basics

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.164

Normalization

But, 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'

Intervals

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()

Chords

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:

  • 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 for major
  • 6 is an alias for majorSixth
  • maj6 is an alias for majorSixth
  • 7 is an alias for majorSeventh
  • maj7 is an alias for majorSeventh
  • maj7b5 is an alias for majorSeventhFlatFive
  • maj7#5 is an alias for majorSeventhSharpFive
  • min is an alias for minor
  • m is an alias for minor
  • min6 is an alias for minorSixth
  • m6 is an alias for minorSixth
  • min7 is an alias for minorSeventh
  • m7 is an alias for minorSeventh
  • m#7 is an alias for minorMajor
  • min#7 is an alias for minorMajor
  • m(maj7) is an alias for minorMajor
  • dom7 is an alias for dominantSeventh
  • dim is an alias for diminished
  • dim7 is an alias for diminishedSeventh
  • m7b5 is an alias for halfDiminshed

Adding Notes to a Chord

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']

Turning a Note into a Chord

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 it

Inverting a Chord

You 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' ]

More Repositories

1

frontend-architecture-topics

What constitutes front-end architecture?
379
star
2

react-and-typescript-projects

TypeScript
247
star
3

aws-v2

JavaScript
195
star
4

enterprise-ui-dev

TypeScript
175
star
5

pizza

Where is the best ๐Ÿ• in a given city?
Ruby
174
star
6

think-piece

A demostration application for working with Firebase and Cloud Firestore
JavaScript
159
star
7

cypress

JavaScript
135
star
8

dropbear

JavaScript
105
star
9

making-music

Notes and resources from my talks about making music for fun and profit.
73
star
10

programming-can-be-fun

A list of ideas to get you unstuck and excited about writing code again
63
star
11

rxjs-fundamentals

JavaScript
63
star
12

react-and-typescript

JavaScript
50
star
13

node-phone-formatter

Parsing and formatting phone numbers so you don't have to.
JavaScript
46
star
14

web-performance

HTML
40
star
15

grudges-react-state

JavaScript
37
star
16

jetsetter

JavaScript
36
star
17

AWS-for-Frontend-Engineers

34
star
18

simple-counter-react-state

HTML
28
star
19

noted-base

JavaScript
27
star
20

star-wars-characters-react-state

JavaScript
27
star
21

clipmaster-9000-tutorial

A guide to building your first menubar application with Electron.
CSS
25
star
22

emberconf-chat

An example application for my EmberConf talk
24
star
23

kanbananza

JavaScript
22
star
24

wordman

JavaScript
21
star
25

lunch-rush

JavaScript
21
star
26

react-firebase-first-flight

CSS
21
star
27

nodebots-workshop

JavaScript
20
star
28

grudges

JavaScript
20
star
29

packing-list

TypeScript
19
star
30

firesale-tutorial

A tutorial on building a Markdown renderer in Electron.
CSS
18
star
31

tip-calculator

JavaScript
16
star
32

hottest-takes

JavaScript
16
star
33

nodebots-v2

JavaScript
15
star
34

hot-takes-redux

JavaScript
14
star
35

basic-counter

JavaScript
14
star
36

lots-to-do

JavaScript
12
star
37

web-security

JavaScript
12
star
38

supertasker

TypeScript
12
star
39

accident-counter-rtk

CSS
12
star
40

cypress-starter

HTML
11
star
41

integration-testing-playground

Svelte
11
star
42

pizza-calculator

How many pizzas should we order?
JavaScript
11
star
43

project-notes

JavaScript
11
star
44

face-theremin

Make music using your face and the Web Audio API
HTML
11
star
45

chores-redux

JavaScript
10
star
46

anthology

TypeScript
10
star
47

audiophonic

Experiments with the Web Audio API
HTML
10
star
48

redux-incident-counter

HTML
10
star
49

socket-synth

A multi-user step sequencer built with the Web Audio API and WebSockets
JavaScript
10
star
50

user-signup-react-state

JavaScript
9
star
51

Frontend-Masters-November-2022

JavaScript
9
star
52

jetsetter-rtk

TypeScript
9
star
53

redux-counter

HTML
8
star
54

typescript-boilerplate

Some basic boilerplate for TypeScript projects
JavaScript
8
star
55

spirit-animal-look-book

CSS
8
star
56

clipmaster-v3

TypeScript
7
star
57

musicbot

An exploration with Johnny-Five, Socket.io, and the Web Audio API
JavaScript
7
star
58

simple-counter

An example application for Steve's React, Redux, and MobX workshops.
HTML
7
star
59

noted

JavaScript
7
star
60

react-and-typescript-v2

TypeScript
7
star
61

penance

Fun with custom renderers for React && React Reconciler (get it?)
JavaScript
6
star
62

star-wars-autocomplete

JavaScript
6
star
63

web-api-demos

Demonstrations from my talk at Full Stack
CSS
5
star
64

fem-firesale

CSS
5
star
65

introduction-to-ios

Notes and code from my GDI Introduction to iOS course
Swift
5
star
66

offices-and-dragons

JavaScript
5
star
67

socketry-client

An example Ember application from my Websockets talk at Denver Ember.js
JavaScript
5
star
68

redux-fundamentals

JavaScript
5
star
69

starwars-redux

JavaScript
5
star
70

figma-for-developers

CSS
5
star
71

name-badges

CSS
4
star
72

trapper-keeper

HTML
4
star
73

firesale-nina

CSS
4
star
74

react-vite-template

CSS
4
star
75

babel-lab

JavaScript
4
star
76

idea-box

Ruby
4
star
77

toney-danza

Super simple oscillator for the Web Audio API
CSS
4
star
78

test-driven-object-oriented-javascript

JavaScript
4
star
79

scratch-workshop

Svelte
3
star
80

taskmaster

A simple to-do list because that's how you make front-end tutorials, right?
HTML
3
star
81

firesale-v3

JavaScript
3
star
82

tweet-stream-react

CSS
3
star
83

react-typescript

JavaScript
3
star
84

ruby-processing-session

Ruby
3
star
85

fem-bookmarker

CSS
3
star
86

ecmascript-enumerations

3
star
87

your-first-lines-of-js

A visual and interactive tutorial for learning JavaScript.
CSS
3
star
88

node-fake-email

Take a name and generate a realistic-looking unreal email address
JavaScript
3
star
89

dog-facts-redux

JavaScript
2
star
90

kanbananza-react-state

JavaScript
2
star
91

jukebox

Time to have some fun with some asynchronous JavaScript patterns. ๐Ÿค˜
JavaScript
2
star
92

colors

TypeScript
2
star
93

react-serialize-unsupported-attributes

Render markup with deprecated attributes.
JavaScript
2
star
94

jetsetter-two

JavaScript
2
star
95

state-managment-in-react

2
star
96

jukebox-graphql-resolver-example

A super simple GraphQL demonstration application.
JavaScript
2
star
97

canvas-starter

Some boilerplate for getting started with HTML5 Canvas.
TypeScript
2
star
98

office-rpg

JavaScript
2
star
99

binary-search-trees

A attempt to implement binary search trees in JavaScript
JavaScript
2
star
100

taskmaster-redux

JavaScript
2
star