Section Durations
Clock and durations utility functions
- Clock: measure elapsed time, time formating,
- Conversions from/to milliseconds, note duration, percentage of note duration, 256th of quarter
Class
Class | Summary |
---|---|
Stopwatch | Stopwatch (French: chronomètre) to measure elapsed time. |
Summary
Return type | Function and summary |
---|---|
number | duration_256th_of_quarter_to_ms(int nbOf256th, number tempo) Convert 256ths of quarter to milliseconds, according to tempo. |
int | 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. |
int | duration_ms_to_256th_of_quarter(number milliseconds, int noteDuration, number tempo) Convert at duration in milliseconds to 256th of quarter, according to tempo |
int | duration_ms_to_note(number milliseconds, number tempo) Convert a duration in milliseconds to a note duration according to tempo. |
int | 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. |
number | duration_note_to_ms(int noteDuration, number tempo) Convert a note duration to milliseconds, according to tempo. |
int | 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. |
number | duration_percent_of_note_to_ms(int percent, int noteDuration, number tempo) Convert a percentage of note duration to milliseconds, according to tempo. |
string | string_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.
Parameter | Type | Default | Description |
---|---|---|---|
noteDuration | int | noteDuration | |
tempo | number | 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.
Parameter | Type | Default | Description |
---|---|---|---|
milliseconds | number | milliseconds | |
tempo | number | 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.
Parameter | Type | Default | Description |
---|---|---|---|
percent | int | percent | |
noteDuration | int | noteDuration | |
tempo | number | 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.
Parameter | Type | Default | Description |
---|---|---|---|
milliseconds | number | milliseconds | |
noteDuration | int | noteDuration | |
tempo | number | 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.
Parameter | Type | Default | Description |
---|---|---|---|
nbOf256th | int | nbOf256th | |
tempo | number | 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
Parameter | Type | Default | Description |
---|---|---|---|
milliseconds | number | milliseconds | |
noteDuration | int | noteDuration | |
tempo | number | 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.
Parameter | Type | Default | Description |
---|---|---|---|
nbOf256th | int | nbOf256th | |
noteDuration | int | noteDuration | |
tempo | number | 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.
Parameter | Type | Default | Description |
---|---|---|---|
nbOf256th | int | nbOf256th | |
noteDuration | int | noteDuration | |
tempo | number | 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.
Parameter | Type | Default | Description |
---|---|---|---|
seconds | number | Time in seconds, 0.010 = 10ms | |
exact | boolean | false | If false, removes details (e.g. no milliseconds if time is minutes and you don't need so much precision). |
clockFormat | boolean | false | Clock 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"