forked from finale-lua/lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayback_selected_staves.lua
114 lines (103 loc) · 5.11 KB
/
playback_selected_staves.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function plugindef()
finaleplugin.RequireSelection = false
finaleplugin.Author = "Nick Mazuk"
finaleplugin.Copyright = "CC0 https://creativecommons.org/publicdomain/zero/1.0/"
finaleplugin.Version = "2.0.1"
finaleplugin.Date = "August 23, 2023"
finaleplugin.CategoryTags = "Playback"
finaleplugin.AuthorURL = "https://nickmazuk.com"
finaleplugin.ScriptGroupName = "Playback selected staves"
finaleplugin.ScriptGroupDescription = [[
Set up playback to the selected staves and measures, using either Solo or Mute
and (optionally) modifying the playback start/end measures.
]]
finaleplugin.AdditionalMenuOptions = [[
Mute selected staves
]]
finaleplugin.AdditionalDescriptions = [[
Sets up playback to the selected region by muting selected staves.
]]
finaleplugin.AdditionalPrefixes = [[
mute_staves = true
]]
finaleplugin.Notes = [[
Select the staves you want soloed or muted, then run this script. If nothing is selected, all solos and mutes
are cleared.
You can optionally use a configuration to start playback at the beginning of the selected region.
(If nothing is selected, it reverts playback to a selected default start option.)
To set the options, create a plain text file called
playback_selected_region.config.txt in a folder called `script_settings` within the same
folder as the script. It can contain any or all of the following configuration parameters.
(The default values are shown.)
```
set_playback_start = false -- if true, modify the playback start measure to match the selection or first measure if none
revert_playback_start = 0 -- revert to start measure playback when no selection exists (1 == leftmost, 2 == current counter)
include_chord_playback = true -- if true, modify chord playback as well
include_expression_playback = true -- if true, modify MIDI expression playback as well
include_end_measure = true -- if true, stop playback at the end measure of the region
```
]]
return "Solo selected staves", "Solo selected staves", "Sets up playback to the selected region."
end
local configuration = require("library.configuration")
local layer = require("library.layer")
local config = {
set_playback_start = false,
revert_playback_start = finale.PLAYBACKSTART_MEASURE,
include_chord_playback = true,
include_expression_playback = true,
include_end_measure = true
}
configuration.get_parameters("playback_selected_region.config.txt", config)
mute_staves = mute_staves or false
function set_layer_playback_data(layer_playback_data, region, staff_number)
layer_playback_data.Play = not region:IsStaffIncluded(staff_number) or not mute_staves
layer_playback_data.Solo = region:IsStaffIncluded(staff_number) and not mute_staves
end
function playback_selected_staves()
local full_doc_region = finale.FCMusicRegion()
full_doc_region:SetFullDocument()
local region = finenv.Region()
for slot = full_doc_region.StartSlot, full_doc_region.EndSlot do
local staff_number = region:CalcStaffNumber(slot)
local staff = finale.FCStaff()
staff:Load(staff_number)
local playback_data = staff:CreateInstrumentPlaybackData()
for this_layer = 1, layer.max_layers() do
set_layer_playback_data(playback_data:GetNoteLayerData(this_layer), region, staff_number)
end
if config.include_chord_playback then
set_layer_playback_data(playback_data:GetChordLayerData(), region, staff_number)
end
if config.include_expression_playback then
set_layer_playback_data(playback_data:GetMidiExpressionLayerData(), region, staff_number)
end
playback_data:Save()
end
if config.set_playback_start then
local playback_prefs = finale.FCPlaybackPrefs()
if playback_prefs:Load(1) then
if region:IsEmpty() then
playback_prefs.StartMode = config.revert_playback_start
playback_prefs.StartMeasure = 1
if playback_prefs.ConfigurePlaybackToEnd then -- if ConfigurePlaybackToEnd method exists (RGPLua 0.68+)
playback_prefs:ConfigurePlaybackToEnd()
else
playback_prefs.StopMeasure = 0x7ffe -- this selects the radio button for "End of Piece"
end
else
if playback_prefs.ConfigurePlaybackRegion then -- if ConfigurePlaybackToRegion exists (RGPLua 0.68+)
playback_prefs:ConfigurePlaybackRegion(region, not config.include_end_measure)
else
playback_prefs.StartMode = finale.PLAYBACKSTART_MEASURE
playback_prefs.StartMeasure = region.StartMeasure
if config.include_end_measure then
playback_prefs.StopMeasure = region.EndMeasure
end
end
end
playback_prefs:Save()
end
end
end
playback_selected_staves()