-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbcfr2000_controller_object.js
223 lines (191 loc) · 4.55 KB
/
bcfr2000_controller_object.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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Copyright 2014-2015 Alan Drees
*
* Purpose:
* Defines the encapsulating BCFR2000 controller
*
* Dependencies
* bcr2000_object.js
* bcf2000_object.js
* bcfr2000_options.js
*
*/
/*
TODO:
1. Modify constructor parameters to handle taking a midi instance and object instance
*/
var BCFR2000 = BCFR2000 || {};
if(typeof BCFR2000.BCFRController === 'undefined') BCFR2000.BCFRController = {};
BCFR2000.BCF_CHANNEL = 1;
BCFR2000.BCR_CHANNEL = 0;
/**\fn BCFR2000.BCFR2000Controller
*
* Constructor for the BCR2000 controller object
*
* @param options options to be passed to the controller object
* @param instance object instance
* @param midi_instance midi io instance to use
*
* @returns None
*/
BCFR2000.BCFRController = function(options, instance, midi_instance)
{
if(typeof midi_instance === 'undefined') var midi_instance = instance;
this.set_options(options);
this.instance = instance;
this.midi_instance = midi_instance;
this.bcr = new Array();
this.bcf = new Array();
this.banks = {};
for(var i = 0; i < BCFR2000.options.bcrs; i++)
{
this.bcr.push(new BCR.BCR2000Controller(BCR.options, i, BCR.build_control_layout, BCFR2000.BCR_CHANNEL, this.midi_instance));
}
for(var i = 0; i < BCFR2000.options.bcfs; i++)
{
this.bcf.push(new BCF.BCF2000Controller(BCF.options, i, BCF.build_control_layout, BCFR2000.BCF_CHANNEL, this.midi_instance));
}
}
/**\fn BCFR2000.BCFR2000Controller.prototype.init
*
* Init function to be called to initalize the
*
* @param banks banks object passed from an encapsulating controller
*
* @returns None
*/
BCFR2000.BCFRController.prototype.init = function(banks)
{
var self = this;
host.getMidiInPort(this.midi_instance).setMidiCallback(function(status, data1, data2){self.onMidi(status, data1, data2);});
if(typeof banks === 'undefined')
{
this.banks.trackbank = host.createMainTrackBank(this.options.tracks, this.options.sends, this.options.scenes);
this.banks.cursortrack = host.createArrangerCursorTrack(this.options.sends, this.options.scenes);
this.banks.cursordevice = host.createCursorDevice();
this.banks.transport = host.createTransport();
this.banks.master_track = host.createMasterTrack(this.options.scenes);
}
else
{
this.banks = banks;
}
var io = true;
//initialize the bcr's
for(var i in this.bcr)
{
if((this.options.io === 'bcr') && io)
{
this.bcr[i].init(true, this.banks);
io = false;
}
else
{
this.bcr[i].init(false, this.banks);
}
}
//initalize the bcf's
for(var i in this.bcf)
{
if((this.options.io === 'bcf') && io)
{
this.bcf[i].init(true, this.banks);
io = false;
}
else
{
this.bcf[i].init(false, this.banks);
}
}
}
/**\fn BCFR2000.BCFR2000Controller.prototype.exit
*
* Exit function to be called when the exit event is fired
*
* @param None
*
* @returns None
*/
BCFR2000.BCFRController.prototype.exit = function()
{
for(var i in this.bcr)
{
this.bcr[i].exit();
}
for(var i in this.bcf)
{
this.bcf[i].exit();
}
}
/**\fn BCFR2000.BCFR2000Controller.prototype.flush
*
* Flush function to be called when a controller's values need to be updated
*
* @param None
*
* @returns None
*/
BCFR2000.BCFRController.prototype.flush = function()
{
//initialize the bcr's
for(var i in this.bcr)
{
this.bcr[i].flush();
}
//initalize the bcf's
for(var i in this.bcf)
{
this.bcf[i].flush();
}
}
/**\fn BCFR2000.BCFRController.prototype.onMidi
*
* Function to be fired on midi input from the controller
*
* @param status
* @param data1
* @param data2
*
* @returns None
*/
BCFR2000.BCFRController.prototype.onMidi = function(status, data1, data2)
{
for(var bcf_device in this.bcf)
{
if(this.bcf[bcf_device].channel === MIDIChannel(status))
{
this.bcf[bcf_device].onMidi(status, data1, data2);
return;
}
}
for(var bcr_device in this.bcr)
{
if(this.bcr[bcr_device].channel === MIDIChannel(status))
{
this.bcr[bcr_device].onMidi(status, data1, data2);
return;
}
}
}
/**\fn BCFR2000.BCFRController.prototype.set_options
*
* Sets controller options
*
* @param options with which to set (use defaults if not set)
*
* @returns None
*/
BCFR2000.BCFRController.prototype.set_options = function(options)
{
this.options = {'bcfs' : 1,
'bcrs' : 1,
'io' : 'bcr',
};
if(typeof options === 'object')
{
for(var option in options)
{
this.options[option] = options[option];
}
}
}