summaryrefslogtreecommitdiffstats
path: root/res/controllers/Hercules-DJ-Control-AIR-scripts.js
blob: ee9685275c8393930a4f785176f3012d9ca88641 (plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
function HerculesAir () {}

HerculesAir.beatStepDeckA1 = 0
HerculesAir.beatStepDeckA2 = 0x44
HerculesAir.beatStepDeckB1 = 0
HerculesAir.beatStepDeckB2 = 0x4C

HerculesAir.scratchEnable_alpha = 1.0/8
HerculesAir.scratchEnable_beta = (1.0/8)/32
HerculesAir.scratchEnable_intervalsPerRev = 128
HerculesAir.scratchEnable_rpm = 33+1/3

HerculesAir.shiftButtonPressed = false
HerculesAir.enableSpinBack = false

HerculesAir.wheel_multiplier = 0.4

HerculesAir.init = function(id) {
    HerculesAir.id = id;

	// extinguish all LEDs
    for (var i = 79; i<79; i++) {
        midi.sendShortMsg(0x90, i, 0x00);
    }
	midi.sendShortMsg(0x90, 0x3B, 0x7f) // headset volume "-" button LED (always on)
	midi.sendShortMsg(0x90, 0x3C, 0x7f) // headset volume "+" button LED (always on)

	if(engine.getValue("[Master]", "headMix") > 0.5) {
		midi.sendShortMsg(0x90, 0x39, 0x7f) // headset "Mix" button LED
	} else {
		midi.sendShortMsg(0x90, 0x3A, 0x7f) // headset "Cue" button LED
	}

    // Set soft-takeover for all Sampler volumes
    for (var i=engine.getValue("[Master]","num_samplers"); i>=1; i--) {
        engine.softTakeover("[Sampler"+i+"]","pregain",true);
    }
    // Set soft-takeover for all applicable Deck controls
    for (var i=engine.getValue("[Master]","num_decks"); i>=1; i--) {
        engine.softTakeover("[Channel"+i+"]","volume",true);
        engine.softTakeover("[Channel"+i+"]","filterHigh",true);
        engine.softTakeover("[Channel"+i+"]","filterMid",true);
        engine.softTakeover("[Channel"+i+"]","filterLow",true);
    }

    engine.softTakeover("[Master]","crossfader",true);

	engine.connectControl("[Channel1]", "beat_active", "HerculesAir.beatProgressDeckA")
	engine.connectControl("[Channel1]", "play", "HerculesAir.playDeckA")

	engine.connectControl("[Channel2]", "beat_active", "HerculesAir.beatProgressDeckB")
	engine.connectControl("[Channel2]", "play", "HerculesAir.playDeckB")
    
    print ("Hercules DJ Control AIR: "+id+" initialized.");
}

HerculesAir.shutdown = function() {
	HerculesAir.resetLEDs()
}

/* -------------------------------------------------------------------------- */

HerculesAir.playDeckA = function() {
	if(engine.getValue("[Channel1]", "play") == 0) {
		// midi.sendShortMsg(0x90, HerculesAir.beatStepDeckA1, 0x00)
		HerculesAir.beatStepDeckA1 = 0x00
		HerculesAir.beatStepDeckA2 = 0x44
	}
}

HerculesAir.playDeckB = function() {
	if(engine.getValue("[Channel2]", "play") == 0) {
		// midi.sendShortMsg(0x90, HerculesAir.beatStepDeckB1, 0x00)
		HerculesAir.beatStepDeckB1 = 0x00
		HerculesAir.beatStepDeckB2 = 0x4C
	}
}

HerculesAir.beatProgressDeckA = function() {
	if(engine.getValue("[Channel1]", "beat_active") == 1) {
		if(HerculesAir.beatStepDeckA1 != 0x00) {
			midi.sendShortMsg(0x90, HerculesAir.beatStepDeckA1, 0x00)
		}

		HerculesAir.beatStepDeckA1 = HerculesAir.beatStepDeckA2

		midi.sendShortMsg(0x90, HerculesAir.beatStepDeckA2, 0x7f)
		if(HerculesAir.beatStepDeckA2 < 0x47) {
			HerculesAir.beatStepDeckA2++
		} else {
			HerculesAir.beatStepDeckA2 = 0x44
		}
	}
}

HerculesAir.beatProgressDeckB = function() {
	if(engine.getValue("[Channel2]", "beat_active") == 1) {
		if(HerculesAir.beatStepDeckB1 != 0) {
			midi.sendShortMsg(0x90, HerculesAir.beatStepDeckB1, 0x00)
		}

		HerculesAir.beatStepDeckB1 = HerculesAir.beatStepDeckB2

		midi.sendShortMsg(0x90, HerculesAir.beatStepDeckB2, 0x7f)
		if(HerculesAir.beatStepDeckB2 < 0x4F) {
			HerculesAir.beatStepDeckB2++
		} else {
			HerculesAir.beatStepDeckB2 = 0x4C
		}
	}
}

HerculesAir.headCue = function(midino, control, value, status, group) {
	if(engine.getValue(group, "headMix") == 0) {
		engine.setValue(group, "headMix", -1.0);
		midi.sendShortMsg(0x90, 0x39, 0x00);
		midi.sendShortMsg(0x90, 0x3A, 0x7f);
	}
};

HerculesAir.headMix = function(midino, control, value, status, group) {
	if(engine.getValue(group, "headMix") != 1) {
		engine.setValue(group, "headMix", 0);
		midi.sendShortMsg(0x90, 0x39, 0x7f);
		midi.sendShortMsg(0x90, 0x3A, 0x00);
	}
};

HerculesAir.sampler = function(midino, control, value, status, group) {
	if(value != 0x00) {
		if(HerculesAir.shiftButtonPressed) {
			engine.setValue(group, "LoadSelectedTrack", 1)
		} else if(engine.getValue(group, "play") == 0) {
			engine.setValue(group, "start_play", 1)
		} else {
			engine.setValue(group, "play", 0)
		}
	}
}

HerculesAir.wheelTurn = function(midino, control, value, status, group) {

    var deck = script.deckFromGroup(group);
    var newValue=(value==0x01 ? 1: -1);
    // See if we're scratching. If not, do wheel jog.
    if (!engine.isScratching(deck)) {
        engine.setValue(group, "jog", newValue* HerculesAir.wheel_multiplier);
        return;
    }

    if (engine.getValue(group, "play") == 0) {
		var new_position = engine.getValue(group,"playposition") + 0.008 * (value == 0x01 ? 1 : -1)
		if(new_position<0) new_position = 0
		if(new_position>1) new_position = 1
		engine.setValue(group,"playposition",new_position);
    } else {
        // Register the movement
        engine.scratchTick(deck,newValue);
    }

}

HerculesAir.jog = function(midino, control, value, status, group) {
    if (HerculesAir.enableSpinBack) {
        HerculesAir.wheelTurn(midino, control, value, status, group);
    } else {
        var deck = script.deckFromGroup(group);
        var newValue = (value==0x01 ? 1:-1);
        engine.setValue(group, "jog", newValue* HerculesAir.wheel_multiplier);
    }
}

HerculesAir.scratch_enable = function(midino, control, value, status, group) {
    var deck = script.deckFromGroup(group);
	if(value == 0x7f) {
		engine.scratchEnable(
			deck,
			HerculesAir.scratchEnable_intervalsPerRev,
			HerculesAir.scratchEnable_rpm,
			HerculesAir.scratchEnable_alpha,
			HerculesAir.scratchEnable_beta
		);
	} else {
		engine.scratchDisable(deck);
	}
}

HerculesAir.shift = function(midino, control, value, status, group) {
	HerculesAir.shiftButtonPressed = (value == 0x7f);
    midi.sendShortMsg(status, control, value);
}


HerculesAir.spinback= function(midino, control, value, status,group) {
    if (value==0x7f) {
        HerculesAir.enableSpinBack = !HerculesAir.enableSpinBack;
        if (HerculesAir.enableSpinBack) {
            midi.sendShortMsg(status,control, 0x7f);
        } else {
            midi.sendShortMsg(status,control, 0x0);
        }
    }
}