An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# pitch-op

[![Build Status](https://travis-ci.org/danigb/music-chord.svg?branch=master)](https://travis-ci.org/danigb/music-chord)
[![Code Climate](https://codeclimate.com/github/danigb/music-chord/badges/gpa.svg)](https://codeclimate.com/github/danigb/music-chord)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![npm version](https://img.shields.io/npm/v/music-chord.svg)](https://www.npmjs.com/package/music-chord)
[![license](https://img.shields.io/npm/l/music-chord.svg)](https://www.npmjs.com/package/music-chord)
[![pitch-array](https://img.shields.io/badge/pitch--array-compatible-yellow.svg)](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:


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](https://github.com/thlorenz/docme)*

## License

MIT License