-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddDepth.js
144 lines (121 loc) · 3.82 KB
/
AddDepth.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
var SCRIPT_TITLE = "Add Depth";
function getClientInfo() {
return {
"name": SV.T(SCRIPT_TITLE),
"author": "ZYFXzz",
"versionNumber": 0.1,
"minEditorVersion": 66048
}
}
//function getTranslations(langCode) {
// if(langCode == "ja-jp") {
// return [
// ["Remove Short Silences", "çŸã„無声区間をå–り除ã?"],
// ["Threshold", "ã—ãã„å??"],
// ["Scope", "スコープ"],
// ["Selected Notes", "é¸æŠžã•ã‚ŒãŸãƒŽãƒ¼ãƒˆ"],
// ["Current Track", "ç¾åœ¨ã®ãƒˆãƒ©ãƒƒã‚?"],
// ["Entire Project", "プãƒã‚¸ã‚§ã‚¯ãƒˆå…¨ä½“"],
// ];
// }
// return [];
//}
function sortNotes(arr_notes) {
return arr_notes.sort(function(a,b) {
if(a.getOnset() < b.getOnset()) return -1;
if(a.getOnset() > b.getOnset()) return 1;
return 0;
});
}
function noteGetter(arr_like, index) {
if(Array.isArray(arr_like)) {
return arr_like[index];
} else {
// the input is a NoteGroup
return arr_like.getNote(index);
}
}
function processNoteSequence(arr_like, N, threshold) {
for(var i = 1; i < N; i ++) {
var currOnset = noteGetter(arr_like, i).getOnset();
var prevEnd = noteGetter(arr_like, i - 1).getEnd();
if(currOnset != prevEnd &&
currOnset - prevEnd < SV.QUARTER * threshold) {
var prevOnset = noteGetter(arr_like, i - 1).getOnset();
noteGetter(arr_like, i - 1).setDuration(currOnset - prevOnset);
}
}
}
function main() {
var myForm = {
"title" : SV.T("Add Depth"),
"buttons" : "OkCancel",
"widgets" : [
{
"name" : "length", "type" : "Slider",
"label" : SV.T("Length"),
"format" : "%.0f/32 Quarters",
"minValue" : 1,
"maxValue" : 32,
"interval" : 1,
"default" : 4
},
{
"name" : "scope", "type" : "ComboBox",
"label" : SV.T("Scope"),
"choices" : [SV.T("Selected Notes"), SV.T("Current Track"),
SV.T("Entire Project")],
"default" : 0
},
{
"name" : "depth", "type" : "Slider",
"label" : SV.T("Depth"),
"format" : "%.0f/6 Keys",
"minValue" : 1,
"maxValue" : 6,
"interval" : 1,
"default" : 2
}
]
};
var result = SV.showCustomDialog(myForm);
var length = result.answers.length / 32.0;
var depth =result.answers.depth;
if(result.status == 1) {
if(result.answers.scope == 0) {
var selection = SV.getMainEditor().getSelection();
var selectedNotes = sortNotes(selection.getSelectedNotes());
var scope = SV.getMainEditor().getCurrentGroup();
var group = scope.getTarget();
var playhead = SV.getPlayback().getPlayhead();
var timeAxis = SV.getProject().getTimeAxis();
var playheadBlicks = timeAxis.getBlickFromSeconds(playhead) - scope.getTimeOffset();
for(var i = 0; i < selectedNotes.length; i ++) {
var note = selectedNotes[i];
var originalOnset = note.getOnset();
var originalEnd = note.getEnd();
var fullDuration = note.getDuration();
// Skip very short notes.
if(fullDuration < SV.QUARTER / 16)
continue;
// Split in the middle by default.
var durationLeft = Math.round(length*SV.QUARTER);
//// // Split at playhead position if intersects.
if(playheadBlicks > originalOnset && playheadBlicks < originalEnd)
durationLeft = playheadBlicks - originalOnset;
// The left note after splitting.
note.setDuration(durationLeft);
var notPitch=note.getPitch();
note.setPitch(notPitch-depth);
// The right note after splitting.
var splitted = SV.create("Note");
splitted.setPitch(notPitch);
splitted.setTimeRange(note.getEnd(), originalEnd - note.getEnd());
splitted.setLyrics("-");
group.addNote(splitted);
selection.selectNote(splitted);
}
}
}
SV.finish();
}