gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 468f3643a7448d3ddf37be79ff4d1ca4993ab991
parent 6aeef9a7991cc34b6dab40d826a097ee34710d20
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Tue, 17 May 2022 00:12:15 +0200

create name to index map for faster lookups

Diffstat:
Msource/jucePluginLib/parameterdescriptions.cpp | 31+++++++++++++++++++------------
Msource/jucePluginLib/parameterdescriptions.h | 1+
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/source/jucePluginLib/parameterdescriptions.cpp b/source/jucePluginLib/parameterdescriptions.cpp @@ -46,17 +46,11 @@ namespace pluginLib bool ParameterDescriptions::getIndexByName(uint32_t& _index, const std::string& _name) const { - for (uint32_t i=0; i<m_descriptions.size(); ++i) - { - const auto& description = m_descriptions[i]; - - if(description.name == _name) - { - _index = i; - return true; - } - } - return false; + const auto it = m_nameToIndex.find(_name); + if(it == m_nameToIndex.end()) + return false; + _index = it->second; + return true; } std::string ParameterDescriptions::loadJson(const std::string& _jsonString) @@ -288,11 +282,24 @@ namespace pluginLib m_descriptions.push_back(d); } + + for (size_t i=0; i<m_descriptions.size(); ++i) + { + const auto& d = m_descriptions[i]; + + if(m_nameToIndex.find(d.name) != m_nameToIndex.end()) + { + errors << "Parameter named " << d.name << " is already defined"; + continue; + } + m_nameToIndex.insert(std::make_pair(d.name, i)); + } + const auto midipackets = json["midipackets"].getDynamicObject(); parseMidiPackets(errors, midipackets); - const auto res = errors.str(); + auto res = errors.str(); assert(res.empty()); return res; } diff --git a/source/jucePluginLib/parameterdescriptions.h b/source/jucePluginLib/parameterdescriptions.h @@ -32,6 +32,7 @@ namespace pluginLib std::map<std::string, ValueList> m_valueLists; std::vector<Description> m_descriptions; + std::map<std::string, uint32_t> m_nameToIndex; std::map<std::string, MidiPacket> m_midiPackets; }; }