rework worker implementation, dont rely on class variables

previous implementation was racy and bound to issues when more
than 1 file change request happened before worker was triggered.

using C++ move assignment is nice, but LV2 worker is a C API
that does not fit non-POD types very well, leading to awkward
implementations alike before with current + staged + deleted models.

let us "downgrade" to raw pointers, which are C compatible.
since LV2 worker rules are well defined, any crashes or racy
behaviour can be considered host-side bugs.

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX
2023-06-15 17:00:02 +02:00
parent 0d7954cf2a
commit 4e9b7d6b49
2 changed files with 90 additions and 83 deletions
+17 -10
View File
@@ -29,7 +29,8 @@ namespace NAM {
enum LV2WorkType {
kWorkTypeLoad,
kWorkTypeSwitch
kWorkTypeSwitch,
kWorkTypeFree
};
struct LV2LoadModelMsg {
@@ -37,6 +38,17 @@ namespace NAM {
char path[MAX_FILE_NAME];
};
struct LV2SwitchModelMsg {
LV2WorkType type;
char path[MAX_FILE_NAME];
::DSP* model;
};
struct LV2FreeModelMsg {
LV2WorkType type;
::DSP* model;
};
class Plugin {
public:
struct Ports {
@@ -54,23 +66,18 @@ namespace NAM {
LV2_Log_Logger logger = {};
LV2_Worker_Schedule* schedule = nullptr;
std::unique_ptr<::DSP> currentModel;
std::unique_ptr<::DSP> stagedModel;
std::unique_ptr<::DSP> deleteModel;
bool stateChanged = false;
::DSP* currentModel = nullptr;
std::string currentModelPath;
std::string stagedModelPath;
std::unordered_map<std::string, double> mNAMParams = {};
Plugin();
~Plugin() = default;
~Plugin();
bool initialize(double rate, const LV2_Feature* const* features) noexcept;
void process(uint32_t n_samples) noexcept;
void write_set_patch(std::string filename);
void write_current_path();
void write_state_changed();
static LV2_Worker_Status work(LV2_Handle instance, LV2_Worker_Respond_Function respond, LV2_Worker_Respond_Handle handle,