Support for dual APC40s
[SugarCubes.git] / DanUtil.pde
index 4861f470e35c2ed184623d95a052e142f393c200..e9cabb15cff9601311d02bd0e171fd9cd6a63b89 100644 (file)
@@ -152,14 +152,14 @@ public class DPat extends SCPattern
 
     boolean    noteOff(Note note) {
                int row = note.getPitch(), col = note.getChannel();
-               for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) return true;
+               for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) { presetManager.dirty(this); return true; }
                updateLights(); return false;
        }
 
     boolean    noteOn(Note note) {
                int row = note.getPitch(), col = note.getChannel();
-               for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col))                      return true;
-               for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true))        return true;
+               for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col))                      { presetManager.dirty(this); return true; }
+               for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true))        { presetManager.dirty(this); return true; }
                if (row == 84 && col==0) { onReset(); return true; }
                println("row: " + row + "  col:   " + col); return false;
        }
@@ -169,6 +169,7 @@ public class DPat extends SCPattern
                for (int i=0; i<params.size(); i++) params.get(i).reset();
                for (int i=0; i<bools .size(); i++) bools.get(i).reset();
                for (int i=0; i<picks .size(); i++) picks.get(i).reset();
+               presetManager.dirty(this); 
                updateLights(); 
        }
 
@@ -201,13 +202,17 @@ public class DPat extends SCPattern
 
                //println (model.xMin + " " + model.yMin + " " +  model.zMin);
                //println (model.xMax + " " + model.yMax + " " +  model.zMax);
-           for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}}
+         //for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}}
+       }
+       
+       void setAPCOutput(MidiOutput output) {
+         APCOut = output;
        }
 
        void updateLights() { if (APCOut == null) return;
            for (int i = 0; i < NumApcRows; ++i) 
-               for (int j = 0; j < 8; ++j)             midiEngine.grid.setState(i, j, 0);
-               for (int i=0; i<picks .size(); i++)     midiEngine.grid.setState(picks.get(i).CurRow-53, picks.get(i).CurCol, 3);
+               for (int j = 0; j < 8; ++j)             APCOut.sendNoteOn(j, 53+i,  0);
+               for (int i=0; i<picks .size(); i++)     APCOut.sendNoteOn(picks.get(i).CurCol, picks.get(i).CurRow, 3);
                for (int i=0; i<bools .size(); i++)     if (bools.get(i).b)     APCOut.sendNoteOn       (bools.get(i).col, bools.get(i).row, 1);
                                                                                                else                                    APCOut.sendNoteOff      (bools.get(i).col, bools.get(i).row, 0);
        }