Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmidi_note_values.lua
More file actions
Latest commit
194 lines (180 loc) · 7.48 KB
/
Copy pathmidi_note_values.lua
File metadata and controls
194 lines (180 loc) · 7.48 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
functionplugindef()
finaleplugin.RequireSelection=true
finaleplugin.Author="Carl Vine"
finaleplugin.AuthorURL="http://carlvine.com/lua/"
finaleplugin.Copyright="https://creativecommons.org/licenses/by/4.0/"
finaleplugin.Version="0.22"
finaleplugin.Date="2024/02/03"
finaleplugin.CategoryTags="MIDI"
finaleplugin.MinJWLuaVersion=0.70
finaleplugin.AdditionalMenuOptions=[[
MIDI Note Duration...
MIDI Note Velocity...
]]
finaleplugin.AdditionalUndoText=[[
MIDI Note Duration
MIDI Note Velocity
]]
finaleplugin.AdditionalDescriptions=[[
Change the MIDI duration of notes on a chosen layer
Change the MIDI velocity of notes on a chosen layer
]]
finaleplugin.AdditionalPrefixes=[[
action = 0
action = 2
]]
finaleplugin.ScriptGroupName="MIDI Note Values"
finaleplugin.ScriptGroupDescription="Change the MIDI velocity and duration of notes on a chosen layer"
finaleplugin.Notes=[[
Change the playback __MIDI Velocity__ and __Duration__ (Start/Stop times)
of every note in the currently selected music on one or all layers.
Choose the _MIDI Note Values_ menu item to change both at once or set them
independently with _MIDI Note Duration_ and _MIDI Note Velocity_.
To affect playback when _Human Playback_ is active you must set
_Velocity_ and _Start/Stop Time_ to __HP Incorporate Data__ at
_Settings_ → _Human Playback_ → _MIDI Data_.
Otherwise set _Key Velocities_ and _Note Durations_ to __Play Recorded__
under _Playback/Record Options_ in the _Playback Controls_ window.
Note that some playback samples don't respond to velocity settings.
Hold down [Shift] when opening the script to
repeat your last choices without a confirmation dialog.
Layer number is "clamped" to a single character so to change
layer just type a new number - delete key not needed.
]]
return"MIDI Note Values...",
"MIDI Note Values",
"Change the MIDI velocity and duration of notes on a chosen layer"
end
action=actionor1-- 0 = Duration only / 1 = Both / 2 = Velocity only
localconfiguration=require("library.configuration")
localmixin=require("library.mixin")
locallayer=require("library.layer")
localutils=require("library.utils")
locallibrary=require("library.general_library")
localscript_name=library.calc_script_name()
localfocus_document=false-- set to true if utils.show_notes_dialog is used
localconfig= {
layer=0,
start_offset=0,
stop_offset=0,
velocity=64,
window_pos_x=false, -- saved dialog window position
window_pos_y=false,
}
localoptions= { -- key; text description
start_offset="Start time (EDU):",
stop_offset="Stop time (EDU):",
velocity="Key Velocity (0-127):",
layer="Layer 1-" ..layer.max_layers() .." (0 = all):"
}
localfunctiondialog_set_position(dialog)
ifconfig.window_pos_xandconfig.window_pos_ythen
dialog:StorePosition()
dialog:SetRestorePositionOnlyData(config.window_pos_x, config.window_pos_y)
dialog:RestorePosition()
end
end
localfunctiondialog_save_position(dialog)
dialog:StorePosition()
config.window_pos_x=dialog.StoredX
config.window_pos_y=dialog.StoredY
configuration.save_user_settings(script_name, config)
end
localfunctionuser_choices()
localoffset=finenv.UI():IsOnMac() and3or0-- extra y-offset for Mac EDIT box
localy, y_step=offset, 25
localedit_x, e_wide=120, 45
localsaved= {}
localdialog=mixin.FCXCustomLuaWindow():SetTitle(finaleplugin.ScriptGroupName)
-- local functions
localfunctionshow_info()
utils.show_notes_dialog(dialog, "About " ..finaleplugin.ScriptGroupName, 400, 247)
focus_document=true-- return focus to document
end
localfunctionkey_check(ctl, name) -- inhibit alphabetic keys and some negation
localval=ctl:GetText()
ifval:find("[^-0-9]")
or (name=="layer" andval:find("[^0-" ..layer.max_layers() .."]"))
or (name=="velocity" andval:find("-"))
then
ifval:find("[?q]") thenshow_info() end
ctl:SetText(saved[name]):SetKeyboardFocus()
elseifval~="" then
ifname=="layer" then
val=val:sub(-1) -- one character only
elseifname=="velocity" then
iftonumber(val) >127thenval="127" end
else-- EDU offsets
localnum_chars= (val:sub(1,1) =="-") and5or4
val=val:sub(1, num_chars) -- 4/5 characters max
end
ctl:SetText(val)
saved[name] =val
end
end
localfunctioncreate_value(name)
saved[name] =config[name] -- restore config values
dialog:CreateStatic(0, y):SetText(options[name]):SetWidth(edit_x)
dialog:CreateEdit(edit_x, y-offset, name):SetText(saved[name])
:SetWidth((name=="layer") and20ore_wide)
:AddHandleCommand(function(self) key_check(self, name) end)
y=y+y_step
end
if (action<=1) then-- "duration" or both
create_value("start_offset")
create_value("stop_offset")
end
if (action>=1) then-- "velocity" or both
create_value("velocity")
end
create_value("layer") -- always
dialog:CreateButton(edit_x+26, y-y_step):SetText("?"):SetWidth(20)
:AddHandleCommand(function() show_info() end)
dialog:CreateOkButton()
dialog:CreateCancelButton()
dialog:RegisterHandleOkButtonPressed(function(self)
fork, _inpairs(options) do
localctl=self:GetControl(k)
ifctlthenconfig[k] =ctl:GetInteger() end
end
end)
dialog_set_position(dialog)
dialog:RegisterCloseWindow(function() dialog_save_position(dialog) end)
return (dialog:ExecuteModal() ==finale.EXECMODAL_OK)
end
functionchange_values()
localprefs=finale.FCPlaybackPrefs()
prefs:Load(1)
localbasekey=prefs:GetBaseKeyVelocity()
forentryineachentrysaved(finenv.Region(), config.layer) do
ifentry:IsNote() then
localperf_mod=finale.FCPerformanceMod()
perf_mod:SetNoteEntry(entry)
fornoteineach(entry) do
perf_mod:LoadAt(note)
ifaction<=1then-- duration
ifnotnote.Tiethen-- don't change stop time of tied notes!
perf_mod.EndOffset=config.stop_offset
end
ifnotnote.TieBackwardsthen
perf_mod.StartOffset=config.start_offset
end
end
ifaction>=1then-- velocity
perf_mod.VelocityDelta=config.velocity-basekey
end
perf_mod:SaveAt(note)
end
end
end
end
functionmidi_note_values()
configuration.get_user_settings(script_name, config, true)
localqim=finenv.QueryInvokedModifierKeys
localmod_down=qimand (qim(finale.CMDMODKEY_ALT) orqim(finale.CMDMODKEY_SHIFT))
ifmod_downoruser_choices() then
change_values()
end
iffocus_documentthenfinenv.UI():ActivateDocumentWindow() end
end
midi_note_values()