From 2839b297d5d4545a606fb98c2e8a504f2256d197 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Sun, 2 May 2021 11:57:10 +0200 Subject: [PATCH] Implement the VST keyswitch interface --- plugins/vst/SfizzVstController.cpp | 55 ++++++++++++++++++++++++++++-- plugins/vst/SfizzVstController.h | 9 ++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/plugins/vst/SfizzVstController.cpp b/plugins/vst/SfizzVstController.cpp index 9b5458d9..4ba9aa6b 100644 --- a/plugins/vst/SfizzVstController.cpp +++ b/plugins/vst/SfizzVstController.cpp @@ -167,6 +167,30 @@ tresult PLUGIN_API SfizzVstControllerNoUi::getMidiControllerAssignment(int32 bus return kResultTrue; } +int32 PLUGIN_API SfizzVstControllerNoUi::getKeyswitchCount(int32 busIndex, int16 channel) +{ + (void)channel; + + if (busIndex != 0) + return 0; + + return keyswitches_.size(); +} + +tresult PLUGIN_API SfizzVstControllerNoUi::getKeyswitchInfo(int32 busIndex, int16 channel, int32 keySwitchIndex, Vst::KeyswitchInfo& info) +{ + (void)channel; + + if (busIndex != 0) + return kResultFalse; + + if (keySwitchIndex < 0 || keySwitchIndex >= keyswitches_.size()) + return kResultFalse; + + info = keyswitches_[keySwitchIndex]; + return kResultTrue; +} + tresult PLUGIN_API SfizzVstControllerNoUi::getParamStringByValue(Vst::ParamID tag, Vst::ParamValue valueNormalized, Vst::String128 string) { switch (tag) { @@ -291,9 +315,9 @@ tresult SfizzVstControllerNoUi::notify(Vst::IMessage* message) static_cast(getProgramList(kProgramListID)); for (int16 pitch = 0; pitch < 128; ++pitch) { Steinberg::String pitchName; - if (!desc.keyLabel[pitch].empty()) + if (desc.keyUsed.test(pitch) && !desc.keyLabel[pitch].empty()) pitchName = Steinberg::String(desc.keyLabel[pitch].c_str()); - else if (!desc.keyswitchLabel[pitch].empty()) + else if (desc.keyswitchUsed.test(pitch) && !desc.keyswitchLabel[pitch].empty()) pitchName = Steinberg::String(desc.keyswitchLabel[pitch].c_str()); list->setPitchName(0, pitch, pitchName); @@ -303,6 +327,33 @@ tresult SfizzVstControllerNoUi::notify(Vst::IMessage* message) if (unitHandler) unitHandler->notifyProgramListChange(kProgramListID, 0); + // update the key switches and notify + size_t idKeyswitch = 0; + for (int16 pitch = 0; pitch < 128; ++pitch) + idKeyswitch += desc.keyswitchUsed.test(pitch); + keyswitches_.resize(idKeyswitch); + + idKeyswitch = 0; + for (int16 pitch = 0; pitch < 128; ++pitch) { + if (!desc.keyswitchUsed.test(pitch)) + continue; + Vst::KeyswitchInfo info {}; + info.typeId = Vst::kNoteOnKeyswitchTypeID; + Steinberg::String(desc.keyswitchLabel[pitch].c_str()).copyTo(info.title); + Steinberg::String(desc.keyswitchLabel[pitch].c_str()).copyTo(info.shortTitle); + info.keyswitchMin = pitch; // TODO reexamine this when supporting keyswitch groups + info.keyswitchMax = pitch; // TODO reexamine this when supporting keyswitch groups + info.keyRemapped = pitch; + info.unitId = Vst::kRootUnitId; + info.flags = 0; + keyswitches_[idKeyswitch++] = info; + } + + Vst::IComponentHandler* componentHandler = getComponentHandler(); + if (componentHandler) + // NOTE(jpc) I think that's the right one, but it needs confirmation + componentHandler->restartComponent(Vst::kNoteExpressionChanged); + // sfzDescriptionUpdate_->deferUpdate(); } diff --git a/plugins/vst/SfizzVstController.h b/plugins/vst/SfizzVstController.h index f976d7e9..cf0b0d7f 100644 --- a/plugins/vst/SfizzVstController.h +++ b/plugins/vst/SfizzVstController.h @@ -11,6 +11,7 @@ #include "public.sdk/source/vst/vstparameters.h" #include "public.sdk/source/common/threadchecker.h" #include "pluginterfaces/vst/ivstmidicontrollers.h" +#include "pluginterfaces/vst/ivstnoteexpression.h" #include "vstgui/plugin-bindings/vst3editor.h" #include #include @@ -21,7 +22,8 @@ using namespace Steinberg; using namespace VSTGUI; class SfizzVstControllerNoUi : public Vst::EditControllerEx1, - public Vst::IMidiMapping { + public Vst::IMidiMapping, + public Vst::IKeyswitchController { public: virtual ~SfizzVstControllerNoUi() {} @@ -30,6 +32,9 @@ public: tresult PLUGIN_API getMidiControllerAssignment(int32 busIndex, int16 channel, Vst::CtrlNumber midiControllerNumber, Vst::ParamID& id) override; + int32 PLUGIN_API getKeyswitchCount (int32 busIndex, int16 channel) override; + tresult PLUGIN_API getKeyswitchInfo (int32 busIndex, int16 channel, int32 keySwitchIndex, Vst::KeyswitchInfo& info) override; + tresult PLUGIN_API getParamStringByValue(Vst::ParamID tag, Vst::ParamValue valueNormalized, Vst::String128 string) override; tresult PLUGIN_API getParamValueByString(Vst::ParamID tag, Vst::TChar* string, Vst::ParamValue& valueNormalized) override; @@ -41,6 +46,7 @@ public: OBJ_METHODS(SfizzVstControllerNoUi, Vst::EditControllerEx1) DEFINE_INTERFACES DEF_INTERFACE(Vst::IMidiMapping) + DEF_INTERFACE(Vst::IKeyswitchController) END_DEFINE_INTERFACES(Vst::EditControllerEx1) REFCOUNT_METHODS(Vst::EditControllerEx1) @@ -52,6 +58,7 @@ protected: Steinberg::IPtr scalaUpdate_; Steinberg::IPtr playStateUpdate_; Vst::ParamID midiMapping_[Vst::kCountCtrlNumber] {}; + std::vector keyswitches_; }; class SfizzVstController : public SfizzVstControllerNoUi, public VSTGUI::VST3EditorDelegate {