Added logging on the background threads rather than the audio thread; added changing_state flag to the file switch

Added a check for changing state in the file uri atom handle
This commit is contained in:
Paul Ferrand 2019-12-14 00:32:59 +01:00
parent f5c095ebda
commit 8d48c73b48

View file

@ -375,6 +375,20 @@ deactivate(LV2_Handle instance)
sfizz_free(self->synth); sfizz_free(self->synth);
} }
static void
sfizz_lv2_send_file_path(sfizz_plugin_t *self)
{
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);
lv2_atom_forge_key(&self->forge, self->patch_property_uri);
lv2_atom_forge_urid(&self->forge, self->sfizz_sfz_file_uri);
lv2_atom_forge_key(&self->forge, self->patch_value_uri);
lv2_atom_forge_path(&self->forge, self->sfz_file_path, strlen(self->sfz_file_path));
lv2_atom_forge_pop(&self->forge, &frame);
}
static void static void
sfizz_lv2_handle_atom_object(sfizz_plugin_t *self, const LV2_Atom_Object *obj) sfizz_lv2_handle_atom_object(sfizz_plugin_t *self, const LV2_Atom_Object *obj)
{ {
@ -409,6 +423,13 @@ sfizz_lv2_handle_atom_object(sfizz_plugin_t *self, const LV2_Atom_Object *obj)
if (key == self->sfizz_sfz_file_uri) if (key == self->sfizz_sfz_file_uri)
{ {
if (self->changing_state)
{
// We're changing the state already; try to advertise to the host that we
// did not change the path file and return
sfizz_lv2_send_file_path(self);
return;
}
const uint32_t original_atom_size = lv2_atom_total_size((const LV2_Atom *)atom); const uint32_t original_atom_size = lv2_atom_total_size((const LV2_Atom *)atom);
const uint32_t null_terminated_atom_size = original_atom_size + 1; const uint32_t null_terminated_atom_size = original_atom_size + 1;
@ -419,6 +440,7 @@ sfizz_lv2_handle_atom_object(sfizz_plugin_t *self, const LV2_Atom_Object *obj)
sfz_file_path->type = self->sfizz_sfz_file_uri; sfz_file_path->type = self->sfizz_sfz_file_uri;
// If the parameter is different from the current one we send it through // If the parameter is different from the current one we send it through
self->changing_state = true;
if (strcmp(self->sfz_file_path, LV2_ATOM_BODY_CONST(sfz_file_path))) if (strcmp(self->sfz_file_path, LV2_ATOM_BODY_CONST(sfz_file_path)))
self->worker->schedule_work(self->worker->handle, null_terminated_atom_size, sfz_file_path); self->worker->schedule_work(self->worker->handle, null_terminated_atom_size, sfz_file_path);
} }
@ -479,23 +501,12 @@ sfizz_lv2_process_midi_event(sfizz_plugin_t *self, const LV2_Atom_Event *ev)
} }
} }
static void sfizz_lv2_send_file_path(sfizz_plugin_t *self)
{
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);
lv2_atom_forge_key(&self->forge, self->patch_property_uri);
lv2_atom_forge_urid(&self->forge, self->sfizz_sfz_file_uri);
lv2_atom_forge_key(&self->forge, self->patch_value_uri);
lv2_atom_forge_path(&self->forge, self->sfz_file_path, strlen(self->sfz_file_path));
lv2_atom_forge_pop(&self->forge, &frame);
}
static void static void
sfizz_lv2_status_log(sfizz_plugin_t *self) sfizz_lv2_status_log(sfizz_plugin_t *self)
{ {
lv2_log_note(&self->logger, "[sfizz] Allocated buffers: %d\n", sfizz_get_num_buffers(self->synth)); lv2_log_note(&self->logger, "[sfizz] Allocated buffers: %d\n", sfizz_get_num_buffers(self->synth));
lv2_log_note(&self->logger, "[sfizz] Allocated bytes: %d bytes\n", sfizz_get_num_bytes(self->synth)); lv2_log_note(&self->logger, "[sfizz] Allocated bytes: %d bytes\n", sfizz_get_num_bytes(self->synth));
lv2_log_note(&self->logger, "[sfizz] Active voices: %d\n", sfizz_get_num_active_voices(self->synth));
} }
static void static void
@ -828,33 +839,51 @@ work(LV2_Handle instance,
const char *sfz_file_path = LV2_ATOM_BODY_CONST(atom); const char *sfz_file_path = LV2_ATOM_BODY_CONST(atom);
if (sfizz_load_file(self->synth, sfz_file_path)) if (sfizz_load_file(self->synth, sfz_file_path))
{ {
strcpy(self->sfz_file_path, sfz_file_path);
lv2_log_note(&self->logger, "[sfizz] File changed to: %s\n", sfz_file_path);
char *unknown_opcodes = sfizz_get_unknown_opcodes(self->synth); char *unknown_opcodes = sfizz_get_unknown_opcodes(self->synth);
if (unknown_opcodes) if (unknown_opcodes)
{ {
lv2_log_note(&self->logger, "[sfizz] Unknown opcodes: %s\n", unknown_opcodes); lv2_log_note(&self->logger, "[sfizz] Unknown opcodes: %s\n", unknown_opcodes);
free(unknown_opcodes); free(unknown_opcodes);
} }
lv2_log_note(&self->logger, "[sfizz] Number of masters: %d\n", sfizz_get_num_masters(self->synth));
lv2_log_note(&self->logger, "[sfizz] Number of groups: %d\n", sfizz_get_num_groups(self->synth));
lv2_log_note(&self->logger, "[sfizz] Number of regions: %d\n", sfizz_get_num_regions(self->synth));
} }
else else
{ {
lv2_log_error(&self->logger, "[sfizz] Error with %s; no file should be loaded.\n", sfz_file_path); lv2_log_error(&self->logger, "[sfizz] Error with %s; no file should be loaded.\n", sfz_file_path);
return LV2_WORKER_ERR_UNKNOWN;
} }
} }
else if (atom->type == self->sfizz_num_voices_uri) else if (atom->type == self->sfizz_num_voices_uri)
{ {
const int num_voices = *(const int *)LV2_ATOM_BODY_CONST(atom); const int num_voices = *(const int *)LV2_ATOM_BODY_CONST(atom);
sfizz_set_num_voices(self->synth, num_voices); sfizz_set_num_voices(self->synth, num_voices);
if (sfizz_get_num_voices(self->synth) == num_voices) {
self->num_voices = num_voices;
lv2_log_note(&self->logger, "[sfizz] Number of voices changed to: %d\n", num_voices);
}
} }
else if (atom->type == self->sfizz_preload_size_uri) else if (atom->type == self->sfizz_preload_size_uri)
{ {
const unsigned int preload_size = *(const unsigned int *)LV2_ATOM_BODY_CONST(atom); const unsigned int preload_size = *(const unsigned int *)LV2_ATOM_BODY_CONST(atom);
sfizz_set_preload_size(self->synth, preload_size); sfizz_set_preload_size(self->synth, preload_size);
if (sfizz_get_preload_size(self->synth) == preload_size) {
self->preload_size = preload_size;
lv2_log_note(&self->logger, "[sfizz] Preload size changed to: %d\n", preload_size);
}
} }
else if (atom->type == self->sfizz_oversampling_uri) else if (atom->type == self->sfizz_oversampling_uri)
{ {
const sfizz_oversampling_factor_t oversampling = const sfizz_oversampling_factor_t oversampling =
*(const sfizz_oversampling_factor_t *)LV2_ATOM_BODY_CONST(atom); *(const sfizz_oversampling_factor_t *)LV2_ATOM_BODY_CONST(atom);
sfizz_set_oversampling_factor(self->synth, oversampling); sfizz_set_oversampling_factor(self->synth, oversampling);
if (sfizz_get_oversampling_factor(self->synth) == oversampling) {
self->oversampling = oversampling;
lv2_log_note(&self->logger, "[sfizz] Oversampling changed to: %d\n", oversampling);
}
} }
else if (atom->type == self->sfizz_log_status_uri) else if (atom->type == self->sfizz_log_status_uri)
{ {
@ -862,7 +891,7 @@ work(LV2_Handle instance,
} }
else else
{ {
lv2_log_error(&self->logger, "[sfizz] Got an unknown atom.\n"); lv2_log_error(&self->logger, "[sfizz] Got an unknown atom in work.\n");
if (self->unmap) if (self->unmap)
lv2_log_error(&self->logger, lv2_log_error(&self->logger,
"URI: %s\n", "URI: %s\n",
@ -888,32 +917,20 @@ work_response(LV2_Handle instance,
const LV2_Atom *atom = (const LV2_Atom *)data; const LV2_Atom *atom = (const LV2_Atom *)data;
if (atom->type == self->sfizz_sfz_file_uri) if (atom->type == self->sfizz_sfz_file_uri)
{ // TODO: could check that everything is indeed changed here {
const char *sfz_file_path = LV2_ATOM_BODY_CONST(atom); self->changing_state = false;
strcpy(self->sfz_file_path, sfz_file_path);
lv2_log_note(&self->logger, "[sfizz] File changed to: %s\n", self->sfz_file_path);
} }
else if (atom->type == self->sfizz_num_voices_uri) else if (atom->type == self->sfizz_num_voices_uri)
{ // TODO: could check that everything is indeed changed here {
const int num_voices = *(const int *)LV2_ATOM_BODY_CONST(atom);
self->num_voices = num_voices;
self->changing_state = false; self->changing_state = false;
lv2_log_note(&self->logger, "[sfizz] Number of voices changed to: %d\n", self->num_voices);
} }
else if (atom->type == self->sfizz_preload_size_uri) else if (atom->type == self->sfizz_preload_size_uri)
{ // TODO: could check that everything is indeed changed here {
const unsigned int preload_size = *(const unsigned int *)LV2_ATOM_BODY_CONST(atom);
self->preload_size = preload_size;
self->changing_state = false; self->changing_state = false;
lv2_log_note(&self->logger, "[sfizz] Preload size changed to: %d\n", self->preload_size);
} }
else if (atom->type == self->sfizz_oversampling_uri) else if (atom->type == self->sfizz_oversampling_uri)
{ // TODO: could check that everything is indeed changed here {
const sfizz_oversampling_factor_t oversampling =
*(const sfizz_oversampling_factor_t *)LV2_ATOM_BODY_CONST(atom);
self->oversampling = oversampling;
self->changing_state = false; self->changing_state = false;
lv2_log_note(&self->logger, "[sfizz] Oversampling changed to: %d\n", self->oversampling);
} }
else if (atom->type == self->sfizz_log_status_uri) else if (atom->type == self->sfizz_log_status_uri)
{ {
@ -921,7 +938,7 @@ work_response(LV2_Handle instance,
} }
else else
{ {
lv2_log_error(&self->logger, "[sfizz] Got an unknown atom.\n"); lv2_log_error(&self->logger, "[sfizz] Got an unknown atom in work response.\n");
if (self->unmap) if (self->unmap)
lv2_log_error(&self->logger, lv2_log_error(&self->logger,
"URI: %s\n", "URI: %s\n",