Skip to content

Commit

Permalink
interim commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemumu committed Mar 8, 2022
1 parent de84779 commit 464a95f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
30 changes: 27 additions & 3 deletions Week 7/Source/Managers/Preset Manager/PresetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ PresetManager::PresetManager(ProcessorInterface* inInterface)
: mProcessorInterface(inInterface)
{
auto presetsFolder = FolderManager::getPresetsFolder();

_constructPresetFilesArray();
}

/* */
Expand All @@ -23,6 +25,17 @@ PresetManager::~PresetManager()

}

/* */
void PresetManager::loadPreset(int inListIndex)
{
auto file_to_load = mPresetFiles[inListIndex];

std::unique_ptr<XmlElement> preset_xml(parseXML(file_to_load));

juce::ValueTree parameter_tree = juce::ValueTree::fromXml(*preset_xml);
mProcessorInterface->getParameterManager()->getValueTree()->replaceState(parameter_tree);
}

/* */
void PresetManager::saveCurrentPreset(String inPresetName)
{
Expand All @@ -39,17 +52,28 @@ void PresetManager::saveCurrentPreset(String inPresetName)
}

preset_file.appendText(xml->toString());

_constructPresetFilesArray();
}

StringArray PresetManager::getCurrentPresetNames()
{
StringArray preset_names;

for (auto file : mPresetFiles) {
preset_names.add(file.getFileNameWithoutExtension());
}

return preset_names;
}

void PresetManager::_constructPresetFilesArray()
{
mPresetFiles.clear();

RangedDirectoryIterator iter(FolderManager::getPresetsFolder(), false, "*.xml");

for (auto entry : iter) {
preset_names.add(entry.getFile().getFileNameWithoutExtension());
mPresetFiles.add(entry.getFile());
}

return preset_names;
}
8 changes: 8 additions & 0 deletions Week 7/Source/Managers/Preset Manager/PresetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class PresetManager {
/* */
~PresetManager();

/* */
void loadPreset(int inListIndex);

/* */
StringArray getCurrentPresetNames();

Expand All @@ -29,6 +32,11 @@ class PresetManager {

private:

/* */
void _constructPresetFilesArray();

Array<File> mPresetFiles;

ProcessorInterface* mProcessorInterface;
};

Expand Down
27 changes: 19 additions & 8 deletions Week 7/Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,15 @@ CoursePluginAudioProcessorEditor::CoursePluginAudioProcessorEditor (CoursePlugin
if (chooser.browseForFileToSave(true)) {
String file_name = chooser.getResult().getFileNameWithoutExtension();
audioProcessor.getPresetManager()->saveCurrentPreset(file_name);
_updatePresetComboBoxOptions();
}
};

_updatePresetComboBoxOptions();

// PRESET LOAD DROPDOWN
auto preset_names = audioProcessor.getPresetManager()->getCurrentPresetNames();

int id = 1;
for (auto preset_name : preset_names) {
mPresetOptions.addItem(preset_name, id);
id++;
}
mPresetOptions.onChange = [this]() {
audioProcessor.getPresetManager()->loadPreset(mPresetOptions.getSelectedItemIndex());
};

addAndMakeVisible(mPresetOptions);

Expand Down Expand Up @@ -99,3 +96,17 @@ void CoursePluginAudioProcessorEditor::resized()
mSavePreset.setBounds(getWidth()-100, 0, 100, 50);
mPresetOptions.setBounds(getWidth()-100, 50, 100, 50);
}

void CoursePluginAudioProcessorEditor::_updatePresetComboBoxOptions()
{
mPresetOptions.clear(dontSendNotification);

// PRESET LOAD DROPDOWN
auto preset_names = audioProcessor.getPresetManager()->getCurrentPresetNames();

int id = 1;
for (auto preset_name : preset_names) {
mPresetOptions.addItem(preset_name, id);
id++;
}
}
2 changes: 2 additions & 0 deletions Week 7/Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CoursePluginAudioProcessorEditor : public juce::AudioProcessorEditor
void resized() override;

private:

void _updatePresetComboBoxOptions();

OwnedArray<Slider> mSliders;
OwnedArray<AudioProcessorValueTreeState::SliderAttachment> mSliderAttachments;
Expand Down

0 comments on commit 464a95f

Please sign in to comment.