microtonal
v1.0.0
Published
A micro library for music composition
Downloads
260
Readme
microtonal
The enterprise of “musical set theory” aspires to catalogue all the chords available to contemporary composers. Unfortunately, this project turns out to be more complicated than one might imagine
Microtonal is a micro (3kb) library to create music compositions
- microtonal
- .name ⇒ string
- .names ⇒ array.<string>
- .scaleGen ⇒ function
- .scales
- .pitch(source) ⇒ number
- .midi(pitch) ⇒ integer
- .toFreq(pitch, [tuning]) ⇒ number
- .fromFreq(freq, [tuning]) ⇒ number
- .tr(pitch, interval) ⇒ number
- .trBy(interval) ⇒ function
- .dist(from, to)
- .distFrom(root) ⇒ function
- .inv(pitch, center) ⇒ number
- .invFrom(center) ⇒ function
- .center(from, to) ⇒ number
- .pc(pitch) ⇒ number
- .pctr(pitchClass, interval) ⇒ number
- .pcdist(fromPitchClass, toPitchClass) ⇒ number
- .pcinv(pitchClass, center) ⇒ number
- .mu(pitches) ⇒ array.<number>
- .sort(mu, [ascending]) ⇒ array.<number>
- .uniq(mu) ⇒ array.<number>
- .pitchset(pitches) ⇒ array.<number>
- .pclist(mu) ⇒ array.<number>
- .pcset(mu) ⇒ array.<number>
- .chromatic(tonic) ⇒ function
- .major(tonic) ⇒ function
- .minor(tonic) ⇒ function
- .pentatonic(tonic) ⇒ function
- .degrees(scale, elements)
microtonal.name ⇒ string
Get the note name of a pitch
Kind: static constant of microtonal
Returns: string - the note name if any
| Param | Type | | --- | --- | | pitch | number |
microtonal.names ⇒ array.<string>
Get the note names of a musical object.
Kind: static constant of microtonal
Returns: array.<string> - the musical object note names
| Param | Type | | --- | --- | | list | array.<number> |
Example
names([60, 61, 62]) => // ['C4', 'C#4', 'D4']
microtonal.scaleGen ⇒ function
Creates a scale generator. A scale generator is a function that returns an scale. An scale is a function that, given a degree number, it returns the scale note.
Kind: static constant of microtonal
| Param | Type | Description | | --- | --- | --- | | intervals | arr | the scale intervals during an octave |
Example
const major = scaleGen([0, 2, 4, 5, 7, 9, 11]);
const Cmajor = major(60)
Cmajor(0) // => 60
Cmajor(1) // => 62
microtonal.scales
A collection of named scales. It includes: chromatic, major, minor
Kind: static constant of microtonal
microtonal.pitch(source) ⇒ number
Creates a pitch. A pitch is a float number representing the height of the note. The pitch is the same as the midi number but with float precission.
Basicaly it tries to parse a float
Kind: static method of microtonal
Returns: number - the pitch
| Param | Type | | --- | --- | | source | number | string |
microtonal.midi(pitch) ⇒ integer
Get the midi value of a pitch. The midi value is the pitch without the float
Kind: static method of microtonal
Returns: integer - the midi number
| Param | Type | | --- | --- | | pitch | number |
microtonal.toFreq(pitch, [tuning]) ⇒ number
Convert a pitch into a frequency
Kind: static method of microtonal
Returns: number - the frequency
| Param | Type | Default | | --- | --- | --- | | pitch | number | | | [tuning] | number | 440 |
microtonal.fromFreq(freq, [tuning]) ⇒ number
Convert a frequency into a pitch
Kind: static method of microtonal
Returns: number - the pitch
| Param | Type | Default | | --- | --- | --- | | freq | number | | | [tuning] | number | 440 |
microtonal.tr(pitch, interval) ⇒ number
Transpose a pitch by an interval
Kind: static method of microtonal
Returns: number - the resulting pitch
| Param | Type | | --- | --- | | pitch | number | | interval | number |
Example
tr(4, 3) => 7
microtonal.trBy(interval) ⇒ function
Creates a function that transposes a pitch by an interval
Kind: static method of microtonal
Returns: function - the transpose function
| Param | Type | | --- | --- | | interval | number |
Example
[60, 61, 82].map(trBy(3));
microtonal.dist(from, to)
Finds the distance between two pitches
Kind: static method of microtonal
| Param | Type | | --- | --- | | from | number | | to | number |
microtonal.distFrom(root) ⇒ function
Creates a function that finds a distance from a root
Kind: static method of microtonal
Returns: function - the distance function
| Param | Type | | --- | --- | | root | number |
microtonal.inv(pitch, center) ⇒ number
Invert a pitch along a center
Kind: static method of microtonal
Returns: number - the inverted pitch
| Param | Type | | --- | --- | | pitch | number | | center | number |
microtonal.invFrom(center) ⇒ function
Creates a function that inverts a note from a center
Kind: static method of microtonal
Returns: function - the invert function
| Param | Type | | --- | --- | | center | pitch |
microtonal.center(from, to) ⇒ number
Find the center between two pitches
Kind: static method of microtonal
Returns: number - center
| Param | Type | | --- | --- | | from | number | | to | number |
microtonal.pc(pitch) ⇒ number
Get the pitch class of a pitch
Kind: static method of microtonal
Returns: number - the pitch class number (0 = C, 1 = D, ... 6 = B with numbers in-between)
| Param | Type | | --- | --- | | pitch | number |
microtonal.pctr(pitchClass, interval) ⇒ number
Transpose a pitch class
Kind: static method of microtonal
Returns: number - the pitch class of the transposition
| Param | Type | | --- | --- | | pitchClass | number | | interval | number |
microtonal.pcdist(fromPitchClass, toPitchClass) ⇒ number
Find the distance between pitch classes
Kind: static method of microtonal
Returns: number - the distance (less or equal to 12)
| Param | Type | | --- | --- | | fromPitchClass | number | | toPitchClass | number |
microtonal.pcinv(pitchClass, center) ⇒ number
Invert a pitch class from a center
Kind: static method of microtonal
Returns: number - the pitch class
| Param | Type | | --- | --- | | pitchClass | number | | center | number |
microtonal.mu(pitches) ⇒ array.<number>
Create a musical object. A musical object is as an ordered series of pitches, uncategorized and uninterpreted.
Kind: static method of microtonal
Returns: array.<number> - the musical object
| Param | Type | | --- | --- | | pitches | array.<number> |
Example
mu('C D E') => [0, 2, 4]
microtonal.sort(mu, [ascending]) ⇒ array.<number>
Sort a musical object
Kind: static method of microtonal
Returns: array.<number> - the sorted musical object
| Param | Type | Default | | --- | --- | --- | | mu | array.<number> | | | [ascending] | boolean | true |
microtonal.uniq(mu) ⇒ array.<number>
Sort and remove duplicates from a musical object
Kind: static method of microtonal
Returns: array.<number> - a new musical object without the duplications
| Param | Type | | --- | --- | | mu | array.<number> |
microtonal.pitchset(pitches) ⇒ array.<number>
Create a pitch set: an unordered sets of pitches
Kind: static method of microtonal
Returns: array.<number> - the pitch set
See: Geometry of Music, p. 40
| Param | Type | | --- | --- | | pitches | array.<number> |
microtonal.pclist(mu) ⇒ array.<number>
Creates a pclist: an unordered collection of pitch class sets
Kind: static method of microtonal
Returns: array.<number> - a new multiset object with the pitch classes
| Param | Type | Description | | --- | --- | --- | | mu | array.<number> | the musical object |
microtonal.pcset(mu) ⇒ array.<number>
Creates a pitch class set: an ordered set of pitch classes
Kind: static method of microtonal
Returns: array.<number> - a new pitch set array with the pitch classes
| Param | Type | Description | | --- | --- | --- | | mu | array.<number> | the musical object |
microtonal.chromatic(tonic) ⇒ function
Creates a chromatic scale.
Kind: static method of microtonal
Returns: function - the scale
| Param | Type | | --- | --- | | tonic | number |
microtonal.major(tonic) ⇒ function
Creates a major scale
Kind: static method of microtonal
Returns: function - the scale
| Param | Type | | --- | --- | | tonic | number |
microtonal.minor(tonic) ⇒ function
Creates a minor scale
Kind: static method of microtonal
Returns: function - the scale
| Param | Type | | --- | --- | | tonic | number |
microtonal.pentatonic(tonic) ⇒ function
Creates a minor scale
Kind: static method of microtonal
Returns: function - the scale
| Param | Type | | --- | --- | | tonic | number |
microtonal.degrees(scale, elements)
Generate a number of degrees of a given scale
Kind: static method of microtonal
| Param | Type | | --- | --- | | scale | function | | elements | number |
Example
const scale = degrees(major(60));
scale(8) // => [60, 62, 64, 65, 67, 69, 71, 72]
scale(-8) // =>