From b5c671a8f94ab287c0a34017d9403ebba2012109 Mon Sep 17 00:00:00 2001 From: George Reales Date: Wed, 19 May 2021 20:09:59 +0200 Subject: [PATCH] MIDI learn menu --- Source/Components/PresetBar.cpp | 0 Source/PluginEditor.cpp | 62 +++++++++++++++++++++++++++++++++ Source/PluginEditor.h | 3 ++ Source/PluginProcessor.cpp | 44 ++++++++++++++++------- Source/PluginProcessor.h | 9 +++-- 5 files changed, 103 insertions(+), 15 deletions(-) mode change 100755 => 100644 Source/Components/PresetBar.cpp diff --git a/Source/Components/PresetBar.cpp b/Source/Components/PresetBar.cpp old mode 100755 new mode 100644 diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 0dcc269..b859b1d 100755 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -435,6 +435,7 @@ void ObxdAudioProcessorEditor::createMenu () PopupMenu skinMenu; PopupMenu fileMenu; PopupMenu viewMenu; + PopupMenu midiMenu; skins = processor.getSkinFiles(); banks = processor.getBankFiles(); { @@ -534,9 +535,57 @@ void ObxdAudioProcessorEditor::createMenu () } viewMenu.addItem(progStart + 1000, "Preset Bar", true, processor.showPresetBar); menu->addSubMenu ("View", viewMenu); + menuMidiNum = progStart +2000; + createMidi(menuMidiNum, midiMenu); + menu->addSubMenu ("MIDI", midiMenu); popupMenus.add (menu); } +void ObxdAudioProcessorEditor::createMidi(int menuNo, PopupMenu &menuMidi) { + File midi_dir = processor.getMidiFolder(); + File default_file = midi_dir.getChildFile("Default.xml"); + if(default_file.exists()){ + if (processor.currentMidiPath != default_file.getFullPathName()){ + menuMidi.addItem(menuNo++, default_file.getFileNameWithoutExtension(), true, false); + } else { + menuMidi.addItem(menuNo++, default_file.getFileNameWithoutExtension(), true, true); + } + midiFiles.add(default_file.getFullPathName()); + } + + File custom_file = midi_dir.getChildFile("Custom.xml"); + + if(custom_file.exists()){ + if (processor.currentMidiPath != custom_file.getFullPathName()){ + menuMidi.addItem(menuNo++, custom_file.getFileNameWithoutExtension(), true, false); + } else { + menuMidi.addItem(menuNo++, custom_file.getFileNameWithoutExtension(), true, true); + } + midiFiles.add(custom_file.getFullPathName()); + } + + DirectoryIterator iter (midi_dir, true, "*.xml"); + StringArray list; + while (iter.next()) + { + list.add(iter.getFile().getFullPathName()); + } + + list.sort(true); + + for (int i =0; i < list.size() ; i ++){ + File f (list[i]); + if (f.getFileNameWithoutExtension() != "Default" && f.getFileNameWithoutExtension() != "Custom" && f.getFileNameWithoutExtension() != "Config") { + if (processor.currentMidiPath != f.getFullPathName()){ + menuMidi.addItem(menuNo++, f.getFileNameWithoutExtension(), true, false); + } else { + menuMidi.addItem(menuNo++, f.getFileNameWithoutExtension(), true, true); + } + midiFiles.add(f.getFullPathName()); + } + } +} + void ObxdAudioProcessorEditor::resultFromMenu (const Point pos) { int result = popupMenus[0]->showAt (Rectangle (pos.getX(), pos.getY(), 1, 1)); @@ -579,6 +628,19 @@ void ObxdAudioProcessorEditor::resultFromMenu (const Point pos) createMenu(); updatePresetBar(); } + else if (result >= menuMidiNum){ + unsigned int selected_idx = result - menuMidiNum; + if (selected_idx >= 0 && selected_idx < midiFiles.size()){ + File f(midiFiles[selected_idx]); + if (f.exists()) { + processor.currentMidiPath = midiFiles[selected_idx]; + processor.bindings.loadFile(f); + processor.updateConfig(); + + createMenu(); + } + } + } } void ObxdAudioProcessorEditor::updatePresetBar(bool resize){ diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index f0f5082..1454f55 100755 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -167,6 +167,7 @@ private: ButtonList* addList(int x, int y, int w, int h, ObxdAudioProcessor& filter, int parameter, String name, Image img); void addMenuButton (int x, int y, int d, const Image&); void createMenu (); + void createMidi(int, PopupMenu &); void resultFromMenu (const Point); void clean(); @@ -275,6 +276,8 @@ private: ApplicationCommandManager commandManager; int countTimer =0; bool needNotifytoHost = false; + Array midiFiles; + int menuMidiNum; }; #endif // PLUGINEDITOR_H_INCLUDED diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 7113118..d1c8a20 100755 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -274,8 +274,7 @@ inline void ObxdAudioProcessor::processMidiPerSample (MidiBuffer::Iterator* iter midiControlledParamSet = true; //bindings[lastMovedController] = lastUsedParameter; bindings.updateCC(lastUsedParameter, lastMovedController); - File midi_file = getDocumentFolder().getChildFile("Midi") - .getChildFile("Custom.xml"); + File midi_file = getMidiFolder().getChildFile("Custom.xml"); bindings.saveFile(midi_file); currentMidiPath = midi_file.getFullPathName(); @@ -791,6 +790,12 @@ File ObxdAudioProcessor::getBanksFolder() const return getDocumentFolder().getChildFile("Banks"); } +File ObxdAudioProcessor::getMidiFolder() const +{ + return getDocumentFolder().getChildFile("Midi"); +} + + File ObxdAudioProcessor::getPresetsFolder() const { return getDocumentFolder().getChildFile("Presets"); @@ -1201,22 +1206,37 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter() void ObxdAudioProcessor::initMidi(){ //Documents > Obxd > MIDI > Default.xml - File default_file = getDocumentFolder().getChildFile("Midi") - .getChildFile("Default.xml"); + File default_file = getMidiFolder().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(); + File midi_config_file = getMidiFolder().getChildFile("Config.xml"); + XmlDocument xmlDoc (midi_config_file); + std::unique_ptr ele_file = xmlDoc.getDocumentElementIfTagMatches("File"); + + if (ele_file) { + String file_name = ele_file->getStringAttribute("name"); + // Midi cc loading + File midi_file = getMidiFolder().getChildFile(file_name); + if (bindings.loadFile(midi_file)){ + currentMidiPath = midi_file.getFullPathName(); } else { - if (bindings.loadFile(default_file)){ - currentMidiPath = default_file.getFullPathName(); + File midi_file = getMidiFolder().getChildFile("Default.xml"); + if (bindings.loadFile(midi_file)){ + currentMidiPath = midi_file.getFullPathName(); } } } } + +void ObxdAudioProcessor::updateConfig(){ + File midi_config_file = getMidiFolder().getChildFile("Config.xml"); + XmlDocument xmlDoc (midi_config_file); + std::unique_ptr ele_file = xmlDoc.getDocumentElementIfTagMatches("File"); + if (ele_file) { + File f(currentMidiPath); + ele_file->setAttribute("name", f.getFileName()); + ele_file->writeTo(midi_config_file.getFullPathName()); + } +} diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index bd9f097..005dc14 100755 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -175,7 +175,7 @@ public: void newPreset(const String &name); void deletePreset(); - bool loadFromFXBFile(const File& fxbFile, bool changeProgram=true); + bool loadFromFXBFile(const File& fxbFile); bool saveFXBFile(const File& fxbFile); bool saveFXPFile(const File& fxpFile); bool saveBank(const File& fxbFile); @@ -191,6 +191,7 @@ public: File getSkinFolder() const; File getPresetsFolder() const; File getBanksFolder() const; + File getMidiFolder() const; File getCurrentSkinFolder() const; void setCurrentSkinFolder(const String& folderName); @@ -219,7 +220,7 @@ private: MidiMessage* nextMidi; MidiMessage* midiMsg; - MidiMap bindings; + bool midiControlledParamSet; bool hasMidiMessage; @@ -238,8 +239,10 @@ public: String currentPreset; File currentPresetFile; void savePreset(); - + MidiMap bindings; bool showPresetBar = false; + + void updateConfig(); private: Array bankFiles; Array skinFiles;