From e19897776a06b20ba5f346ed92a91145cd50fbb7 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 29 Oct 2012 04:23:42 +0000 Subject: [PATCH] Carla: add destructors to *_RDF structs, remove *_rdf_free() --- c++/carla-backend/ladspa.cpp | 2 +- c++/carla-backend/lv2.cpp | 4 +- c++/carla-includes/carla_ladspa.h | 37 --- c++/carla-includes/carla_lv2.h | 393 ------------------------------ c++/carla-includes/ladspa_rdf.h | 33 ++- c++/carla-includes/lv2_rdf.h | 130 +++++++++- 6 files changed, 155 insertions(+), 444 deletions(-) diff --git a/c++/carla-backend/ladspa.cpp b/c++/carla-backend/ladspa.cpp index 4a6062a..30a3538 100644 --- a/c++/carla-backend/ladspa.cpp +++ b/c++/carla-backend/ladspa.cpp @@ -72,7 +72,7 @@ public: } if (rdf_descriptor) - ladspa_rdf_free(rdf_descriptor); + delete rdf_descriptor; } // ------------------------------------------------------------------- diff --git a/c++/carla-backend/lv2.cpp b/c++/carla-backend/lv2.cpp index cdd0231..88f5431 100644 --- a/c++/carla-backend/lv2.cpp +++ b/c++/carla-backend/lv2.cpp @@ -150,7 +150,7 @@ struct Lv2EventData { }; Lv2EventData() - : type(0), + : type(0x0), rindex(0), port(nullptr) {} }; @@ -399,7 +399,7 @@ public: } if (rdf_descriptor) - lv2_rdf_free(rdf_descriptor); + delete rdf_descriptor; if (features[lv2_feature_id_event] && features[lv2_feature_id_event]->data) delete (LV2_Event_Feature*)features[lv2_feature_id_event]->data; diff --git a/c++/carla-includes/carla_ladspa.h b/c++/carla-includes/carla_ladspa.h index 0f232b3..3fc6393 100644 --- a/c++/carla-includes/carla_ladspa.h +++ b/c++/carla-includes/carla_ladspa.h @@ -79,43 +79,6 @@ const LADSPA_RDF_Descriptor* ladspa_rdf_dup(const LADSPA_RDF_Descriptor* const r return new_descriptor; } -// Delete object -static inline -void ladspa_rdf_free(const LADSPA_RDF_Descriptor* const rdf_descriptor) -{ - if (rdf_descriptor->Title) - free((void*)rdf_descriptor->Title); - - if (rdf_descriptor->Creator) - free((void*)rdf_descriptor->Creator); - - if (rdf_descriptor->PortCount > 0) - { - for (unsigned long i=0; i < rdf_descriptor->PortCount; i++) - { - const LADSPA_RDF_Port* const Port = &rdf_descriptor->Ports[i]; - - if (Port->Label) - free((void*)Port->Label); - - if (Port->ScalePointCount > 0) - { - for (unsigned long j=0; j < Port->ScalePointCount; j++) - { - const LADSPA_RDF_ScalePoint* const ScalePoint = &Port->ScalePoints[j]; - - if (ScalePoint->Label) - free((void*)ScalePoint->Label); - } - delete[] Port->ScalePoints; - } - } - delete[] rdf_descriptor->Ports; - } - - delete rdf_descriptor; -} - // ------------------------------------------------------------------------------------------------ static inline diff --git a/c++/carla-includes/carla_lv2.h b/c++/carla-includes/carla_lv2.h index e4683f4..a305dc1 100644 --- a/c++/carla-includes/carla_lv2.h +++ b/c++/carla-includes/carla_lv2.h @@ -1073,399 +1073,6 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI URI) return nullptr; } -// Copy RDF object -static inline -const LV2_RDF_Descriptor* lv2_rdf_dup(const LV2_RDF_Descriptor* const rdf_descriptor) -{ - CARLA_ASSERT(rdf_descriptor); - - LV2_RDF_Descriptor* const new_descriptor = new LV2_RDF_Descriptor; - - new_descriptor->Type = rdf_descriptor->Type; - new_descriptor->UniqueID = rdf_descriptor->UniqueID; - - new_descriptor->PortCount = rdf_descriptor->PortCount; - new_descriptor->PresetCount = rdf_descriptor->PresetCount; - new_descriptor->FeatureCount = rdf_descriptor->FeatureCount; - new_descriptor->ExtensionCount = rdf_descriptor->ExtensionCount; - new_descriptor->UICount = rdf_descriptor->UICount; - - if (rdf_descriptor->URI) - new_descriptor->URI = strdup(rdf_descriptor->URI); - - if (rdf_descriptor->Name) - new_descriptor->Name = strdup(rdf_descriptor->Name); - - if (rdf_descriptor->Author) - new_descriptor->Author = strdup(rdf_descriptor->Author); - - if (rdf_descriptor->License) - new_descriptor->License = strdup(rdf_descriptor->License); - - if (rdf_descriptor->Binary) - new_descriptor->Binary = strdup(rdf_descriptor->Binary); - - if (rdf_descriptor->Bundle) - new_descriptor->Bundle = strdup(rdf_descriptor->Bundle); - - // Ports - if (new_descriptor->PortCount > 0) - { - new_descriptor->Ports = new LV2_RDF_Port[new_descriptor->PortCount]; - - for (uint32_t i=0; i < new_descriptor->PortCount; i++) - { - LV2_RDF_Port* const Port = &new_descriptor->Ports[i]; - - Port->Type = rdf_descriptor->Ports[i].Type; - Port->Properties = rdf_descriptor->Ports[i].Properties; - Port->Designation = rdf_descriptor->Ports[i].Designation; - - Port->MidiMap.Type = rdf_descriptor->Ports[i].MidiMap.Type; - Port->MidiMap.Number = rdf_descriptor->Ports[i].MidiMap.Number; - - Port->Points.Hints = rdf_descriptor->Ports[i].Points.Hints; - Port->Points.Default = rdf_descriptor->Ports[i].Points.Default; - Port->Points.Minimum = rdf_descriptor->Ports[i].Points.Minimum; - Port->Points.Maximum = rdf_descriptor->Ports[i].Points.Maximum; - - Port->Unit.Type = rdf_descriptor->Ports[i].Unit.Type; - Port->Unit.Hints = rdf_descriptor->Ports[i].Unit.Hints; - - Port->ScalePointCount = rdf_descriptor->Ports[i].ScalePointCount; - - if (rdf_descriptor->Ports[i].Name) - Port->Name = strdup(rdf_descriptor->Ports[i].Name); - - if (rdf_descriptor->Ports[i].Symbol) - Port->Symbol = strdup(rdf_descriptor->Ports[i].Symbol); - - if (rdf_descriptor->Ports[i].Unit.Name) - Port->Unit.Name = strdup(rdf_descriptor->Ports[i].Unit.Name); - - if (rdf_descriptor->Ports[i].Unit.Render) - Port->Unit.Render = strdup(rdf_descriptor->Ports[i].Unit.Render); - - if (rdf_descriptor->Ports[i].Unit.Symbol) - Port->Unit.Symbol = strdup(rdf_descriptor->Ports[i].Unit.Symbol); - - if (Port->ScalePointCount > 0) - { - Port->ScalePoints = new LV2_RDF_PortScalePoint[Port->ScalePointCount]; - - for (uint32_t j=0; j < Port->ScalePointCount; j++) - { - Port->ScalePoints[j].Value = rdf_descriptor->Ports[i].ScalePoints[j].Value; - - if (rdf_descriptor->Ports[i].ScalePoints[j].Label) - Port->ScalePoints[j].Label = strdup(rdf_descriptor->Ports[i].ScalePoints[j].Label); - } - } - } - } - -#if 0 - // Presets - if (new_descriptor->PresetCount > 0) - { - new_descriptor->Presets = new LV2_RDF_Preset[new_descriptor->PresetCount]; - - for (uint32_t i=0; i < new_descriptor->PresetCount; i++) - { - LV2_RDF_Preset* const Preset = &new_descriptor->Presets[i]; - - Preset->PortCount = rdf_descriptor->Presets[i].PortCount; - Preset->StateCount = rdf_descriptor->Presets[i].StateCount; - - if (rdf_descriptor->Presets[i].URI) - Preset->URI = strdup(rdf_descriptor->Presets[i].URI); - - if (rdf_descriptor->Presets[i].Label) - Preset->Label = strdup(rdf_descriptor->Presets[i].Label); - - // Ports - if (Preset->PortCount > 0) - { - Preset->Ports = new LV2_RDF_PresetPort[Preset->PortCount]; - - for (uint32_t j=0; j < Preset->PortCount; j++) - { - Preset->Ports[j].Value = rdf_descriptor->Presets[i].Ports[j].Value; - - if (rdf_descriptor->Presets[i].Ports[j].Symbol) - Preset->Ports[j].Symbol = strdup(rdf_descriptor->Presets[i].Ports[j].Symbol); - } - } - - // States - if (Preset->StateCount > 0) - { - Preset->States = new LV2_RDF_PresetState[Preset->StateCount]; - - for (uint32_t j=0; j < Preset->StateCount; j++) - { - Preset->States[j].Type = rdf_descriptor->Presets[i].States[j].Type; - - if (rdf_descriptor->Presets[i].States[j].Key) - Preset->States[j].Key = strdup(rdf_descriptor->Presets[i].States[j].Key); - - // TODO - copy value - } - } - } - } -#endif - - // Features - if (new_descriptor->FeatureCount > 0) - { - new_descriptor->Features = new LV2_RDF_Feature[new_descriptor->FeatureCount]; - - for (uint32_t i=0; i < new_descriptor->FeatureCount; i++) - { - new_descriptor->Features[i].Type = rdf_descriptor->Features[i].Type; - - if (rdf_descriptor->Features[i].URI) - new_descriptor->Features[i].URI = strdup(rdf_descriptor->Features[i].URI); - } - } - - // Extensions - if (new_descriptor->ExtensionCount > 0) - { - new_descriptor->Extensions = new LV2_URI[new_descriptor->ExtensionCount]; - - for (uint32_t i=0; i < new_descriptor->ExtensionCount; i++) - { - if (rdf_descriptor->Extensions[i]) - new_descriptor->Extensions[i] = strdup(rdf_descriptor->Extensions[i]); - } - } - - // UIs - if (new_descriptor->UICount > 0) - { - new_descriptor->UIs = new LV2_RDF_UI[new_descriptor->UICount]; - - for (uint32_t i=0; i < new_descriptor->UICount; i++) - { - LV2_RDF_UI* const UI = &new_descriptor->UIs[i]; - - UI->Type = rdf_descriptor->UIs[i].Type; - - UI->FeatureCount = rdf_descriptor->UIs[i].FeatureCount; - UI->ExtensionCount = rdf_descriptor->UIs[i].ExtensionCount; - - if (rdf_descriptor->UIs[i].URI) - UI->URI = strdup(rdf_descriptor->UIs[i].URI); - - if (rdf_descriptor->UIs[i].Binary) - UI->Binary = strdup(rdf_descriptor->UIs[i].Binary); - - if (rdf_descriptor->UIs[i].Bundle) - UI->Bundle = strdup(rdf_descriptor->UIs[i].Bundle); - - // UI Features - if (UI->FeatureCount > 0) - { - UI->Features = new LV2_RDF_Feature[UI->FeatureCount]; - - for (uint32_t j=0; j < UI->FeatureCount; j++) - { - UI->Features[j].Type = rdf_descriptor->UIs[i].Features[j].Type; - - if (rdf_descriptor->UIs[i].Features[j].URI) - UI->Features[j].URI = strdup(rdf_descriptor->UIs[i].Features[j].URI); - } - } - - // UI Extensions - if (UI->ExtensionCount > 0) - { - UI->Extensions = new LV2_URI[UI->ExtensionCount]; - - for (uint32_t j=0; j < UI->ExtensionCount; j++) - { - if (rdf_descriptor->UIs[i].Extensions[j]) - UI->Extensions[j] = strdup(rdf_descriptor->UIs[i].Extensions[j]); - } - } - } - } - - return new_descriptor; -} - -// Delete object -static inline -void lv2_rdf_free(const LV2_RDF_Descriptor* const rdf_descriptor) -{ - if (rdf_descriptor->URI) - free((void*)rdf_descriptor->URI); - - if (rdf_descriptor->Name) - free((void*)rdf_descriptor->Name); - - if (rdf_descriptor->Author) - free((void*)rdf_descriptor->Author); - - if (rdf_descriptor->License) - free((void*)rdf_descriptor->License); - - if (rdf_descriptor->Binary) - free((void*)rdf_descriptor->Binary); - - if (rdf_descriptor->Bundle) - free((void*)rdf_descriptor->Bundle); - - if (rdf_descriptor->PortCount > 0) - { - for (uint32_t i=0; i < rdf_descriptor->PortCount; i++) - { - const LV2_RDF_Port* const Port = &rdf_descriptor->Ports[i]; - - if (Port->Name) - free((void*)Port->Name); - - if (Port->Symbol) - free((void*)Port->Symbol); - - if (Port->Unit.Name) - free((void*)Port->Unit.Name); - - if (Port->Unit.Render) - free((void*)Port->Unit.Render); - - if (Port->Unit.Symbol) - free((void*)Port->Unit.Symbol); - - if (Port->ScalePointCount > 0) - { - for (uint32_t j=0; j < Port->ScalePointCount; j++) - { - const LV2_RDF_PortScalePoint* const PortScalePoint = &Port->ScalePoints[j]; - - if (PortScalePoint->Label) - free((void*)PortScalePoint->Label); - } - delete[] Port->ScalePoints; - } - } - delete[] rdf_descriptor->Ports; - } - -#if 0 - if (rdf_descriptor->PresetCount > 0) - { - for (uint32_t i=0; i < rdf_descriptor->PresetCount; i++) - { - const LV2_RDF_Preset* const Preset = &rdf_descriptor->Presets[i]; - - if (Preset->URI) - free((void*)Preset->URI); - - if (Preset->Label) - free((void*)Preset->Label); - - if (Preset->PortCount > 0) - { - for (uint32_t j=0; j < Preset->PortCount; j++) - { - const LV2_RDF_PresetPort* const PresetPort = &Preset->Ports[j]; - - if (PresetPort->Symbol) - free((void*)PresetPort->Symbol); - } - delete[] Preset->Ports; - } - - if (Preset->StateCount > 0) - { - for (uint32_t j=0; j < Preset->StateCount; j++) - { - const LV2_RDF_PresetState* const PresetState = &Preset->States[j]; - - if (PresetState->Key) - free((void*)PresetState->Key); - - // TODO - delete value - } - delete[] Preset->States; - } - } - delete[] rdf_descriptor->Presets; - } -#endif - - if (rdf_descriptor->FeatureCount > 0) - { - for (uint32_t i=0; i < rdf_descriptor->FeatureCount; i++) - { - const LV2_RDF_Feature* const Feature = &rdf_descriptor->Features[i]; - - if (Feature->URI) - free((void*)Feature->URI); - } - delete[] rdf_descriptor->Features; - } - - if (rdf_descriptor->ExtensionCount > 0) - { - for (uint32_t i=0; i < rdf_descriptor->ExtensionCount; i++) - { - const LV2_URI Extension = rdf_descriptor->Extensions[i]; - - if (Extension) - free((void*)Extension); - } - delete[] rdf_descriptor->Extensions; - } - - if (rdf_descriptor->UICount > 0) - { - for (uint32_t i=0; i < rdf_descriptor->UICount; i++) - { - const LV2_RDF_UI* const UI = &rdf_descriptor->UIs[i]; - - if (UI->URI) - free((void*)UI->URI); - - if (UI->Binary) - free((void*)UI->Binary); - - if (UI->Bundle) - free((void*)UI->Bundle); - - if (UI->FeatureCount > 0) - { - for (uint32_t j=0; j < UI->FeatureCount; j++) - { - const LV2_RDF_Feature* const Feature = &UI->Features[j]; - - if (Feature->URI) - free((void*)Feature->URI); - } - delete[] UI->Features; - } - - if (UI->ExtensionCount > 0) - { - for (uint32_t j=0; j < UI->ExtensionCount; j++) - { - const LV2_URI Extension = UI->Extensions[j]; - - if (Extension) - free((void*)Extension); - } - delete[] UI->Extensions; - } - } - delete[] rdf_descriptor->UIs; - } - - delete rdf_descriptor; -} - // ------------------------------------------------------------------------------------------------ static inline diff --git a/c++/carla-includes/ladspa_rdf.h b/c++/carla-includes/ladspa_rdf.h index 37e0769..b462747 100644 --- a/c++/carla-includes/ladspa_rdf.h +++ b/c++/carla-includes/ladspa_rdf.h @@ -123,6 +123,12 @@ struct LADSPA_RDF_ScalePoint { LADSPA_RDF_ScalePoint() : Value(0.0f), Label(nullptr) {} + + ~LADSPA_RDF_ScalePoint() + { + if (Label) + free((void*)Label); + } }; // Port @@ -137,13 +143,22 @@ struct LADSPA_RDF_Port { LADSPA_RDF_ScalePoint* ScalePoints; LADSPA_RDF_Port() - : Type(0), - Hints(0), + : Type(0x0), + Hints(0x0), Label(nullptr), Default(0.0f), Unit(0), ScalePointCount(0), ScalePoints(nullptr) {} + + ~LADSPA_RDF_Port() + { + if (Label) + free((void*)Label); + + if (ScalePoints) + delete[] ScalePoints; + } }; // Plugin @@ -157,12 +172,24 @@ struct LADSPA_RDF_Descriptor { LADSPA_RDF_Port* Ports; LADSPA_RDF_Descriptor() - : Type(0), + : Type(0x0), UniqueID(0), Title(nullptr), Creator(nullptr), PortCount(0), Ports(nullptr) {} + + ~LADSPA_RDF_Descriptor() + { + if (Title) + free((void*)Title); + + if (Creator) + free((void*)Creator); + + if (Ports) + delete[] Ports; + } }; #endif // LADSPA_RDF_INCLUDED diff --git a/c++/carla-includes/lv2_rdf.h b/c++/carla-includes/lv2_rdf.h index c981ae8..07db2dd 100644 --- a/c++/carla-includes/lv2_rdf.h +++ b/c++/carla-includes/lv2_rdf.h @@ -308,7 +308,7 @@ struct LV2_RDF_PortPoints { LV2_Data Maximum; LV2_RDF_PortPoints() - : Hints(0), + : Hints(0x0), Default(0.0f), Minimum(0.0f), Maximum(1.0f) {} @@ -324,10 +324,22 @@ struct LV2_RDF_PortUnit { LV2_RDF_PortUnit() : Type(0), - Hints(0), + Hints(0x0), Name(nullptr), Render(nullptr), Symbol(nullptr) {} + + ~LV2_RDF_PortUnit() + { + if (Name) + free((void*)Name); + + if (Render) + free((void*)Render); + + if (Symbol) + free((void*)Symbol); + } }; // Port Scale Point @@ -338,6 +350,12 @@ struct LV2_RDF_PortScalePoint { LV2_RDF_PortScalePoint() : Label(nullptr), Value(0.0f) {} + + ~LV2_RDF_PortScalePoint() + { + if (Label) + free((void*)Label); + } }; // Port @@ -356,16 +374,25 @@ struct LV2_RDF_Port { LV2_RDF_PortScalePoint* ScalePoints; LV2_RDF_Port() - : Type(0), - Properties(0), + : Type(0x0), + Properties(0x0), Designation(0), Name(nullptr), Symbol(nullptr), - MidiMap(), - Points(), - Unit(), ScalePointCount(0), ScalePoints(nullptr) {} + + ~LV2_RDF_Port() + { + if (Name) + free((void*)Name); + + if (Symbol) + free((void*)Symbol); + + if (ScalePoints) + delete[] ScalePoints; + } }; // Preset Port @@ -376,6 +403,12 @@ struct LV2_RDF_PresetPort { LV2_RDF_PresetPort() : Symbol(nullptr), Value(0.0f) {} + + ~LV2_RDF_PresetPort() + { + if (Symbol) + free((void*)Symbol); + } }; // Preset State @@ -389,6 +422,12 @@ struct LV2_RDF_PresetState { LV2_RDF_PresetState() : Type(0), Key(nullptr) {} + + ~LV2_RDF_PresetState() + { + if (Key) + free((void*)Key); + } }; // Preset @@ -409,6 +448,21 @@ struct LV2_RDF_Preset { Ports(nullptr), StateCount(0), States(nullptr) {} + + ~LV2_RDF_Preset() + { + if (URI) + free((void*)URI); + + if (Label) + free((void*)Label); + + if (Ports) + delete[] Ports; + + if (States) + delete[] States; + } }; // Feature @@ -419,6 +473,12 @@ struct LV2_RDF_Feature { LV2_RDF_Feature() : Type(0), URI(nullptr) {} + + ~LV2_RDF_Feature() + { + if (URI) + free((void*)URI); + } }; // UI @@ -443,6 +503,24 @@ struct LV2_RDF_UI { Features(nullptr), ExtensionCount(0), Extensions(nullptr) {} + + ~LV2_RDF_UI() + { + if (URI) + free((void*)URI); + + if (Binary) + free((void*)Binary); + + if (Bundle) + free((void*)Bundle); + + if (Features) + delete[] Features; + + if (Extensions) + delete[] Extensions; + } }; // Plugin @@ -472,7 +550,7 @@ struct LV2_RDF_Descriptor { LV2_RDF_UI* UIs; LV2_RDF_Descriptor() - : Type(0), + : Type(0x0), URI(nullptr), Name(nullptr), Author(nullptr), @@ -490,6 +568,42 @@ struct LV2_RDF_Descriptor { Extensions(nullptr), UICount(0), UIs(nullptr) {} + + ~LV2_RDF_Descriptor() + { + if (URI) + free((void*)URI); + + if (Name) + free((void*)Name); + + if (Author) + free((void*)Author); + + if (License) + free((void*)License); + + if (Binary) + free((void*)Binary); + + if (Bundle) + free((void*)Bundle); + + if (Ports) + delete[] Ports; + + if (Presets) + delete[] Presets; + + if (Features) + delete[] Features; + + if (Extensions) + delete[] Extensions; + + if (UIs) + delete[] UIs; + } }; #endif /* LV2_RDF_INCLUDED */