pitch-op
October 21, 2015 · View on GitHub
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
API
-
add(a, b) → {Array}
-
Add two pitches or intervals. Can be used to tranpose pitches.
Parameters:
Name Type Description aArray one pitch or interval in pitch-array format
bArray the other pitch or interval in pitch-array format
- Source:
Returns:
both pitches or intervals added in pitch-array format
- Type
- Array
Example
var op = require('pitch-op') op.add([3, 0, 0], [4, 0, 0]) // => [0, 0, 1] -
comparator(descending) → {function}
-
Get a comparator to sort pitches by height (frequency)
Parameters:
Name Type Description descendingBoolean set to
trueif want a descending comparatorReturns:
the comparator function
- Type
- function
Example
arrayOfPitches.sort(op.comparator()) -
multiply(n, a) → {Array}
-
Multiply a pitch or interval by a scalar
Parameters:
Name Type Description nArray the scalar
aArray the pitch or interval in pitch-array format
- Source:
Returns:
the pitch or interval multiplied in pitch-array format
- Type
- Array
Example
var op = require('pitch-op') op.multiply(2, [4, 0, 0]) // => [1, 0, 1] -
pitchClass(pitch) → {Array}
-
Get pitch class of a pitch.
Parameters:
Name Type Description pitchArray the pitch
Returns:
the pitch class of the pitch
- Type
- Array
Example
pitchClass([1, -2, 3]) // => [1, -2, nul] -
semitones(pitch) → {Integer}
-
Get distance in semitones from
[0, 0, 0]('C0'or'1P')Parameters:
Name Type Description pitchArray the pitch or interval
Returns:
the distance
- Type
- Integer
Example
op.semitones([1, 1, 0]) // => 3 op.semitones([0, 0, 0]) // => 0 -
setDefaultOctave(octave, pitch)
-
Set the octave only if not present
This function can be partially applied (Integer -> Array -> Array)
Parameters:
Name Type Description octaveInteger the octave number
pitchArray the pitch
Example
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)) -
setOctave(octave, pitch) → {Array}
-
Set octave of a pitch.
This function can be partially applied (Integer -> Array -> Array)
Parameters:
Name Type Description octaveInteger the octave to set
pitchArray the pitch
Returns:
the pitch with the given octave
- Type
- Array
Example
setOctave(2, [1, 2, 0]) // => [1, 2, 2] // partially applied, you get a function: arrayOfPitchs.map(setOctave(2)) -
simplify(interval) → {Array}
-
Simplify interval (set the octave to 0)
Parameters:
Name Type Description intervalArray the interval
Returns:
the simplified interval
- Type
- Array
Example
op.simplify([1, 2, 3]) // => [1, 2, 0] -
subtract(a, b) → {Array}
-
Subtract two pitches or intervals. Can be used to find the distance between pitches.
Parameters:
Name Type Description aArray one pitch or interval in pitch-array format
bArray the other pitch or interval in pitch-array format
- Source:
Returns:
both pitches or intervals substracted pitch-array format
- Type
- Array
Example
var op = require('pitch-op') op.subtract([4, 0, 0], [3, 0, 0]) // => [1, 0, 0]
generated with docme
License
MIT License