-public class DGlobals {
- boolean bInit = false;
- MidiOutput APCOut = null;
- MidiInput APCIn = null, OxygenIn = null;
- DPat CurPat = null;
-
-
- float Sliders[] = new float [] {1,0,0,0,0,0,0,0};
- String SliderText[] = new String[] {"Level", "SpinHue", "Spark", "Xwave", "Ywave", "Trails", "??", "??", "??"};
-
- void SetNoteOn (int row, int col, int clr){ if (APCOut != null) APCOut.sendNoteOn (col, row, clr); }
- void SetNoteOff (int row, int col, int clr){ if (APCOut != null) APCOut.sendNoteOff (col, row, clr); }
- void SetKnob (int cc , int c , int v ){ if (APCOut != null) APCOut.sendController (cc , c, v); }
-
- DBool GetBool (int i) { return (DBool)CurPat.bools .get(i); }
- Pick GetPick (int i) { return (Pick) CurPat.picks .get(i); }
- DParam GetParam(int i) { return (DParam) CurPat.params.get(i); }
-
- float _Dim () { return Sliders[0]; }
- float _SpinHue () { return Sliders[1]; }
- float _Spark () { return Sliders[2]; }
- float _XWave () { return Sliders[3]; }
- float _YWave () { return Sliders[4]; }
- float _Trails () { return Sliders[5]; }
-
- void Init () {
- if (bInit) return; bInit=true;
- for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}}
- for (MidiInputDevice i: RWMidi.getInputDevices ()) { if (i.toString().contains("APC")) { i.createInput (this); break;}}
- }
-
- boolean isFocused () { return CurPat != null && CurPat == midiEngine.getFocusedDeck().getActivePattern(); }
- void Deactivate (DPat p) { if (p != CurPat) return; uiDebugText.setText(""); CurPat = null; }
- void Activate (DPat p) {
- CurPat = p;
- while (lx.tempo.bpm() > 40) lx.tempo.setBpm(lx.tempo.bpm()/2);
- for (int i=0; i<p.params.size(); i++) GetParam(i).reset();
- for (int i=0; i<p.bools .size(); i++) GetBool (i).reset();
- for (int i=0; i<p.picks .size(); i++) GetPick (i).reset();
- UpdateLights();
- }
-
- void SetText() {
- if (!isFocused()) return;
- String Text1="", Text2="";
- for (int i=0; i<CurPat.bools.size(); i++) if (GetBool(i).b) Text1 += " " + GetBool(i).tag + " ";
- for (int i=0; i<CurPat.picks.size(); i++) Text1 += GetPick(i).tag + ": " + GetPick(i).CurDesc() + " ";
- for (int i=0; i<8; i++) Text2 += SliderText[i] + ": " + round(100*Sliders[i]) + " ";
- uiDebugText.setText(Text1, Text2);
- }
-
- void UpdateLights() {
- if (!isFocused() || APCOut == null) return;
- for (int i=53;i< 58; i++) for (int j=0; j<NumApcCols; j++) SetNoteOn(i, j, 0);
- for (int i=48;i< 56; i++) SetKnob(0, i, 0);
- for (int i=16;i< 20; i++) SetKnob(0, i, 0);
-
- for (int i=0; i<CurPat.params.size(); i++) SetKnob ( 0, i<8 ? 48+i : 16 + i - 8, round(GetParam(i).Val()*127) );
- for (int i=0; i<CurPat.picks .size(); i++) SetNoteOn (GetPick(i).CurRow, GetPick(i).CurCol, 3);
- for (int i=0; i<CurPat.bools .size(); i++) if (GetBool(i).b) SetNoteOn (GetBool(i).row, GetBool(i).col, 1);
- else SetNoteOff (GetBool(i).row, GetBool(i).col, 0);
- }
-
- void controllerChangeReceived(rwmidi.Controller cc) {
- if (cc.getCC() == 7 && btwn(cc.getChannel(),0,7)) { Sliders[cc.getChannel()] = 1.*cc.getValue()/127.; }
- }
-
- void noteOffReceived(Note note) { if (!isFocused()) return;
- int row = note.getPitch(), col = note.getChannel();
- for (int i=0; i<CurPat.bools.size(); i++) if (GetBool(i).set(row, col, false)) return;
- UpdateLights();
- }
-
- void noteOnReceived (Note note) { if (!isFocused()) return;
- int row = note.getPitch(), col = note.getChannel();
- for (int i=0; i<CurPat.picks.size(); i++) if (GetPick(i).set(row, col)) return;
- for (int i=0; i<CurPat.bools.size(); i++) if (GetBool(i).set(row, col, true)) return;
- //println("row: " + row + " col: " + col);
- }
-}
-//----------------------------------------------------------------------------------------------------------------------------------