From aa250fc799be73bef6b32bd075b1d07ee5a640fc Mon Sep 17 00:00:00 2001 From: George Reales Date: Sun, 16 May 2021 18:15:11 +0200 Subject: [PATCH] Enhanced MIDI CC --- Source/PluginProcessor.cpp | 39 +++++++++++++++++++++++++++++++++++--- Source/PluginProcessor.h | 4 ++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index e246672..964f95f 100755 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -89,6 +89,7 @@ ObxdAudioProcessor::ObxdAudioProcessor() } apvtState.state = ValueTree (JucePlugin_Name); + initMidi(); } ObxdAudioProcessor::~ObxdAudioProcessor() @@ -271,11 +272,19 @@ inline void ObxdAudioProcessor::processMidiPerSample (MidiBuffer::Iterator* iter lastMovedController = midiMsg->getControllerNumber(); if (programs.currentProgramPtr->values[MIDILEARN] > 0.5f){ midiControlledParamSet = true; - bindings[lastMovedController] = lastUsedParameter; + //bindings[lastMovedController] = lastUsedParameter; + bindings.updateCC(lastMovedController, lastUsedParameter); + File midi_file = getDocumentFolder().getChildFile("Midi") + .getChildFile("Custom.xml"); + bindings.saveFile(midi_file); + currentMidiPath = midi_file.getFullPathName(); + setEngineParameterValue (MIDILEARN, 0, true); lastMovedController = 0; lastUsedParameter = 0; midiControlledParamSet = false; + + } if (bindings[lastMovedController] > 0) @@ -373,7 +382,7 @@ void ObxdAudioProcessor::getStateInformation(MemoryBlock& destData) xmlState.addChildElement(xprogs); - bindings.setXml(xmlState); + //bindings.setXml(xmlState); copyXmlToBinary(xmlState, destData); } @@ -430,7 +439,7 @@ void ObxdAudioProcessor::setStateInformation(const void* data, int sizeInBytes) } } - bindings.getXml(*xmlState); + //bindings.getXml(*xmlState); #if ! DEMOVERSION setCurrentProgram(xmlState->getIntAttribute(S("currentProgram"), 0)); @@ -1184,3 +1193,27 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter() { return new ObxdAudioProcessor(); } + + + +void ObxdAudioProcessor::initMidi(){ + //Documents > Obxd > MIDI > Default.xml + File default_file = getDocumentFolder().getChildFile("Midi") + .getChildFile("Default.xml"); + if (!default_file.exists()){ + bindings.saveFile(default_file); + } + + File midi_custom_file = getDocumentFolder().getChildFile("Midi") + .getChildFile("Custom.xml"); + + if (midi_custom_file.exists()) { + if (bindings.loadFile(midi_custom_file)){ + currentMidiPath = midi_custom_file.getFullPathName(); + } else { + if (bindings.loadFile(default_file)){ + currentMidiPath = default_file.getFullPathName(); + } + } + } +} diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index d24affe..b8fca73 100755 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -138,7 +138,7 @@ public: //============================================================================== void initAllParams(); - + void initMidi(); const String getInputChannelName (int channelIndex) const override; // WATCH OUT! const String getOutputChannelName (int channelIndex) const override; // WATCH OUT! bool isInputChannelStereoPair (int index) const override; // WATCH OUT! @@ -234,7 +234,7 @@ public: File currentBankFile; void saveBank(); - + String currentMidiPath; String currentPreset; File currentPresetFile; void savePreset();