-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scale Pitch Deviation.lua
119 lines (90 loc) · 2.71 KB
/
Scale Pitch Deviation.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
115
116
117
118
119
SCRIPT_TITLE = "Scale Pitch Deviation"
-- Standard header
function getClientInfo()
return {
name = SV:T(SCRIPT_TITLE),
author = "David Cuny",
versionNumber = 1,
minEditorVersion = 65537
}
end
-- main function
function main()
-- create a form
local form = {
title = SV:T(SCRIPT_TITLE),
message = "",
buttons = "OkCancel",
widgets = {
{
-- pitch sliding scale
name = "pScale",
type = "Slider",
label = SV:T("Pitch Deviation Scaling Percent"),
format = "%3.0f",
minValue = 25,
maxValue = 400,
interval = 10,
default = 100
},
}
}
-- render the dialog
local results = SV:showCustomDialog(form)
-- not cancelled?
if results.status then
doScaling(results.answers)
end
-- clean up and exit
SV:finish()
end
-- Return a table of notes containing all the selected notes
function getStartAndEnd(options)
-- get the selected items from the Editor object
local selection = SV:getMainEditor():getSelection()
-- get the selected notes from the selected items
local selectedNotes = selection:getSelectedNotes()
-- exit routine if no notes selected
if #selectedNotes == 0 then
return nil
end
-- get onset and end of first note
local theOnset = selectedNotes[1]:getOnset()
local theEnd = selectedNotes[1]:getEnd()
-- loop through remainder of notes
for i = 2, #selectedNotes do
-- get the note
local theNote = selectedNotes[i]
theOnset = math.min( theOnset, theNote:getOnset() )
theEnd = math.max( theEnd, theNote:getEnd() )
end
-- return the ranges table for each selected note
return theOnset, theEnd
end
-- Scale the pitch deviation
function doScaling(options)
-- get scaling supplied by the user
local pScale = options.pScale / 100
-- find the start of the first selected note and the end of the last selected note
local startBlicks, endBlicks = getStartAndEnd(options)
-- no selected notes?
if not startBlicks then
SV:showMessageBox("Warning", "No notes selected.")
-- exit, doing nothing
return
end
-- get the current group from the main editor {NoteGroupReference}
local scope = SV:getMainEditor():getCurrentGroup()
-- get the target {NoteGroup}
local group = scope:getTarget()
-- get the {Automation} from the group by name
local amPitchDelta = group:getParameter("pitchDelta")
local controlPoints = amPitchDelta:getPoints(startBlicks, endBlicks)
-- loop through the automation values
for key, p in ipairs( controlPoints ) do
-- scale value, but keep in range
local scaled = math.min( p[2] * pScale, 1200 )
-- replace value with scaled value
amPitchDelta:add( p[1], scaled )
end
end