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)
project(NeuralAmpModelerLv2 VERSION 0.1.0)
project(NeuralAmpModelerLv2 VERSION 0.1.1)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+3 -2
View File
@@ -27,7 +27,7 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
return nullptr;
}
catch(const std::exception& e)
catch(const std::exception)
{
return nullptr;
}
@@ -36,7 +36,8 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
static void connect_port(LV2_Handle instance, uint32_t port, void* data)
{
auto nam = static_cast<NAM::Plugin*>(instance);
*(reinterpret_cast<void**>(&nam->ports)+port) = data;
*(reinterpret_cast<void**>(&nam->ports)+port) = data;
}
static void activate(LV2_Handle) {}
+69 -57
View File
@@ -25,7 +25,8 @@ namespace NAM {
// for fetching initial options, can be null
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))
map = static_cast<LV2_URID_Map*>(features[i]->data);
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 nam = static_cast<NAM::Plugin*>(instance);
::DSP* model = nullptr;
LV2SwitchModelMsg response = { kWorkTypeSwitch, {}, {} };
LV2_Worker_Status result = LV2_WORKER_SUCCESS;
try
{
// load model from path
const size_t pathlen = strlen(msg->path);
::DSP* model;
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);
respond(handle, sizeof(response), &response);
return LV2_WORKER_SUCCESS;
}
catch (std::exception& e)
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;
}
break;
respond(handle, sizeof(response), &response);
return result;
}
case kWorkTypeFree:
{
auto msg = static_cast<const LV2FreeModelMsg*>(data);
delete msg->model;
return LV2_WORKER_SUCCESS;
}
@@ -293,7 +302,8 @@ namespace NAM {
lv2_log_trace(&nam->logger, "Saving state\n");
if (!nam->currentModel) {
if (!nam->currentModel)
{
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,
uint32_t flags, const LV2_Feature* const* features)
{
//if (!haveLog) return LV2_STATE_SUCCESS;
auto nam = static_cast<NAM::Plugin*>(instance);
// Get model_Path from state
@@ -343,58 +351,62 @@ namespace NAM {
lv2_log_trace(&nam->logger, "Restoring model '%s'\n", (const char*)value);
if (!value) {
lv2_log_error(&nam->logger, "Missing model_Path\n");
return LV2_STATE_ERR_NO_PROPERTY;
}
if (type != nam->uris.atom_Path) {
lv2_log_error(&nam->logger, "Non-path model_Path\n");
return LV2_STATE_ERR_BAD_TYPE;
}
LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data(features, LV2_STATE__mapPath);
if (map_path == nullptr)
{
lv2_log_error(&nam->logger, "LV2_STATE__mapPath unsupported by host\n");
return LV2_STATE_ERR_NO_FEATURE;
}
// Map abstract state path to absolute path
char* path = map_path->absolute_path(map_path->handle, (const char *)value);
size_t pathLen = strlen(path);
NAM::LV2LoadModelMsg msg = { NAM::kWorkTypeLoad, {} };
LV2_State_Status result = LV2_STATE_SUCCESS;
if (pathLen < MAX_FILE_NAME)
// 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);
if (map_path == nullptr)
{
lv2_log_error(&nam->logger, "LV2_STATE__mapPath unsupported by host\n");
return LV2_STATE_ERR_NO_FEATURE;
}
// Map abstract state path to absolute path
char* path = map_path->absolute_path(map_path->handle, (const char *)value);
size_t pathLen = strlen(path);
if (pathLen >= 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;
}
else
{
memcpy(msg.path, path, pathLen);
}
LV2_State_Free_Path* free_path = (LV2_State_Free_Path*)lv2_features_data(features, LV2_STATE__freePath);
if (free_path != nullptr)
{
free_path->free_path(free_path->handle, path);
}
else
{
#ifndef _WIN32 // Can't free host-allocated memory on plugin side under Windows
free(path);
#endif
}
}
if (result == LV2_STATE_SUCCESS)
{
// 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);
result = LV2_STATE_ERR_UNKNOWN;
}
LV2_State_Free_Path* free_path = (LV2_State_Free_Path*)lv2_features_data(features, LV2_STATE__freePath);
if (free_path != nullptr)
{
free_path->free_path(free_path->handle, path);
}
else
{
#ifndef _WIN32 // Can't free host-allocated memory on plugin side under Windows
free(path);
#endif
nam->currentModelPath = msg.path;
}
return result;
@@ -410,7 +422,7 @@ namespace NAM {
lv2_atom_forge_key(&atom_forge, uris.patch_property);
lv2_atom_forge_urid(&atom_forge, uris.model_Path);
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);
}
-1
View File
@@ -114,7 +114,6 @@ namespace NAM {
LV2_Atom_Forge atom_forge = {};
LV2_Atom_Forge_Frame sequence_frame;
float m_rate;
float inputLevel = 0;
float outputLevel = 0;
int32_t maxBufferSize = 0;