Section Numbers

Numbers utility functions.

Summary

Return typeFunction and summary
stringCompareMyrScriptVersion(string version)
Is MyrScript =, < or > version x.y.z?
stringCompareVersions(string a, string b)
Compare two version numbers in x.y.z string format.
string, intSMPitchToString(int pitch, int preferredAccidental, int compatible, string preferredNote)
Extension and bugfix for builtin PitchToString function.
intSMStringToPitch(string name)
Extension and bugfix for builtin StringToPitch function.
numberround(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").

ParameterTypeDefaultDescription
versionstring 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.

ParameterTypeDefaultDescription
astring  
bstring  
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.

ParameterTypeDefaultDescription
numnumber Number to round()
numberOfDecimalsint0Number 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

ParameterTypeDefaultDescription
pitchint  
preferredAccidentalintAUTOPreferred accidental in MSDefine. HA can handle A## and Bbb as note names.
compatibleintffalseIf true return value that HA can handle, 11 instead of B-1, a value in bounds.
preferredNotestring""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)

ParameterTypeDefaultDescription
namestring 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.