Merge pull request #961 from paulfd/last-keyswitch-state
Remember the last keyswitch used in the states
This commit is contained in:
commit
290c556a61
6 changed files with 59 additions and 1 deletions
|
|
@ -120,6 +120,7 @@ sfizz_lv2_map_required_uris(sfizz_plugin_t *self)
|
|||
self->sfizz_num_voices_uri = map->map(map->handle, SFIZZ__numVoices);
|
||||
self->sfizz_preload_size_uri = map->map(map->handle, SFIZZ__preloadSize);
|
||||
self->sfizz_oversampling_uri = map->map(map->handle, SFIZZ__oversampling);
|
||||
self->sfizz_last_keyswitch_uri = map->map(map->handle, SFIZZ__lastKeyswitch);
|
||||
self->sfizz_log_status_uri = map->map(map->handle, SFIZZ__logStatus);
|
||||
self->sfizz_check_modification_uri = map->map(map->handle, SFIZZ__checkModification);
|
||||
self->sfizz_osc_blob_uri = map->map(map->handle, SFIZZ__OSCBlob);
|
||||
|
|
@ -323,6 +324,14 @@ sfizz_lv2_receive_message(void* data, int delay, const char* path, const char* s
|
|||
|
||||
sfizz_plugin_t *self = (sfizz_plugin_t *)data;
|
||||
|
||||
if (!strcmp(path, "/sw/last/current") && sig)
|
||||
{
|
||||
if (sig[0] == 'i')
|
||||
self->last_keyswitch = args[0].i;
|
||||
else if (sig[0] == 'N')
|
||||
self->last_keyswitch = -1;
|
||||
}
|
||||
|
||||
// transmit to UI as OSC blob
|
||||
uint8_t *osc_temp = self->osc_temp;
|
||||
uint32_t osc_size = sfizz_prepare_message(osc_temp, OSC_TEMP_SIZE, path, sig, args);
|
||||
|
|
@ -1301,6 +1310,7 @@ restore(LV2_Handle instance,
|
|||
}
|
||||
|
||||
// Set default values
|
||||
self->last_keyswitch = -1;
|
||||
sfizz_lv2_get_default_sfz_path(self, self->sfz_file_path, MAX_PATH_SIZE);
|
||||
sfizz_lv2_get_default_scala_path(self, self->scala_file_path, MAX_PATH_SIZE);
|
||||
|
||||
|
|
@ -1351,6 +1361,13 @@ restore(LV2_Handle instance,
|
|||
}
|
||||
}
|
||||
|
||||
value = retrieve(handle, self->sfizz_last_keyswitch_uri, &size, &type, &val_flags);
|
||||
if (value)
|
||||
{
|
||||
int last_keyswitch = *(const int*)value;
|
||||
self->last_keyswitch = last_keyswitch;
|
||||
}
|
||||
|
||||
// Collect all CC values present in the state
|
||||
std::unique_ptr<absl::optional<float>[]> cc_values(
|
||||
new absl::optional<float>[sfz::config::numCCs]);
|
||||
|
|
@ -1405,6 +1422,11 @@ restore(LV2_Handle instance,
|
|||
}
|
||||
}
|
||||
|
||||
if (self->last_keyswitch >= 0 && self->last_keyswitch <= 127) {
|
||||
sfizz_send_hd_note_on(self->synth, 0, self->last_keyswitch, 1.0f);
|
||||
sfizz_send_hd_note_off(self->synth, 1, self->last_keyswitch, 0.0f);
|
||||
}
|
||||
|
||||
spin_mutex_unlock(self->synth_mutex);
|
||||
|
||||
return status;
|
||||
|
|
@ -1474,6 +1496,15 @@ save(LV2_Handle instance,
|
|||
absl::string_view((const char*)self->sfz_blob_data, self->sfz_blob_size));
|
||||
self->sfz_blob_mutex->unlock();
|
||||
|
||||
if (self->last_keyswitch >= 0 && self->last_keyswitch <= 127) {
|
||||
store(handle,
|
||||
self->sfizz_last_keyswitch_uri,
|
||||
&self->last_keyswitch,
|
||||
sizeof(int),
|
||||
self->atom_int_uri,
|
||||
LV2_STATE_IS_POD);
|
||||
}
|
||||
|
||||
for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) {
|
||||
if (desc.ccUsed.test(cc) && !desc.sustainOrSostenuto.test(cc)) {
|
||||
LV2_URID urid = sfizz_lv2_ccmap_map(self->ccmap, int(cc));
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#define SFIZZ__numVoices SFIZZ_URI ":" "numvoices"
|
||||
#define SFIZZ__preloadSize SFIZZ_URI ":" "preload_size"
|
||||
#define SFIZZ__oversampling SFIZZ_URI ":" "oversampling"
|
||||
#define SFIZZ__lastKeyswitch SFIZZ_URI ":" "last_keyswitch"
|
||||
// These ones are just for the worker
|
||||
#define SFIZZ__logStatus SFIZZ_URI ":" "log_status"
|
||||
#define SFIZZ__checkModification SFIZZ_URI ":" "check_modification"
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ struct sfizz_plugin_t
|
|||
LV2_URID sfizz_num_voices_uri {};
|
||||
LV2_URID sfizz_preload_size_uri {};
|
||||
LV2_URID sfizz_oversampling_uri {};
|
||||
LV2_URID sfizz_last_keyswitch_uri {};
|
||||
LV2_URID sfizz_log_status_uri {};
|
||||
LV2_URID sfizz_check_modification_uri {};
|
||||
LV2_URID sfizz_active_voices_uri {};
|
||||
|
|
@ -120,6 +121,7 @@ struct sfizz_plugin_t
|
|||
float sample_rate {};
|
||||
std::atomic<int> must_update_midnam {};
|
||||
volatile bool must_automate_cc {};
|
||||
int last_keyswitch { -1 };
|
||||
|
||||
// Current instrument description
|
||||
std::mutex *sfz_blob_mutex {};
|
||||
|
|
|
|||
|
|
@ -227,6 +227,10 @@ void SfizzVstProcessor::syncStateToSynth()
|
|||
synth->setScalaRootKey(_state.scalaRootKey);
|
||||
synth->setTuningFrequency(_state.tuningFrequency);
|
||||
synth->loadStretchTuningByRatio(_state.stretchedTuning);
|
||||
if (_state.lastKeyswitch >= 0 && _state.lastKeyswitch <= 127) {
|
||||
synth->hdNoteOn(0, _state.lastKeyswitch, 1.0f);
|
||||
synth->hdNoteOff(1, _state.lastKeyswitch, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
tresult PLUGIN_API SfizzVstProcessor::canProcessSampleSize(int32 symbolicSampleSize)
|
||||
|
|
@ -669,6 +673,14 @@ bool SfizzVstProcessor::processUpdate(FUnknown* changedUnknown, int32 message)
|
|||
|
||||
void SfizzVstProcessor::receiveOSC(int delay, const char* path, const char* sig, const sfizz_arg_t* args)
|
||||
{
|
||||
if (!strcmp(path, "/sw/last/current") && sig)
|
||||
{
|
||||
if (sig[0] == 'i')
|
||||
_state.lastKeyswitch = args[0].i;
|
||||
else if (sig[0] == 'N')
|
||||
_state.lastKeyswitch = -1;
|
||||
}
|
||||
|
||||
uint8_t* oscTemp = _oscTemp.get();
|
||||
uint32 oscSize = sfizz_prepare_message(oscTemp, kOscTempSize, path, sig, args);
|
||||
if (oscSize <= kOscTempSize) {
|
||||
|
|
|
|||
|
|
@ -73,6 +73,14 @@ tresult SfizzVstState::load(IBStream* state)
|
|||
oscillatorQuality = defaults.oscillatorQuality;
|
||||
}
|
||||
|
||||
if (version >= 4) {
|
||||
if (!s.readInt32(lastKeyswitch))
|
||||
return kResultFalse;
|
||||
}
|
||||
else {
|
||||
lastKeyswitch = -1;
|
||||
}
|
||||
|
||||
controllers.clear();
|
||||
if (version >= 2) {
|
||||
uint32 count;
|
||||
|
|
@ -135,6 +143,9 @@ tresult SfizzVstState::store(IBStream* state) const
|
|||
if (!s.writeInt32(oscillatorQuality))
|
||||
return kResultFalse;
|
||||
|
||||
if (!s.writeInt32(lastKeyswitch))
|
||||
return kResultFalse;
|
||||
|
||||
{
|
||||
uint32 ccCount = 0;
|
||||
uint32 ccLimit = uint32(std::min(controllers.size(), size_t(0x10000)));
|
||||
|
|
|
|||
|
|
@ -27,9 +27,10 @@ public:
|
|||
float stretchedTuning = 0.0;
|
||||
int32 sampleQuality = 2;
|
||||
int32 oscillatorQuality = 1;
|
||||
int32 lastKeyswitch = -1;
|
||||
std::vector<absl::optional<float>> controllers;
|
||||
|
||||
static constexpr uint64 currentStateVersion = 3;
|
||||
static constexpr uint64 currentStateVersion = 4;
|
||||
|
||||
tresult load(IBStream* state);
|
||||
tresult store(IBStream* state) const;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue