Section Inputs

Input functions, to ask user to enter number, select in a list of choices, two values as XY coordinates.

This adds inputs to builtin EnterString(...).

See
Fonts
Numbers

Summary

Return typeFunction and summary
string, string, intChooseColor(string object, table suggestedColors, selected)
Ask the user to choose one color in a menu.
string, int, int, stringChooseFont(string object, table suggestedFonts, selected)
Ask the user to choose one font in a menu.
tableChooseStaves(Score score, boolean multiple, boolean visibleOnly, function filterFunc, function selectFunc, int minNbOfChoice, int maxNbOfChoice)
Ask the user to choose one or multiple staves.
tableChooseStavesGroups(Score score, boolean multiple, boolean visibleOnly, function filterFunc, function selectFunc)
Ask the user to choose one or multiple staves groups.
TargetChooseTarget(Score score, string prompt, int selectedBar, string selectedName)
Select a Target (rehearsal mark) in the Score.
intChooseView(Score score, boolean index, int (default=current)
Ask the user to choose one view, or a value for ViewIndex.
string, int, int, stringEnterFont(string font, face, number size, string color)
Ask the user to choose font, face, size and color using the built-in EditTextStyle() dialog.
numberEnterNumber(string text, number defaultValue, number minValue, number maxValue)
Ask the user to enter a number.
number, numberEnterXY(string prompt, number minX, number maxX, number stepX, number factoryX, number currentX, number minY, number maxY, number stepY, number factoryY, number currentY, string displayValuesMask)
Ask to enter X,Y coordinates in a plotter with X and Y axis.
tableMenuMultipleChoice(string title, Lexicon lexicon, datas, int minNbOfChoice, int maxNbOfChoice)
Menu to pick multiple value in a list of items as checkboxes.
 MenuSingleChoice(string title, Lexicon lexicon, datas)
Menu to pick one value in a list of items as radio buttons.
tableMidiGetEventFiltered(boolean allowNoteOn, boolean allowNoteOff, boolean allowCC, boolean allowProgramChange, boolean allowAftertouch, boolean allowPitchBend, boolean allowOthers, int delay, table allowedSources)
Apply a filter to Midi.GetEvent to exclude some Midi messages and return all events since last call.
booleanSMConfirmation(string msg)
Add accessibility to built-in Confirmation() function.

Functions

EnterNumber(string text, number defaultValue, number minValue, number maxValue)

Ask the user to enter a number.

Use EnterString(...), and checks that the entered is a number within bounds. In case of error, ask again.

ParameterTypeDefaultDescription
textstring Text to dispaly in prompt popup
defaultValuenumbernilA pre-defined value, or nil to force user to enter a value.
minValuenumbernilIf specified, entered value is bound by min and max.
maxValuenumbernilIf specified, entered value is bound by min and max.
Return
number: or nil if user cancelled the choice.

EnterXY(string prompt, number minX, number maxX, number stepX, number factoryX, number currentX, number minY, number maxY, number stepY, number factoryY, number currentY, string displayValuesMask)

Ask to enter X,Y coordinates in a plotter with X and Y axis.

It's handy when you ask for 2 values, as X and Y offsets.

See sample code below

ParameterTypeDefaultDescription
promptstring A prompt text above the plotter, nil means no prompt text.
minXnumber0Minimal value for X
maxXnumber0Maximal value for X
stepXnumber1Step between two consecutive X possible values. e.g. 1 for a value from 0 to 127, 0.01 for fine adjustement of object position in the score... The bigger the faster mouse wheel and keyboard will change the value.
factoryXnumbercurrentXDefault (factory) value for X, a dual click on the slider goes back to this value
currentXnumberfactoryXCurrent displayed X value
minYnumber0Minimal value for Y
maxYnumber0Maximal value for Y
stepYnumber1Step between two consecutive Y possible values. e.g. 1 for a value from 0 to 127, 0.01 for fine adjustement of object position in the score... The bigger the faster mouse wheel and keyboard will change the value.
factoryYnumbercurrentYDefault (factory) value for Y, a dual click on the slider goes back to this value
currentYnumberfactoryYCurrent displayed Y value
displayValuesMaskstring"%x, %y"Mask for displaying values, %x and %y are replaced by values.
Returns
number: X, nil if user cancelled the dialog
number: Y, nil if user cancelled the dialog
Errors
if minX >= maxX or minY >= maxY
if factoryX or currentX are outside of [minX:maxX] range
if factoryY or currentY are outside of [minY:maxY] range
if factoryX and currentX, or factoryY and currentY are nil.
Example


 -- Create a new document with one staff, go to Page mode.
 -- This code moves first staff name position
 -- X between -50 and 50, Y between -30 and 30, steps are 1
 -- Negative Y go up, positive Y go down.
 -- Factory position is 0,0, current is 5,-24
   Include "SMUtils"
   x,y = EnterXY("Test XY",
    -50, 50, 1, 0, 5,
    -30, 30, 1, 0, -24,
    false, true, {FrontScore()},
    function(x,y,args)
      local staff = args[1].FirstStaff
      staff.TitleXOffset, staff.TitleYOffset = x, y
      Application.UpdateScores()
    end,
    "%x px, %y px" -- not mandatory, just show that unit is pixel (in 72 DPI)
  )

SMConfirmation(string msg)

Add accessibility to built-in Confirmation() function.

ParameterTypeDefaultDescription
msgstring msg
Return
boolean: The same result than Confirmation(msg)

MenuSingleChoice(string title, Lexicon lexicon, datas)

Menu to pick one value in a list of items as radio buttons.

Single choice menu with radio buttons.

ParameterTypeDefaultDescription
titlestring Menu title
lexiconLexicon Lexicon for title and captions translation, nil for no translation.
datas  Can be a Map, a Collection or a table. Map keys are the values, map's value are string or table. Collection and table values are string or table.
table contents:
  1. string: the caption,
  2. Optional boolean: selected
  3. Optional: value, any kind of object, not necessary in a Map
  4. Optional string: left icon, "image:filename.ext" where filename.ext is in script directory or one of Harmony's install subdir, or "text:..." a short (styled or not) text
  5. Optional string: Keyboard shortcut
Return
choosen value (or caption), or nil if user canceled the choice.
Example


 local sd = MenuSingleChoice("Change stems direction", nil,
      {{"Auto", true, STEM_AUTO, "image:stemupdown.png"},
       {"Up", false, STEM_UP, "image:stemup.png"},
       {"Down", false, STEM_DOWN, "image:stemdown.png"}
      })
 if sd then -- change the stems direction of symbols
 else -- no selection, user canceled the choice
 end

MenuMultipleChoice(string title, Lexicon lexicon, datas, int minNbOfChoice, int maxNbOfChoice)

Menu to pick multiple value in a list of items as checkboxes.

For example, ChooseStaves(...) call it.

Multiple choice menu with checkboxes.

ParameterTypeDefaultDescription
titlestring Menu title
lexiconLexicon Lexicon for title and captions translation, nil for no translation.
datas  Can be a Map, a Collection or a table. Map keys are the values, map's value are string or table. Collection and table values are string or table.
table contents:
  1. string: the caption,
  2. Optional boolean: selected
  3. Optional: value, any kind of object, not necessary in a Map
  4. Optional string: left icon, "image:filename.ext" where filename.ext is in script directory or one of Harmony's install subdir, or "text:..." a short (styled or not) text
  5. Optional string: Keyboard shortcut
minNbOfChoiceint1Minimum number of items to choose, 0 means user can select nothing.
maxNbOfChoiceint0Maximum number of items to choose, 0 means no limit.
Return
table: Choosen values (or captions), or nil if user canceled the choice.

ChooseStaves(Score score, boolean multiple, boolean visibleOnly, function filterFunc, function selectFunc, int minNbOfChoice, int maxNbOfChoice)

Ask the user to choose one or multiple staves.

The builtin Score.UserChooseStaves(...) is a bit less flexible and not 100% browsable with keyboard. This custom version allow shortcuts, from 1 to 9 for 9 first staves, then the first available letter.

Here is what it looks like:

ChooseStaves(...) displays a menu with checkboxes.

ParameterTypeDefaultDescription
scoreScore score
multiplebooleantruetrue if several staves can be chosen, false if only one staff can be chosen.
visibleOnlybooleantruetrue if only visible staves are provided.
filterFuncfunction Function that receives Score and Staff arguments, returns true if the staff appears in list, false if not.
selectFuncfunction Function that receives Score and Staff arguments, returns true if the staff is selected by default, false if not selected.
minNbOfChoiceint1Minimum number of staves to choose, 0 means user can choose no staff. No effect if multiple is false.
maxNbOfChoiceint0Maximum number of staves to choose, 0 means no limit. No effect if multiple is false.
Return
table: Table of choosen staves, can be empty, or nil if user canceled the choice.

ChooseStavesGroups(Score score, boolean multiple, boolean visibleOnly, function filterFunc, function selectFunc)

Ask the user to choose one or multiple staves groups.

ParameterTypeDefaultDescription
scoreScore score
multiplebooleantruetrue if several staves groups can be chosen, false if only one staves group can be chosen.
visibleOnlybooleantruetrue if only visible staves groups are provided.
filterFuncfunction Function that receives Score and StavesGroup arguments, returns true if the staves group appears in list, false if not.
selectFuncfunction Function that receives Score and StavesGroup arguments, returns true if the staves group is selected by default, false if not selected.
Return
table: Array of choosen staves groups, can be empty, or nil if user canceled the choice.

ChooseView(Score score, boolean index, int (default=current)

Ask the user to choose one view, or a value for ViewIndex.

ParameterTypeDefaultDescription
scoreScore score
indexboolean Add the choices
  • 0 = all views
  • -1 = general view
  • -2 = all views including staff
  • -3 = all views except general view
(default=currentint view) selected index
Return
int: view index

ChooseFont(string object, table suggestedFonts, selected)

Ask the user to choose one font in a menu.

Choose tempo font menu
If available, the list starts by the font set in global settings > Fonts for object (e.g. "Tempo", "Staff name", see GetPreferredFont(..)),
then, a list of favorites fonts,
then, a list of suggested fonts (e.g. found in score).

ParameterTypeDefaultDescription
objectstring One of the items in the global settings dialog in English: "Staff name", "Break text", "Tempo", "Rules names", "Effects & ornaments", "Tablature key", "Tablature grace note", "Tablature note", "Chord grid name", "Chord grid display", "Chord grid summary", "Key summary", "Karaoke line", "Ruler", "Help window", "Array", "Pop up menus"
or another object of your choice such as "Lyrics".
suggestedFontstable A table of TextStyle or table {name, face, size[, color]}
selected  A TextStyle or table {name, face, size[, color]}
Returns
string: Font name, nil if user canceled the choice.
int: Font face, sum of FACE_* constants in MSDefine
int: Size
string: RGB color

EnterFont(string font, face, number size, string color)

Ask the user to choose font, face, size and color using the built-in EditTextStyle() dialog.

EnterFont(...) calls EditTextStyle(...)
Returns TextStyle properties instead of TextStyle object itself, as it is mandatory to dispose it, and often forgotten.

ParameterTypeDefaultDescription
fontstringnilDefault font
face nilDefault face. A number (sum of FACE_* constants) or a string like "BI" for bold italic, second returned value by FontFaceNumberToString(...).
sizenumbernilDefault size
colorstringnilDefault color in RGB format.
Returns
string: Font name, nil if user canceled the choice.
int: Font face, sum of FACE_* constants in MSDefine
int: Size
string: RGB color

ChooseColor(string object, table suggestedColors, selected)

Ask the user to choose one color in a menu.

Choose staff line color, there are 5 favorites
If available, the list starts by a list of favorites colors, saved by previous choices for the same object (e.g. "Staff background").
Then, a list of suggested colors (e.g. found in score).
Then, the ability to pick a new color from the Color Picker, and save it to favorites for faster use next times.

ParameterTypeDefaultDescription
objectstring The name you want, e.g. "Staff background", "Staff lines"...
suggestedColorstablenilA table of string in [#]RRGGBB format (recommanded), or number color index
selected  A string in [#]RRGGBB format or number color index
Returns
string: Choosen color, in RRGGBB format, or nil if user canceled the choice.
string: Choosen color, in #RRGGBB format, or nil if user canceled the choice.
int: Color index, or nearest in 256 colors palette, or nil if user canceled the choice.

ChooseTarget(Score score, string prompt, int selectedBar, string selectedName)

Select a Target (rehearsal mark) in the Score.

ParameterTypeDefaultDescription
scoreScore score
promptstring"Select a rehearsal mark"Title of the menu.
selectedBarint0Preselect target from the bar number selectedBar:
  • negative means no pre-selection,
  • nil or 0 means current cursor position (Score.TimeBeginSelection),
  • Positive number pre-selects the target where Target.Bar <= selectedBar.
selectedNamestringnilSelect the target which displayed name is selectedName. nil means no selection from the target displayed name.
Return
Target: Selected target or nil if user canceled the choice.

MidiGetEventFiltered(boolean allowNoteOn, boolean allowNoteOff, boolean allowCC, boolean allowProgramChange, boolean allowAftertouch, boolean allowPitchBend, boolean allowOthers, int delay, table allowedSources)

Apply a filter to Midi.GetEvent to exclude some Midi messages and return all events since last call.

You can exclude:

  1. message you don't need, e.g. aftertouch
  2. a lot of steps while moving a controller (slider, knob, pitch bend).
    To do this, set a delay in milliseconds. This result in a loss of data, note suitable for fine control of sound, but useful when hardware controllers replace mouse or computer keyboard inputs.

ParameterTypeDefaultDescription
allowNoteOnbooleantrueAllow Note On events?
allowNoteOffbooleantrueAllow Note Off events?
allowCCbooleantrueAllow controller change events?
allowProgramChangebooleantrueAllow PC event?
allowAftertouchbooleantrueAllow aftertouch event?
allowPitchBendbooleantrueAllow pitch bend event?
allowOthersbooleantrueAllow other events?
delayint0Delay in milliseconds for CC and pitch bend, reduce the number of events returned while the wheel or controller is sliding / rotating.
If delay is set, then only the last value is returned.
allowedSourcestablenilThe accepted sources (nil means all - no filter):
  • INPUT_SOURCE_UNKNOWN: none/unknown
  • INPUT_SOURCE_MIDI: from an external MIDI device
  • INPUT_SOURCE_VIRTUAL_KBD: from a click on a virtual keyboard
  • INPUT_SOURCE_COMPUTER_KBD: from the computer keyboard
  • INPUT_SOURCE_PLAYED_MUSIC: from the played score
Return
table: Table of Midi events, each item are structured as:
  • Event, int: type of event :
    • 1 mean note on (key pressed),
    • 2 mean note off or note on with velocity = 0 (key released)
    • 10 means polyphonic aftertouch
    • 11 means CC, Controller Change (modulation wheel, pedal, knobs, cursors, bank change...)
    • 12 means PC, Program Change
    • 13 means channel aftertouch
    • 14 means pitch bend
  • Channel, int: the channel from 0 to 15
  • Pitch, int: the note pitch / selected controller / program from 0 to 127
  • Velocity, int: the velocity / controller value from 0 to 127
  • TimeMs, int: the time position in millisecond of the event
  • TimePos, number: the time position in the playing score (-1 if no score currently playing)
  • Source, int: the source for this event (MSDefine constant):
    • INPUT_SOURCE_UNKNOWN: none/unknown
    • INPUT_SOURCE_MIDI: from an external MIDI device
    • INPUT_SOURCE_VIRTUAL_KBD: from a click on a virtual keyboard
    • INPUT_SOURCE_COMPUTER_KBD: from the computer keyboard
    • INPUT_SOURCE_PLAYED_MUSIC: from the played score