Section Staves

Staff utility functions

See
Staff
StavesGroups
StavesGroup

Summary

Return typeFunction and summary
tableChooseStaves(Score score, boolean multiple, boolean visibleOnly, function filterFunc, function selectFunc, int minNbOfChoice, int maxNbOfChoice)
Ask the user to choose one or multiple staves.
 CopyBarNumberings(Staff source, Staff dest)
Copy bar numberings settings from one staff to another.
intDeleteDisabledCurves(Staff staff)
Remove the parameter curves that have been disabled.
intDeleteEmptyCurves(Staff staff)
Remove the empty parameter curves when they have no values.
booleanEnsureObjectInStaffArea(Score score, Staff staff, obj)
Ensure an object is in the Staff area, move it vertically if needed.
tableGetChordsFromStaff(Score score, Staff staff, boolean held)
Get the chords of a Staff from the chord line and return detailed informations.
CollectionGetDynamicsThatApplyToStaff(Score score, Staff staff)
Get all Dynamic that apply to the specified Staff.
table, intGetMergedStaves(Staff staff)
Get all staves merged with staff, included.
tableGetStavesGroups(Score score, Staff staff)
Get all StavesGroups of the score or containing staff if this argument is provided.
tableGetStavesInGroup(StavesGroup sg)
Return an array of staves in StavesGroup sg
 JumpAndSelectBar(Score score, int barN, Staff staffBegin, Staff stafEnd)
Jump to the requested bar number and select it, all staves or the requested staff if not nil.
intSMApplyToAllSelectedSymbols(Score score, function processFunc, boolean excludeSpecials)
Apply a function to all selected symbols, individually selected or continous selection.
intSMApplyToAllSymbols(Score score, staves, int firstBar, int lastBar, function processFunc, boolean excludeSpecials)
Apply a function to all symbols in the score, or staff, or in a range of bars.
Symbol, StaffSearchNextSymbol(Score score, staves, from, function matcher)
Search next symbol with custom matcher function, in whole score or a list of staves, at a time position or after a symbol.
Symbol, StaffSearchPreviousSymbol(Score score, staves, from, function matcher)
Search previous symbol with custom matcher function, in whole score or a list of staves, at a time position or before a symbol.
 SetGhostRestDisplayMode(Score score, int grdm)
Set the ghost rest display mode for all staves in all views.
 StaffSetAmbitus(Score score, Staff staff, boolean state)
Set the ambitus enabled or disabled for staff, and also at score's level else ambitus won't display.

Functions

SMApplyToAllSelectedSymbols(Score score, function processFunc, boolean excludeSpecials)

Apply a function to all selected symbols, individually selected or continous selection.

MSLibrary's ApplyToAllSelectedSymbols(...) function doesn't handle individually selected symbols, and browse from last to first, which is safe for symbol deletion. This customized browse selected notes on all staves from first to last, not convenient for deletion. It can skips ghost rests and special symbols, handles individual and continuous (range) selection.

