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(...)
.
Summary
Return type | Function and summary |
---|---|
string, string, int | ChooseColor(string object, table suggestedColors, selected) Ask the user to choose one color in a menu. |
string, int, int, string | ChooseFont(string object, table suggestedFonts, selected) Ask the user to choose one font in a menu. |
table | ChooseStaves(Score score, boolean multiple, boolean visibleOnly, function filterFunc, function selectFunc, int minNbOfChoice, int maxNbOfChoice) Ask the user to choose one or multiple staves. |
table | ChooseStavesGroups(Score score, boolean multiple, boolean visibleOnly, function filterFunc, function selectFunc) Ask the user to choose one or multiple staves groups. |
Target | ChooseTarget(Score score, string prompt, int selectedBar, string selectedName) Select a Target (rehearsal mark) in the Score. |
int | ChooseView(Score score, boolean index, int (default=current) Ask the user to choose one view, or a value for ViewIndex. |
string, int, int, string | EnterFont(string font, face, number size, string color) Ask the user to choose font, face, size and color using the built-in EditTextStyle() dialog. |
number | EnterNumber(string text, number defaultValue, number minValue, number maxValue) Ask the user to enter a number. |
number, number | 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. |
table | MenuMultipleChoice(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. | |
table | 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. |
boolean | SMConfirmation(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.
Parameter | Type | Default | Description |
---|---|---|---|
text | string | Text to dispaly in prompt popup | |
defaultValue | number | nil | A pre-defined value, or nil to force user to enter a value. |
minValue | number | nil | If specified, entered value is bound by min and max. |
maxValue | number | nil | If 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.
Parameter | Type | Default | Description |
---|---|---|---|
prompt | string | A prompt text above the plotter, nil means no prompt text. | |
minX | number | 0 | Minimal value for X |
maxX | number | 0 | Maximal value for X |
stepX | number | 1 | Step 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. |
factoryX | number | currentX | Default (factory) value for X, a dual click on the slider goes back to this value |
currentX | number | factoryX | Current displayed X value |
minY | number | 0 | Minimal value for Y |
maxY | number | 0 | Maximal value for Y |
stepY | number | 1 | Step 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. |
factoryY | number | currentY | Default (factory) value for Y, a dual click on the slider goes back to this value |
currentY | number | factoryY | Current displayed Y value |
displayValuesMask | string | "%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.
Parameter | Type | Default | Description |
---|---|---|---|
msg | string | 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.
Parameter | Type | Default | Description |
---|---|---|---|
title | string | Menu title | |
lexicon | Lexicon | 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:
|
- 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.
Parameter | Type | Default | Description |
---|---|---|---|
title | string | Menu title | |
lexicon | Lexicon | 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:
| ||
minNbOfChoice | int | 1 | Minimum number of items to choose, 0 means user can select nothing. |
maxNbOfChoice | int | 0 | Maximum 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.
Parameter | Type | Default | Description |
---|---|---|---|
score | Score | score | |
multiple | boolean | true | true if several staves can be chosen, false if only one staff can be chosen. |
visibleOnly | boolean | true | true if only visible staves are provided. |
filterFunc | function | Function that receives Score and Staff arguments, returns true if the staff appears in list, false if not. | |
selectFunc | function | Function that receives Score and Staff arguments, returns true if the staff is selected by default, false if not selected. | |
minNbOfChoice | int | 1 | Minimum number of staves to choose, 0 means user can choose no staff. No effect if multiple is false. |
maxNbOfChoice | int | 0 | Maximum 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.
Parameter | Type | Default | Description |
---|---|---|---|
score | Score | score | |
multiple | boolean | true | true if several staves groups can be chosen, false if only one staves group can be chosen. |
visibleOnly | boolean | true | true if only visible staves groups are provided. |
filterFunc | function | Function that receives Score and StavesGroup arguments, returns true if the staves group appears in list, false if not. | |
selectFunc | function | 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.
Parameter | Type | Default | Description |
---|---|---|---|
score | Score | score | |
index | boolean | Add the choices
| |
(default=current | int | view) selected index |
- Return
- int: view index
ChooseFont(string object, table suggestedFonts, selected)
Ask the user to choose one font in a menu.
"Tempo", "Staff name"
, see GetPreferredFont(..)
),
then, a list of favorites fonts,
then, a list of suggested fonts (e.g. found in score).
Parameter | Type | Default | Description |
---|---|---|---|
object | string | 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". | |
suggestedFonts | table | 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(...)
Parameter | Type | Default | Description |
---|---|---|---|
font | string | nil | Default font |
face | nil | Default face. A number (sum of FACE_* constants) or a string like "BI" for bold italic, second returned value by FontFaceNumberToString(...) . | |
size | number | nil | Default size |
color | string | nil | Default 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.
"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.
Parameter | Type | Default | Description |
---|---|---|---|
object | string | The name you want, e.g. "Staff background", "Staff lines" ... | |
suggestedColors | table | nil | A 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.
Parameter | Type | Default | Description |
---|---|---|---|
score | Score | score | |
prompt | string | "Select a rehearsal mark" | Title of the menu. |
selectedBar | int | 0 | Preselect target from the bar number selectedBar:
|
selectedName | string | nil | Select 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:
- message you don't need, e.g. aftertouch
- 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.
Parameter | Type | Default | Description |
---|---|---|---|
allowNoteOn | boolean | true | Allow Note On events? |
allowNoteOff | boolean | true | Allow Note Off events? |
allowCC | boolean | true | Allow controller change events? |
allowProgramChange | boolean | true | Allow PC event? |
allowAftertouch | boolean | true | Allow aftertouch event? |
allowPitchBend | boolean | true | Allow pitch bend event? |
allowOthers | boolean | true | Allow other events? |
delay | int | 0 | Delay 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. |
allowedSources | table | nil | The accepted sources (nil means all - no filter):
|
- 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
- Event, int: type of event :