convert

Time# convert

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

Methods

# (static) beats_to_msec(beats, bpmopt, units_per_beatopt) → {Array.<Number>}

Returns an array of beats as expressed in their duration in milliseconds

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

An array of beats

bpm Number <optional>
60

The tempo

units_per_beat Number <optional>
1

The number of units each beat subdivides to.

Source:
Returns:

An array with the pattern in milliseconds

Type
Array.<Number>
Example
let time = new Time()
time.convert.beats_to_msec([2,3,2,1],120,2) // [ 500, 750, 500, 250 ]

# (static) beats_to_ratios(array, relate_only_to_firstopt) → {Array.<Number>}

Returns the new tempo, if the number of beats_in_old_tempo occupies the same time as the number of beats_in_new_tempo, and the old tempo being old_tempo.

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

An array of beats

relate_only_to_first Boolean <optional>
false

When true, all ratios will be calculated based on the first value. Otherwised, they'll be calculated based on their relationship with the previous beat.

Source:
Returns:

An array with the ratios

Type
Array.<Number>
Example
let time = new Time()
time.convert.beats_to_ratios([2,3,2,1]) // [ 1.5, 0.6666666666666666, 0.5 ]

# (static) beats_to_tempo(beats_in_old_tempo, beats_in_new_tempo, old_tempo) → {Number}

Returns the new tempo, if the number of beats_in_old_tempo occupies the same time as the number of beats_in_new_tempo, and the old tempo being old_tempo.

Parameters:
Name Type Description
beats_in_old_tempo Number

The number of beats in the old tempo

beats_in_new_tempo Number

The equivalent number of beats in the new tempo

old_tempo Number

The old tempo

Source:
Returns:

The new tempo

Type
Number
Example
let time = new Time()
time.convert.beats_to_tempo(4,6,60) // returns 90