ParameterTypeDefaultDescription
scoreScore score
processFuncfunction Function with two Symbol and Staff arguments, which returns true (= 1) if symbol has been processed, -1 to stop the process. Other returned values are ignored, process continue to next symbol.
excludeSpecialsbooleanfalseExclude ghost rest, mesure repeat (%, %2, %4), and unison in divisi (//)?
Return
int: Number of processed symbols
Error
if score is not a Score or processFunc is not a function.
See
SMApplyToAllSymbols

SMApplyToAllSymbols(Score score, staves, int firstBar, int lastBar, function processFunc, boolean excludeSpecials)

Apply a function to all symbols in the score, or staff, or in a range of bars.

ParameterTypeDefaultDescription
scoreScore score
staves nil
  • nil means all staves
  • a Staff object to apply only to that staff
  • a table of Staff to apply to a list of staves
firstBarint1First bar to start applying the function.
lastBarintscore.NumberOfBarsLast bar to stop applying the function.
processFuncfunction Function with two Symbol and Staff arguments, which returns true (= 1) if symbol has been processed, -1 to stop the process. Other returned values are ignored, process continue to next symbol.
excludeSpecialsbooleanfalseExclude ghost rests, bar repeats (%, %2, %4) and unison in divisi (//)?
Return
int: Number of processed symbols
Error
if arguments have wrong types.
See
SMApplyToAllSelectedSymbols

GetDynamicsThatApplyToStaff(Score score, Staff staff)

Get all Dynamic that apply to the specified Staff.

Dynamics are:

  • velocity changes (crescendo, decrescendo, pppp to fff)
  • Tempo change
  • Pedal on/off
  • Ottava

ParameterTypeDefaultDescription
scoreScore score
staffStaff staff
Return
Collection: of Dynamics that apply to staff are on attached to it, or one of merged staves with it, or one of the staves of the group, or to the whole score.
Error
if score or staff are nil

GetChordsFromStaff(Score score, Staff staff, boolean held)

Get the chords of a Staff from the chord line and return detailed informations.

This is useful to build bass and chords accompaniments, perform analysis, or whatever you want.
The returned structure is a table, indexed from 1 to number of chords. Each element is a table which contains properties:

  • Chord: a Chord object, able to parse more complex notations than HA. From this object, you can obtain the list of notes, chord octave, bass octave (2 octaves lower), inversion...
  • BarNumber: the bar number where the chord is writed
  • TimeBegin: time (in tick, from the beginning of the score), where the chord starts to play
  • TimeEnd: time (in ticks, from the beginning of the score), where the chord ends, just before next chord or an empty cell/bar.
  • ArppegioDelay: by default, staff.ChordArpeggioDelay. May change if [Annn] command has been encountered in chord line.

ParameterTypeDefaultDescription
scoreScore score
staffStaff staff
heldbooleannilHold chord until next is encountered? If nil, use the chord line setup of the staff. HA needs underscore (_) to hold a chord, but this is unsightly for printing, and works randomly.
Return
table: table
See
Chord for more details about Chord object.
Example

local chords = GetChordsFromStaff(FrontScore(), FrontScore().FirstStaff)
 for i=1,getn(chords) do
   print("Chord #" .. i .. ": "..chords[i].Chord:toASCIIName())
   print("Bar #" .. chords[i].BarNumber)
   print(tdebug(chords[i].Chord:notes()))
 end

EnsureObjectInStaffArea(Score score, Staff staff, obj)

Ensure an object is in the Staff area, move it vertically if needed.

ParameterTypeDefaultDescription
scoreScore score
staffStaff staff
obj  Object: Dynamic, StaffText, FXProcessor, Picture
Return
boolean: true if object has been moved vertically, false otherwise.

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.

GetStavesGroups(Score score, Staff staff)

Get all StavesGroups of the score or containing staff if this argument is provided.

ParameterTypeDefaultDescription
scoreScore score
staffStaffnilIf nil, return all StavesGroups of the score, else return the ones containing staff.
Return
table: An array of StavesGroups, ordered from first to last Staff (Score.FirstStavesGroup is the first created in the document, not the first printed). Array is empty if no StavesGroups found.
Error
if score is not a Score or staff is not a Staff

GetStavesInGroup(StavesGroup sg)

Return an array of staves in StavesGroup sg

ParameterTypeDefaultDescription
sgStavesGroup sg
Return
table: Array of Staff

GetMergedStaves(Staff staff)

Get all staves merged with staff, included.

If staff is not merged, it returns {staff}, 1, only the argument staff, and 1 is the index of it in the table.

ParameterTypeDefaultDescription
staffStaff staff
Returns
table: Table of Staff objects
int: The index of staff in the table.

StaffSetAmbitus(Score score, Staff staff, boolean state)

Set the ambitus enabled or disabled for staff, and also at score's level else ambitus won't display.

ParameterTypeDefaultDescription
scoreScore score
staffStaff staff
stateboolean true to show ambitus, false to hide it.

JumpAndSelectBar(Score score, int barN, Staff staffBegin, Staff stafEnd)

Jump to the requested bar number and select it, all staves or the requested staff if not nil.

Try to position the selected bar near the center of the screen, unlike Score.JumpToBar(...) which also doesn't select.

ParameterTypeDefaultDescription
scoreScore score
barNint Bar number, must be lower or equal to Score.NumberOfBars
staffBeginStaffnilIf not nil, first or only staff to select, instead of all staves.
stafEndStaffnilIf not nil, last staff to select
Error
if barN > score.NumberOfBars or staff is not nil and not a Staff.

DeleteDisabledCurves(Staff staff)

Remove the parameter curves that have been disabled.

ParameterTypeDefaultDescription
staffStaff staff
Return
int: Number of deleted curves

DeleteEmptyCurves(Staff staff)

Remove the empty parameter curves when they have no values.

ParameterTypeDefaultDescription
staffStaff staff
Return
int: Number of deleted curves

CopyBarNumberings(Staff source, Staff dest)

Copy bar numberings settings from one staff to another.

ParameterTypeDefaultDescription
sourceStaff source
destStaff dest

SetGhostRestDisplayMode(Score score, int grdm)

Set the ghost rest display mode for all staves in all views.

ParameterTypeDefaultDescription
scoreScore score
grdmint 
  • 0 = don't display
  • 1 = display with a mark
  • 2 = display whole rest in empty bars
  • 3 = display with real rests

SearchNextSymbol(Score score, staves, from, function matcher)

Search next symbol with custom matcher function, in whole score or a list of staves, at a time position or after a symbol.

ParameterTypeDefaultDescription
scoreScore score
staves nil
  • nil means all staves (whole score)
  • a Staff object to search in this staff only
  • a table of Staff objects to search in multiple staves
from 0
  • A int for a time, the result may be the symbol at this position
  • a Symbol to start search from this symbol, result is never this symbol
matcherfunctionnilA function that accepts a Symbol argument and returns true if the symbol matches the criteria(s) of the search. If matcher is nil then return the next symbol which is not a ghost rest.
Returns
Symbol: First matching symbol at time from or after from symbol, nil if not found (end of music is reached)
Staff: The staff containing the returned symbol, or nil if not found
Example


 local m = function(sym) return sym.IsRest; end
 local rest, staff = SearchNextSymbol(FrontScore(), nil, 0, m)
 local cpt = 0
 while rest do
   cpt = cpt + 1
   print("#"..cpt, "staff #"..staff.Index, "time="..rest.Time)
   rest, staff = SearchNextSymbol(FrontScore(), nil, rest, m)
 end

SearchPreviousSymbol(Score score, staves, from, function matcher)

Search previous symbol with custom matcher function, in whole score or a list of staves, at a time position or before a symbol.

ParameterTypeDefaultDescription
scoreScore score
staves nil
  • nil means all staves (whole score)
  • a Staff object to search in this staff only
  • a table of Staff objects to search in multiple staves
from music duration
  • A int for a time, the result may be the symbol at this position
  • a Symbol to start search from this symbol, result is never this symbol
matcherfunctionnilA function that accepts a Symbol argument and returns true if the symbol matches the criteria(s) of the search. If matcher is nil then return the previous symbol which is not a ghost rest.
Returns
Symbol: First matching symbol at time from or before from symbol, nil if not found (start of music is reached)
Staff: The staff containing the returned symbol, or nil if not found
Example


 local m = function(sym) return sym.IsRest; end
 local rest, staff = SearchPreviousSymbol(FrontScore(), nil, nil, m)
 local cpt = 0
 while rest do
   cpt = cpt + 1
   print("#"..cpt, "staff #"..staff.Index, "time="..rest.Time)
   rest, staff = SearchPreviousSymbol(FrontScore(), nil, rest, m)
 end