Music pitch operator is a fast and low level library to manipulate pitches or intervals in pitch-array format.
Probably you wanto to use a higher level library:
- pitch-transpose: transpose pitches
- music-gamut: work with groups of notes or intervals
- music-scale: music scales made easy
- music-chord: music chords library
-
Add two pitches or intervals. Can be used to tranpose pitches.
Name Type Description a
Array one pitch or interval in pitch-array format
b
Array the other pitch or interval in pitch-array format
- Source:
both pitches or intervals added in pitch-array format
- Type
- Array
var op = require('pitch-op') op.add([3, 0, 0], [4, 0, 0]) // => [0, 0, 1]
-
Get a comparator to sort pitches by height (frequency)
Name Type Description descending
Boolean set to
true
if want a descending comparatorthe comparator function
- Type
- function
arrayOfPitches.sort(op.comparator())
-
Multiply a pitch or interval by a scalar
Name Type Description n
Array the scalar
a
Array the pitch or interval in pitch-array format
- Source:
the pitch or interval multiplied in pitch-array format
- Type
- Array
var op = require('pitch-op') op.multiply(2, [4, 0, 0]) // => [1, 0, 1]
-
Get pitch class of a pitch.
Name Type Description pitch
Array the pitch
the pitch class of the pitch
- Type
- Array
pitchClass([1, -2, 3]) // => [1, -2, nul]
-
Get distance in semitones from
[0, 0, 0]
('C0'
or'1P'
)Name Type Description pitch
Array the pitch or interval
the distance
- Type
- Integer
op.semitones([1, 1, 0]) // => 3 op.semitones([0, 0, 0]) // => 0
-
Set the octave only if not present
This function can be partially applied (Integer -> Array -> Array)
Name Type Description octave
Integer the octave number
pitch
Array the pitch
op.setDefaultOctave(1, [1, 2, null]) // => [1, 2, 1] op.setDefaultOctave(1, [1, 2, 3]) // => [1, 2, 3] // partially applied: arrayOfPitches.map(op.setDefaultOctave(3))
-
Set octave of a pitch.
This function can be partially applied (Integer -> Array -> Array)
Name Type Description octave
Integer the octave to set
pitch
Array the pitch
the pitch with the given octave
- Type
- Array
setOctave(2, [1, 2, 0]) // => [1, 2, 2] // partially applied, you get a function: arrayOfPitchs.map(setOctave(2))
-
Simplify interval (set the octave to 0)
Name Type Description interval
Array the interval
the simplified interval
- Type
- Array
op.simplify([1, 2, 3]) // => [1, 2, 0]
-
Subtract two pitches or intervals. Can be used to find the distance between pitches.
Name Type Description a
Array one pitch or interval in pitch-array format
b
Array the other pitch or interval in pitch-array format
- Source:
both pitches or intervals substracted pitch-array format
- Type
- Array
var op = require('pitch-op') op.subtract([4, 0, 0], [3, 0, 0]) // => [1, 0, 0]
generated with docme
MIT License