Section Batch
Batch processing.
- Examples
--CREATOR: Sylvain --NAME: Change score title font --BATCH: Score -- assume this script is in Scripts > Notation > Score menu local n,f,s,c = ChooseFont("Title") if n then local fl, fs = FontFaceNumberToString(f) if BatchIsRecording("Score") == true then BatchAdd("Score", "Title font = "..n.." "..s.." "..fl, function(score) local sty = score.Title.Style sty.Font, sty.Face, sty.Size, sty.Color = %n, %fs, %s, %c score.Title.String = PurgeStringStyle(score.Title.String) end ) elseif FrontScore() ~= nil then local sty = FrontScore().Title.Style sty.Font, sty.Face, sty.Size, sty.Color = n,fs,s,c FrontScore().Title.String = PurgeStringStyle(FrontScore().Title.String) end end
-- Demonstrate batch processing BatchStartRecording("Score") -- Ask for the font Run("ChangeTitleFont") -- Ask for something else -- Include "another script that do crazy things on Score object" BatchStopRecording("Score") local folder = GetFolderName() if folder ~= nil then BrowseFolder(folder, "*.myr", function(fileName) local score = Load(fileName, false, false, false, false, false, false, false, false, 0) BatchExecute("Score", {score}) return true -- continue browsing end ) end BatchClear("Score")
Summary
| Return type | Function and summary |
|---|---|
| BatchAdd(string batchName, string label, function func) Stack a function for batch processing. | |
| BatchClear(string batchName) Clear the batch stack, in case of cancellation or when all calls are done. | |
| int | BatchExecute(string batchName, Score score, object) Execute the batch function stack on the objects in argument table. |
| BatchIsRecording(string batchName) Is the batch currently stacking? | |
| BatchStartRecording(string batchName) Just set a flag that tells we are currently recording and stacking functions for further batch processing. | |
| BatchStopRecording(string batchName) Cancel the flag that tells we are recording and stacking operations for batch processing, without clearing the stack. | |
| table | table_unique(table tab) Remove duplicates from a table |
Functions
BatchStartRecording(string batchName)
Just set a flag that tells we are currently recording and stacking functions for further batch processing.
| Parameter | Type | Default | Description |
|---|---|---|---|
| batchName | string | Batch name, by convention the type of object function will accept as argument ("Score", "Staff"...). |
BatchStopRecording(string batchName)
Cancel the flag that tells we are recording and stacking operations for batch processing, without clearing the stack.
| Parameter | Type | Default | Description |
|---|---|---|---|
| batchName | string | Batch name, by convention the type of object function will accept as argument ("Score", "Staff"...). |
- Return
- int Stack size
BatchIsRecording(string batchName)
Is the batch currently stacking?
If yes, then function must be stacked by BatchAdd, else performed directly.
| Parameter | Type | Default | Description |
|---|---|---|---|
| batchName | string | Batch name, by convention the type of object function will accept as argument ("Score", "Staff"...). |
- Return
- bvool
trueif recording,nil(for false) if not - Example
if BatchIsRecording("Score") == true then BatchAdd("Score", "My action", MyFunction) else MyFunction(FrontScore()) end
BatchAdd(string batchName, string label, function func)
Stack a function for batch processing.
| Parameter | Type | Default | Description |
|---|---|---|---|
| batchName | string | Batch name, by convention the type of object function will accept as argument ("Score", "Staff"...). | |
| label | string | Just a label to show progression or report an error with context. | |
| func | function | The function that will be performed later, by BatchExecute.
|
BatchClear(string batchName)
Clear the batch stack, in case of cancellation or when all calls are done.
| Parameter | Type | Default | Description |
|---|---|---|---|
| batchName | string | Batch name, by convention the type of object function will accept as argument ("Score", "Staff"...). |
BatchExecute(string batchName, Score score, object)
Execute the batch function stack on the objects in argument table.
| Parameter | Type | Default | Description |
|---|---|---|---|
| batchName | string | Batch name, by convention the type of object function will accept as argument ("Score", "Staff"...). | |
| score | Score | If needed, the score on which the batch will be processed | |
| object | nil | The object (Staff, Instrument...) that will be given as first argument to each function in the stack. |
- Return
- int: Number of functions called.
table_unique(table tab)
Remove duplicates from a table
| Parameter | Type | Default | Description |
|---|---|---|---|
| tab | table | tab |
- Return
- table: table