summaryrefslogtreecommitdiffstats
path: root/res/controllers/Behringer-BCD3000-scripts.js
blob: d69328b20cf41246667942d54a7edf909d722263 (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
function BehringerBCD3000 () {}
BehringerBCD3000.debug = false;
BehringerBCD3000.escratch = [false, false];

//sensitivity setting
BehringerBCD3000.UseAcceleration = true;
BehringerBCD3000.JogSensivity = 0.5;

BehringerBCD3000.init = function (id) { // called when the device is opened & set up
	
	BehringerBCD3000.reset();

	// Ask BCD to send the current values of all rotary knobs and sliders
	midi.sendShortMsg(0xB0,0x64,0x7F);

	// Set jog acceleration
	if (BehringerBCD3000.UseAcceleration)
		midi.sendShortMsg(0xB0, 0x63, 0x7F);
	else
		midi.sendShortMsg(0xB0, 0x63, 0x0);
};

BehringerBCD3000.shutdown = function () {

	BehringerBCD3000.reset();

	// Reenable jog acceleration 
	if (!BehringerBCD3000.UseAcceleration)
		midi.sendShortMsg(0xB0, 0x63, 0x7F);
};

BehringerBCD3000.reset = function () {

	// Turn off all the lights
	for (i = 0; i <= 25; i++) {
		midi.sendShortMsg(0xB0, i, 0);
	}

};

BehringerBCD3000.getDeck = function (group) {
	if (group == "[Channel1]")
		return 0;
	else if (group == "[Channel2]")
		return 1;
	
	print("Invalid group : " + group);
	return -1; // error
}


//Scratch, cue search and pitch bend function
BehringerBCD3000.jogWheel = function (channel, control, value, status, group) {


	deck = BehringerBCD3000.getDeck(group);

	if (BehringerBCD3000.escratch[deck]) {

		scratchValue = (value - 0x40);
		engine.scratchTick(deck + 1, scratchValue);

		if (BehringerBCD3000.debug)
			print(group + " scratch tick : " + scratchValue);

	} else {

		jogValue = (value - 0x40) * BehringerBCD3000.JogSensivity;
		engine.setValue(group, "jog", jogValue);

		if (BehringerBCD3000.debug)
			print(group + " pitching jog adjust : " + jogValue);

	}
};

//Scratch button function 
BehringerBCD3000.scratchButton = function (channel, control, value, status, group) {

	if (value != 0x7F)
		return;

	deck = BehringerBCD3000.getDeck(group);

	BehringerBCD3000.escratch[deck] = !BehringerBCD3000.escratch[deck];

	if (BehringerBCD3000.debug)
		print(group + " scratch enabled :" + BehringerBCD3000.escratch[deck]);

	if (BehringerBCD3000.escratch[deck]) {
		// Turn on the scratch light
		if (!deck)
			midi.sendShortMsg(0xB0, 0x13, 0x7F);
		else
			midi.sendShortMsg(0xB0, 0x0B, 0x7F);

		// Enable scratching
		engine.scratchEnable(deck + 1, 100, 33+1/3, 1.0/8, (1.0/8)/32);

	} else {
		// Turn off the scratch light
		if (!deck)	
			midi.sendShortMsg(0xB0, 0x13, 0x00);
		else
			midi.sendShortMsg(0xB0, 0x0B, 0x00);

		// Disable scratching
		engine.scratchDisable(deck + 1);
	}
};

//Set loop function 
BehringerBCD3000.loop = function (channel, control, value, status, group) {
	if (value)
		action = "loop_in";
	else
		action = "loop_out";

	if (BehringerBCD3000.debug)
		print(group + " " + action);

	 engine.setValue(group, action, 1);
};