Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lv2 midi rollback #1054

Merged
merged 4 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmake/LV2Config.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This option is for MIDI CC support in absence of host midi:binding support
option(SFIZZ_LV2_PSA "Enable plugin-side MIDI automations" OFF)
option(SFIZZ_LV2_PSA "Enable plugin-side MIDI automations" ON)

# Configuration for this plugin
# TODO: generate version from git
Expand Down Expand Up @@ -57,6 +57,10 @@ function(sfizz_lv2_generate_controllers_ttl FILE)
")
math(EXPR _j "${SFIZZ_NUM_CCS}-1")
foreach(_i RANGE "${_j}")
if(_i LESS 128 AND SFIZZ_LV2_PSA)
continue() # Don't generate automation parameters for CCs with plugin-side automation
endif()

string_left_pad(_i "${_i}" 3 0)
file(APPEND "${FILE}" "
sfizz:cc${_i}
Expand Down
1 change: 1 addition & 0 deletions cmake/SfizzConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Release asserts: ${SFIZZ_RELEASE_ASSERTS}

Install prefix: ${CMAKE_INSTALL_PREFIX}
LV2 destination directory: ${LV2PLUGIN_INSTALL_DIR}
LV2 plugin-side CC automation ${SFIZZ_LV2_PSA}

Compiler CXX debug flags: ${CMAKE_CXX_FLAGS_DEBUG}
Compiler CXX release flags: ${CMAKE_CXX_FLAGS_RELEASE}
Expand Down
4 changes: 3 additions & 1 deletion plugins/lv2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ endif()

if(SFIZZ_LV2_PSA)
target_compile_definitions(${LV2PLUGIN_PRJ_NAME} PRIVATE "SFIZZ_LV2_PSA=1")
target_compile_definitions(${LV2PLUGIN_PRJ_NAME}_ui PRIVATE "SFIZZ_LV2_PSA=1")
if(SFIZZ_LV2_UI)
target_compile_definitions(${LV2PLUGIN_PRJ_NAME}_ui PRIVATE "SFIZZ_LV2_PSA=1")
endif()
endif()

# Explicitely strip all symbols on Linux but lv2_descriptor()
Expand Down
33 changes: 0 additions & 33 deletions plugins/lv2/sfizz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ instantiate(const LV2_Descriptor *descriptor,

self->ccmap = sfizz_lv2_ccmap_create(self->map);
self->cc_current = new float[sfz::config::numCCs]();
self->ccauto = new absl::optional<float>[sfz::config::numCCs];

self->synth = sfizz_create_synth();
self->client = sfizz_create_client(self);
Expand Down Expand Up @@ -678,7 +677,6 @@ cleanup(LV2_Handle instance)
spin_mutex_destroy(self->synth_mutex);
sfizz_delete_client(self->client);
sfizz_free(self->synth);
delete[] self->ccauto;
delete[] self->cc_current;
sfizz_lv2_ccmap_free(self->ccmap);
delete self;
Expand Down Expand Up @@ -806,7 +804,6 @@ sfizz_lv2_handle_atom_object(sfizz_plugin_t *self, int delay, const LV2_Atom_Obj
float value = *(const float *)LV2_ATOM_BODY_CONST(atom);
sfizz_automate_hdcc(self->synth, delay, cc, value);
self->cc_current[cc] = value;
self->ccauto[cc] = absl::nullopt;
}
}
else if (key == self->sfizz_sfz_file_uri)
Expand Down Expand Up @@ -874,15 +871,6 @@ sfizz_lv2_process_midi_event(sfizz_plugin_t *self, const LV2_Atom_Event *ev)
unsigned cc = msg[1];
float value = float(msg[2]) * (1.0f / 127.0f);

// Send
if (sfizz_is_sustain_or_sostenuto(self, cc)) {
sfizz_automate_hdcc(self->synth,
(int)ev->time.frames,
(int)cc,
value);
break;
}

// Note(jpc) CC must be mapped by host, not handled here.
// See LV2 midi:binding.
#if defined(SFIZZ_LV2_PSA)
Expand All @@ -894,9 +882,6 @@ sfizz_lv2_process_midi_event(sfizz_plugin_t *self, const LV2_Atom_Event *ev)
(int)ev->time.frames,
(int)cc,
value);
self->cc_current[cc] = value;
self->ccauto[cc] = value;
self->have_ccauto = true;
}
break;
case LV2_MIDI_CTL_ALL_NOTES_OFF:
Expand Down Expand Up @@ -1249,18 +1234,6 @@ run(LV2_Handle instance, uint32_t sample_count)
self->midnam->update(self->midnam->handle);
}

