Structure for storage of CC automation

This commit is contained in:
Jean Pierre Cimalando 2021-04-05 19:01:36 +02:00
parent 2436414ad8
commit d2d01b73b3
2 changed files with 24 additions and 24 deletions

View file

@ -478,6 +478,8 @@ instantiate(const LV2_Descriptor *descriptor,
self->ccmap = sfizz_lv2_ccmap_create(self->map); self->ccmap = sfizz_lv2_ccmap_create(self->map);
self->ccauto = new absl::optional<float>[sfz::config::numCCs];
self->synth = sfizz_create_synth(); self->synth = sfizz_create_synth();
self->client = sfizz_create_client(self); self->client = sfizz_create_client(self);
self->synth_mutex = spin_mutex_create(); self->synth_mutex = spin_mutex_create();
@ -485,7 +487,6 @@ instantiate(const LV2_Descriptor *descriptor,
sfizz_set_receive_callback(self->client, &sfizz_lv2_receive_message); sfizz_set_receive_callback(self->client, &sfizz_lv2_receive_message);
self->sfz_blob_mutex = new std::mutex; self->sfz_blob_mutex = new std::mutex;
self->sfz_desc_mutex = new std::mutex;
sfizz_lv2_load_file(self, self->sfz_file_path); sfizz_lv2_load_file(self, self->sfz_file_path);
sfizz_lv2_load_scala_file(self, self->scala_file_path); sfizz_lv2_load_scala_file(self, self->scala_file_path);
@ -501,11 +502,10 @@ cleanup(LV2_Handle instance)
sfizz_plugin_t *self = (sfizz_plugin_t *)instance; sfizz_plugin_t *self = (sfizz_plugin_t *)instance;
delete[] self->sfz_blob_data; delete[] self->sfz_blob_data;
delete self->sfz_blob_mutex; delete self->sfz_blob_mutex;
delete self->sfz_desc;
delete self->sfz_desc_mutex;
spin_mutex_destroy(self->synth_mutex); spin_mutex_destroy(self->synth_mutex);
sfizz_delete_client(self->client); sfizz_delete_client(self->client);
sfizz_free(self->synth); sfizz_free(self->synth);
delete[] self->ccauto;
sfizz_lv2_ccmap_free(self->ccmap); sfizz_lv2_ccmap_free(self->ccmap);
delete self; delete self;
} }
@ -985,26 +985,25 @@ run(LV2_Handle instance, uint32_t sample_count)
// Request OSC updates // Request OSC updates
sfizz_send_message(self->synth, self->client, 0, "/sw/last/current", "", nullptr); sfizz_send_message(self->synth, self->client, 0, "/sw/last/current", "", nullptr);
spin_mutex_unlock(self->synth_mutex);
if (self->midnam && self->must_update_midnam.exchange(0)) if (self->midnam && self->must_update_midnam.exchange(0))
{ {
self->midnam->update(self->midnam->handle); self->midnam->update(self->midnam->handle);
} }
if (self->must_automate_cc && self->sfz_desc_mutex->try_lock()) if (self->have_ccauto)
{ {
if (self->must_automate_cc) { for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) {
const InstrumentDescription* desc = self->sfz_desc; absl::optional<float> value = self->ccauto[cc];
for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) { if (value) {
if (desc->ccUsed.test(cc)) sfizz_lv2_send_controller(self, cc, *value);
sfizz_lv2_send_controller(self, cc, desc->ccDefault[cc]); self->ccauto[cc] = absl::nullopt;
} }
self->must_automate_cc = false;
} }
self->sfz_desc_mutex->unlock(); self->have_ccauto = false;
} }
spin_mutex_unlock(self->synth_mutex);
lv2_atom_forge_pop(&self->forge, &notify_frame); lv2_atom_forge_pop(&self->forge, &notify_frame);
} }
@ -1123,13 +1122,14 @@ sfizz_lv2_update_sfz_info(sfizz_plugin_t *self)
delete[] old_data; delete[] old_data;
// Keep a copy of the instrument description // Mark all the used CCs for automation with default values
const InstrumentDescription* desc = new InstrumentDescription(parseDescriptionBlob(blob)); const InstrumentDescription desc = parseDescriptionBlob(blob);
self->sfz_desc_mutex->lock(); for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) {
delete self->sfz_desc; if (desc.ccUsed.test(cc)) {
self->sfz_desc = desc; self->ccauto[cc] = desc.ccDefault[cc];
self->must_automate_cc = true; // mark all CC for automation self->have_ccauto = true;
self->sfz_desc_mutex->unlock(); }
}
} }
static bool static bool

View file

@ -11,11 +11,10 @@
#include <sfizz.h> #include <sfizz.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <absl/types/optional.h>
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
struct InstrumentDescription;
#define DEFAULT_SCALA_FILE "Contents/Resources/DefaultScale.scl" #define DEFAULT_SCALA_FILE "Contents/Resources/DefaultScale.scl"
#define DEFAULT_SFZ_FILE "Contents/Resources/DefaultInstrument.sfz" #define DEFAULT_SFZ_FILE "Contents/Resources/DefaultInstrument.sfz"
// This assumes that the longest path is the default sfz file; if not, change it // This assumes that the longest path is the default sfz file; if not, change it
@ -121,8 +120,9 @@ struct sfizz_plugin_t
const uint8_t *volatile sfz_blob_data {}; const uint8_t *volatile sfz_blob_data {};
volatile uint32_t sfz_blob_size {}; volatile uint32_t sfz_blob_size {};
std::mutex *sfz_desc_mutex {}; // CC queued for automation on next run(). (synchronized by `synth_mutex`)
const InstrumentDescription* sfz_desc {}; absl::optional<float>* ccauto {};
volatile bool have_ccauto {};
// Timing data // Timing data
int bar {}; int bar {};