Internally check that a change is needed or not

This commit is contained in:
Paul Ferrand 2020-05-13 15:17:03 +02:00
parent cced103479
commit 7d98349e16
2 changed files with 13 additions and 11 deletions

View file

@ -950,10 +950,6 @@ work(LV2_Handle instance,
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);
if (sfizz_get_num_voices(self->synth) == num_voices) {
return LV2_WORKER_SUCCESS; // Nothing to do
}
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) { if (sfizz_get_num_voices(self->synth) == num_voices) {
lv2_log_note(&self->logger, "[sfizz] Number of voices changed to: %d\n", num_voices); lv2_log_note(&self->logger, "[sfizz] Number of voices changed to: %d\n", num_voices);
@ -964,9 +960,6 @@ work(LV2_Handle instance,
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);
if (sfizz_get_preload_size(self->synth) == preload_size)
return LV2_WORKER_SUCCESS; // Nothing to do
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) { if (sfizz_get_preload_size(self->synth) == preload_size) {
lv2_log_note(&self->logger, "[sfizz] Preload size changed to: %d\n", preload_size); lv2_log_note(&self->logger, "[sfizz] Preload size changed to: %d\n", preload_size);
@ -978,10 +971,6 @@ work(LV2_Handle instance,
{ {
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);
if (sfizz_get_oversampling_factor(self->synth) == oversampling) {
return LV2_WORKER_SUCCESS; // Nothing to do
}
sfizz_set_oversampling_factor(self->synth, oversampling); sfizz_set_oversampling_factor(self->synth, oversampling);
if (sfizz_get_oversampling_factor(self->synth) == oversampling) { if (sfizz_get_oversampling_factor(self->synth) == oversampling) {
lv2_log_note(&self->logger, "[sfizz] Oversampling changed to: %d\n", oversampling); lv2_log_note(&self->logger, "[sfizz] Oversampling changed to: %d\n", oversampling);

View file

@ -1054,6 +1054,11 @@ void sfz::Synth::setNumVoices(int numVoices) noexcept
{ {
ASSERT(numVoices > 0); ASSERT(numVoices > 0);
const std::lock_guard<std::mutex> disableCallback { callbackGuard }; const std::lock_guard<std::mutex> disableCallback { callbackGuard };
// fast path
if (numVoices == this->numVoices)
return;
resetVoices(numVoices); resetVoices(numVoices);
} }
@ -1077,6 +1082,10 @@ void sfz::Synth::setOversamplingFactor(sfz::Oversampling factor) noexcept
{ {
const std::lock_guard<std::mutex> disableCallback { callbackGuard }; const std::lock_guard<std::mutex> disableCallback { callbackGuard };
// fast path
if (factor == oversamplingFactor)
return;
for (auto& voice : voices) for (auto& voice : voices)
voice->reset(); voice->reset();
@ -1094,6 +1103,10 @@ void sfz::Synth::setPreloadSize(uint32_t preloadSize) noexcept
{ {
const std::lock_guard<std::mutex> disableCallback { callbackGuard }; const std::lock_guard<std::mutex> disableCallback { callbackGuard };
// fast path
if (preloadSize == resources.filePool.getPreloadSize())
return;
resources.filePool.setPreloadSize(preloadSize); resources.filePool.setPreloadSize(preloadSize);
} }