convert

EDO# convert

A collection of functions that convert an input into other equivalent representations

Methods

# (static) cents_to_interval(interval, roundopt) → {Number}

Expresses cents as intervallic unit (in given EDO)

Parameters:
Name Type Attributes Default Description
interval Number

cents

round Boolean <optional>
true

whether to round the decimals in case not a round number

Source:
Returns:

An equivilant value represented in intervallic units

Type
Number
Example
let edo = new EDO(24) // define a tuning with 24 divisions of the octave
edo.convert.cents_to_interval(6)
//returns 2

# (static) cents_to_ratio(cents) → {Number}

Returns a ratio as a decimal number from an interval represented in cents

Parameters:
Name Type Description
cents Number

an interval in cents

Source:
Returns:

a ratio

Type
Number
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.cents_to_ratio(700)
// returns 1.4983070768766815

# (static) freq_to_midi(hz) → {Object}

Returns the midi_note and cents offset for a given pitch frequency in hertz

Parameters:
Name Type Description
hz Number

Some frequency of a pitch

Source:
Returns:

{midi: the midi-note number, cents: fine-tuning of note in cents}

Type
Object
Example
let edo = new EDO()
edo.convert.freq_to_midi(445)
//returns
{ midi: 69, cents: 20 }

# (static) interval_to_cents(interval) → {Number}

Returns a value in cents from a given interval

Parameters:
Name Type Description
interval Number

Some interval

Source:
Returns:

the interval represented in cents

Type
Number
Example
let edo = new EDO(17) // define a tuning with 17 divisions of the octave
edo.convert.interval_to_cents(6)
//returns 423.5294117647059

# (static) interval_to_ratio(interval) → {Number}

Returns a ratio as a decimal number from a given interval

Parameters:
Name Type Description
interval Number | Array.<Number>

Some interval

Source:
Returns:

a ratio

Type
Number
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.interval_to_ratio(7)
// returns 1.4983070768766815

# (static) intervals_to_pitches(intervals, starting_pitchopt, moduloopt) → {Array.<Number>|Array.<Array.<Number>>}

Given a list of intervals (or list of lists), returns pitches made with the intervals starting from starting_pitch

Parameters:
Name Type Attributes Default Description
intervals Array.<Number> | Array.<Array.<Number>>

a list of intervals

starting_pitch Number <optional>
0
modulo Boolean <optional>

if modulo is provided, the pitches will conform to it

Source:
Returns:

The input as pitches

Type
Array.<Number> | Array.<Array.<Number>>
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.intervals_to_pitches([2,3])
//returns [ 0, 2, 5 ]

# (static) intervals_to_scale(intervals) → {Number}

Gets a series of intervallic units . Returns a scale as list of pitch classes

Remark: "pitch classes" conform to the current tuning system used. 0-11 in 12EDO, 0-16 in 17EDO, etc.

Parameters:
Name Type Description
intervals Array.<Number>

A list of intervals

Source:
Returns:

A scale made up by adding the intervals in order

Type
Number
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.intervals_to_scale([2, 2, 1, 2, 2, 2, 1])
// returns [0,2,4,5,7,9,11]

# (static) midi_to_freq(note_number, offsetopt, Aopt) → {Array.<Number>|Number}

Returns the frequency of the midi note

Parameters:
Name Type Attributes Default Description
note_number Array.<Number> | Number

a midi note number or an array of midi note numbers

offset Number <optional>
0

By how much to offset every given number

A Number <optional>
440

What is the tuning of A

Source:
Returns:

the frequency of the midi note

Type
Array.<Number> | Number
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.midi_to_freq(69) //returns 440
edo.convert.midi_to_freq([69,70]) //returns [ 440, 466.1637615180899 ]

# (static) midi_to_intervals(midi) → {Array.<Number>}

Given a list of midi notes, returns a list of intervals

Parameters:
Name Type Description
midi Array.<Number>

a list of midi pitches

Source:
Returns:

The input as intervals

