https://github.com/danigb/pitch-op
Music pitch operator
https://github.com/danigb/pitch-op
Last synced: 7 months ago
JSON representation
Music pitch operator
- Host: GitHub
- URL: https://github.com/danigb/pitch-op
- Owner: danigb
- License: mit
- Created: 2015-10-12T20:12:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-21T09:53:52.000Z (over 10 years ago)
- Last Synced: 2024-12-27T11:34:48.388Z (over 1 year ago)
- Language: JavaScript
- Size: 134 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
# pitch-op
[](https://travis-ci.org/danigb/music-chord)
[](https://codeclimate.com/github/danigb/music-chord)
[](https://github.com/feross/standard)
[](https://www.npmjs.com/package/music-chord)
[](https://www.npmjs.com/package/music-chord)
[](https://github.com/danigb/pitch-array)
Music pitch operator is a fast and low level library to manipulate pitches or intervals in [pitch-array](https://github.com/danigb/pitch-array) format.
Probably you wanto to use a higher level library:
- [pitch-transpose](https://github.com/danigb/pitch-transpose): transpose pitches
- [music-gamut](https://github.com/danigb/music-gamut): work with groups of notes or intervals
- [music-scale](https://github.com/danigb/music-scale): music scales made easy
- [music-chord](https://github.com/danigb/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
a
Array
one pitch or interval in pitch-array format
b
Array
the other pitch or interval in pitch-array format
- Source:
Returns:
-
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
descending
Boolean
set to true if want a descending comparator
Returns:
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
n
Array
the scalar
a
Array
the pitch or interval in pitch-array format
- Source:
Returns:
-
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
pitch
Array
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
pitch
Array
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
octave
Integer
the octave number
pitch
Array
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
octave
Integer
the octave to set
pitch
Array
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
interval
Array
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
a
Array
one pitch or interval in pitch-array format
b
Array
the other pitch or interval in pitch-array format
- Source:
Returns:
-
Type
-
Array
Example
var op = require('pitch-op')
op.subtract([4, 0, 0], [3, 0, 0]) // => [1, 0, 0]
*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT License