-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomaticVelocityBuilds.js
48 lines (41 loc) · 1.58 KB
/
automaticVelocityBuilds.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
/* Automatic Velocity Builds
Script by: Daniel Turner
License: MIT */
var NeedsTimingInfo = true; // enables timing info object
// sliders and menu selection
var PluginParameters = [
{name:"Build Length", defaultValue:4, minValue:1, maxValue:16, numberOfSteps:15, unit:" measures", type:"lin"},
{name:"Build Range", defaultValue:127, minValue:1, maxValue:127, numberOfSteps:126, type:"lin"},
{name:"Peak Velocity", defaultValue:127, minValue:0, maxValue:127, numberOfSteps:127, type:"lin"},
{name:"Build Mode", type:'menu', valueStrings:["Linear", "Exponential"], defaultValue:0}];
function HandleMIDI(event)
{
// load slider and menu parameters
var measures = GetParameter("Build Length");
var range = GetParameter("Build Range");
var maxVelocity = GetParameter("Peak Velocity");
var buildMode = GetParameter("Build Mode");
// get current beat and set up number of beats for each build
var logicInfo = GetTimingInfo();
var beat = logicInfo.blockStartBeat + logicInfo.blockLength;
var buildLength = logicInfo.meterNumerator * measures;
var beatPositionInBuild = (beat-1) % buildLength;
var newVelocity;
// calculate velocity for linear setting
newVelocity = beatPositionInBuild * (range / buildLength);
// calculate velocity for exponential setting
if (buildMode === 1) {
newVelocity = Math.pow(newVelocity, 2)/range;
}
// compensate for range bottom and set peak velocity offset
newVelocity += (maxVelocity - range);
// minimum value for velocity is 0
if (newVelocity > 0) {
event.velocity = newVelocity;
}
else {
event.velocity = 0;
}
// send note to Logic
event.send();
}