Type
Array.<Number>
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.midi_to_intervals([60,64,57,61])
//returns [ 4, -7, 4 ]

# (static) midi_to_name(note_number, offset) → {Array.<String>|String}

Returns the name of the note (including octave) from a midi value

Parameters:
Name Type Description
note_number Array.<Number> | Number

a midi note number or an array of midi note numbers

offset Number

an amount by which to shift note_number

Source:
Returns:

The input as note name(s)

Type
Array.<String> | String
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.midi_to_name([60,62])
//returns ["C4","D4"]

# (static) name_to_scale(name) → {Scale}

Gets a scale's name, and returns it as a Scale object

Parameters:
Name Type Description
name String

a scale's name (based on this API's naming formula)

Source:
Returns:

a scale object

Type
Scale
Example
let edo = new EDO(12) // define a tuning system
edo.convert.name_to_scale('12-1387')
//returns Scale object corresponding to the diatonic scale

# (static) pc_to_name(pc) → {String}

Returns the name of a note from a given pitch class (supports only 12-edo)

Parameters:
Name Type Description
pc Number | Array.<Number>

a pitch class

Source:
Returns:

The input as a note name

Type
String
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.pc_to_name(4)
//returns "E"

# (static) pitches_to_freq(note_number, freq_0opt) → {Array.<Number>|Number}

Returns the frequency of the given notes

Parameters:
Name Type Attributes Default Description
note_number Array.<Number> | Number

a set of pitches

freq_0 Number <optional>
440

The frequency of note 0

Source:
Returns:

the frequency of the notes

Type
Array.<Number> | Number

# (static) pitches_to_PCs(pitches) → {Array.<Number>}

Normalizes any input to include pitch-classes only (to ignore octave displacement)

Remark: "pitch classes" conform to the current tuning system used. 0-11 in 12EDO, 0-16 in 17EDO, etc.

Parameters:
Name Type Description
pitches Array.<Number>

any collection of pitches (e.g. a melody)

Source:
Returns:

the input as pitch classes

Type
Array.<Number>
Example
let edo = new EDO(12) // define a tuning system with 12 divisions of the octave
edo.convert.pitches_to_PCs([0,2,12,-2,7])
//returns [0,2,0,10,7]

# (static) ratio_to_cents(ratio) → {Number}

Returns a value in cents to a given input ratio

Parameters:
Name Type Description
ratio Number

A harmonic ratio

Source:
Returns:

The ratio represented in cents

Type
Number
Example
let edo = new EDO(12) // define a tuning system
edo.convert.ratio_to_cents(5/4)
//returns 386.3137138648348

# (static) ratio_to_interval(ratio, toleranceopt) → {Array.<Number>}

Returns all of the intervallic units in the EDO that equal to a given ratio (with a given tolerance in cents)

Remark: "intervallic units" conform to the current tuning system used. E.g., 0-11 occupy 1 octave in 12EDO, 0-16 in 17EDO, etc.

Parameters:
Name Type Attributes Default Description
ratio Number

A harmonic ratio

tolerance Number <optional>
10

a tolerance (allowed error) in cents

Source:
Returns:

Intervals that fit that ratio

Type
Array.<Number>
Examples
let edo = new EDO(12) // define a tuning system
edo.convert.ratio_to_interval(3/2)
//[7]
let edo = new EDO(12) // define a tuning system
edo.convert.ratio_to_interval(5/4,20) //increased the default tolerance (default 10 won't accept IC 4)
//returns [4]

# (static) to_steps(lst, cacheopt) → {Array.<Number>}

Gets a melody as pitches and returns the melody as intervals

Parameters:
Name Type Attributes Default Description
lst Array.<number>

a collection of pitches

cache Boolean <optional>
false

when true the result is cached for faster future retrieval

Source:
Returns:

an array of intervals

Type
Array.<Number>
Example
let edo = new EDO(12) // define a tuning system
edo.convert.to_steps([0,2,4,5,7,9,11])
//returns [ 2, 2, 1, 2, 2, 2 ]