-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathController.js
More file actions
230 lines (198 loc) · 10.1 KB
/
Copy pathController.js
File metadata and controls
230 lines (198 loc) · 10.1 KB
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
224
225
226
227
228
229
// Written by Michael Schmalle - teotigraphix.com
// (c) 2014
// Licensed under LGPLv3 - http://www.gnu.org/licenses/lgpl-3.0.txt
GlobalConfig.MASTER_TRACK_TEXT_LENGTH = 6;
GlobalConfig.TRACK_BANK_TEXT_LENGTH = 13;
GlobalConfig.CURSOR_DEVICE_TEXT_LENGTH = 6;
function Controller (kind)
{
Config.init ();
this.addConfigListeners ();
var output = new MidiOutput ();
var input = new MaschineMidiInput ();
input.init ();
this.scales = new Scales(36, 52, 4, 4);
this.model = new Model (21, this.scales, 8, 4, 4);
this.model.sessionTrackBank = new TrackBankProxy (4, 4, 4);
this.model.getTrackBank ().addTrackSelectionListener (doObject (this, function (index, isSelected)
{
// if in master mode switch to track when a track is selected
if (isSelected && this.surface.isActiveMode (Maschine.MODE_MASTER))
this.surface.setPendingMode (Maschine.MODE_TRACK);
if (this.surface.isActiveView (Maschine.VIEW_PLAY))
this.surface.getActiveView ().updateNoteMapping ();
}));
if (kind == Maschine.STUDIO)
{
this.surface = new MaschineStudio (output, input);
}
else if (kind == Maschine.MK2)
{
this.surface = new MaschineMK2 (output, input);
}
else if (kind == Maschine.MIKROMK2)
{
this.surface = new MaschineMikroMK2 (output, input);
}
else if (kind == Maschine.MK1)
{
this.surface = new MaschineMK1 (output, input);
}
// add Modes
this.surface.addMode (Maschine.MODE_SELECT, new SelectMode (this.model));
this.surface.addMode (Maschine.MODE_PRESET, new PresetMode (this.model));
this.surface.addMode (Maschine.MODE_SCALE, new ScalesMode (this.model));
this.surface.addMode (Maschine.MODE_NAVIGATE, new NavigateMode (this.model));
this.surface.addMode (Maschine.MODE_TRACK, new TrackMode (this.model));
this.surface.addMode (Maschine.MODE_VOLUME, new VolumeMode (this.model));
this.surface.addMode (Maschine.MODE_PAN, new PanMode (this.model));
this.surface.addMode (Maschine.MODE_SCALE_LAYOUT, new ScaleLayoutMode (this.model));
this.surface.addMode (Maschine.MODE_CLIP, new ClipMode (this.model));
this.surface.addMode (Maschine.MODE_XFADE, new CrossFadeMode (this.model));
this.surface.addMode (Maschine.MODE_MASTER, new MasterMode (this.model));
this.surface.addMode (Maschine.MODE_GROOVE, new GrooveMode (this.model));
this.surface.addMode (Maschine.MODE_FRAME, new FrameMode (this.model));
this.surface.addMode (Maschine.MODE_ACCENT, new AccentMode (this.model));
this.surface.addMode (Maschine.MODE_TRACK_VIEW, new TrackViewMode (this.model));
this.surface.addMode (Maschine.MODE_SCENE_TRIGGER, new SceneTriggerMode (this.model));
this.surface.addMode (Maschine.MODE_CLIP_TRIGGER, new ClipTriggerMode (this.model));
this.surface.addMode (Maschine.MODE_TEMPO, new TempoMode (this.model));
this.surface.addMode (Maschine.MODE_DRUM_CHANNEL, new DrumChannelMode (this.model));
this.surface.addMode (Maschine.MODE_CLIP_LENGTH, new ClipLengthMode (this.model));
this.surface.addMode (Maschine.MODE_SEND1, new SendMode (this.model, Maschine.MODE_SEND1));
this.surface.addMode (Maschine.MODE_SEND2, new SendMode (this.model, Maschine.MODE_SEND2));
this.surface.addMode (Maschine.MODE_SEND3, new SendMode (this.model, Maschine.MODE_SEND3));
this.surface.addMode (Maschine.MODE_SEND4, new SendMode (this.model, Maschine.MODE_SEND4));
this.surface.addMode (Maschine.MODE_BANK_DEVICE, new DeviceMode (this.model));
this.surface.addMode (Maschine.MODE_PARAM_PAGE_SELECT, new ParamPageSelectMode (this.model));
this.surface.addMode (Maschine.MODE_DEVICE_LAYER, new DeviceLayerMode (this.model));
this.surface.addMode (Maschine.MODE_BANK_COMMON, new ParamPageMode (this.model, Maschine.MODE_BANK_COMMON, 'Common'));
this.surface.addMode (Maschine.MODE_BANK_ENVELOPE, new ParamPageMode (this.model, Maschine.MODE_BANK_ENVELOPE, 'Envelope'));
this.surface.addMode (Maschine.MODE_BANK_DIRECT, new DirectParameterMode (this.model, Maschine.MODE_BANK_DIRECT, 'Direct'));
this.surface.addMode (Maschine.MODE_BANK_MODULATE, new ParamPageMode (this.model, Maschine.MODE_BANK_MODULATE, 'Modulate'));
this.surface.addMode (Maschine.MODE_BANK_MACRO, new ParamPageMode (this.model, Maschine.MODE_BANK_MACRO, 'Macro'));
this.surface.addMode (Maschine.MODE_BANK_USER, new ParamPageMode (this.model, Maschine.MODE_BANK_USER, 'User'));
// add Views
this.surface.addView (Maschine.VIEW_PLAY, new PlayView (this.model));
this.surface.addView (Maschine.VIEW_MODE, new ModeView (this.model));
this.surface.addView (Maschine.VIEW_NAVIGATE_ACTION, new NavigateActionView (this.model));
this.surface.addView (Maschine.VIEW_DRUM, new DrumView (this.model));
this.surface.addView (Maschine.VIEW_SEQUENCER, new StepSequencerView (this.model));
this.surface.addView (Maschine.VIEW_CLIP_TRIGGER, new ClipTriggerView (this.model));
this.surface.addView (Maschine.VIEW_SCENE_TRIGGER, new SceneTriggerView (this.model));
this.surface.addView (Maschine.VIEW_EIDT_TOOLS, new EditToolsView (this.model));
this.surface.addView (Maschine.VIEW_MUTE, new MuteView (this.model));
this.surface.addView (Maschine.VIEW_SOLO, new SoloView (this.model));
this.surface.addView (Maschine.VIEW_TRACK, new TrackView (this.model));
this.surface.addViewChangeListener (doObject (this, function (oldViewId, newViewId)
{
}));
this.surface.addModeListener (doObject (this, function (oldMode, newMode)
{
this.updateMode (-1);
this.updateMode (newMode);
}));
this.surface.setDefaultMode (Maschine.getDefaultModeBankId ());
// set active view & mode
this.surface.setActiveView (Maschine.VIEW_PLAY);
this.surface.setPendingMode (Maschine.MODE_BANK_MACRO);
}
Controller.prototype = new AbstractController ();
Controller.prototype.flush = function ()
{
AbstractController.prototype.flush.call (this);
this.validateViews ();
};
Controller.prototype.validateViews = function ()
{
for (var i = 0; i < Maschine.VIEW_BUTTONS.length; i++)
{
var info = Maschine.VIEW_BUTTONS[i];
this.surface.lightButton (info[1], this.surface.isActiveView (info[0]));
}
var isKeyboard = (this.surface.isActiveView (Maschine.VIEW_PLAY) ||
this.surface.isActiveView (Maschine.VIEW_DRUM));
this.surface.lightButton (MaschineButton.PAD_MODE, isKeyboard);
this.model.getCursorDevice ().drumPadBank.setIndication (this.surface.isActiveView (Maschine.VIEW_DRUM));
};
Controller.prototype.updateMode = function (mode)
{
//println("updateMode() " + mode);
this.updateIndication (mode);
// update button lights based on mode
for (var i = MaschineButton.TOP_ROW_0; i <= MaschineButton.TOP_ROW_7; i++)
this.surface.lightButton (i, false);
this.surface.lightButton (MaschineButton.BROWSE, this.surface.isActiveMode(Maschine.MODE_PRESET));
this.surface.lightColor (MaschineButton.GROUP_D, COLOR.ON_DIM);
};
Controller.prototype.updateIndication = function (mode)
{
var isVolume = mode == Maschine.MODE_VOLUME;
var isPan = mode == Maschine.MODE_PAN;
var tb = this.model.getCurrentTrackBank ();
var selectedTrack = tb.getSelectedTrack ();
for (var i = 0; i < 8; i++)
{
var hasTrackSel = selectedTrack != null && selectedTrack.index == i && mode == Maschine.MODE_TRACK;
tb.setVolumeIndication (i, isVolume || hasTrackSel);
tb.setPanIndication (i, isPan || hasTrackSel);
for (var j = 0; j < 4; j++)
{
tb.setSendIndication (i, j,
mode == Maschine.MODE_SEND1 && j == 0 ||
mode == Maschine.MODE_SEND2 && j == 1 ||
mode == Maschine.MODE_SEND3 && j == 2 ||
mode == Maschine.MODE_SEND4 && j == 3 ||
hasTrackSel
);
}
var cd = this.model.getCursorDevice ();
cd.getParameter (i).setIndication (mode == Maschine.MODE_BANK_DEVICE);
cd.getCommonParameter (i).setIndication (mode == Maschine.MODE_BANK_COMMON);
cd.getEnvelopeParameter (i).setIndication (mode == Maschine.MODE_BANK_ENVELOPE);
cd.getMacro (i).getAmount ().setIndication (mode == Maschine.MODE_BANK_MACRO);
var uc = this.model.getUserControlBank ();
uc.getControl (i).setIndication (mode == Maschine.MODE_BANK_USER);
var mt = this.model.getMasterTrack ();
mt.setVolumeIndication (mode == Maschine.MODE_MASTER);
mt.setPanIndication (mode == Maschine.MODE_MASTER);
this.model.getGroove ().setIndication (mode == Maschine.MODE_GROOVE);
}
};
Controller.prototype.addConfigListeners = function ()
{
Config.addPropertyListener (Config.MODE_BANK_DEFAULT, doObject (this, function ()
{
this.surface.setDefaultMode (Maschine.getDefaultModeBankId ());
this.surface.setPendingMode (Maschine.getDefaultModeBankId ());
this.surface.getMode (Maschine.MODE_PARAM_PAGE_SELECT).setCurrentMode (Maschine.getDefaultModeBankId (), true);
}));
Config.addPropertyListener (Config.SCALES_SCALE, doObject (this, function ()
{
this.scales.setScaleByName (Config.scale);
var view = this.surface.getActiveView ();
if (view != null)
view.updateNoteMapping ();
}));
Config.addPropertyListener (Config.SCALES_BASE, doObject (this, function ()
{
this.scales.setScaleOffsetByName (Config.scaleBase);
var view = this.surface.getActiveView ();
if (view != null)
view.updateNoteMapping ();
}));
Config.addPropertyListener (Config.SCALES_IN_KEY, doObject (this, function ()
{
this.scales.setChromatic (!Config.scaleInKey);
var view = this.surface.getActiveView ();
if (view != null)
view.updateNoteMapping ();
}));
Config.addPropertyListener (Config.SCALES_LAYOUT, doObject (this, function ()
{
this.scales.setScaleLayoutByName (Config.scaleLayout);
var view = this.surface.getActiveView ();
if (view != null)
view.updateNoteMapping ();
}));
};