From a622c91fae05b8f6c37e0da01e1fd563b55b6713 Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Fri, 13 Sep 2024 17:22:21 -0400 Subject: [PATCH 1/8] XML serializing --- .../Serialization/chowdsp_BaseSerializer.h | 195 +++++++++++++----- .../Serialization/chowdsp_Serialization.h | 35 ++++ .../Serialization/chowdsp_XMLSerializer.h | 117 ++++++++--- .../Backend/chowdsp_NonParamState.cpp | 19 +- .../Backend/chowdsp_ParamHolder.cpp | 23 ++- .../Backend/chowdsp_ParameterTypeHelpers.h | 33 ++- .../Backend/chowdsp_PluginStateImpl.cpp | 30 +-- .../Backend/chowdsp_PluginStateImpl.h | 2 +- .../Backend/chowdsp_StateValue.h | 56 ++++- .../Version/chowdsp_Version.cpp | 2 +- .../chowdsp_version/Version/chowdsp_Version.h | 8 +- 11 files changed, 396 insertions(+), 124 deletions(-) diff --git a/modules/common/chowdsp_serialization/Serialization/chowdsp_BaseSerializer.h b/modules/common/chowdsp_serialization/Serialization/chowdsp_BaseSerializer.h index c7e1e4c90..4569882f9 100644 --- a/modules/common/chowdsp_serialization/Serialization/chowdsp_BaseSerializer.h +++ b/modules/common/chowdsp_serialization/Serialization/chowdsp_BaseSerializer.h @@ -15,12 +15,25 @@ namespace serialization_detail using DeserializedType = const json&; static auto createBaseElement() { return SerializedType {}; } + static auto createBaseElement(juce::String id) { return SerializedType {}; } static void addChildElement (SerializedType&, SerializedType&&) {} //NOSONAR static auto getChildElement (DeserializedType, int) { return false; } + static auto getChildElement (DeserializedType, juce::String) { return false; } + static int getNumChildElements (DeserializedType) { return 0; } + static int getNumAttributes (DeserializedType) { return 0; } + static juce::String getAttributeName (DeserializedType, int i) { return ""; } - template - static SerializedType serialize (const C&) + static auto getAttribute (DeserializedType, juce::String id) { return false; } + + template + static SerializedType serialize (const C&, SerializedType t, juce::String id) + { + return {}; + } + + template + static SerializedType serialize (const C&, SerializedType t) { return {}; } @@ -35,6 +48,11 @@ namespace serialization_detail static void deserialize (DeserializedType, C&) { } + + template + static void deserialize (juce::String, C&) + { + } }; // The reason we need this "detail" namespace is so that we can define these static method @@ -95,81 +113,155 @@ class BaseSerializer return serial; } - /** Serializer for arithmetic types */ +// /** Serializer for arithmetic types */ +// template +// static std::enable_if_t, SerialType> +// serialize (T x) +// { +// return Serializer::serializeArithmeticType (x); +// } +// /** Deserializer for arithmetic types */ +// template +// static std::enable_if_t, void> +// deserialize (DeserialType serial, T& x) +// { +// x = Serializer::template deserializeArithmeticType (serial); +// } + + /** Serializes an arithmetic type. */ template static std::enable_if_t, SerialType> - serialize (T x) + serialize(SerialType& parent, juce::String id, T x) { - return Serializer::serializeArithmeticType (x); + return Serializer::serializeArithmeticType(parent, id, x); } - /** Deserializer for arithmetic types */ + /** Deserializes an arithmetic type. */ template - static std::enable_if_t, void> - deserialize (DeserialType serial, T& x) + static std::enable_if_t, T> + deserialize(DeserialType serial, juce::String id,T& x) { - x = Serializer::template deserializeArithmeticType (serial); + x = Serializer::template deserializeArithmeticType(serial, id); } - /** Serializer for enum types */ - template - static std::enable_if_t, SerialType> - serialize (T x) - { - return Serializer::serializeEnumType (x); - } - /** Deserializer for enum types */ + + + + + /** Serializes an enum type. */ template - static std::enable_if_t, void> - deserialize (DeserialType serial, T& x) + static SerialType serializeEnumType(SerialType& parent, juce::String id, T x) { - x = Serializer::template deserializeEnumType (serial); + return Serializer::serializeEnumType(parent, id, x); } - /** Serializer for string types */ + /** Deserializes an enum type. */ template - static std::enable_if_t, SerialType> - serialize (const T& x) + static T deserializeEnumType(DeserialType serial, juce::String id, T& x) { - return Serializer::serializeString (x); + x = Serializer::template deserializeEnumType(serial, id); } - /** Deserializer for string types */ +// /** Serializer for enum types */ +// template +// static std::enable_if_t, SerialType> +// serialize (T x) +// { +// return Serializer::serializeEnumType (x); +// } +// +// /** Deserializer for enum types */ +// template +// static std::enable_if_t, void> +// deserialize (DeserialType serial, T& x) { +// x = Serializer::template deserializeEnumType (serial); +// } + +// /** Serializer for string types */ +// template +// static std::enable_if_t, SerialType> +// serialize (const T& x) +// { +// return Serializer::serializeString (x); +// } +// +// /** Deserializer for string types */ +// template +// static std::enable_if_t, void> +// deserialize (DeserialType serial, T& x) +// { +// x = Serializer::template deserializeString (serial); +// } + /** Serializes a string. */ template - static std::enable_if_t, void> - deserialize (DeserialType serial, T& x) + static std::enable_if_t || std::is_same_v, SerialType> + serializeString(SerialType& parent, juce::String id, const T& x) { - x = Serializer::template deserializeString (serial); + return Serializer::serializeString(parent, id, x); } -#if JUCE_MODULE_AVAILABLE_juce_graphics - /** Serializer for juce::Point types */ + /** Deserializes a string. */ template - static std::enable_if_t, SerialType> - serialize (const T& point) + static std::enable_if_t || std::is_same_v, T> + deserializeString(DeserialType serial, juce::String id, T& x) { - auto serial = Serializer::createBaseElement(); - Serializer::addChildElement (serial, serialize (point.x)); - Serializer::addChildElement (serial, serialize (point.y)); - return serial; + x = Serializer::template deserializeString(serial, id); } - /** Deserializer for juce::Point types */ - template - static std::enable_if_t, void> - deserialize (DeserialType serial, T& point) - { - if (Serializer::getNumChildElements (serial) != 2) +#if JUCE_MODULE_AVAILABLE_juce_graphics +// /** Serializer for juce::Point types */ +// template +// static std::enable_if_t, SerialType> +// serialize (const T& point) +// { +// auto serial = Serializer::createBaseElement(); +// Serializer::addChildElement (serial, serialize (point.x)); +// Serializer::addChildElement (serial, serialize (point.y)); +// return serial; +// } + +// /** Deserializer for juce::Point types */ +// template +// static std::enable_if_t, void> +// deserialize (DeserialType serial, T& point) +// { +// if (Serializer::getNumChildElements (serial) != 2) +// { +// jassertfalse; // the serialized data does not contain the correct number of elements to fill this array! +// point = {}; +// return; +// } +// +// deserialize (Serializer::getChildElement (serial, 0), point.x); +// deserialize (Serializer::getChildElement (serial, 1), point.y); +// } + + /** Serializer for juce::Point types */ + template + static std::enable_if_t, SerialType> + serialize (const T& point, SerialType &parent) { - jassertfalse; // the serialized data does not contain the correct number of elements to fill this array! - point = {}; - return; + + Serializer::addChildElement (parent, "x", (point.x) ); + Serializer::addChildElement (parent, "y" (point.y)); + return parent; + } + + /** Deserializer for juce::Point types */ + template + static std::enable_if_t, void> + deserialize (DeserialType serial, T& point) { + if (Serializer::getNumChildElements(serial) != 2) { + jassertfalse; // the serialized data does not contain the correct number of elements to fill this array! + point = {}; + return; + } + point.x = Serializer::template deserializeArithmeticType(serial, "point_x"); + point.y = Serializer::template deserializeArithmeticType(serial, "point_y"); + } - deserialize (Serializer::getChildElement (serial, 0), point.x); - deserialize (Serializer::getChildElement (serial, 1), point.y); - } #endif /** Serializer for container types */ @@ -279,6 +371,13 @@ class BaseSerializer return T::template serialize (object); } + +/** Serializer for types with custom serialization behaviour */ + template + static std::enable_if_t, SerialType> serialize (const T& object, SerialType& parent) + { + return T::template serialize (object, parent); + } /** Deserializer for types with custom deserialization behaviour */ template static std::enable_if_t, void> deserialize (DeserialType serial, T& object) diff --git a/modules/common/chowdsp_serialization/Serialization/chowdsp_Serialization.h b/modules/common/chowdsp_serialization/Serialization/chowdsp_Serialization.h index d3490a8df..d0e2764d8 100644 --- a/modules/common/chowdsp_serialization/Serialization/chowdsp_Serialization.h +++ b/modules/common/chowdsp_serialization/Serialization/chowdsp_Serialization.h @@ -15,6 +15,15 @@ namespace Serialization return Serializer::template serialize (objectToSerialize); } + template + typename Serializer::SerializedType serialize (const TypeToSerialize& objectToSerialize,typename Serializer::SerializedType& serial) + { + static_assert (std::is_base_of_v || std::is_same_v, + "Serializer type must be derived from BaseSerializer"); + + return Serializer::template serialize (objectToSerialize, serial); + } + /** Serialize an object to a file with a given serializer */ template void serialize (const TypeToSerialize& objectToSerialize, const juce::File& targetFile) @@ -40,6 +49,26 @@ namespace Serialization Serializer::template deserialize (deserial, objectToDeserialize); } + /** Deserialize an object with a given serializer */ + template + void deserialize (const typename Serializer::SerializedType& serial, juce::String id, TypeToDeserialize& objectToDeserialize) + { + static_assert (std::is_base_of_v || std::is_same_v, + "Serializer type must be derived from BaseSerializer"); + + const auto deserial = Serializer::template getDeserial (serial); + Serializer::template deserialize (deserial, id, objectToDeserialize); + } + + template + void deserialize (const typename Serializer::DeserializedType& serial, juce::String id, TypeToDeserialize& objectToDeserialize) + { + static_assert (std::is_base_of_v || std::is_same_v, + "Serializer type must be derived from BaseSerializer"); + + //const auto deserial = Serializer::template getDeserial (serial); + Serializer::template deserialize (serial, id, objectToDeserialize); + } /** Deserialize an object from a file with a given serializer */ template void deserialize (const juce::File& file, TypeToDeserialize& objectToDeserialize) @@ -60,5 +89,11 @@ namespace Serialization { deserialize (Serializer::fromBinaryData (data, dataSize), objectToDeserialize); } + /** Deserialize an object from a file with a given serializer */ + template + void deserialize (const juce::XmlElement* xml, TypeToDeserialize& objectToDeserialize) + { + deserialize (Serializer::fromXML (xml), objectToDeserialize); + } } // namespace Serialization } // namespace chowdsp diff --git a/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h b/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h index f5d6a3254..10ece9e2d 100644 --- a/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h +++ b/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h @@ -38,6 +38,11 @@ class XMLSerializer : public BaseSerializer return serial; } + static SerializedType fromXML(const juce::XmlElement* xmlElement) + { + return std::unique_ptr(const_cast(xmlElement)); + } + static SerializedType fromMemoryBlock (const juce::MemoryBlock& block) { auto serial = juce::parseXML (block.toString()); @@ -52,16 +57,34 @@ class XMLSerializer : public BaseSerializer return serial; } - static auto createBaseElement() + static auto createBaseElement(juce::String id) { - return std::make_unique (defaultID); + return std::make_unique (id); } static void addChildElement (SerializedType& parent, SerializedType&& newChild) // NOSONAR { parent->addChildElement (newChild.release()); } + static void addChildElement (SerializedType& parent, juce::String newChild) // NOSONAR + { + parent->addChildElement (new juce::XmlElement(newChild)); + } + static void addChildElement (SerializedType& parent, juce::String element, float f) // NOSONAR + { + parent->setAttribute (element, juce::String(f,3)); + } + static void addChildElement (SerializedType& parent, juce::String element,juce::Point point) // NOSONAR + { + parent->setAttribute ("point_x",juce::String(point.getX())); + parent->setAttribute ("point_y",juce::String(point.getY())); + + } + static void addChildElement (SerializedType& parent, juce::String element, juce::String f) // NOSONAR + { + parent->setAttribute (element, f); + } static juce::XmlElement* getChildElement (DeserializedType parent, int index) { if (parent == nullptr || ! juce::isPositiveAndBelow (index, parent->getNumChildElements())) @@ -72,6 +95,16 @@ class XMLSerializer : public BaseSerializer return parent->getChildElement (index); } + static juce::XmlElement* getChildElement (DeserializedType parent, juce::String attr ) + { +// if (parent == nullptr || ! juce::isPositiveAndBelow (index, parent->getNumChildElements())) +// { +// jassertfalse; +// return {}; +// } + + return parent->getChildByName(attr); + } static int getNumChildElements (DeserializedType serial) { @@ -84,80 +117,112 @@ class XMLSerializer : public BaseSerializer return serial->getNumChildElements(); } + static int getNumAttributes (DeserializedType serial) + { + if (serial == nullptr) + { + jassertfalse; + return 0; + } + + return serial->getNumAttributes(); + } + static juce::String getAttributeName (DeserializedType serial, int i) + { + if (serial == nullptr) + { + jassertfalse; + return ""; + } + + return serial->getAttributeName(i); + } + + static juce::String getAttribute (DeserializedType serial, int i) + { + if (serial == nullptr) + { + jassertfalse; + return ""; + } + + return serial->getAttributeName(i); + } + + + template - static std::enable_if_t, SerializedType> serializeArithmeticType (T x) + static std::enable_if_t, SerializedType> serializeArithmeticType (SerializedType& parent, juce::String id, T x) { - auto element = createBaseElement(); - element->setAttribute (defaultID, (int) x); - return element; + + parent->setAttribute (id, (int) x); + return parent; } template - static std::enable_if_t, SerializedType> serializeArithmeticType (T x) + static std::enable_if_t, SerializedType> serializeArithmeticType (SerializedType& parent, juce::String id, T x) { - auto element = createBaseElement(); - element->setAttribute (defaultID, (double) x); - return element; + parent->setAttribute (id, (double) x); + return parent; } template static std::enable_if_t, T> - deserializeArithmeticType (DeserializedType serial) + deserializeArithmeticType (DeserializedType serial, juce::String id) { if (serial == nullptr) return T {}; - return (T) serial->getIntAttribute (defaultID); + return (T) serial->getIntAttribute (id); } template static std::enable_if_t, T> - deserializeArithmeticType (DeserializedType serial) + deserializeArithmeticType (DeserializedType serial, juce::String id) { if (serial == nullptr) return T {}; - return (T) serial->getDoubleAttribute (defaultID); + return (T) serial->getDoubleAttribute (id); } template - static SerializedType serializeEnumType (T x) + static SerializedType serializeEnumType (SerializedType& parent, juce::String id, T x) { - return serializeArithmeticType (static_cast (x)); + return serializeArithmeticType (parent, id,static_cast ( x)); } template - static T deserializeEnumType (DeserializedType serial) + static T deserializeEnumType (DeserializedType serial, juce::String id) { - return static_cast (deserializeArithmeticType (serial)); + return static_cast (deserializeArithmeticType (serial, id)); } template - static SerializedType serializeString (const T& x) + static SerializedType serializeString (SerializedType& parent, juce::String id, const T& x) { - auto element = createBaseElement(); - element->setAttribute (defaultID, x); - return element; + parent->setAttribute (id, x); + return std::move(parent); } template static std::enable_if_t, T> - deserializeString (DeserializedType serial) + deserializeString (DeserializedType serial, juce::String id) { if (serial == nullptr) return T {}; - return deserializeString (serial).toStdString(); + return deserializeString (serial,id).toStdString(); } template static std::enable_if_t, T> - deserializeString (DeserializedType serial) + deserializeString (DeserializedType serial, juce::String id) { if (serial == nullptr) return T {}; - return serial->getStringAttribute (defaultID); + return serial->getStringAttribute (id); } private: diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp index 587657924..1186d105c 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp @@ -34,7 +34,7 @@ inline void NonParamState::validateStateValues() const template typename Serializer::SerializedType NonParamState::serialize (const NonParamState& state) { - auto serial = Serializer::createBaseElement(); + auto serial = Serializer::createBaseElement("nonparam"); for (const auto& value : state.values) value->serialize (serial); return serial; @@ -44,18 +44,19 @@ template void NonParamState::deserialize (typename Serializer::DeserializedType deserial, const NonParamState& state) { juce::StringArray namesThatHaveBeenDeserialized {}; - if (const auto numNamesAndVals = Serializer::getNumChildElements (deserial); numNamesAndVals % 2 == 0) + if (const auto numNamesAndVals = Serializer::getNumAttributes (deserial)) { - for (int i = 0; i < numNamesAndVals; i += 2) + for (int i = 0; i < numNamesAndVals; i++) { juce::String name {}; - Serialization::deserialize (Serializer::getChildElement (deserial, i), name); - const auto valueDeserial = Serializer::getChildElement (deserial, i + 1); + name = Serializer::getAttributeName (deserial, i); +//Serialization::deserialize (Serializer::getChildElement (deserial, i), name); + //const auto valueDeserial = Serializer::getChildElement (deserial, i + 1); for (auto& value : state.values) { if (name == toString (value->name)) { - value->deserialize (valueDeserial); + value->deserialize (deserial); namesThatHaveBeenDeserialized.add (name); } } @@ -65,7 +66,10 @@ void NonParamState::deserialize (typename Serializer::DeserializedType deserial, { jassertfalse; // state loading error } - + for(auto id: namesThatHaveBeenDeserialized) + { + DBG("nonparam " + id); + } // set all un-matched objects to their default values for (auto& value : state.values) { @@ -73,4 +77,5 @@ void NonParamState::deserialize (typename Serializer::DeserializedType deserial, value->reset(); } } + } // namespace chowdsp diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp index 57e0ca76a..3ee6981e7 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp @@ -137,7 +137,7 @@ size_t ParamHolder::doForAllParameters (Callable&& callable, size_t index) const template typename Serializer::SerializedType ParamHolder::serialize (const ParamHolder& paramHolder) { - auto serial = Serializer::createBaseElement(); + auto serial = Serializer::createBaseElement(paramHolder.name); paramHolder.doForAllParameters ( [&serial] (auto& param, size_t) { @@ -149,22 +149,27 @@ typename Serializer::SerializedType ParamHolder::serialize (const ParamHolder& p template void ParamHolder::deserialize (typename Serializer::DeserializedType deserial, ParamHolder& paramHolder) { + juce::StringArray paramIDsThatHaveBeenDeserialized {}; - if (const auto numParamIDsAndVals = Serializer::getNumChildElements (deserial); numParamIDsAndVals % 2 == 0) + if (const auto numParamIDsAndVals = Serializer::getNumAttributes (deserial)) { - for (int i = 0; i < numParamIDsAndVals; i += 2) + for (int i = 0; i < numParamIDsAndVals; i += 1) { juce::String paramID {}; - Serialization::deserialize (Serializer::getChildElement (deserial, i), paramID); - const auto paramDeserial = Serializer::getChildElement (deserial, i + 1); + paramID = Serializer::getAttributeName (deserial, i); +//DBG("PArAMID" + paramID); + //Serialization::deserialize (, paramID); +//const auto paramDeserial = Serializer::getAttribute (deserial,paramID); + + paramHolder.doForAllParameters ( - [paramDeserial, + [&deserial, ¶mID = std::as_const (paramID), ¶mIDsThatHaveBeenDeserialized] (auto& param, size_t) { if (param.paramID == paramID) { - ParameterTypeHelpers::deserializeParameter (paramDeserial, param); + ParameterTypeHelpers::deserializeParameter (deserial, param); paramIDsThatHaveBeenDeserialized.add (paramID); } }); @@ -175,6 +180,10 @@ void ParamHolder::deserialize (typename Serializer::DeserializedType deserial, P jassertfalse; // state loading error } + for(auto id: paramIDsThatHaveBeenDeserialized) + { + DBG("deserialzied " + id); + } // set all un-matched objects to their default values paramHolder.doForAllParameters ( [¶mIDsThatHaveBeenDeserialized] (auto& param, size_t) diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterTypeHelpers.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterTypeHelpers.h index 9c887485f..f936e845f 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterTypeHelpers.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterTypeHelpers.h @@ -59,8 +59,8 @@ namespace ParameterTypeHelpers template void serializeParameter (typename Serializer::SerializedType& serial, const ParamType& param) { - Serializer::addChildElement (serial, param.paramID); - Serializer::addChildElement (serial, getValue (param)); + + Serializer::addChildElement (serial, param.paramID,getValue (param)); } template @@ -70,10 +70,35 @@ namespace ParameterTypeHelpers } template - void deserializeParameter (const typename Serializer::SerializedType& serial, ParamType& param) + std::enable_if_t, void> + deserializeParameter (const typename Serializer::SerializedType& serial, ParamType& param) + { + ParameterElementType val; + Serialization::deserialize (serial,param.paramID, val); + if constexpr (std::is_same_v,bool>) + { + DBG("paramid" + param.paramID + "val " + juce::String(static_cast(val))); + } else + { + DBG("paramid" + param.paramID + "val " + juce::String(val)); + } + + setValue (val, param); + } + template + std::enable_if_t, void> + deserializeParameter (const typename Serializer::DeserializedType& serial, ParamType& param) { ParameterElementType val; - Serialization::deserialize (serial, val); + Serialization::deserialize (serial,param.paramID, val); +// if constexpr (std::is_same_v,bool>) +// { +// DBG("paramid" + param.paramID + "val " + juce::String(static_cast(val))); +// } else +// { +// DBG("paramid" + param.paramID + "val " + juce::String(val)); +// } + setValue (val, param); } } // namespace ParameterTypeHelpers diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp index 29b1affc6..7230a6f67 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp @@ -42,14 +42,14 @@ template typename Serializer::SerializedType PluginStateImpl::serialize (const PluginStateImpl& object) { - auto serial = Serializer::createBaseElement(); + auto serial = Serializer::createBaseElement("testing"); #if defined JucePlugin_VersionString - Serializer::addChildElement (serial, Serializer::template serialize (currentPluginVersion)); +// Serializer::template serialize (currentPluginVersion, serial); #endif Serializer::addChildElement (serial, Serializer::template serialize (object.nonParams)); - Serializer::addChildElement (serial, Serializer::template serialize (object.params)); + Serializer::addChildElement(serial, Serializer::template serialize (object.params)); return serial; } @@ -60,9 +60,9 @@ void PluginStateImpl::deserialize { enum { -#if defined JucePlugin_VersionString - versionChildIndex, -#endif +//#if defined JucePlugin_VersionString +// versionChildIndex, +//#endif nonParamStateChildIndex, paramStateChildIndex, expectedNumChildElements, @@ -74,15 +74,15 @@ void PluginStateImpl::deserialize return; } -#if defined JucePlugin_VersionString - Serializer::template deserialize (Serializer::getChildElement (serial, versionChildIndex), object.pluginStateVersion); -#else - using namespace version_literals; - object.pluginStateVersion = "0.0.0"_v; -#endif - - Serializer::template deserialize (Serializer::getChildElement (serial, nonParamStateChildIndex), object.nonParams); - Serializer::template deserialize (Serializer::getChildElement (serial, paramStateChildIndex), object.params); +//#if defined JucePlugin_VersionString +// Serializer::template deserialize (Serializer::getChildElement (serial, versionChildIndex), object.pluginStateVersion); +//#else +// using namespace version_literals; +// object.pluginStateVersion = "0.0.0"_v; +//#endif +// + Serializer::template deserialize (Serializer::getChildElement (serial, "nonparam"), object.nonParams); + Serializer::template deserialize (Serializer::getChildElement (serial, object.params.getName()), object.params); } template diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h index 3f1e26291..1f48e4a36 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h @@ -9,7 +9,7 @@ namespace chowdsp * @tparam NonParameterState Struct containing all of the plugin's non-parameter state as StateValue objects. * @tparam Serializer A type that implements chowdsp::BaseSerializer (JSONSerializer by default) */ -template +template class PluginStateImpl : public PluginState { static_assert (std::is_base_of_v, "ParameterState must be a chowdsp::ParamHolder!"); diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_StateValue.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_StateValue.h index 82599395a..47f7b82cc 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_StateValue.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_StateValue.h @@ -13,6 +13,8 @@ struct StateValueBase virtual void serialize (JSONSerializer::SerializedType&) const {} virtual void deserialize (JSONSerializer::DeserializedType) {} + virtual void serialize (XMLSerializer::SerializedType&) const {} + virtual void deserialize (XMLSerializer::DeserializedType) {} const std::string_view name; Broadcaster changeBroadcaster; }; @@ -68,36 +70,68 @@ struct StateValue : StateValueBase /** Resets the value to its default state */ void reset() override { set (defaultValue); } - /** JSON Serializer */ - void serialize (JSONSerializer::SerializedType& serial) const override + + + /** XML Serializer */ + void serialize (XMLSerializer::SerializedType& serial) const override { - serialize (serial, *this); + serialize (serial, *this); } - /** JSON Deserializer */ - void deserialize (JSONSerializer::DeserializedType deserial) override + /** XML Deserializer */ + void deserialize (XMLSerializer::DeserializedType deserial) override { - deserialize (deserial, *this); + + deserialize (deserial, *this); } +// /** JSON Serializer */ +// void serialize (JSONSerializer::SerializedType& serial) const override +// { +// serialize (serial, *this); +// } +// +// /** JSON Deserializer */ +// void deserialize (JSONSerializer::DeserializedType deserial) override +// { +// deserialize (deserial, *this); +// } const T defaultValue; private: + + template + static std::enable_if_t, void> + serialize (typename Serializer::SerializedType& serial,const StateValue& value) { + Serializer::addChildElement (serial, toString(value.name), value.get()); + + } + template + static std::enable_if_t, void> + serialize (typename Serializer::SerializedType& serial, const StateValue& value) + { + Serializer::addChildElement (serial, toString(value.name)); + Serializer::addChildElement (serial, Serialization::serialize (value.get())); + } + template - static void serialize (typename Serializer::SerializedType& serial, const StateValue& value) + static std::enable_if_t, void> + deserialize (typename Serializer::DeserializedType deserial, StateValue& value) { - Serializer::addChildElement (serial, value.name); - Serializer::addChildElement (serial, Serialization::serialize (value.get())); + T val {}; + Serialization::deserialize (deserial, val); + value.set (val); } template - static void deserialize (typename Serializer::DeserializedType deserial, StateValue& value) + static std::enable_if_t, void> + deserialize (typename Serializer::DeserializedType deserial, StateValue& value) { T val {}; +//std::unique_ptr xmlElementPtr(const_cast(deserial)); Serialization::deserialize (deserial, val); value.set (val); } - T currentValue; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StateValue) diff --git a/modules/plugin/chowdsp_version/Version/chowdsp_Version.cpp b/modules/plugin/chowdsp_version/Version/chowdsp_Version.cpp index bec3d8f07..362b461b4 100644 --- a/modules/plugin/chowdsp_version/Version/chowdsp_Version.cpp +++ b/modules/plugin/chowdsp_version/Version/chowdsp_Version.cpp @@ -24,7 +24,7 @@ Version::Version (const juce::String& versionStr) patch = tokens[2].getIntValue(); } -juce::String Version::getVersionString() const +const juce::String Version::getVersionString() const { return juce::String (major) + "." + juce::String (minor) + "." + juce::String (patch); } diff --git a/modules/plugin/chowdsp_version/Version/chowdsp_Version.h b/modules/plugin/chowdsp_version/Version/chowdsp_Version.h index f189e32e8..326be5e03 100644 --- a/modules/plugin/chowdsp_version/Version/chowdsp_Version.h +++ b/modules/plugin/chowdsp_version/Version/chowdsp_Version.h @@ -54,7 +54,7 @@ class Version constexpr Version& operator= (Version&&) noexcept = default; /** Returns the version as a string of the form MAJOR.MINOR.PATCH. */ - [[nodiscard]] juce::String getVersionString() const; + [[nodiscard]] const juce::String getVersionString() const; /** Returns an integer hint for this version value. */ [[nodiscard]] constexpr int getVersionHint() const { return major * 10000 + minor * 100 + patch; } @@ -70,9 +70,9 @@ class Version template static void deserialize (typename Serializer::DeserializedType serial, Version& object) { - juce::String versionString; - Serializer::template deserialize (serial, versionString); - object = Version { versionString }; +// juce::String versionString; +// Serializer::template deserialize (serial, versionString); +// object = Version { versionString }; } friend constexpr bool operator== (const Version& v1, const Version& v2) noexcept; From 27d09b3028787dae14e2b47af05991c5961f9051 Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Fri, 20 Sep 2024 11:44:38 -0400 Subject: [PATCH 2/8] added dbug info --- .../ParamUtils/chowdsp_ParameterTypes.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h index b4e35eb91..d8627a170 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h @@ -71,6 +71,11 @@ class FloatParameter : public juce::AudioParameterFloat, /** Returns the current parameter value accounting for any modulation that is currently applied. */ operator float() const noexcept { return getCurrentValue(); } // NOSONAR, NOLINT(google-explicit-constructor): we want to be able to do implicit conversion here + /** Print debug info. */ + void printDebug() const + { + DBG(paramID + " : " + juce::String(get())); + } private: const float unsnappedDefault; const juce::NormalisableRange normalisableRange; @@ -89,6 +94,10 @@ class ChoiceParameter : public juce::AudioParameterChoice, : juce::AudioParameterChoice (parameterID, parameterName, parameterChoices, defaultItemIndex) { } + void printDebug() const + { + DBG(paramID + " : " + juce::String(getIndex())); // Using getIndex() for ChoiceParameter + } using Ptr = OptionalPointer; @@ -127,6 +136,10 @@ class EnumChoiceParameter : public ChoiceParameter { return magic_enum::enum_value ((size_t) getIndex()); } + void printDebug() const + { + DBG(paramID + " : " + juce::String(static_cast(get()))); + } using Ptr = OptionalPointer; @@ -143,7 +156,10 @@ class BoolParameter : public juce::AudioParameterBool, : juce::AudioParameterBool (parameterID, parameterName, defaultBoolValue) { } - + void printDebug() const + { + DBG(paramID + " : " + juce::String(static_cast(get()))); + } using Ptr = OptionalPointer; private: From 2df01f93d90e2ff536c333219fc8c8aafd9bc385 Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Mon, 23 Sep 2024 13:45:42 -0400 Subject: [PATCH 3/8] serializing and changing the pluginbase --- .../Serialization/chowdsp_XMLSerializer.h | 2 ++ .../PluginBase/chowdsp_PluginBase.h | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h b/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h index 10ece9e2d..a603d1fd1 100644 --- a/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h +++ b/modules/common/chowdsp_serialization/Serialization/chowdsp_XMLSerializer.h @@ -28,6 +28,8 @@ class XMLSerializer : public BaseSerializer static void toMemoryBlock (const SerializedType& serial, juce::MemoryBlock& block) // NOSONAR { auto&& outStream = juce::MemoryOutputStream (block, false); + // magic number to identify memory blocks that we've stored as XML + const juce::uint32 magicXmlNumber = 0x21324356; serial->writeTo (outStream); } diff --git a/modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h b/modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h index bd01a51e3..3ab7731b6 100644 --- a/modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h +++ b/modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h @@ -251,11 +251,19 @@ void PluginBase

