diff --git a/resources/neural_amp_modeler.ttl.in b/resources/neural_amp_modeler.ttl.in index 7c2efea..23a2530 100644 --- a/resources/neural_amp_modeler.ttl.in +++ b/resources/neural_amp_modeler.ttl.in @@ -9,6 +9,7 @@ @prefix param: . @prefix patch: . @prefix state: . +@prefix work: . <@NAM_LV2_ID@> a doap:Project; @@ -28,8 +29,9 @@ lv2:microVersion @PROJECT_VERSION_PATCH@; doap:license ; - lv2:requiredFeature urid:map; + lv2:requiredFeature urid:map, work:schedule; lv2:optionalFeature lv2:hardRTCapable; + lv2:extensionData work:interface; rdfs:comment "An LV2 implementation of Neural Amp Modeler"; diff --git a/src/nam_lv2.cpp b/src/nam_lv2.cpp index e6302bc..ae249d6 100644 --- a/src/nam_lv2.cpp +++ b/src/nam_lv2.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "nam_plugin.hpp" @@ -64,7 +65,36 @@ static void cleanup(LV2_Handle instance) { delete static_cast(instance); } -static const void* extension_data(const char*) { return nullptr; } +static LV2_Worker_Status +work(LV2_Handle instance, + LV2_Worker_Respond_Function respond, + LV2_Worker_Respond_Handle handle, + uint32_t size, + const void* data) +{ + + return LV2_WORKER_SUCCESS; +} + +static LV2_Worker_Status +work_response(LV2_Handle instance, + uint32_t size, + const void* data) +{ + return LV2_WORKER_SUCCESS; +} + +static const void* +extension_data(const char* uri) +{ + static const LV2_Worker_Interface worker = { work, work_response, NULL }; + + if (!strcmp(uri, LV2_WORKER__interface)) { + return &worker; + } + + return NULL; +} static const LV2_Descriptor descriptor = { "http://github.com/mikeoliphant/neural-amp-modeler-lv2", diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index 2098dfa..1d3e1bd 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -11,7 +11,6 @@ namespace NAM { Plugin::Plugin(float rate) { - namModel = get_dsp("C:\\Users\\oliph\\AppData\\Roaming\\GuitarSim\\NAM\\AC15Brkup.nam"); } void Plugin::map_uris(LV2_URID_Map* map) noexcept { @@ -30,7 +29,46 @@ namespace NAM { } void Plugin::process(uint32_t n_samples) noexcept { - namModel->process(ports.audio_in, ports.audio_out, n_samples, 1.0, 1.0, mNAMParams); - namModel->finalize_(n_samples); + if (ports.control) { + LV2_ATOM_SEQUENCE_FOREACH(ports.control, event) { + if (event->body.type == uris.atom_Object) { + const auto obj = reinterpret_cast(&event->body); + + if (obj->body.otype == uris.patch_Set) + { + const LV2_Atom* property = NULL; + const LV2_Atom* file_path = NULL; + + lv2_atom_object_get(obj, uris.patch_property, &property, 0); + + if (property && (property->type == uris.atom_URID)) + { + if (((const LV2_Atom_URID*)property)->body == uris.model_Path) + { + lv2_atom_object_get(obj, uris.patch_value, &file_path, 0); + + if (file_path && (file_path->size > 0)) + { + namModel = get_dsp((const char*)LV2_ATOM_BODY_CONST(file_path)); + } + } + } + } + } + } + } + + if (namModel == nullptr) + { + for (int i = 0; i < n_samples; i++) + { + ports.audio_out[i] = ports.audio_in[i]; + } + } + else + { + namModel->process(ports.audio_in, ports.audio_out, n_samples, 1.0, 1.0, mNAMParams); + namModel->finalize_(n_samples); + } } }