From 0d7954cf2ae5aadaa1b8c76e9aad010f86170f3e Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 15 Jun 2023 16:42:45 +0200 Subject: [PATCH] General cleanup, no functional changes Signed-off-by: falkTX --- resources/neural_amp_modeler.ttl.in | 6 +++--- src/nam_lv2.cpp | 4 +--- src/nam_plugin.cpp | 25 +++++++++++-------------- src/nam_plugin.h | 11 +++++------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/resources/neural_amp_modeler.ttl.in b/resources/neural_amp_modeler.ttl.in index b7b4eff..701cec4 100644 --- a/resources/neural_amp_modeler.ttl.in +++ b/resources/neural_amp_modeler.ttl.in @@ -14,10 +14,10 @@ @prefix mod: . <@NAM_LV2_ID@#model> - a lv2:Parameter; + a lv2:Parameter; mod:fileTypes "nam,nammodel"; - rdfs:label "Neural Model"; - rdfs:range atom:Path. + rdfs:label "Neural Model"; + rdfs:range atom:Path. <@NAM_LV2_ID@> a lv2:Plugin, lv2:SimulatorPlugin; diff --git a/src/nam_lv2.cpp b/src/nam_lv2.cpp index 771440d..553dcf9 100644 --- a/src/nam_lv2.cpp +++ b/src/nam_lv2.cpp @@ -66,10 +66,8 @@ static const void* extension_data(const char* uri) static const LV2_State_Interface state = {NAM::Plugin::save, NAM::Plugin::restore}; static const LV2_Worker_Interface worker = { NAM::Plugin::work, NAM::Plugin::work_response, NULL }; - if (!strcmp(uri, LV2_STATE__interface)) { + if (!strcmp(uri, LV2_STATE__interface)) return &state; - } - if (!strcmp(uri, LV2_WORKER__interface)) return &worker; diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index c3ac658..e2c7530 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -17,8 +17,6 @@ namespace NAM { bool Plugin::initialize(double rate, const LV2_Feature* const* features) noexcept { - logger.log = nullptr; - for (size_t i = 0; features[i]; ++i) { if (std::string(features[i]->URI) == std::string(LV2_URID__map)) map = static_cast(features[i]->data); @@ -146,8 +144,8 @@ namespace NAM { void Plugin::process(uint32_t n_samples) noexcept { - lv2_atom_forge_set_buffer(&atom_forge,(uint8_t*)ports.notify,ports.notify->atom.size); - lv2_atom_forge_sequence_head(&atom_forge,&sequence_frame,uris.units_frame); + lv2_atom_forge_set_buffer(&atom_forge, (uint8_t*)ports.notify, ports.notify->atom.size); + lv2_atom_forge_sequence_head(&atom_forge, &sequence_frame, uris.units_frame); LV2_ATOM_SEQUENCE_FOREACH(ports.control, event) { @@ -173,7 +171,7 @@ namespace NAM { { lv2_atom_object_get(obj, uris.patch_value, &file_path, 0); - if (file_path && (file_path->size > 0) && (file_path->size < 1024)) + if (file_path && (file_path->size > 0) && (file_path->size < MAX_FILE_NAME)) { LV2LoadModelMsg msg = { kWorkTypeLoad, {} }; @@ -210,10 +208,7 @@ namespace NAM { } } - if (currentModel == nullptr) - { - } - else + if (currentModel != nullptr) { currentModel->process(&ports.audio_out, &ports.audio_out, 1, n_samples, 1.0, 1.0, mNAMParams); currentModel->finalize_(n_samples); @@ -286,7 +281,7 @@ namespace NAM { } else { -#ifndef _WIN32 // Can't free library allocated memory on Windows +#ifndef _WIN32 // Can't free host-allocated memory on plugin side under Windows free(apath); #endif } @@ -335,7 +330,7 @@ namespace NAM { LV2_State_Status result = LV2_STATE_SUCCESS; - if (pathLen < 1024) + if (pathLen < MAX_FILE_NAME) { // Schedule model to be loaded by the provided worker NAM::LV2LoadModelMsg msg = { NAM::kWorkTypeLoad, {} }; @@ -345,7 +340,7 @@ namespace NAM { } else { - lv2_log_error(&nam->logger, "Model path is too long (max 1024 chars)\n"); + lv2_log_error(&nam->logger, "Model path is too long (max %u chars)\n", MAX_FILE_NAME); result = LV2_STATE_ERR_UNKNOWN; } @@ -358,7 +353,7 @@ namespace NAM { } else { -#ifndef _WIN32 // Can't free library allocated memory on Windows +#ifndef _WIN32 // Can't free host-allocated memory on plugin side under Windows free(path); #endif } @@ -385,7 +380,9 @@ namespace NAM { LV2_Atom_Forge_Frame frame; lv2_atom_forge_object(&atom_forge, &frame, 0, uris.state_StateChanged); - /* object with no properties */ + + /* object with no properties */ + lv2_atom_forge_pop(&atom_forge, &frame); } diff --git a/src/nam_plugin.h b/src/nam_plugin.h index 038c843..ddd4a59 100644 --- a/src/nam_plugin.h +++ b/src/nam_plugin.h @@ -25,6 +25,7 @@ #define MODEL_URI PlUGIN_URI "#model" namespace NAM { + static constexpr unsigned int MAX_FILE_NAME = 1024; enum LV2WorkType { kWorkTypeLoad, @@ -33,7 +34,7 @@ namespace NAM { struct LV2LoadModelMsg { LV2WorkType type; - char path[1024]; + char path[MAX_FILE_NAME]; }; class Plugin { @@ -49,9 +50,9 @@ namespace NAM { Ports ports = {}; - LV2_URID_Map* map; - LV2_Log_Logger logger; - LV2_Worker_Schedule* schedule; + LV2_URID_Map* map = nullptr; + LV2_Log_Logger logger = {}; + LV2_Worker_Schedule* schedule = nullptr; std::unique_ptr<::DSP> currentModel; std::unique_ptr<::DSP> stagedModel; @@ -82,8 +83,6 @@ namespace NAM { const LV2_Feature* const* features); private: - static constexpr size_t MAX_FILE_NAME = 1024; - struct URIs { LV2_URID atom_Object; LV2_URID atom_Float;