-
Notifications
You must be signed in to change notification settings - Fork 1
/
old_synthvGrowl.js
175 lines (156 loc) · 5.33 KB
/
old_synthvGrowl.js
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
function getClientInfo() {
return {
"name": "SynthV Growl",
"category": "old_version",
"author": "PNCSS",
"versionNumber": 1,
"minEditorVersion": 0
};
}
// Wrapper function to know the flow of code
function main() {
/*
1st check user inputs
2nd start a core routine
3rd end plugin
*/
if (validateBeforeStarting()) {
var formResult = SV.showCustomDialog(makeForm());
if (formResult.status) {
coreRoutine(formResult);
SV.showMessageBox("title", "end");
}
}
SV.finish();
}
// Validate user request
function validateBeforeStarting() {
// if selected notes is empty, show message box and finish
if (SV.getMainEditor().getSelection().getSelectedNotes().length < 1) {
SV.showMessageBox("Selected Notes is Empty", "You have to select at least one note.");
return false;
}
return true;
}
// create custom dialog form
// TODO: localization
function makeForm() {
return {
"title": "SynthV Growl",
"message": "Apply Growl to selected notes.\n Select range and growl value",
"buttons": "OkCancel",
"widgets": [{
"name": "startPos",
"type": "Slider",
"label": "Start Position",
"format": "%1.1f",
"minValue": 0,
"maxValue": 100,
"interval": 0.1,
"default": 0
},
{
"name": "endPos",
"type": "Slider",
"label": "End Position",
"format": "%1.1f",
"minValue": 0,
"maxValue": 100,
"interval": 0.1,
"default": 100
},
{
"name": "depth",
"type": "Slider",
"label": "Growl Depth",
"format": "%1.1f",
"minValue": 0,
"maxValue": 600,
"interval": 0.1,
"default": 90
},
{
"name": "frequency",
"type": "Slider",
"label": "Pitch frequency 1/N",
"format": "%1.0f",
"minValue": 1,
"maxValue": 10000,
"interval": 1,
"default": 500
},
]
}
}
function coreRoutine(formResult) {
var dataObject = getDataObject();
for (var index = 0; index < dataObject.notes.length; index++) {
var note = dataObject.notes[index];
var positions = getActualStartAndEndPosition(note, formResult.answers.startPos, formResult.answers.endPos);
var posArr = makePositionArray(positions.sPos, positions.ePos, formResult.answers.frequency);
growl(dataObject.ptichParameter, posArr, formResult.answers.depth);
}
}
// Create filted data, and return them as an Object
function getDataObject() {
var selectedNotes = SV.getMainEditor().getSelection().getSelectedNotes();
var currentNoteGroup = selectedNotes[0].getParent();
var pitchParameter = currentNoteGroup.getParameter("pitchDelta");
return {
notes: selectedNotes,
ptichParameter: pitchParameter,
}
}
// Create duration corresponding to 1% unit
function makeDurationUnitBasedPercent(note) {
var totalDuration = note.getDuration();
return totalDuration / 100;
}
// Calculate start position
function getActualStartPosition(curStartPos, unit, startPositionPercent) {
return curStartPos + (unit * startPositionPercent);
}
// Calculate end position
function getActualEndPosition(curEndPos, unit, endPositionPercent) {
var actualEndPosPercent = 100 - endPositionPercent;
return curEndPos - (unit * actualEndPosPercent);
}
// Return both start position and end position
function getActualStartAndEndPosition(note, startPositionPercent, endPositionPercent) {
var unit = makeDurationUnitBasedPercent(note);
// var sPos = getActualStartPosition(note.getOnset(), unit, startPositionPercent);
// var ePos = getActualEndPosition(note.getEnd(), unit, endPositionPercent);
return {
sPos: getActualStartPosition(note.getOnset(), unit, startPositionPercent),
ePos: getActualEndPosition(note.getEnd(), unit, endPositionPercent)
};
}
// Returns an array of positions to modify the pitch.
function makePositionArray(sPos, ePos, freq) {
// Calculate actual duration
function makeActualDuration(sPos, ePos) {
return ePos - sPos;
}
var actualDuration = makeActualDuration(sPos, ePos);
var durationUnitFrequency = actualDuration / freq;
var result = [];
for (var pos = sPos; pos <= ePos; pos += durationUnitFrequency) {
result.push(pos);
}
return result;
}
// Apply pitch values
function growl(pitchParam, posArr, depth) {
var isNegative = false;
// Remove all pitch value between the range
pitchParam.remove(posArr[0], posArr[posArr.length-1]);
// Both ends of the specified range are fixed at zero so that other notes are not affected.
pitchParam.add(posArr[0] - 100, 0);
pitchParam.add(posArr[posArr.length-1] + 100, 0);
for (var index = 0; index < posArr.length; index++) {
var pos = posArr[index];
var value = isNegative ? -1 * depth : depth;
pitchParam.add(pos, value);
isNegative = !isNegative;
}
}