if (self->have_ccauto)
{
for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) {
absl::optional<float> value = self->ccauto[cc];
if (value) {
sfizz_lv2_send_controller(self, self->patch_set_uri, cc, *value);
self->ccauto[cc] = absl::nullopt;
}
}
self->have_ccauto = false;
}

spin_mutex_unlock(self->synth_mutex);

#if defined(SFIZZ_LV2_UI)
Expand Down Expand Up @@ -1408,9 +1381,6 @@ sfizz_lv2_update_sfz_info(sfizz_plugin_t *self)
const InstrumentDescription desc = parseDescriptionBlob(blob);
for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) {
if (desc.ccUsed.test(cc) && !desc.sustainOrSostenuto.test(cc)) {
// Mark all the used CCs for automation with default values
self->ccauto[cc] = desc.ccValue[cc];
self->have_ccauto = true;
// Update the current CCs
self->cc_current[cc] = desc.ccValue[cc];
}
Expand Down Expand Up @@ -1579,9 +1549,6 @@ restore(LV2_Handle instance,
if (value) {
// Set CC in the synth
sfizz_automate_hdcc(self->synth, 0, int(cc), *value);
// Mark CCs for automation with state values
self->ccauto[cc] = *value;
self->have_ccauto = true;
// Update the current CCs
self->cc_current[cc] = *value;
}
Expand Down
4 changes: 0 additions & 4 deletions plugins/lv2/sfizz_lv2_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ struct sfizz_plugin_t
// updated by hdcc or file load
float *cc_current {};

// CC queued for automation on next run(). (synchronized by `synth_mutex`)
absl::optional<float>* ccauto {};
volatile bool have_ccauto {};

// Timing data
int bar {};
double bar_beat {};
Expand Down
11 changes: 11 additions & 0 deletions plugins/lv2/sfizz_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,17 @@ void sfizz_ui_t::uiSendValue(EditId id, const EditValue& v)
default:
if (editIdIsCC(id)) {
int cc = ccForEditId(id);
#if defined(SFIZZ_LV2_PSA)
if (cc >= 0 && cc < 128) {
// Send MIDI message
uint8_t msg[3];
msg[0] = 0xB0;
msg[1] = static_cast<uint8_t>(cc);
msg[2] = static_cast<uint8_t>(v.to_float() * 127);
uiSendMIDI(msg, 3);
break;
}
#endif
LV2_URID urid = sfizz_lv2_ccmap_map(ccmap.get(), cc);
sendController(urid, v.to_float());
}
Expand Down
3 changes: 2 additions & 1 deletion src/sfizz/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ bool Layer::registerCC(int ccNumber, float ccValue, float randValue) noexcept

sequenceSwitched_ =
((sequenceCounter_++ % region.sequenceLength) == region.sequencePosition - 1);
if (isSwitchedOn())

if (isSwitchedOn() && (ccValue != midiState_.getCCValue(ccNumber)))
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/SynthT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,10 +1983,10 @@ TEST_CASE("[Synth] Sequences also work on cc triggers")
synth.cc(0, 61, 20);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine", "*saw" } );
synth.cc(0, 61, 20);
synth.cc(0, 61, 21);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine", "*saw" } );
synth.cc(0, 61, 20);
synth.cc(0, 61, 22);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine", "*saw", "*sine" } );
}
Expand Down