Manipulate note pitches with ease. Uses a two valued coordinated system to represent the pitch. Play nicely with intervalo
This is an idea of how teoria.js can be modularized to a very granular level. Inspired by a talk with @saebekassebil and the lodash library.
var pitch = require('pitch');
pitch('a4') // -> [0, 0];
pitch.str([0, 0]) // -> a4
pitch.name([0, 0]) // -> a
pitch.transpose('a2', [-1, 2]) // -> [-1, 2]
Also, you can require the individual methods you need:
var parse = require('pitch/parse');
var transpose = require('pitch/transpose');
var str = require('pitch/str');
str(transpose(parse('c2'), [-1, 2])) // -> d2
This is a list of the implemented methods. All of they are available by default if you require the entrie library:
var pitch = require('pitch');
You can load only the desired method:
var transpose = require('pitch/transpose');
Returns the string symbolic of the accidental sign (x, #, b or bb)
pitch.accidental(pitch('c#2')); // => '#'
Returns the piano key number
pitch.key(pitch('a4')); // => 49
Returns the name of the note, in lowercase letter.
Note: this method is called name
in teoria.js
pitch.letter(pitch('D#3')); // => 'd'
Returns the numeric value of the octave of the note
pitch.octave(pitch('f#5')); // => 5
Returns the coord of the given string (in scientific notation). If the param is an array of two elements, it returns the array
pitch.parse('f#2'); // => [ -4, 3 ]
pitch.parse([ -4, 3 ]) // => [ -4, 3 ]
Note: pitch('c#2')
and pitch.parse('c#2')
are equivalents.
Alias: pitch.toString(coord)
Returns a string representation of the given coordinates in scientific notation.
pitch.str([ -4, 3 ]); // => 'f#2'
pitch.toString([ -4, 3 ]); // => 'f#2'
Transpose the a pitch by an interval. Both parameters must be in coord notation. You can use intervalo library.
If only one interval param is supplied, returns a tranposer: a function that transposes certain interval.
For example, given a M2 ([ -1, 2]
) interval:
pitch.transpose(pitch('e3'), [-1, 2]); // => [-3, 3] (f#3)
var transposer = pitch.transpose([-1, 2]); // Function
transposer(pitch('e3')); // => [-3, 3]
Build a web ready distribution:
npm install
npm test
npm start
## License
MIT License