1
NumarkN4 = new Controller();
3
NumarkN4.currentDeck = function (group) {
4
if (group == "[Channel1]")
6
else if (group == "[Channel2]")
8
print("Invalid group : " + group);
12
NumarkN4.currentDeck2 = function (group) {
13
if (group == "[Channel1]")
15
else if (group == "[Channel2]")
18
print("Invalid group : " + group);
22
NumarkN4.init = function(id) { // called when the MIDI device is opened & set up
23
NumarkN4.id = id; // Store the ID of this device for later use
24
midi.sendShortMsg(0xb0, 0x39, 0x01);
25
//midi.sendShortMsg(0xB0, 0x39, 0x00);
26
NumarkN4.directoryMode = false;
28
NumarkN4.scratchMode = [false, false];
29
NumarkN4.scratchTimer = [-1, -1];
31
NumarkN4.manualLooping = [false, false];
32
NumarkN4.touched = [false, false];
36
{ "directory": 0x73, "file": 0x72 },
39
//0x1e = deck 1 triangle light
40
//0x1f = deck 2 triangle light
41
//0x20 = deck 3 triangle light
43
//0x39 = all lights around the outside
44
//0x40 = headphone cue button 1
45
//0x41 = headphone cue button 2
46
//0x42 = headphone cue button 3
47
//0x44 = vid fade 1 deck 1
48
//0x45 = vid fade 1 deck 2
49
//0x46 = vid fade 2 deck 1
50
//0x47 = vid fade 2 deck 2
51
//0x48 = vid fade 3 deck 1
52
//0x49 = vid fade 3 deck 2
53
//0x4a = vid fade 4 deck 1
54
//0x4b = vid fade 4 deck 2
59
{ "rate": 0x70, "scratchMode": 0x39, "manualLoop": 0x61, "loopIn": 0x53, "loopOut": 0x54, "reLoop": 0x55 },
61
{ "rate": 0x71, "scratchMode": 0x30, "manualLoop": 0x62, "loopIn": 0x56, "loopOut": 0x57, "reLoop": 0x58 }
63
NumarkN4.setLED(NumarkN4.leds[0]["file"], true);
66
NumarkN4.setLED = function(value, status) {
72
midi.sendShortMsg(0xB0, value, status);
75
NumarkN4.light = function(channel, control, value, status, group) {
77
midi.sendShortMsg(0xbf, value, 0x7f);
81
NumarkN4.scratch_sensitivity = 80;
83
NumarkN4.jogWheel = function(channel, control, value, status, group) {
84
var deck = NumarkN4.groupToDeck(group);
85
var adjustedJog = parseFloat(value);
87
if (adjustedJog > 63) { // Counter-clockwise
89
adjustedJog = value - 128;
92
if (NumarkN4.scratchMode[deck-1]) {
93
if (NumarkN4.scratchTimer[deck-1] == -1) {
94
engine.scratchEnable(deck, 128, 33+1/3, 1.0/8, (1.0/8)/32);
96
engine.stopTimer(NumarkN4.scratchTimer[deck-1]);
98
engine.scratchTick(deck, adjustedJog);
99
NumarkN4.scratchTimer[deck-1] = engine.beginTimer(20, "NumarkN4.jogWheelStopScratch(" + deck + ")", true);
101
var gammaInputRange = 23; // Max jog speed
102
var maxOutFraction = 0.5; // Where on the curve it should peak; 0.5 is half-way
103
var sensitivity = 0.5; // Adjustment gamma
104
var gammaOutputRange = 3; // Max rate change
105
if (engine.getValue(group,"play")) {
106
adjustedJog = posNeg * gammaOutputRange * Math.pow(Math.abs(adjustedJog) / (gammaInputRange * maxOutFraction), sensitivity);
108
adjustedJog = gammaOutputRange * adjustedJog / (gammaInputRange * maxOutFraction);
110
engine.setValue(group, "jog", adjustedJog);
114
NumarkN4.jogWheelStopScratch = function(deck) {
115
NumarkN4.scratchTimer[deck-1] = -1;
116
engine.scratchDisable(deck);
119
NumarkN4.toggleScratchMode = function(channel, control, value, status, group) {
120
var deck = NumarkN4.groupToDeck(group);
121
// Toggle setting and light
123
if (NumarkN4.scratchMode[deck-1]) {
124
NumarkN4.scratchMode[deck-1] = false;
126
NumarkN4.scratchMode[deck-1] = true;
129
//NumarkN4.setLED(NumarkN4.leds[deck]["scratchMode"], NumarkN4.scratchMode[deck-1]);
135
NumarkN4.groupToDeck = function(group) {
136
var matches = group.match(/^\[Channel(\d+)\]$/);
137
if (matches == null) {
144
NumarkN4.SelectTrack = function(channel, control, value, status, group) {
146
engine.setValue("[Playlist]","SelectNextTrack",1);
149
engine.setValue("[Playlist]","SelectPrevTrack",1);
153
NumarkN4.menuNext = function (channel, control, value, status, group) {
155
engine.setValue("[Playlist]","SelectNextPlaylist",1);
159
NumarkN4.menuPrev = function (channel, control, value, status, group) {
161
engine.setValue("[Playlist]","SelectPrevPlaylist",1);
165
NumarkN4.cue = function (channel, control, value, status, group) {
166
var currentlyPlaying = engine.getValue(NumarkN4.currentDeck2(group),"play");
167
if ((currentlyPlaying == 1) & (value == 0x7F)) {
168
engine.setValue(NumarkN4.currentDeck2(group),"cue_default",1);
170
else if ((currentlyPlaying == 0) & (value == 0x7F)) {
171
engine.setValue(NumarkN4.currentDeck2(group),"cue_default",1);
174
engine.setValue(NumarkN4.currentDeck2(group),"cue_default",0);
178
NumarkN4.touch = function (channel, control, value, status, group) {
179
var deck = NumarkN4.groupToDeck(group);
180
var currentlyPlaying = engine.getValue(NumarkN4.currentDeck2(group),"play");
181
if ((currentlyPlaying == 1) & (value == 0x7F & (NumarkN4.touched[deck-1] == false))) {
182
engine.setValue(NumarkN4.currentDeck2(group),"play",0);
183
NumarkN4.touched[deck-1] = true;
185
if ((currentlyPlaying == 0) & (value == 0x00) & (NumarkN4.touched[deck-1] == true)) {
186
engine.setValue(NumarkN4.currentDeck2(group),"play",1);
187
NumarkN4.touched[deck-1] = false;
191
//0x40 = headphone cue button 1
192
//0x41 = headphone cue button 2
193
NumarkN4.headcue = function (channel, control, value, status, group) {
194
var deck = NumarkN4.groupToDeck(group);
196
if ((status == 0x90) & (control == 0x31)){
197
midi.sendShortMsg(0xB0, 0x41, 0x00);
198
engine.setValue(NumarkN4.currentDeck2(group),"pfl",1);
201
if ((status == 0x80) & (control == 0x31)){
202
engine.setValue(NumarkN4.currentDeck2(group),"pfl",0);
205
if ((status == 0x90) & (control == 0x32)){
206
midi.sendShortMsg(0xB0, 0x40, 0x00);
207
engine.setValue(NumarkN4.currentDeck2(group),"pfl",1);
210
if ((status == 0x80) & (control == 0x32)){
211
engine.setValue(NumarkN4.currentDeck2(group),"pfl",0);