Merge pull request #269 from jpcima/lv2

Fix LV2 problems with the atom sequence
This commit is contained in:
JP Cimalando 2020-06-12 21:56:10 +02:00 committed by GitHub
commit f120cadcf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -112,7 +112,7 @@ typedef struct
// Atom forge // Atom forge
LV2_Atom_Forge forge; ///< Forge for writing atoms in run thread LV2_Atom_Forge forge; ///< Forge for writing atoms in run thread
LV2_Atom_Forge_Frame notify_frame; ///< Cached for worker replies LV2_Atom_Forge forge_secondary; ///< Forge for writing into other buffers
// Logger // Logger
LV2_Log_Logger logger; LV2_Log_Logger logger;
@ -366,6 +366,7 @@ instantiate(const LV2_Descriptor *descriptor,
// Initialize the forge // Initialize the forge
lv2_atom_forge_init(&self->forge, self->map); lv2_atom_forge_init(&self->forge, self->map);
lv2_atom_forge_init(&self->forge_secondary, self->map);
// Check the options for the block size and sample rate parameters // Check the options for the block size and sample rate parameters
if (options) if (options)
@ -445,12 +446,16 @@ static void
sfizz_lv2_send_file_path(sfizz_plugin_t *self, LV2_URID urid, const char *path) sfizz_lv2_send_file_path(sfizz_plugin_t *self, LV2_URID urid, const char *path)
{ {
LV2_Atom_Forge_Frame frame; LV2_Atom_Forge_Frame frame;
lv2_atom_forge_frame_time(&self->forge, 0);
lv2_atom_forge_object(&self->forge, &frame, 0, self->patch_set_uri); bool write_ok =
lv2_atom_forge_key(&self->forge, self->patch_property_uri); lv2_atom_forge_frame_time(&self->forge, 0) &&
lv2_atom_forge_urid(&self->forge, urid); lv2_atom_forge_object(&self->forge, &frame, 0, self->patch_set_uri) &&
lv2_atom_forge_key(&self->forge, self->patch_value_uri); lv2_atom_forge_key(&self->forge, self->patch_property_uri) &&
lv2_atom_forge_urid(&self->forge, urid) &&
lv2_atom_forge_key(&self->forge, self->patch_value_uri) &&
lv2_atom_forge_path(&self->forge, path, (uint32_t)strlen(path)); lv2_atom_forge_path(&self->forge, path, (uint32_t)strlen(path));
if (write_ok)
lv2_atom_forge_pop(&self->forge, &frame); lv2_atom_forge_pop(&self->forge, &frame);
} }
@ -487,28 +492,28 @@ sfizz_lv2_handle_atom_object(sfizz_plugin_t *self, const LV2_Atom_Object *obj)
return; return;
} }
typedef struct
{
LV2_Atom atom;
char body[MAX_PATH_SIZE];
} sfizz_path_atom_buffer_t;
if (key == self->sfizz_sfz_file_uri) if (key == self->sfizz_sfz_file_uri)
{ {
const uint32_t original_atom_size = lv2_atom_total_size((const LV2_Atom *)atom); LV2_Atom_Forge *forge = &self->forge_secondary;
const uint32_t null_terminated_atom_size = original_atom_size + 1; sfizz_path_atom_buffer_t buffer;
char atom_buffer[MAX_PATH_SIZE]; lv2_atom_forge_set_buffer(forge, (uint8_t *)&buffer, sizeof(buffer));
memcpy(&atom_buffer, atom, original_atom_size); if (lv2_atom_forge_typed_string(forge, self->sfizz_sfz_file_uri, LV2_ATOM_BODY_CONST(atom), strnlen(LV2_ATOM_BODY_CONST(atom), atom->size)))
atom_buffer[original_atom_size] = 0; // Null terminate the string for safety self->worker->schedule_work(self->worker->handle, lv2_atom_total_size(&buffer.atom), &buffer.atom);
LV2_Atom *sfz_file_path = (LV2_Atom *)&atom_buffer;
sfz_file_path->type = self->sfizz_sfz_file_uri;
self->worker->schedule_work(self->worker->handle, null_terminated_atom_size, sfz_file_path);
self->check_modification = false; self->check_modification = false;
} }
else if (key == self->sfizz_scala_file_uri) else if (key == self->sfizz_scala_file_uri)
{ {
const uint32_t original_atom_size = lv2_atom_total_size((const LV2_Atom *)atom); LV2_Atom_Forge *forge = &self->forge_secondary;
const uint32_t null_terminated_atom_size = original_atom_size + 1; sfizz_path_atom_buffer_t buffer;
char atom_buffer[MAX_PATH_SIZE]; lv2_atom_forge_set_buffer(forge, (uint8_t *)&buffer, sizeof(buffer));
memcpy(&atom_buffer, atom, original_atom_size); if (lv2_atom_forge_typed_string(forge, self->sfizz_scala_file_uri, LV2_ATOM_BODY_CONST(atom), strnlen(LV2_ATOM_BODY_CONST(atom), atom->size)))
atom_buffer[original_atom_size] = 0; // Null terminate the string for safety self->worker->schedule_work(self->worker->handle, lv2_atom_total_size(&buffer.atom), &buffer.atom);
LV2_Atom *scala_file_path = (LV2_Atom *)&atom_buffer;
scala_file_path->type = self->sfizz_scala_file_uri;
self->worker->schedule_work(self->worker->handle, null_terminated_atom_size, scala_file_path);
self->check_modification = false; self->check_modification = false;
} }
else else
@ -684,7 +689,9 @@ run(LV2_Handle instance, uint32_t sample_count)
lv2_atom_forge_set_buffer(&self->forge, (uint8_t *)self->notify_port, notify_capacity); lv2_atom_forge_set_buffer(&self->forge, (uint8_t *)self->notify_port, notify_capacity);
// Start a sequence in the notify output port. // Start a sequence in the notify output port.
lv2_atom_forge_sequence_head(&self->forge, &self->notify_frame, 0); LV2_Atom_Forge_Frame notify_frame;
if (!lv2_atom_forge_sequence_head(&self->forge, &notify_frame, 0))
assert(false);
LV2_ATOM_SEQUENCE_FOREACH(self->control_port, ev) LV2_ATOM_SEQUENCE_FOREACH(self->control_port, ev)
{ {
@ -775,6 +782,8 @@ run(LV2_Handle instance, uint32_t sample_count)
{ {
self->midnam->update(self->midnam->handle); self->midnam->update(self->midnam->handle);
} }
lv2_atom_forge_pop(&self->forge, &notify_frame);
} }
static uint32_t static uint32_t