Section Numbers
Numbers utility functions.
Summary
Return type | Function and summary |
---|---|
string | CompareMyrScriptVersion(string version) Is MyrScript =, < or > version x.y.z? |
string | CompareVersions(string a, string b) Compare two version numbers in x.y.z string format. |
string, int | SMPitchToString(int pitch, int preferredAccidental, int compatible, string preferredNote) Extension and bugfix for builtin PitchToString function. |
int | SMStringToPitch(string name) Extension and bugfix for builtin StringToPitch function. |
number | round(number num, int numberOfDecimals) Round a number. |
Functions
CompareMyrScriptVersion(string version)
Is MyrScript =, < or > version x.y.z?
As Application.MyrScriptVersion
is a string, comparison may fail in the future, "10.1.1" is greater than "9.9.9" but string comparison will stay it's lower (because "1" < "9").
Parameter | Type | Default | Description |
---|---|---|---|
version | string | Version to compare, in x.y.z form (e.g.: "1.6.9") |
- Return
- string: "<", ">" or "=" if version is lower, greater or equal to MyrScript version.
CompareVersions(string a, string b)
Compare two version numbers in x.y.z string format.
Parameter | Type | Default | Description |
---|---|---|---|
a | string | ||
b | string |
- Return
- string: "<", ">" or "=" if a is lower, greater or equal to b.
- Example
CompareVersions("9.9.7", "9.9.6") --> ">"
round(number num, int numberOfDecimals)
Round a number.
Parameter | Type | Default | Description |
---|---|---|---|
num | number | Number to round() | |
numberOfDecimals | int | 0 | Number of decimals |
- Return
- number: the rounded number, i.e.
floor(number + 0.5)
for an integer (no decimals)
SMPitchToString(int pitch, int preferredAccidental, int compatible, string preferredNote)
Extension and bugfix for builtin PitchToString function.
- Allow pitches out of 0..127 bounds, but keep in mind that HA can't handle them!
PitchToString(11)
gives 11,SMPitchToString(11)
returns B-1
Parameter | Type | Default | Description |
---|---|---|---|
pitch | int | ||
preferredAccidental | int | AUTO | Preferred accidental in MSDefine. HA can handle A## and Bbb as note names. |
compatible | int | ffalse | If true return value that HA can handle, 11 instead of B-1, a value in bounds. |
preferredNote | string | "" | English note "A" to "G", if no preferred accidental or AUTO, select the enharmonic from the preferred note. If result is "A" and preferred note is "G" then result will be "G##". |
- Returns
- string: Anglo-saxon note name followed by octave, e.g. "Ab5".
- int: Accidental for the note, one of MSDefine NATURAL,FLAT,SHARP,DOUBLE_FLAT,DOUBLE_SHARP constants.
SMStringToPitch(string name)
Extension and bugfix for builtin StringToPitch function.
- Allow pitches out of 0..127 bounds
StringToPitch("B-1")
gives the strange 71 result,SMStringToPitch("B-1")
returns 11- Handles double-sharp (## or x) and double-flat (bb)
Parameter | Type | Default | Description |
---|---|---|---|
name | string | English not name followed by octave. If octave is missing, considers it's the 4th octave. |
- Return
- int: May be out of 0..127 range.