Skip to content

Commit

Permalink
cleaned up patch selector code
Browse files Browse the repository at this point in the history
fixed issue where saving a patch causes it to look like none is selected
  • Loading branch information
hsetlik committed Jun 3, 2021
1 parent 08c646f commit e92ce99
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
77 changes: 37 additions & 40 deletions Source/PatchManagerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,47 @@

#include "PatchManagerComponent.h"

void PatchSelector::addPatch(std::unique_ptr<juce::XmlElement> &currentXml, int idNum)
{
if(currentXml != nullptr)
{
if(currentXml->hasAttribute("HexFmPatchName"))
{
auto presetName = currentXml->getStringAttribute("HexFmPatchName");
patchNames.add(presetName);
addItem(presetName, idNum);
}
}
}
void PatchSelector::selectNewest()
{
int newestIndex = 0;
for(int i = 0; i < patchNames.size(); ++i)
{
if(!lastPatchNames.contains(patchNames[i]))
{
newestIndex = i;
setSelectedItemIndex(newestIndex);
setText(getItemText(newestIndex));
lastPatchNames = patchNames;
return;
}
}
}

void PatchSelector::initialize()
{
int nextId = 1;
patchNames.clear();
if(lib->bassGroup.patches.size() > 0)
{
addSectionHeading("Bass");
addSeparator();
for(auto f : lib->bassGroup.patches)
{
std::unique_ptr<juce::XmlElement> currentXml = juce::parseXML(f);
if(currentXml != nullptr)
{
if(currentXml->hasAttribute("HexFmPatchName"))
{
auto presetName = currentXml->getStringAttribute("HexFmPatchName");
patchNames.add(presetName);
addItem(presetName, nextId);
++nextId;
}
}
addPatch(currentXml, nextId);
++nextId;
}
}

Expand All @@ -40,16 +61,8 @@ void PatchSelector::initialize()
for(auto f : lib->leadGroup.patches)
{
std::unique_ptr<juce::XmlElement> currentXml = juce::parseXML(f);
if(currentXml != nullptr)
{
if(currentXml->hasAttribute("HexFmPatchName"))
{
auto presetName = currentXml->getStringAttribute("HexFmPatchName");
patchNames.add(presetName);
addItem(presetName, nextId);
++nextId;
}
}
addPatch(currentXml, nextId);
++nextId;
}
}

Expand All @@ -60,16 +73,8 @@ void PatchSelector::initialize()
for(auto f : lib->chordGroup.patches)
{
std::unique_ptr<juce::XmlElement> currentXml = juce::parseXML(f);
if(currentXml != nullptr)
{
if(currentXml->hasAttribute("HexFmPatchName"))
{
auto presetName = currentXml->getStringAttribute("HexFmPatchName");
patchNames.add(presetName);
addItem(presetName, nextId);
++nextId;
}
}
addPatch(currentXml, nextId);
++nextId;
}
}

Expand All @@ -80,16 +85,8 @@ void PatchSelector::initialize()
for(auto f : lib->padGroup.patches)
{
std::unique_ptr<juce::XmlElement> currentXml = juce::parseXML(f);
if(currentXml != nullptr)
{
if(currentXml->hasAttribute("HexFmPatchName"))
{
auto presetName = currentXml->getStringAttribute("HexFmPatchName");
patchNames.add(presetName);
addItem(presetName, nextId);
++nextId;
}
}
addPatch(currentXml, nextId);
++nextId;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Source/PatchManagerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ class PatchSelector : public juce::ComboBox
PatchSelector() : lib(std::make_unique<PatchLibrary>())
{
initialize();
lastPatchNames = patchNames;
}
~PatchSelector(){}
void initialize();
void selectNewest();
void addPatch(std::unique_ptr<juce::XmlElement>& element, int idNum);
void reInitList()
{
clear();
lib.reset(new PatchLibrary());
initialize();
selectNewest();

}
int getIndexWithText(juce::String text)
{
Expand All @@ -38,6 +43,7 @@ class PatchSelector : public juce::ComboBox
return getNumItems() - 1;
}
juce::StringArray patchNames;
juce::StringArray lastPatchNames;
private:
std::unique_ptr<PatchLibrary> lib;
};
Expand Down

0 comments on commit e92ce99

Please sign in to comment.