::processBlock (juce::AudioBuffer& buffer, juce::MidiBu processAudioBlock (buffer); } - +// magic number to identify memory blocks that we've stored as XML + const juce::uint32 magicXmlNumber = 0x21324356; #if JUCE_MODULE_AVAILABLE_chowdsp_plugin_state template void PluginBase::getStateInformation (juce::MemoryBlock& data) { +// { +// juce::MemoryOutputStream out (data, false); +// out.writeInt (magicXmlNumber); +// out.writeInt (0); +// xml.writeTo (out, XmlElement::TextFormat().singleLine()); +// out.writeByte (0); +// } state.serialize (data); } From 7e0276a715a265149c8af8bbb7a04c363c891a61 Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Wed, 2 Oct 2024 15:53:26 -0400 Subject: [PATCH 4/8] removed assert for empty params --- .../plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp index 3ee6981e7..f4b81c3ba 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp @@ -177,7 +177,7 @@ void ParamHolder::deserialize (typename Serializer::DeserializedType deserial, P } else { - jassertfalse; // state loading error + // jassertfalse; // state loading error } for(auto id: paramIDsThatHaveBeenDeserialized) From 3d90a4341255667eedafb55761e83b5cd2b3fc9c Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Tue, 5 Nov 2024 15:44:10 -0500 Subject: [PATCH 5/8] making ParamHolder virtual to allow dynamic cast to paramtypes --- .../plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h index 6fcf78dc7..0850a3ff5 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h @@ -15,7 +15,7 @@ class ParamHolder ParamHolder (ParamHolder&&) noexcept = default; ParamHolder& operator= (ParamHolder&&) noexcept = default; - + virtual ~ParamHolder() = default; /** Adds parameters to the ParamHolder. */ template std::enable_if_t, void> From e939a0a3a3feff2cf87b477468c537163dd8c972 Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Thu, 14 Nov 2024 12:35:59 -0500 Subject: [PATCH 6/8] edits for dynamic parms --- .../chowdsp_ParameterConversions.cpp | 15 ++++++++++- .../ParamUtils/chowdsp_ParameterConversions.h | 5 ++++ .../ParamUtils/chowdsp_ParameterTypes.h | 26 +++++++++++++++++++ .../Backend/chowdsp_ParamHolder.h | 10 +++---- .../Backend/chowdsp_ParameterListeners.cpp | 6 ++--- .../Backend/chowdsp_ParameterListeners.h | 13 +++++++--- 6 files changed, 63 insertions(+), 12 deletions(-) diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp index 108018298..129107e68 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp @@ -59,6 +59,19 @@ juce::String floatValToString (float floatVal) { return floatValToStringDecimal<2> (floatVal); } + juce::String semitonesValToString (float semitonesVal, bool snapToInt) + { + auto semitonesStr = snapToInt + ? juce::String (static_cast (semitonesVal)) + " st" + : juce::String (semitonesVal, 2, false) + " st"; + if (semitonesVal > 0.0f) + semitonesStr = "+" + semitonesStr; + return semitonesStr; + } -float stringToFloatVal (const juce::String& s) { return s.getFloatValue(); } + float stringToSemitonesVal (const juce::String& s) { return s.getFloatValue(); } + + + + float stringToFloatVal (const juce::String& s) { return s.getFloatValue(); } } // namespace chowdsp::ParamUtils diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h index 3659c946b..3f9f2294a 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h @@ -24,4 +24,9 @@ juce::String floatValToStringDecimal (float floatVal) return { floatVal, NumDecimalPlaces, false }; } float stringToFloatVal (const juce::String& s); + + juce::String semitonesValToString (float semitonesVal, bool snapToInt); + float stringToSemitonesVal (const juce::String& s); + + } // namespace chowdsp::ParamUtils diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h index d8627a170..fe20301c1 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterTypes.h @@ -280,4 +280,30 @@ class RatioParameter : public FloatParameter private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RatioParameter) }; + +/** A float parameter which specifically stores a semitones value. */ + class SemitonesParameter : public FloatParameter + { + public: + SemitonesParameter (const ParameterID& parameterID, + const juce::String& paramName, + juce::NormalisableRange paramRange, + float defaultValue, + bool snapToInt = false) + : FloatParameter ( + parameterID, + paramName, + (paramRange.interval = snapToInt ? 1.0f : paramRange.interval, paramRange), + defaultValue, + [snapToInt] (float val) + { return ParamUtils::semitonesValToString (val, snapToInt); }, + &ParamUtils::stringToSemitonesVal) + { + } + + using Ptr = OptionalPointer; + + private: + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SemitonesParameter) + }; } // namespace chowdsp diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h index 0850a3ff5..61c2c43f0 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h @@ -85,17 +85,17 @@ class ParamHolder /** Assign this function to apply version streaming to your non-parameter state. */ std::function versionStreamingCallback = nullptr; - + std::vector> floatParams; + std::vector> choiceParams; + std::vector> boolParams; + std::vector otherParams; private: void add() const { // base case! } - std::vector> floatParams; - std::vector> choiceParams; - std::vector> boolParams; - std::vector otherParams; + juce::String name; bool isOwning; diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp index 1b23a334d..c34c722a8 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp @@ -29,9 +29,9 @@ void ParameterListeners::updateBroadcastersFromMessageThread() continue; paramInfo.value = paramInfo.paramCookie->getValue(); - - audioThreadBroadcastQueue.try_enqueue ([this, i = index] - { callAudioThreadBroadcaster (i); }); + if( audioThreadBroadcasters.size() > index) { + audioThreadBroadcastQueue.try_enqueue([this, i = index] { callAudioThreadBroadcaster(i); }); + } callMessageThreadBroadcaster (index); } } diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h index 527868d7c..307f3645c 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h @@ -54,12 +54,19 @@ class ParameterListeners : private juce::Timer if (paramInfoIter == paramInfoList.end()) { - jassertfalse; // trying to listen to a parameter that is not part of this state! - return {}; + //jassertfalse; // trying to listen to a parameter that is not part of this state! + //return {}; + paramInfoList.push_back(ParamInfo{¶m, param.getValue()}); } + const auto _paramInfoIter = std::find_if (paramInfoList.begin(), paramInfoList.end(), [¶m] (const ParamInfo& info) + { return info.paramCookie == ¶m; }); - const auto index = (size_t) std::distance (paramInfoList.begin(), paramInfoIter); + const auto index = (size_t) std::distance (paramInfoList.begin(), _paramInfoIter); auto& broadcasterList = listenerThread == ParameterListenerThread::MessageThread ? messageThreadBroadcasters : audioThreadBroadcasters; + if(broadcasterList.size() <= index) + { + broadcasterList.push_back(Broadcaster()); + } return broadcasterList[index].connect (std::forward (args...)); } From e73a1eea058db1eea5c1ecf07a0503270cbab01f Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Thu, 14 Nov 2024 13:20:35 -0500 Subject: [PATCH 7/8] :static transpose values --- .../Backend/chowdsp_ParamHolder.h | 13 ++++++++----- .../Backend/chowdsp_ParameterListeners.cpp | 6 +++--- .../Backend/chowdsp_ParameterListeners.h | 13 +++---------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h index 61c2c43f0..c8b9a4fdd 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.h @@ -85,17 +85,20 @@ class ParamHolder /** Assign this function to apply version streaming to your non-parameter state. */ std::function versionStreamingCallback = nullptr; - std::vector> floatParams; - std::vector> choiceParams; - std::vector> boolParams; - std::vector otherParams; + std::vector>* getFloatParams() + { + return &floatParams; + } private: void add() const { // base case! } - + std::vector> floatParams; + std::vector> choiceParams; + std::vector> boolParams; + std::vector otherParams; juce::String name; bool isOwning; diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp index c34c722a8..1b23a334d 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.cpp @@ -29,9 +29,9 @@ void ParameterListeners::updateBroadcastersFromMessageThread() continue; paramInfo.value = paramInfo.paramCookie->getValue(); - if( audioThreadBroadcasters.size() > index) { - audioThreadBroadcastQueue.try_enqueue([this, i = index] { callAudioThreadBroadcaster(i); }); - } + + audioThreadBroadcastQueue.try_enqueue ([this, i = index] + { callAudioThreadBroadcaster (i); }); callMessageThreadBroadcaster (index); } } diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h index 307f3645c..527868d7c 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParameterListeners.h @@ -54,19 +54,12 @@ class ParameterListeners : private juce::Timer if (paramInfoIter == paramInfoList.end()) { - //jassertfalse; // trying to listen to a parameter that is not part of this state! - //return {}; - paramInfoList.push_back(ParamInfo{¶m, param.getValue()}); + jassertfalse; // trying to listen to a parameter that is not part of this state! + return {}; } - const auto _paramInfoIter = std::find_if (paramInfoList.begin(), paramInfoList.end(), [¶m] (const ParamInfo& info) - { return info.paramCookie == ¶m; }); - const auto index = (size_t) std::distance (paramInfoList.begin(), _paramInfoIter); + const auto index = (size_t) std::distance (paramInfoList.begin(), paramInfoIter); auto& broadcasterList = listenerThread == ParameterListenerThread::MessageThread ? messageThreadBroadcasters : audioThreadBroadcasters; - if(broadcasterList.size() <= index) - { - broadcasterList.push_back(Broadcaster()); - } return broadcasterList[index].connect (std::forward (args...)); } From 04e0a8b4054d941a3aa1475bdf3b34ab2d7c6e67 Mon Sep 17 00:00:00 2001 From: Davis Polito Date: Thu, 14 Nov 2024 16:49:25 -0500 Subject: [PATCH 8/8] fixing some borgs --- .../ParamUtils/chowdsp_ParameterConversions.cpp | 13 ------------- .../ParamUtils/chowdsp_ParameterConversions.h | 4 ---- .../Backend/chowdsp_NonParamState.cpp | 14 +++++--------- .../Backend/chowdsp_ParamHolder.cpp | 11 ++++------- 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp index 00c36de14..57607a1aa 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.cpp @@ -80,19 +80,6 @@ juce::String floatValToString (float floatVal) { return floatValToStringDecimal<2> (floatVal); } - juce::String semitonesValToString (float semitonesVal, bool snapToInt) - { - auto semitonesStr = snapToInt - ? juce::String (static_cast (semitonesVal)) + " st" - : juce::String (semitonesVal, 2, false) + " st"; - if (semitonesVal > 0.0f) - semitonesStr = "+" + semitonesStr; - return semitonesStr; - } - - float stringToSemitonesVal (const juce::String& s) { return s.getFloatValue(); } - - float stringToFloatVal (const juce::String& s) { return s.getFloatValue(); } } // namespace chowdsp::ParamUtils diff --git a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h index f3c7a6efc..3bd3bbf30 100644 --- a/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h +++ b/modules/plugin/chowdsp_parameters/ParamUtils/chowdsp_ParameterConversions.h @@ -28,8 +28,4 @@ juce::String floatValToStringDecimal (float floatVal) } float stringToFloatVal (const juce::String& s); - juce::String semitonesValToString (float semitonesVal, bool snapToInt); - float stringToSemitonesVal (const juce::String& s); - - } // namespace chowdsp::ParamUtils diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp index 4780a405f..c79902acc 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_NonParamState.cpp @@ -55,7 +55,7 @@ void NonParamState::deserialize (typename Serializer::DeserializedType deserial, for (auto& value : state.values) { - if (name == value->name) + if (name == toString(value->name)) { value->deserialize (deserial); @@ -69,18 +69,14 @@ void NonParamState::deserialize (typename Serializer::DeserializedType deserial, { jassertfalse; // state loading error } - for(auto id: namesThatHaveBeenDeserialized) - { + for(auto id: namesThatHaveBeenDeserialized) { DBG("nonparam " + id); } // set all un-matched objects to their default values - if (! namesThatHaveBeenDeserialized.empty()) + for (auto& value : state.values) { - for (auto& value : state.values) - { - if (std::find (namesThatHaveBeenDeserialized.begin(), namesThatHaveBeenDeserialized.end(), value->name) == namesThatHaveBeenDeserialized.end()) - value->reset(); - } + if (! namesThatHaveBeenDeserialized.contains (toString (value->name))) + value->reset(); } } diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp index b94ffa882..bec6b880d 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_ParamHolder.cpp @@ -227,18 +227,15 @@ void ParamHolder::deserialize (typename Serializer::DeserializedType deserial, P DBG("deserialzied " + id); } // set all un-matched objects to their default values - if (! paramIDsThatHaveBeenDeserialized.empty()) - { +// if (! paramIDsThatHaveBeenDeserialized.empty()) +// { paramHolder.doForAllParameters ( [¶mIDsThatHaveBeenDeserialized] (auto& param, size_t) { - if (std::find (paramIDsThatHaveBeenDeserialized.begin(), - paramIDsThatHaveBeenDeserialized.end(), - std::string_view { param.paramID.toRawUTF8(), param.paramID.getNumBytesAsUTF8() }) - == paramIDsThatHaveBeenDeserialized.end()) + if (! paramIDsThatHaveBeenDeserialized.contains (param.paramID)) ParameterTypeHelpers::resetParameter (param); }); - } +// } } inline void ParamHolder::applyVersionStreaming (const Version& version)