Section Durations

Clock and durations utility functions

Class

ClassSummary
StopwatchStopwatch (French: chronomètre) to measure elapsed time.

Summary

Return typeFunction and summary
numberduration_256th_of_quarter_to_ms(int nbOf256th, number tempo)
Convert 256ths of quarter to milliseconds, according to tempo.
intduration_256th_of_quarter_to_percent_of_note(int nbOf256th, int noteDuration, number tempo)
Convert 256ths of quarter to a percentage of a note duration, according to tempo.
intduration_ms_to_256th_of_quarter(number milliseconds, int noteDuration, number tempo)
Convert at duration in milliseconds to 256th of quarter, according to tempo
intduration_ms_to_note(number milliseconds, number tempo)
Convert a duration in milliseconds to a note duration according to tempo.
intduration_ms_to_percent_of_note(number milliseconds, int noteDuration, number tempo)
Convert a duration in milliseconds to a percentage of a note duration, according to tempo.
numberduration_note_to_ms(int noteDuration, number tempo)
Convert a note duration to milliseconds, according to tempo.
intduration_percent_of_note_to_256th_of_quarter(int nbOf256th, int noteDuration, number tempo)
Convert a percentage of a note duration to 256ths of quarter, according to tempo.
numberduration_percent_of_note_to_ms(int percent, int noteDuration, number tempo)
Convert a percentage of note duration to milliseconds, according to tempo.
stringstring_time(number seconds, boolean exact, boolean clockFormat)
Converts a time (music duration, debug chrono...) into readable string.

Functions

duration_note_to_ms(int noteDuration, number tempo)

Convert a note duration to milliseconds, according to tempo.

ParameterTypeDefaultDescription
noteDurationint noteDuration
temponumber tempo
Return
number: Rounded to 3 decimals
Error
if noteDuration is nil, if tempo is nil or <= 0

duration_ms_to_note(number milliseconds, number tempo)

Convert a duration in milliseconds to a note duration according to tempo.

ParameterTypeDefaultDescription
millisecondsnumber milliseconds
temponumber tempo
Return
int: A note duration, comparable to DURATION_QUARTER and other constants in MSDefine
Error
if milliseconds is nil, or tempo is nil or <= 0

duration_percent_of_note_to_ms(int percent, int noteDuration, number tempo)

Convert a percentage of note duration to milliseconds, according to tempo.

ParameterTypeDefaultDescription
percentint percent
noteDurationint noteDuration
temponumber tempo
Return
number: Rounded to 3 decimals
Error
if percent is nil, if noteDuration is nil, if tempo is nil or <= 0

duration_ms_to_percent_of_note(number milliseconds, int noteDuration, number tempo)

Convert a duration in milliseconds to a percentage of a note duration, according to tempo.

ParameterTypeDefaultDescription
millisecondsnumber milliseconds
noteDurationint noteDuration
temponumber tempo
Return
int: Percent of noteDuration
Error
if milliseconds is nil, if noteDuration is nil, if tempo is nil or <= 0

duration_256th_of_quarter_to_ms(int nbOf256th, number tempo)

Convert 256ths of quarter to milliseconds, according to tempo.

ParameterTypeDefaultDescription
nbOf256thint nbOf256th
temponumber tempo
Return
number: Rounded to 3 decimals
Error
if nbOf256th is nil, if tempo is nil or <= 0

duration_ms_to_256th_of_quarter(number milliseconds, int noteDuration, number tempo)

Convert at duration in milliseconds to 256th of quarter, according to tempo

ParameterTypeDefaultDescription
millisecondsnumber milliseconds
noteDurationint noteDuration
temponumber tempo
Return
int: 256th of quarter
Error
if milliseconds is nil, if noteDuration is nil, if tempo is nil or <= 0

duration_256th_of_quarter_to_percent_of_note(int nbOf256th, int noteDuration, number tempo)

Convert 256ths of quarter to a percentage of a note duration, according to tempo.

ParameterTypeDefaultDescription
nbOf256thint nbOf256th
noteDurationint noteDuration
temponumber tempo
Return
int: int
Error
if nbOf256th is nil, if noteDuration is nil, if tempo is nil or <= 0

duration_percent_of_note_to_256th_of_quarter(int nbOf256th, int noteDuration, number tempo)

Convert a percentage of a note duration to 256ths of quarter, according to tempo.

ParameterTypeDefaultDescription
nbOf256thint nbOf256th
noteDurationint noteDuration
temponumber tempo
Return
int: int
Error
if nbOf256th is nil, if noteDuration is nil, if tempo is nil or <= 0

string_time(number seconds, boolean exact, boolean clockFormat)

Converts a time (music duration, debug chrono...) into readable string.

ParameterTypeDefaultDescription
secondsnumber Time in seconds, 0.010 = 10ms
exactbooleanfalseIf false, removes details (e.g. no milliseconds if time is minutes and you don't need so much precision).
clockFormatbooleanfalseClock format: returns 00:03.010 instead of 3s 10ms
Return
string: "10 ms", "3 s 456 ms", "1 min 14 s", 00:03.010...
See
Stopwatch:new
Example


 s = 1.0102345 -- 1 second, 10,2345 ms
 print(string_time(s)) --> "1.01 s"
 print(string_time(s, true)) --> "1 s 10.234 ms"
 print(string_time(s, false, true)) --> "00:01.010"
 print(string_time(s, true, true)) --> "00:01.010234"
 s = s + 2*60 -- add 2 minutes
 print(string_time(s)) --> "2 min 1 s"
 print(string_time(s, true)) --> "2 min 1 s 10.234 ms"
 print(string_time(s, false, true)) --> "02:01.010"
 print(string_time(s, true, true)) --> "02:01.010234"