-
Notifications
You must be signed in to change notification settings - Fork 4
/
ControlMapping.js
114 lines (100 loc) · 3.71 KB
/
ControlMapping.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
/**
*
*/
function ControlMapping() {
this.controls = {};
// Array Mapping
this.notemapping = {};
/** @type {SliderModeHandler} */
this.sliderBank = null;
var fxNoteMapping = this.notemapping;
var mapNoteMatrix = function(gridelement) {
var mapping = null;
if (!(gridelement.channel in fxNoteMapping)) {
mapping = {};
fxNoteMapping[gridelement.channel] = mapping;
} else {
mapping = fxNoteMapping[gridelement.channel];
}
var size = gridelement.size;
for(var key=gridelement.basevalue; key < size+gridelement.basevalue;key++) {
mapping[key] = gridelement;
}
};
this.buttonMatrix = new ButtonGrid("ButtonMatrix",GroupControlsId.BUTTON, ControlGroups.BUTTONMATRIX,0,8,8);
this.sceneRow = new ButtonGrid("SceneRow",GroupControlsId.SCENE, ControlGroups.SCENE_ROW,1,1,8);
this.groupRow = new ButtonGrid("GroupRow",GroupControlsId.GROUP,ControlGroups.GROUP_ROW,1,1,8);
mapNoteMatrix(this.buttonMatrix);
mapNoteMatrix(this.sceneRow);
mapNoteMatrix(this.groupRow);
this.init = function() {
this.buttonMatrix.init();
this.sceneRow.init();
this.groupRow.init();
};
this.exit = function() {
//this.buttonMatrix.init(false);
var midistatus = MIDI.NOTE << 4 | 0;
this.sliderBank.exit();
for(var i=0;i<64;i++) {
host.getMidiOutPort(0).sendMidi(midistatus, ControlGroups.BUTTONMATRIX+i, 0);
}
for(var key in this.controls) {
if (this.controls.hasOwnProperty(key)) {
this.controls[key].reset();
}
}
};
this.createButton = function(ccNr) {
var button = new Button(ccNr);
this.controls[ccNr] = button;
return button;
};
this.createSlider = function(ccNr) {
var slider = new Slider(ccNr);
this.controls[ccNr] = slider;
return slider;
};
this.fullUpdate = function() {
for(var ccNr in this.controls) {
if (this.controls.hasOwnProperty(ccNr)) {
this.controls[ccNr].resendLast();
}
}
this.buttonMatrix.fullUpdate();
this.sceneRow.fullUpdate();
this.groupRow.fullUpdate();
};
/**
* @param {function} callback receiving end of the MIDI Messages
*/
this.setButtonMatrixCallback = function(callback) {
this.buttonMatrixCallback = callback;
};
this.handleMidi = function(midistatus, midival1, midival2) {
var channel = midistatus & 0xF;
var type = midistatus >> 4;
switch(type) {
case MIDI.CC:
if(channel === 0 && midival1 in this.controls) {
var button = this.controls[midival1];
button.doCallback(midival2, midival1);
return true;
}
break;
case MIDI.NOTE:
if(channel in this.notemapping && midival1 in this.notemapping[channel]) {
var gridelement = this.notemapping[channel][midival1];
if(gridelement) {
var coords = gridelement.toCoords(midival1);
if(this.buttonMatrixCallback !== undefined && typeof this.buttonMatrixCallback === 'function') {
this.buttonMatrixCallback(gridelement, coords[0], coords[1], midival2, midival1);
}
return true;
}
}
break;
}
return false;
};
}