From 1f974cbc418e3c35bb6010e1d7e566a9af63ff48 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Sat, 19 Oct 2013 13:39:04 -0700 Subject: [PATCH] Add preset saving and deck focus --- _Internals.pde | 11 ++++++----- _MIDI.pde | 47 ++++++++++++++++++++++++++++++++++------------- _Presets.pde | 32 +++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 19 deletions(-) diff --git a/_Internals.pde b/_Internals.pde index 9d6b118..2e3af44 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -51,8 +51,8 @@ HeronLX lx; LXPattern[] patterns; MappingTool mappingTool; PandaDriver[] pandaBoards; -MidiEngine midiEngine; PresetManager presetManager; +MidiEngine midiEngine; // Display configuration mode boolean mappingMode = false; @@ -134,14 +134,15 @@ void setup() { glucose.lx.addEffects(effects(glucose)); logTime("Built effects"); - // MIDI devices - midiEngine = new MidiEngine(); - logTime("Setup MIDI devices"); - // Preset manager presetManager = new PresetManager(); logTime("Loaded presets"); + // MIDI devices + midiEngine = new MidiEngine(); + presetManager.setMidiEngine(midiEngine); + logTime("Setup MIDI devices"); + // Build output driver PandaMapping[] pandaMappings = buildPandaList(); pandaBoards = new PandaDriver[pandaMappings.length]; diff --git a/_MIDI.pde b/_MIDI.pde index 5f25dda..9a3ce5c 100644 --- a/_MIDI.pde +++ b/_MIDI.pde @@ -451,17 +451,7 @@ public class APC40MidiInput extends GenericDeviceMidiInput { break; } break; - - case 52: // CLIP STOP - if (nChan < PresetManager.NUM_PRESETS) { - if (shiftOn) { - presetManager.store(nChan); - } else { - presetManager.select(nChan); - } - } - break; - + case 82: // scene 1 EFF_boom.trigger(); break; @@ -549,7 +539,17 @@ public class APC40MidiInput extends GenericDeviceMidiInput { break; } break; - + + case 52: // CLIP STOP + if (nChan < PresetManager.NUM_PRESETS) { + if (shiftOn) { + presetManager.store(nChan); + } else { + presetManager.select(nChan); + } + } + break; + case 90: // SEND C long tapDelta = millis() - tap1; if (lbtwn(tapDelta,5000,300*1000)) { // hackish tapping mechanism @@ -645,16 +645,37 @@ class APC40MidiOutput implements LXParameter.Listener, GridOutput { for (Engine.Deck d : lx.engine.getDecks()) { d.addListener(deckListener); } + presetManager.addListener(new PresetListener() { + public void onPresetLoaded(Preset preset) { + for (int i = 0; i < 8; ++i) { + output.sendNoteOn(i, 52, (preset.index == i) ? 1 : 0); + } + } + public void onPresetDirty(Preset preset) { + output.sendNoteOn(preset.index, 52, 2); + } + public void onPresetStored(Preset preset) { + onPresetLoaded(preset); + } + public void onPresetUnloaded() { + for (int i = 0; i < 8; ++i) { + output.sendNoteOn(i, 52, 0); + } + } + }); resetParameters(); midiEngine.grid.addOutput(this); lx.cycleBaseHue(60000); output.sendNoteOn(6, 49, 127); - // Turn off the track selection lights + // Turn off the track selection lights and preset selectors for (int i = 0; i < 8; ++i) { output.sendNoteOn(i, 51, 0); + output.sendNoteOn(i, 52, 0); } + + // Turn off the MASTER selector output.sendNoteOn(0, 80, 0); } diff --git a/_Presets.pde b/_Presets.pde index 7743cbf..f1855c6 100644 --- a/_Presets.pde +++ b/_Presets.pde @@ -2,6 +2,7 @@ interface PresetListener { public void onPresetLoaded(Preset preset); public void onPresetDirty(Preset preset); public void onPresetStored(Preset preset); + public void onPresetUnloaded(); } class PresetManager implements LXParameter.Listener { @@ -32,6 +33,28 @@ class PresetManager implements LXParameter.Listener { } } } + for (Engine.Deck deck : lx.engine.getDecks()) { + deck.addListener(new Engine.AbstractListener() { + public void patternDidChange(Engine.Deck deck, LXPattern pattern) { + if (midiEngine.getFocusedDeck() == deck) { + if (pattern != loadedPattern) { + onPresetDirty(); + } + } + } + }); + } + } + + public void setMidiEngine(MidiEngine midiEngine) { + midiEngine.addListener(new MidiEngineListener() { + public void onFocusedDeck(int deckIndex) { + loadedPreset = null; + for (PresetListener listener : listeners) { + listener.onPresetUnloaded(); + } + } + }); } public void addListener(PresetListener listener) { @@ -44,6 +67,9 @@ class PresetManager implements LXParameter.Listener { public void store(int index) { presets[index].store(midiEngine.getFocusedPattern()); + for (PresetListener listener : listeners) { + listener.onPresetStored(presets[index]); + } select(index); } @@ -65,12 +91,16 @@ class PresetManager implements LXParameter.Listener { } } - public void onParameterChanged(LXParameter p) { + private void onPresetDirty() { for (PresetListener listener : listeners) { listener.onPresetDirty(loadedPreset); } } + public void onParameterChanged(LXParameter p) { + onPresetDirty(); + } + public void write() { String[] lines = new String[NUM_PRESETS]; int i = 0; -- 2.34.1