Skip to content

danigb/pitch-op

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pitch-op

Build Status Code Climate js-standard-style npm version license pitch-array

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:

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:

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
descending Boolean

set to true if want a descending comparator

Source:
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:

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
pitch Array

the pitch

Source:
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

Source:
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

Source:
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

Source:
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

Source:
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:

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

About

Music pitch operator

Resources

License

Stars

Watchers

Forks

Packages

No packages published