-
Notifications
You must be signed in to change notification settings - Fork 0
/
American-Audio-VMS4-alt-scripts.js
160 lines (125 loc) · 3.46 KB
/
American-Audio-VMS4-alt-scripts.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
VMS4 = new Controller();
VMS4.msb = {};
VMS4.jog_prev = {};
VMS4.vinyl = { 1: false, 2: false };
VMS4.scratch_timer = { 1: false, 2: false };
VMS4.track_knob_prev = {};
VMS4.pitch_lock = {};
// Extinguish all LEDs
VMS4.shutdown = function ()
{
for (i=12; i<=77; i++)
midi.sendShortMsg( 0x80, i, 0x00 );
}
// Pause
VMS4.pause = function( channel, control, value, status, group )
{
if( engine.getValue(group, "play") )
engine.setValue( group, "play", 0 );
}
// Jog wheel
VMS4.jogMsb = function( channel, control, value, status, group )
{
VMS4.msb[group] = value;
}
VMS4.jogLsb = function( channel, control, value, status, group )
{
// LSB<<7 + MSB
var pos = (VMS4.msb[group] << 7) + value;
var deck = group=="[Channel1]" ? 1 : 2;
// Enable scratch
if( VMS4.vinyl[deck] && !VMS4.scratch_timer[deck] )
engine.scratchEnable( deck, 1500, 45, 1.0/8, 1.0/8/32 );
// Reset timer
if( VMS4.vinyl[deck] )
{
if( VMS4.scratch_timer[deck] )
engine.stopTimer( VMS4.scratch_timer[deck] );
VMS4.scratch_timer[deck] = engine.beginTimer( 50, "VMS4.scratchTimeout("+deck+")", true );
}
// Initialized
if( !isNaN(VMS4.jog_prev[group]) )
{
var offset = pos - VMS4.jog_prev[group];
if( offset > 8192 )
offset -= 16384;
else if( offset < -8192 )
offset += + 16384;
if( VMS4.scratch_timer[deck] )
engine.scratchTick( deck, offset );
else
engine.setValue( group, "jog", offset/40.0 );
}
// Save previous position
VMS4.jog_prev[group] = pos;
}
// Stop scrach by timer
VMS4.scratchTimeout = function( deck )
{
VMS4.scratch_timer[deck] = false;
engine.scratchDisable( deck );
}
// Enable/disable vinyl mode
VMS4.vinylToggle = function( channel, control, value, status, group )
{
var deck = group=="[Channel1]" ? 1 : 2;
VMS4.vinyl[deck] = !VMS4.vinyl[deck];
// LED
var led = { 1: 0x27, 2: 0x49 };
if( VMS4.vinyl[deck] )
midi.sendShortMsg( 0x90, led[deck], 0x7f );
else
midi.sendShortMsg( 0x80, led[deck], 0x00 );
}
VMS4.beatjump = function( channel, control, value, status, group )
{
var jump_len = { 0x0f: -16.0, 0x10: 16.0, 0x31: -16.0, 0x32: 16.0 };
var len = engine.getValue( group, "track_samples" ) / engine.getValue( group, "track_samplerate" ) / 2.0;
var bpm = engine.getValue( group, "file_bpm" );
var beat_size = 60.0 / bpm / len;
var pos = engine.getValue( group, "playposition" ) + beat_size*jump_len[control];
engine.setValue( group, "playposition", pos );
}
// Flanger toggle
VMS4.flangerToggle = function( channel, control, value, status, group )
{
if( status == 0x90 )
engine.setValue( group, "flanger", 1 );
else
engine.setValue( group, "flanger", 0 );
}
VMS4.trackSelect = function( channel, control, value, status, group )
{
// Initialized
if( !isNaN(VMS4.track_knob_prev[group]) )
{
var offset = value - VMS4.track_knob_prev[group];
if( offset > 64 )
offset -= 128;
else if( offset < -64 )
offset += 128;
engine.setValue( "[Playlist]", "SelectTrackKnob", offset );
}
VMS4.track_knob_prev[group] = value;
}
// Lock pitch in center position
VMS4.pitchLock = function( channel, control, value, status, group )
{
if( status == 0x90 )
{
engine.setValue( group, "rate", 0.0 );
VMS4.pitch_lock[group] = true;
}
else
VMS4.pitch_lock[group] = false;
}
// pitch control
VMS4.pitch = function( channel, control, value, status, group )
{
// Locked on 0
if( VMS4.pitch_lock[group] )
return;
var value = (value << 7) | control;
var rate = (8192-value) / 8191.0;
engine.setValue( group, "rate", rate );
}