6 Commits

Author SHA1 Message Date
Mike Oliphant c990eedf33 Bump version 2023-07-07 07:29:50 -07:00
Mike Oliphant 0255f36ae4 Don't report a worker error if we can't load a model since we're already logging an error. 2023-07-04 16:28:57 -07:00
Mike Oliphant 207fb2281e Fixed some warnings 2023-07-04 14:55:17 -07:00
Mike Oliphant dbf00f0ed3 Formatting 2023-07-04 14:53:39 -07:00
Mike Oliphant 33a0c08327 Set currentModelPath in restore() - even if it is null or empty.
Set it to empty and clear the current model if a model fails to load.
2023-07-04 13:03:46 -07:00
Mike Oliphant cde3df4e84 Update to latest NAM Core 2023-06-23 08:07:43 -07:00
5 changed files with 74 additions and 62 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(NeuralAmpModelerLv2 VERSION 0.1.0) project(NeuralAmpModelerLv2 VERSION 0.1.1)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+2 -1
View File
@@ -27,7 +27,7 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
return nullptr; return nullptr;
} }
catch(const std::exception& e) catch(const std::exception)
{ {
return nullptr; return nullptr;
} }
@@ -36,6 +36,7 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
static void connect_port(LV2_Handle instance, uint32_t port, void* data) static void connect_port(LV2_Handle instance, uint32_t port, void* data)
{ {
auto nam = static_cast<NAM::Plugin*>(instance); auto nam = static_cast<NAM::Plugin*>(instance);
*(reinterpret_cast<void**>(&nam->ports)+port) = data; *(reinterpret_cast<void**>(&nam->ports)+port) = data;
} }
+46 -34
View File
@@ -25,7 +25,8 @@ namespace NAM {
// for fetching initial options, can be null // for fetching initial options, can be null
LV2_Options_Option* options = nullptr; LV2_Options_Option* options = nullptr;
for (size_t i = 0; features[i]; ++i) { for (size_t i = 0; features[i]; ++i)
{
if (std::string(features[i]->URI) == std::string(LV2_URID__map)) if (std::string(features[i]->URI) == std::string(LV2_URID__map))
map = static_cast<LV2_URID_Map*>(features[i]->data); map = static_cast<LV2_URID_Map*>(features[i]->data);
else if (std::string(features[i]->URI) == std::string(LV2_WORKER__schedule)) else if (std::string(features[i]->URI) == std::string(LV2_WORKER__schedule))
@@ -85,11 +86,14 @@ namespace NAM {
auto msg = static_cast<const LV2LoadModelMsg*>(data); auto msg = static_cast<const LV2LoadModelMsg*>(data);
auto nam = static_cast<NAM::Plugin*>(instance); auto nam = static_cast<NAM::Plugin*>(instance);
::DSP* model = nullptr;
LV2SwitchModelMsg response = { kWorkTypeSwitch, {}, {} };
LV2_Worker_Status result = LV2_WORKER_SUCCESS;
try try
{ {
// load model from path // load model from path
const size_t pathlen = strlen(msg->path); const size_t pathlen = strlen(msg->path);
::DSP* model;
if (pathlen == 0 || pathlen >= MAX_FILE_NAME) if (pathlen == 0 || pathlen >= MAX_FILE_NAME)
{ {
@@ -119,24 +123,29 @@ namespace NAM {
} }
} }
LV2SwitchModelMsg response = { kWorkTypeSwitch, {}, model }; response.model = model;
memcpy(response.path, msg->path, pathlen); memcpy(response.path, msg->path, pathlen);
}
catch (std::exception)
{
response.path[0] = '\0';
lv2_log_error(&nam->logger, "Unable to load model from: '%s'\n", msg->path);
//result = LV2_WORKER_ERR_UNKNOWN;
}
respond(handle, sizeof(response), &response); respond(handle, sizeof(response), &response);
return LV2_WORKER_SUCCESS; return result;
}
catch (std::exception& e)
{
lv2_log_error(&nam->logger, "Unable to load model from: '%s'\n", msg->path);
}
break;
} }
case kWorkTypeFree: case kWorkTypeFree:
{ {
auto msg = static_cast<const LV2FreeModelMsg*>(data); auto msg = static_cast<const LV2FreeModelMsg*>(data);
delete msg->model; delete msg->model;
return LV2_WORKER_SUCCESS; return LV2_WORKER_SUCCESS;
} }
@@ -293,7 +302,8 @@ namespace NAM {
lv2_log_trace(&nam->logger, "Saving state\n"); lv2_log_trace(&nam->logger, "Saving state\n");
if (!nam->currentModel) { if (!nam->currentModel)
{
return LV2_STATE_SUCCESS; return LV2_STATE_SUCCESS;
} }
@@ -331,8 +341,6 @@ namespace NAM {
LV2_State_Status Plugin::restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, LV2_State_Status Plugin::restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle,
uint32_t flags, const LV2_Feature* const* features) uint32_t flags, const LV2_Feature* const* features)
{ {
//if (!haveLog) return LV2_STATE_SUCCESS;
auto nam = static_cast<NAM::Plugin*>(instance); auto nam = static_cast<NAM::Plugin*>(instance);
// Get model_Path from state // Get model_Path from state
@@ -343,16 +351,17 @@ namespace NAM {
lv2_log_trace(&nam->logger, "Restoring model '%s'\n", (const char*)value); lv2_log_trace(&nam->logger, "Restoring model '%s'\n", (const char*)value);
if (!value) { NAM::LV2LoadModelMsg msg = { NAM::kWorkTypeLoad, {} };
lv2_log_error(&nam->logger, "Missing model_Path\n");
return LV2_STATE_ERR_NO_PROPERTY;
}
if (type != nam->uris.atom_Path) { LV2_State_Status result = LV2_STATE_SUCCESS;
lv2_log_error(&nam->logger, "Non-path model_Path\n");
return LV2_STATE_ERR_BAD_TYPE;
}
// Check if a path is set
if (!value || (type != nam->uris.atom_Path))
{
msg.path[0] = '\0';
}
else
{
LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data(features, LV2_STATE__mapPath); LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data(features, LV2_STATE__mapPath);
if (map_path == nullptr) if (map_path == nullptr)
@@ -367,22 +376,16 @@ namespace NAM {
size_t pathLen = strlen(path); size_t pathLen = strlen(path);
LV2_State_Status result = LV2_STATE_SUCCESS; if (pathLen >= MAX_FILE_NAME)
if (pathLen < MAX_FILE_NAME)
{
// Schedule model to be loaded by the provided worker
NAM::LV2LoadModelMsg msg = { NAM::kWorkTypeLoad, {} };
memcpy(msg.path, path, pathLen);
nam->schedule->schedule_work(nam->schedule->handle, sizeof(msg), &msg);
}
else
{ {
lv2_log_error(&nam->logger, "Model path is too long (max %u chars)\n", MAX_FILE_NAME); lv2_log_error(&nam->logger, "Model path is too long (max %u chars)\n", MAX_FILE_NAME);
result = LV2_STATE_ERR_UNKNOWN; result = LV2_STATE_ERR_UNKNOWN;
} }
else
{
memcpy(msg.path, path, pathLen);
}
LV2_State_Free_Path* free_path = (LV2_State_Free_Path*)lv2_features_data(features, LV2_STATE__freePath); LV2_State_Free_Path* free_path = (LV2_State_Free_Path*)lv2_features_data(features, LV2_STATE__freePath);
@@ -396,6 +399,15 @@ namespace NAM {
free(path); free(path);
#endif #endif
} }
}
if (result == LV2_STATE_SUCCESS)
{
// Schedule model to be loaded by the provided worker
nam->schedule->schedule_work(nam->schedule->handle, sizeof(msg), &msg);
nam->currentModelPath = msg.path;
}
return result; return result;
} }
@@ -410,7 +422,7 @@ namespace NAM {
lv2_atom_forge_key(&atom_forge, uris.patch_property); lv2_atom_forge_key(&atom_forge, uris.patch_property);
lv2_atom_forge_urid(&atom_forge, uris.model_Path); lv2_atom_forge_urid(&atom_forge, uris.model_Path);
lv2_atom_forge_key(&atom_forge, uris.patch_value); lv2_atom_forge_key(&atom_forge, uris.patch_value);
lv2_atom_forge_path(&atom_forge, currentModelPath.c_str(), currentModelPath.length() + 1); lv2_atom_forge_path(&atom_forge, currentModelPath.c_str(), (uint32_t)currentModelPath.length() + 1);
lv2_atom_forge_pop(&atom_forge, &frame); lv2_atom_forge_pop(&atom_forge, &frame);
} }
-1
View File
@@ -114,7 +114,6 @@ namespace NAM {
LV2_Atom_Forge atom_forge = {}; LV2_Atom_Forge atom_forge = {};
LV2_Atom_Forge_Frame sequence_frame; LV2_Atom_Forge_Frame sequence_frame;
float m_rate;
float inputLevel = 0; float inputLevel = 0;
float outputLevel = 0; float outputLevel = 0;
int32_t maxBufferSize = 0; int32_t maxBufferSize = 0;