From 66081465723aa501989cfc39efb97fadc16d8b8f Mon Sep 17 00:00:00 2001 From: Sophia Poirier <2997196+sophiapoirier@users.noreply.github.com> Date: Sat, 1 Oct 2022 12:39:08 -0700 Subject: [PATCH] define named type dfx::ParameterID --- bufferoverride/bufferoverride-base.h | 5 +- bufferoverride/bufferoverride.h | 4 +- bufferoverride/bufferoverrideformalities.cpp | 6 +- bufferoverride/gui/bufferoverrideeditor.cpp | 28 +- bufferoverride/gui/bufferoverrideeditor.h | 6 +- dfx-library/dfxdefines.h | 7 +- dfx-library/dfxparameter.cpp | 10 +- dfx-library/dfxparameter.h | 6 +- dfx-library/dfxplugin-audiounit.cpp | 60 +-- dfx-library/dfxplugin-base.h | 30 +- dfx-library/dfxplugin-rtas.cpp | 178 +++++---- dfx-library/dfxplugin-vst.cpp | 52 +-- dfx-library/dfxplugin.cpp | 378 +++++++++---------- dfx-library/dfxplugin.h | 308 +++++++-------- dfx-library/dfxsettings.cpp | 243 ++++++------ dfx-library/dfxsettings.h | 49 ++- dfxgui/dfxguibutton.cpp | 34 +- dfxgui/dfxguibutton.h | 10 +- dfxgui/dfxguicontrol.cpp | 6 +- dfxgui/dfxguicontrol.h | 14 +- dfxgui/dfxguicontrol.hpp | 33 +- dfxgui/dfxguidialog.cpp | 14 +- dfxgui/dfxguidialog.h | 8 +- dfxgui/dfxguieditor.cpp | 278 +++++++------- dfxgui/dfxguieditor.h | 105 +++--- dfxgui/dfxguimisc.h | 6 +- dfxgui/dfxguislider.cpp | 39 +- dfxgui/dfxguislider.h | 21 +- dfxgui/dfxguitextdisplay.cpp | 14 +- dfxgui/dfxguitextdisplay.h | 6 +- dfxgui/idfxguicontrol.h | 8 +- eqsync/eqsync.cpp | 4 +- eqsync/eqsync.h | 4 +- eqsync/gui/eqsynceditor.cpp | 12 +- eqsync/gui/eqsynceditor.h | 6 +- exemplar/exemplar.cpp | 136 +++---- exemplar/exemplar.h | 60 +-- fonttest/fonttest.h | 6 +- geometer/geometer-base.h | 29 +- geometer/geometer.cpp | 39 +- geometer/geometer.h | 6 +- geometer/gui/geometereditor.cpp | 18 +- geometer/gui/geometereditor.h | 10 +- midigater/midigater.h | 4 +- monomaker/gui/monomakereditor.cpp | 4 +- monomaker/monomaker.h | 4 +- polarizer/gui/polarizereditor.cpp | 8 +- polarizer/polarizer.h | 4 +- rezsynth/gui/rezsyntheditor.cpp | 58 +-- rezsynth/gui/rezsyntheditor.h | 8 +- rezsynth/rezsynth.h | 4 +- scrubby/gui/scrubbyeditor.cpp | 65 ++-- scrubby/gui/scrubbyeditor.h | 4 +- scrubby/scrubby.h | 6 +- scrubby/scrubbyformalities.cpp | 5 +- scrubby/scrubbyprocess.cpp | 12 +- skidder/gui/skiddereditor.cpp | 10 +- skidder/gui/skiddereditor.h | 6 +- skidder/skidder.h | 6 +- skidder/skiddermidi.cpp | 23 +- slowft/slowft.cpp | 57 +-- slowft/slowft.h | 29 +- stub-dfxplugin/dfxplugin-stub.h | 4 +- thrush/thrush.cpp | 80 ++-- thrush/thrush.h | 28 +- transverb/gui/transverbeditor.cpp | 72 ++-- transverb/gui/transverbeditor.h | 14 +- transverb/transverb-base.h | 13 +- transverb/transverb.h | 4 +- transverb/transverbformalities.cpp | 33 +- turntablist/turntablist.cpp | 34 +- turntablist/turntablist.h | 6 +- turntablist/turntablisteditor.mm | 35 +- windowingstub/windowingstub.cpp | 6 +- windowingstub/windowingstub.h | 4 +- 75 files changed, 1477 insertions(+), 1469 deletions(-) diff --git a/bufferoverride/bufferoverride-base.h b/bufferoverride/bufferoverride-base.h index ded9f5bd..d9b29177 100644 --- a/bufferoverride/bufferoverride-base.h +++ b/bufferoverride/bufferoverride-base.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Buffer Override. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ @@ -25,12 +25,13 @@ To contact the author, use the contact form at http://destroyfx.org/ #include #include +#include "dfxdefines.h" #include "dfxmisc.h" #include "dfxpluginproperties.h" //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kDivisor, kBufferSize_MS, diff --git a/bufferoverride/bufferoverride.h b/bufferoverride/bufferoverride.h index f8eed743..9d1aa423 100644 --- a/bufferoverride/bufferoverride.h +++ b/bufferoverride/bufferoverride.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Buffer Override. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -43,7 +43,7 @@ class BufferOverride final : public DfxPlugin void processaudio(float const* const* inAudio, float* const* outAudio, size_t inNumFrames) override; void processparameters() override; - void parameterChanged(long inParameterIndex) override; + void parameterChanged(dfx::ParameterID inParameterID) override; long dfx_GetPropertyInfo(dfx::PropertyID inPropertyID, dfx::Scope inScope, unsigned int inItemIndex, size_t& outDataSize, dfx::PropertyFlags& outFlags) override; long dfx_GetProperty(dfx::PropertyID, dfx::Scope inScope, unsigned int inItemIndex, void* outData) override; diff --git a/bufferoverride/bufferoverrideformalities.cpp b/bufferoverride/bufferoverrideformalities.cpp index 7e1a8b86..8a24546f 100644 --- a/bufferoverride/bufferoverrideformalities.cpp +++ b/bufferoverride/bufferoverrideformalities.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Buffer Override. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "bufferoverride-base.h" @@ -398,9 +398,9 @@ void BufferOverride::processparameters() } //------------------------------------------------------------------------- -void BufferOverride::parameterChanged(long inParameterIndex) +void BufferOverride::parameterChanged(dfx::ParameterID inParameterID) { - switch (inParameterIndex) + switch (inParameterID) { case kDivisor: case kBufferSize_MS: diff --git a/bufferoverride/gui/bufferoverrideeditor.cpp b/bufferoverride/gui/bufferoverrideeditor.cpp index a6c115a6..69064182 100644 --- a/bufferoverride/gui/bufferoverrideeditor.cpp +++ b/bufferoverride/gui/bufferoverrideeditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Buffer Override. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "bufferoverrideeditor.h" @@ -203,7 +203,7 @@ static bool bufferSizeDisplayProc(float inValue, char* outText, void* inEditor) // Generate the display text for the divisor or buffer LFO rate. // This depends on the slider value and whether we're synced to tempo. -static bool lfoRateGenDisplayProc(float inValue, char* outText, void* inEditor, long rateSyncParameterID, long tempoSyncParameterID) +static bool lfoRateGenDisplayProc(float inValue, char* outText, void* inEditor, dfx::ParameterID rateSyncParameterID, dfx::ParameterID tempoSyncParameterID) { auto const dgEditor = static_cast(inEditor); if (dgEditor->getparameter_b(tempoSyncParameterID)) @@ -295,17 +295,17 @@ long BufferOverrideEditor::OpenEditor() DGRect pos; - auto const divisorLFORateTag = getparameter_b(kDivisorLFOTempoSync) ? kDivisorLFORate_Sync : kDivisorLFORate_Hz; + auto const divisorLFORateParameterID = getparameter_b(kDivisorLFOTempoSync) ? kDivisorLFORate_Sync : kDivisorLFORate_Hz; pos.set(kDivisorLFORateSliderX, kDivisorLFORateSliderY, kLFOSliderWidth, kSliderHeight); - mDivisorLFORateSlider = emplaceControl(this, divisorLFORateTag, pos, dfx::kAxis_Horizontal, sliderHandleImage); + mDivisorLFORateSlider = emplaceControl(this, divisorLFORateParameterID, pos, dfx::kAxis_Horizontal, sliderHandleImage); mDivisorLFORateSlider->setAlternateHandle(sliderHandleImage_glowing); pos.set(kDivisorLFODepthSliderX, kDivisorLFODepthSliderY, kLFOSliderWidth, kSliderHeight); emplaceControl(this, kDivisorLFODepth, pos, dfx::kAxis_Horizontal, sliderHandleImage)->setAlternateHandle(sliderHandleImage_glowing); - auto const bufferLFORateTag = getparameter_b(kBufferLFOTempoSync) ? kBufferLFORate_Sync : kBufferLFORate_Hz; + auto const bufferLFORateParameterID = getparameter_b(kBufferLFOTempoSync) ? kBufferLFORate_Sync : kBufferLFORate_Hz; pos.set(kBufferLFORateSliderX, kBufferLFORateSliderY, kLFOSliderWidth, kSliderHeight); - mBufferLFORateSlider = emplaceControl(this, bufferLFORateTag, pos, dfx::kAxis_Horizontal, sliderHandleImage); + mBufferLFORateSlider = emplaceControl(this, bufferLFORateParameterID, pos, dfx::kAxis_Horizontal, sliderHandleImage); mBufferLFORateSlider->setAlternateHandle(sliderHandleImage_glowing); pos.set(kBufferLFODepthSliderX, kBufferLFODepthSliderY, kLFOSliderWidth, kSliderHeight); @@ -323,9 +323,9 @@ long BufferOverrideEditor::OpenEditor() pos.set(kTempoSliderX, kTempoSliderY, kTempoSliderWidth, kSliderHeight); emplaceControl(this, kTempo, pos, dfx::kAxis_Horizontal, sliderHandleImage)->setAlternateHandle(sliderHandleImage_glowing); - auto const bufferSizeTag = getparameter_b(kBufferTempoSync) ? kBufferSize_Sync : kBufferSize_MS; + auto const bufferSizeParameterID = getparameter_b(kBufferTempoSync) ? kBufferSize_Sync : kBufferSize_MS; pos.set(kDivisorBufferBoxX, kDivisorBufferBoxY, kDivisorBufferBoxWidth, kDivisorBufferBoxHeight); - mDivisorBufferBox = emplaceControl(this, kDivisor, bufferSizeTag, pos, xyBoxHandleImage, nullptr, + mDivisorBufferBox = emplaceControl(this, kDivisor, bufferSizeParameterID, pos, xyBoxHandleImage, nullptr, VSTGUI::CSliderBase::kLeft | VSTGUI::CSliderBase::kTop); mDivisorBufferBox->setAlternateHandles(xyBoxHandleImage_divisor_glowing, xyBoxHandleImage_buffer_glowing); mDivisorBufferBox->setIntegralPosition(true); @@ -335,16 +335,16 @@ long BufferOverrideEditor::OpenEditor() emplaceControl(this, kDivisor, pos, divisorDisplayProc, nullptr, nullptr, dfx::TextAlignment::Center, kValueDisplayFontSize * 2.0f, kLCDCyanTextColor, kValueDisplayFont); pos.set(kBufferDisplayX, kBufferDisplayY, kOLEDDisplayWidth, kOLEDDisplayHeight); - mBufferSizeDisplay = emplaceControl(this, bufferSizeTag, pos, bufferSizeDisplayProc, this, nullptr, dfx::TextAlignment::Center, kValueDisplayFontSize * 2.0f, kLCDCyanTextColor, kValueDisplayFont); + mBufferSizeDisplay = emplaceControl(this, bufferSizeParameterID, pos, bufferSizeDisplayProc, this, nullptr, dfx::TextAlignment::Center, kValueDisplayFontSize * 2.0f, kLCDCyanTextColor, kValueDisplayFont); pos.set(kDivisorLFORateDisplayX, kDivisorLFORateDisplayY, kLCDDisplayWidth, kLCDDisplayHeight); - mDivisorLFORateDisplay = emplaceControl(this, divisorLFORateTag, pos, divisorLFORateDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kLCDGreenTextColor, kValueDisplayFont); + mDivisorLFORateDisplay = emplaceControl(this, divisorLFORateParameterID, pos, divisorLFORateDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kLCDGreenTextColor, kValueDisplayFont); pos.set(kDivisorLFODepthDisplayX, kDivisorLFODepthDisplayY, kLCDDisplayWidth, kLCDDisplayHeight); emplaceControl(this, kDivisorLFODepth, pos, lfoDepthDisplayProc, nullptr, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kLCDGreenTextColor, kValueDisplayFont); pos.set(kBufferLFORateDisplayX, kBufferLFORateDisplayY, kLCDDisplayWidth, kLCDDisplayHeight); - mBufferLFORateDisplay = emplaceControl(this, bufferLFORateTag, pos, bufferLFORateDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kLCDGreenTextColor, kValueDisplayFont); + mBufferLFORateDisplay = emplaceControl(this, bufferLFORateParameterID, pos, bufferLFORateDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kLCDGreenTextColor, kValueDisplayFont); pos.set(kBufferLFODepthDisplayX, kBufferLFODepthDisplayY, kLCDDisplayWidth, kLCDDisplayHeight); emplaceControl(this, kBufferLFODepth, pos, lfoDepthDisplayProc, nullptr, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kLCDGreenTextColor, kValueDisplayFont); @@ -445,7 +445,7 @@ void BufferOverrideEditor::CloseEditor() //----------------------------------------------------------------------------- -void BufferOverrideEditor::parameterChanged(long inParameterID) +void BufferOverrideEditor::parameterChanged(dfx::ParameterID inParameterID) { IDGControl* slider = nullptr; DGTextDisplay* textDisplay = nullptr; @@ -457,7 +457,7 @@ void BufferOverrideEditor::parameterChanged(long inParameterID) case kBufferTempoSync: { HandleTempoSyncChange(); - constexpr std::array parameterIDs = { kBufferSize_MS, kBufferSize_Sync }; + constexpr std::array parameterIDs = { kBufferSize_MS, kBufferSize_Sync }; newParameterID = parameterIDs[useSyncParam]; slider = mDivisorBufferBox->getControlByParameterID(parameterIDs[!useSyncParam]); textDisplay = mBufferSizeDisplay; @@ -656,7 +656,7 @@ void BufferOverrideEditor::mouseovercontrolchanged(IDGControl* currentControlUnd //----------------------------------------------------------------------------- void BufferOverrideEditor::HandleTempoSyncChange() { - auto const updateTextDisplay = [this](DGTextDisplay* control, long tempoSyncParameterID) + auto const updateTextDisplay = [this](DGTextDisplay* control, dfx::ParameterID tempoSyncParameterID) { auto const allowTextEdit = !getparameter_b(tempoSyncParameterID); control->setTextEditEnabled(allowTextEdit); diff --git a/bufferoverride/gui/bufferoverrideeditor.h b/bufferoverride/gui/bufferoverrideeditor.h index e2a1be83..662a0c5f 100644 --- a/bufferoverride/gui/bufferoverrideeditor.h +++ b/bufferoverride/gui/bufferoverrideeditor.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------ -Copyright (C) 2001-2021 Sophia Poirier +Copyright (C) 2001-2022 Sophia Poirier This file is part of Buffer Override. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Buffer Override. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -35,7 +35,7 @@ class BufferOverrideEditor final : public DfxGuiEditor long OpenEditor() override; void CloseEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; void mouseovercontrolchanged(IDGControl* currentControlUnderMouse) override; private: diff --git a/dfx-library/dfxdefines.h b/dfx-library/dfxdefines.h index a80859bb..001cd100 100644 --- a/dfx-library/dfxdefines.h +++ b/dfx-library/dfxdefines.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. These are our general global defines and constants, to be included @@ -100,11 +100,14 @@ somewhere in the include tree for every file for a DfxPlugin. #ifdef __cplusplus #include +#include namespace dfx { + using ParameterID = unsigned int; + // to indicate "not a real parameter" or something like that - static constexpr long kParameterID_Invalid = -1; + static constexpr ParameterID kParameterID_Invalid = std::numeric_limits::max(); static constexpr size_t kParameterNameMaxLength = 64; static constexpr size_t kPresetNameMaxLength = 64; diff --git a/dfx-library/dfxparameter.cpp b/dfx-library/dfxparameter.cpp index e3f95a1b..a370b639 100644 --- a/dfx-library/dfxparameter.cpp +++ b/dfx-library/dfxparameter.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our class for doing all kinds of fancy plugin parameter stuff. @@ -807,18 +807,18 @@ DfxPreset::DfxPreset(size_t inNumParameters) } //----------------------------------------------------------------------------- -void DfxPreset::setvalue(long inParameterIndex, DfxParam::Value inValue) +void DfxPreset::setvalue(dfx::ParameterID inParameterIndex, DfxParam::Value inValue) { - if ((inParameterIndex >= 0) && (inParameterIndex < static_cast(mValues.size()))) + if (inParameterIndex < mValues.size()) { mValues[inParameterIndex] = inValue; } } //----------------------------------------------------------------------------- -DfxParam::Value DfxPreset::getvalue(long inParameterIndex) const +DfxParam::Value DfxPreset::getvalue(dfx::ParameterID inParameterIndex) const { - if ((inParameterIndex >= 0) && (inParameterIndex < static_cast(mValues.size()))) + if (inParameterIndex < mValues.size()) { return mValues[inParameterIndex]; } diff --git a/dfx-library/dfxparameter.h b/dfx-library/dfxparameter.h index 7ec081ce..a69580cf 100644 --- a/dfx-library/dfxparameter.h +++ b/dfx-library/dfxparameter.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our class for doing all kinds of fancy plugin parameter stuff. @@ -602,8 +602,8 @@ class DfxPreset public: explicit DfxPreset(size_t inNumParameters); - void setvalue(long inParameterIndex, DfxParam::Value inValue); - DfxParam::Value getvalue(long inParameterIndex) const; + void setvalue(dfx::ParameterID inParameterIndex, DfxParam::Value inValue); + DfxParam::Value getvalue(dfx::ParameterID inParameterIndex) const; void setname(std::string_view inText); std::string getname() const { diff --git a/dfx-library/dfxplugin-audiounit.cpp b/dfx-library/dfxplugin-audiounit.cpp index cc4b1649..3adcbf34 100644 --- a/dfx-library/dfxplugin-audiounit.cpp +++ b/dfx-library/dfxplugin-audiounit.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our class for E-Z plugin-making and E-Z multiple-API support. @@ -68,7 +68,7 @@ void DfxPlugin::PostConstructor() // make the global-scope element aware of the parameters' values // this must happen after AUBase::PostConstructor because the elements are created there - for (long i = 0; i < getnumparameters(); i++) + for (dfx::ParameterID i = 0; i < getnumparameters(); i++) { if (!hasparameterattribute(i, DfxParam::kAttribute_Unused)) // XXX should we do it like this, or override GetParameterList? { @@ -298,7 +298,7 @@ OSStatus DfxPlugin::GetPropertyInfo(AudioUnitPropertyID inPropertyID, break; // get/set the current MIDI learner parameter case dfx::kPluginProperty_MidiLearner: - outDataSize = sizeof(int32_t); + outDataSize = sizeof(uint32_t); outWritable = true; break; // get/set the MIDI assignment for a parameter @@ -467,7 +467,7 @@ OSStatus DfxPlugin::GetProperty(AudioUnitPropertyID inPropertyID, if ((pvt->otherDesc.format == kOtherPluginFormat_kVST) && (pvt->otherDesc.plugin.mSubType == PLUGIN_ID)) { pvt->auParamID = pvt->otherParamID; - pvt->auValue = expandparametervalue(static_cast(pvt->otherParamID), pvt->otherValue); + pvt->auValue = expandparametervalue(pvt->otherParamID, pvt->otherValue); } else { @@ -488,7 +488,7 @@ OSStatus DfxPlugin::GetProperty(AudioUnitPropertyID inPropertyID, } #endif auto& value = request->value; - auto const paramID = static_cast(inElement); + dfx::ParameterID const parameterID = inElement; switch (request->inValueItem) { case dfx::ParameterValueItem::Current: @@ -496,13 +496,13 @@ OSStatus DfxPlugin::GetProperty(AudioUnitPropertyID inPropertyID, switch (request->inValueType) { case DfxParam::ValueType::Float: - value.f = getparameter_f(paramID); + value.f = getparameter_f(parameterID); break; case DfxParam::ValueType::Int: - value.i = getparameter_i(paramID); + value.i = getparameter_i(parameterID); break; case DfxParam::ValueType::Boolean: - value.b = getparameter_b(paramID); + value.b = getparameter_b(parameterID); break; default: assert(false); @@ -516,13 +516,13 @@ OSStatus DfxPlugin::GetProperty(AudioUnitPropertyID inPropertyID, switch (request->inValueType) { case DfxParam::ValueType::Float: - value.f = getparameterdefault_f(paramID); + value.f = getparameterdefault_f(parameterID); break; case DfxParam::ValueType::Int: -// value.i = getparameterdefault_i(paramID); +// value.i = getparameterdefault_i(parameterID); break; case DfxParam::ValueType::Boolean: -// value.b = getparameterdefault_b(paramID); +// value.b = getparameterdefault_b(parameterID); break; default: assert(false); @@ -536,13 +536,13 @@ OSStatus DfxPlugin::GetProperty(AudioUnitPropertyID inPropertyID, switch (request->inValueType) { case DfxParam::ValueType::Float: - value.f = getparametermin_f(paramID); + value.f = getparametermin_f(parameterID); break; case DfxParam::ValueType::Int: - value.i = getparametermin_i(paramID); + value.i = getparametermin_i(parameterID); break; case DfxParam::ValueType::Boolean: -// value.b = getparametermin_b(paramID); +// value.b = getparametermin_b(parameterID); value.b = false; break; default: @@ -557,13 +557,13 @@ OSStatus DfxPlugin::GetProperty(AudioUnitPropertyID inPropertyID, switch (request->inValueType) { case DfxParam::ValueType::Float: - value.f = getparametermax_f(paramID); + value.f = getparametermax_f(parameterID); break; case DfxParam::ValueType::Int: - value.i = getparametermax_i(paramID); + value.i = getparametermax_i(parameterID); break; case DfxParam::ValueType::Boolean: -// value.b = getparametermax_b(paramID); +// value.b = getparametermax_b(parameterID); value.b = true; break; default: @@ -752,7 +752,7 @@ OSStatus DfxPlugin::GetProperty(AudioUnitPropertyID inPropertyID, break; // get the current MIDI learner parameter case dfx::kPluginProperty_MidiLearner: - *static_cast(outData) = getmidilearner(); + *static_cast(outData) = getmidilearner(); break; // get the MIDI assignment for a parameter case dfx::kPluginProperty_ParameterMidiAssignment: @@ -910,7 +910,7 @@ OSStatus DfxPlugin::SetProperty(AudioUnitPropertyID inPropertyID, } #endif auto const& value = request->value; - long paramID = inElement; + dfx::ParameterID const parameterID = inElement; switch (request->inValueItem) { case dfx::ParameterValueItem::Current: @@ -918,16 +918,16 @@ OSStatus DfxPlugin::SetProperty(AudioUnitPropertyID inPropertyID, switch (request->inValueType) { case DfxParam::ValueType::Float: - setparameter_f(paramID, value.f); - postupdate_parameter(paramID); + setparameter_f(parameterID, value.f); + postupdate_parameter(parameterID); break; case DfxParam::ValueType::Int: - setparameter_i(paramID, value.i); - postupdate_parameter(paramID); + setparameter_i(parameterID, value.i); + postupdate_parameter(parameterID); break; case DfxParam::ValueType::Boolean: - setparameter_b(paramID, value.b); - postupdate_parameter(paramID); + setparameter_b(parameterID, value.b); + postupdate_parameter(parameterID); break; default: assert(false); @@ -1004,7 +1004,7 @@ OSStatus DfxPlugin::SetProperty(AudioUnitPropertyID inPropertyID, break; // set the current MIDI learner parameter case dfx::kPluginProperty_MidiLearner: - setmidilearner(*static_cast(inData)); + setmidilearner(*static_cast(inData)); break; // set the MIDI assignment for a parameter case dfx::kPluginProperty_ParameterMidiAssignment: @@ -1394,7 +1394,7 @@ OSStatus DfxPlugin::SetParameter(AudioUnitParameterID inParameterID, OSStatus DfxPlugin::GetPresets(CFArrayRef* outData) const { // figure out how many valid (loaded) presets we actually have... - long validNumPresets = 0; + CFIndex validNumPresets = 0; for (size_t i = 0; i < getnumpresets(); i++) { // if (presetnameisvalid(i)) @@ -1404,7 +1404,7 @@ OSStatus DfxPlugin::GetPresets(CFArrayRef* outData) const } } // whoops, looks like we don't actually have any presets - AUSDK_Require(validNumPresets > 0, kAudioUnitErr_InvalidProperty);//kAudioUnitErr_PropertyNotInUse? + AUSDK_Require(validNumPresets > 0, kAudioUnitErr_PropertyNotInUse); // this is just to say that the property is supported (GetPropertyInfo needs this) if (!outData) @@ -1522,7 +1522,7 @@ OSStatus DfxPlugin::RestoreState(CFPropertyListRef inData) // XXX should we rethink this and load parameter settings always before mDfxSettings->restore()? // load the parameter settings that were restored // by the inherited base class implementation of RestoreState - for (long i = 0; i < getnumparameters(); i++) + for (dfx::ParameterID i = 0; i < getnumparameters(); i++) { setparameter_f(i, Globals()->GetParameter(i)); } @@ -1532,7 +1532,7 @@ OSStatus DfxPlugin::RestoreState(CFPropertyListRef inData) #endif // make any listeners aware of the changes in the parameter values - for (long i = 0; i < getnumparameters(); i++) + for (dfx::ParameterID i = 0; i < getnumparameters(); i++) { postupdate_parameter(i); } diff --git a/dfx-library/dfxplugin-base.h b/dfx-library/dfxplugin-base.h index 3b4a10f5..3567b904 100644 --- a/dfx-library/dfxplugin-base.h +++ b/dfx-library/dfxplugin-base.h @@ -18,12 +18,15 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once +#include "dfxdefines.h" + + // should be pretty much implied: // if the plugin is an instrument, then it uses MIDI #if TARGET_PLUGIN_IS_INSTRUMENT @@ -218,6 +221,19 @@ enum +//----------------------------------------------------------------------------- +constexpr int32_t ParameterID_ToVST(ParameterID inParameterID) noexcept +{ + return (inParameterID == kParameterID_Invalid) ? -1 : static_cast(inParameterID); +} +//----------------------------------------------------------------------------- +constexpr ParameterID ParameterID_FromVST(int32_t inParameterIndexVST) noexcept +{ + return (inParameterIndexVST < 0) ? kParameterID_Invalid : static_cast(inParameterIndexVST); +} + + + #ifdef TARGET_API_RTAS //----------------------------------------------------------------------------- @@ -227,21 +243,23 @@ constexpr long kParameterValueShortNameMax_RTAS = 6; // XXX hack constexpr long kParameterID_RTASGlobalBypass = 1; constexpr long kParameterID_RTASOffset = kParameterID_RTASGlobalBypass + 1; //----------------------------------------------------------------------------- -constexpr long ParameterID_ToRTAS(long inParameterID) +constexpr long ParameterID_ToRTAS(ParameterID inParameterID) noexcept { - return inParameterID + kParameterID_RTASOffset; + auto const offsetIndex = static_cast(inParameterID) + kParameterID_RTASOffset; + return (inParameterID == kParameterID_Invalid) ? -1 : offsetIndex; } //----------------------------------------------------------------------------- -constexpr long ParameterID_FromRTAS(long inParameterIndex_RTAS) +constexpr ParameterID ParameterID_FromRTAS(long inParameterIndexRTAS) noexcept { - return inParameterIndex_RTAS - kParameterID_RTASOffset; + auto const offsetIndex = inParameterIndexRTAS - kParameterID_RTASOffset; + return (offsetIndex < 0) ? kParameterID_Invalid : static_cast(offsetIndex); } // XXX a hack to handle the fact that CPluginControl_Percent (annoyingly) // automatically converts to and from internal 0-1 values and external 0-100 values constexpr double kRTASPercentScalar = 0.01; -#endif +#endif // TARGET_API_RTAS } // namespace dfx diff --git a/dfx-library/dfxplugin-rtas.cpp b/dfx-library/dfxplugin-rtas.cpp index 38b0ed3b..06d302e3 100644 --- a/dfx-library/dfxplugin-rtas.cpp +++ b/dfx-library/dfxplugin-rtas.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our class for E-Z plugin-making and E-Z multiple-API support. @@ -91,9 +91,9 @@ void DfxPlugin::EffectInit() /* long bypassControlIndex = 0; ComponentResult bypassResult = GetMasterBypassControl(&bypassControlIndex); -CPluginControl_Discrete * bypassControl = dynamic_cast( GetControl(bypassControlIndex) ); -char bypassName[32]; -bypassControl->GetNameOfLength(bypassName, sizeof(bypassName)-1, 0); +CPluginControl_Discrete* bypassControl = dynamic_cast( GetControl(bypassControlIndex) ); +char bypassName[32] {}; +bypassControl->GetNameOfLength(bypassName, std::size(bypassName) - 1, 0); fprintf(stderr, "%s IsAutomatable() = %s (error = %ld)\n", bypassName, bypassControl->IsAutomatable() ? "true" : "false", bypassResult); */ } @@ -151,7 +151,7 @@ void DfxPlugin::AddParametersToList() DefineMasterBypassControlIndex(dfx::kParameterID_RTASGlobalBypass); OSType paramFourCharID = 0; - for (long i = 0; i < getnumparameters(); i++) + for (dfx::ParameterID i = 0; i < getnumparameters(); i++) { if (!parameterisvalid(i)) { @@ -168,7 +168,7 @@ void DfxPlugin::AddParametersToList() { paramFourCharID = DFX_IterateAlphaNumericFourCharCode(paramFourCharID); } - bool const paramAutomatable = (getparameterattributes(i) & (DfxParam::kAttribute_Hidden | DfxParam::kAttribute_Unused)) ? false : true; + bool const paramAutomatable = !(hasparameterattribute(i, DfxParam::kAttribute_Hidden) || hasparameterattribute(i, DfxParam::kAttribute_Unused)); constexpr int numCurvedSteps = 1000; double const stepSize_default = (paramMax_f - paramMin_f) / (double)numCurvedSteps; auto const paramCurve = getparametercurve(i); @@ -256,25 +256,33 @@ void DfxPlugin::AddParametersToList() //----------------------------------------------------------------------------- // XXX implement -ComponentResult DfxPlugin::GetControlNameOfLength(long inParameterIndex, char * outName, long inNameLength, OSType inControllerType, FicBoolean * outReverseHighlight) +ComponentResult DfxPlugin::GetControlNameOfLength(long inParameterIndex, char* outName, long inNameLength, OSType inControllerType, FicBoolean* outReverseHighlight) { - if (outName == NULL) + if (outName == nullptr) + { return paramErr; + } /* if (inNameLength <= dfx::kParameterShortNameMax_RTAS) { - char * shortNameString = NULL; + char* shortNameString = nullptr; if (inParameterIndex == dfx::kParameterID_RTASGlobalBypass) + { shortNameString = "Bypass"; // any shortened version of this is fine + } else + { shortNameString = GetParameterShortName( dfx::ParameterID_FromRTAS(inParameterIndex) ); - if (shortNameString != NULL) + } + if (shortNameString != nullptr) { strlcpy(outName, shortNameString, inNameLength + 1); outName[inNameLength] = 0; - if (outReverseHighlight != NULL) + if (outReverseHighlight != nullptr) + { *outReverseHighlight = false; // XXX assume control is not to be highlighted + } return noErr; } } @@ -287,14 +295,16 @@ ComponentResult DfxPlugin::GetControlNameOfLength(long inParameterIndex, char * // XXX implement ComponentResult DfxPlugin::GetValueString(long inParameterIndex, long inValue, StringPtr outValueString, long inMaxLength) { - if (outValueString == NULL) + if (outValueString == nullptr) + { return paramErr; + } /* if (inMaxLength <= dfx::kParameterValueShortNameMax_rtas) { auto const shortValueString = GetParameterValueShortString(dfx::ParameterID_FromRTAS(inParameterIndex), inValue); - if (shortValueString != NULL) + if (shortValueString != nullptr) { strlcpy((char*)(outValueString + 1), shortValueString, inMaxLength + 1); outValueString[0] = ((signed)strlen(shortValueString) > inMaxLength) ? inMaxLength : strlen(shortValueString); @@ -315,20 +325,22 @@ void DfxPlugin::UpdateControlValueInAlgorithm(long inParameterIndex) return; } - inParameterIndex = dfx::ParameterID_FromRTAS(inParameterIndex); - if (! parameterisvalid(inParameterIndex) ) + auto const parameterID = dfx::ParameterID_FromRTAS(inParameterIndex); + if (!parameterisvalid(parameterID)) + { return; + } - switch ( getparametervaluetype(inParameterIndex) ) + switch (getparametervaluetype(parameterID)) { case DfxParam::ValueType::Float: - parameters[inParameterIndex].set_f( GetParameter_f_FromRTAS(inParameterIndex) ); + parameters[parameterID].set_f(GetParameter_f_FromRTAS(parameterID)); break; case DfxParam::ValueType::Int: - parameters[inParameterIndex].set_i( GetParameter_i_FromRTAS(inParameterIndex) ); + parameters[parameterID].set_i(GetParameter_i_FromRTAS(parameterID)); break; case DfxParam::ValueType::Boolean: - parameters[inParameterIndex].set_b( GetParameter_b_FromRTAS(inParameterIndex) ); + parameters[parameterID].set_b(GetParameter_b_FromRTAS(parameterID)); break; default: break; @@ -336,7 +348,7 @@ void DfxPlugin::UpdateControlValueInAlgorithm(long inParameterIndex) } //----------------------------------------------------------------------------- -double DfxPlugin::GetParameter_f_FromRTAS(long inParameterID) +double DfxPlugin::GetParameter_f_FromRTAS(dfx::ParameterID inParameterID) { double resultValue = dynamic_cast(GetControl(dfx::ParameterID_ToRTAS(inParameterID)))->GetContinuous(); if ( (getparameterunit(inParameterID) == DfxParam::Unit::Percent) || (getparameterunit(inParameterID) == DfxParam::Unit::DryWetMix) ) @@ -345,7 +357,7 @@ double DfxPlugin::GetParameter_f_FromRTAS(long inParameterID) } //----------------------------------------------------------------------------- -int64_t DfxPlugin::GetParameter_i_FromRTAS(long inParameterID) +int64_t DfxPlugin::GetParameter_i_FromRTAS(dfx::ParameterID inParameterID) { int64_t resultValue = dynamic_cast(GetControl(dfx::ParameterID_ToRTAS(inParameterID)))->GetDiscrete(); if ( getparameterusevaluestrings(inParameterID) ) @@ -354,16 +366,18 @@ int64_t DfxPlugin::GetParameter_i_FromRTAS(long inParameterID) } //----------------------------------------------------------------------------- -bool DfxPlugin::GetParameter_b_FromRTAS(long inParameterID) +bool DfxPlugin::GetParameter_b_FromRTAS(dfx::ParameterID inParameterID) { return (GetParameter_i_FromRTAS(inParameterID) != 0); } //----------------------------------------------------------------------------- -ComponentResult DfxPlugin::IsControlAutomatable(long inControlIndex, short * outItIs) +ComponentResult DfxPlugin::IsControlAutomatable(long inControlIndex, short* outItIs) { - if (outItIs == NULL) + if (outItIs == nullptr) + { return paramErr; + } // XXX test this first, since dfx::ParameterID_FromRTAS() makes it an invalid ID if (inControlIndex == dfx::kParameterID_RTASGlobalBypass) @@ -372,14 +386,20 @@ ComponentResult DfxPlugin::IsControlAutomatable(long inControlIndex, short * out return noErr; } - inControlIndex = dfx::ParameterID_FromRTAS(inControlIndex); - if (! parameterisvalid(inControlIndex) ) + auto const parameterID = dfx::ParameterID_FromRTAS(inControlIndex); + if (!parameterisvalid(parameterID)) + { return paramErr; + } - if ( getparameterattributes(inControlIndex) & (DfxParam::kAttribute_Unused | DfxParam::kAttribute_Hidden) ) + if (hasparameterattribute(parameterID, DfxParam::kAttribute_Unused) || hasparameterattribute(parameterID, DfxParam::kAttribute_Hidden)) + { *outItIs = 0; + } else + { *outItIs = 1; + } return noErr; } @@ -429,7 +449,7 @@ double CPluginControl_DfxCurved::ConvertControlToContinuous(long control) const #pragma mark - //----------------------------------------------------------------------------- -ComponentResult DfxPlugin::SetChunk(OSType inChunkID, SFicPlugInChunk * chunk) +ComponentResult DfxPlugin::SetChunk(OSType inChunkID, SFicPlugInChunk* chunk) { return TARGET_API_BASE_CLASS::SetChunk(inChunkID, chunk); } @@ -452,7 +472,7 @@ UInt32 DfxPlugin::ProcessAudio(bool inIsGlobalBypassed) long totalInputSamples = 0; // total number of input samples in one input buffer // use the mono channel input sample number (guaranteed to be connected) - if (GetInputConnection(0) != NULL) + if (GetInputConnection(0) != nullptr) { totalInputSamples = GetInputConnection(0)->mNumSamplesInBuf; } @@ -460,17 +480,19 @@ UInt32 DfxPlugin::ProcessAudio(bool inIsGlobalBypassed) for (SInt32 ch = 0; ch < GetNumOutputs(); ch++) { // XXX what to do if there are no valid connections for the channel? - mInputAudioStreams_as[ch] = NULL; - mOutputAudioStreams_as[ch] = NULL; + mInputAudioStreams_as[ch] = nullptr; + mOutputAudioStreams_as[ch] = nullptr; DAEConnectionPtr outputConnection = GetOutputConnection(ch); - if (outputConnection != NULL) // if no valid connection, don't do anything + if (outputConnection != nullptr) // if no valid connection, don't do anything { mOutputAudioStreams_as[ch] = (float*)(outputConnection->mBuffer); DAEConnectionPtr inputConnection = GetInputConnection(ch); - if (inputConnection != NULL) // have a valid input connection + if (inputConnection != nullptr) // have a valid input connection + { mInputAudioStreams_as[ch] = (float*)(inputConnection->mBuffer); + } else // no input connection; use default value of zero { // (re)allocate the zero audio buffer if it is not currently large enough for this rendering slice @@ -484,12 +506,16 @@ UInt32 DfxPlugin::ProcessAudio(bool inIsGlobalBypassed) if (inIsGlobalBypassed) { for (long i = 0; i < totalInputSamples; i++) + { mOutputAudioStreams_as[ch][i] = mInputAudioStreams_as[ch][i]; + } } // do the sample number adjustment outputConnection->mNumSamplesInBuf = totalInputSamples; - if (inputConnection != NULL) + if (inputConnection != nullptr) + { inputConnection->mNumSamplesInBuf = 0; + } } } @@ -508,7 +534,7 @@ UInt32 DfxPlugin::ProcessAudio(bool inIsGlobalBypassed) #endif //----------------------------------------------------------------------------- -void DfxPlugin::RenderAudio(float ** inAudioStreams, float ** outAudioStreams, long inNumFramesToProcess) +void DfxPlugin::RenderAudio(float** inAudioStreams, float** outAudioStreams, long inNumFramesToProcess) { preprocessaudio(dfx::math::ToUnsigned(inNumFramesToProcess)); @@ -582,7 +608,7 @@ void DfxPlugin::RenderAudio(float ** inAudioStreams, float ** outAudioStreams, l // RTAS clip monitoring for (SInt32 channel = 0; (channel < GetNumOutputs()) && !fClipped; channel++) { - if (outAudioStreams[channel] == NULL) // XXX possible in AudioSuite + if (outAudioStreams[channel] == nullptr) // XXX possible in AudioSuite { continue; } @@ -618,10 +644,10 @@ void DfxPlugin::RenderAudio(float ** inAudioStreams, float ** outAudioStreams, l #pragma mark - //----------------------------------------------------------------------------- -CPlugInView * DfxPlugin::CreateCPlugInView() +CPlugInView* DfxPlugin::CreateCPlugInView() { #if TARGET_PLUGIN_HAS_GUI - CNoResourceView * ui = NULL; + std::unique_ptr ui; try { if (!mCustomUI_p) @@ -630,7 +656,7 @@ CPlugInView * DfxPlugin::CreateCPlugInView() mCustomUI_p->GetRect( &(mPIWinRect.left), &(mPIWinRect.top), &(mPIWinRect.right), &(mPIWinRect.bottom) ); } - ui = new CNoResourceView; + ui = std::make_unique(); #if PT_SDK_VERSION < 0x08000000 constexpr long viewSizeOffset = 1; // XXX +1 because of a bug where CNoResourceView::SetSize() subtracts 1 from width and height #else @@ -638,20 +664,20 @@ CPlugInView * DfxPlugin::CreateCPlugInView() #endif ui->SetSize(mPIWinRect.right+viewSizeOffset, mPIWinRect.bottom+viewSizeOffset); - mNoUIView_p = (CTemplateNoUIView *) ui->AddView2("!NoUIView[('NoID')]", 0, 0, mPIWinRect.right, mPIWinRect.bottom, false); + mNoUIView_p = (CTemplateNoUIView*) ui->AddView2("!NoUIView[('NoID')]", 0, 0, mPIWinRect.right, mPIWinRect.bottom, false); - if (mNoUIView_p != NULL) + if (mNoUIView_p != nullptr) + { mNoUIView_p->SetCustomUI(mCustomUI_p.get()); + } } catch (...) { mCustomUI_p.reset(); - if (ui != NULL) - delete ui; - ui = NULL; + ui.reset(); } - return ui; + return ui.release(); #else OSType meterFourCharID = 0; @@ -676,12 +702,16 @@ CPlugInView * DfxPlugin::CreateCPlugInView() #if TARGET_PLUGIN_HAS_GUI //----------------------------------------------------------------------------- -void DfxPlugin::GetViewRect(Rect * outViewRect) +void DfxPlugin::GetViewRect(Rect* outViewRect) { if (!mCustomUI_p) + { mCustomUI_p.reset(CreateCTemplateCustomUI(this)); - if (outViewRect == NULL) + } + if (outViewRect == nullptr) + { return; + } mCustomUI_p->GetRect( &(mPIWinRect.left), &(mPIWinRect.top), &(mPIWinRect.right), &(mPIWinRect.bottom) ); outViewRect->left = mPIWinRect.left; @@ -696,7 +726,7 @@ void DfxPlugin::SetViewPort(GrafPtr inPort) mMainPort = inPort; CEffectProcess::SetViewPort(mMainPort); - if (mMainPort != NULL) + if (mMainPort != nullptr) { if (mCustomUI_p) { @@ -710,16 +740,18 @@ void DfxPlugin::SetViewPort(GrafPtr inPort) } #endif - void * windowPtr = NULL; - #if TARGET_OS_WIN32 - windowPtr = (void*) ASI_GethWnd((WindowPtr)mMainPort); - #elif TARGET_OS_MAC - windowPtr = (void*) GetWindowFromPort(mMainPort); - #endif + void* windowPtr = nullptr; + #if TARGET_OS_WIN32 + windowPtr = (void*) ASI_GethWnd((WindowPtr)mMainPort); + #elif TARGET_OS_MAC + windowPtr = (void*) GetWindowFromPort(mMainPort); + #endif mCustomUI_p->Open(windowPtr, mLeftOffset, mTopOffset); - if (mNoUIView_p != NULL) + if (mNoUIView_p != nullptr) + { mNoUIView_p->SetEnable(true); + } #if TARGET_OS_WIN32 mCustomUI_p->Draw(mPIWinRect.left, mPIWinRect.top, mPIWinRect.right, mPIWinRect.bottom); @@ -729,9 +761,13 @@ void DfxPlugin::SetViewPort(GrafPtr inPort) else { if (mCustomUI_p) + { mCustomUI_p->Close(); - if (mNoUIView_p != NULL) + } + if (mNoUIView_p != nullptr) + { mNoUIView_p->SetEnable(false); + } } return; } @@ -743,13 +779,13 @@ long DfxPlugin::SetControlValue(long inControlIndex, long inValue) } //----------------------------------------------------------------------------- -long DfxPlugin::GetControlValue(long inControlIndex, long * outValue) +long DfxPlugin::GetControlValue(long inControlIndex, long* outValue) { return static_cast(CProcess::GetControlValue(inControlIndex, outValue)); } //----------------------------------------------------------------------------- -long DfxPlugin::GetControlDefaultValue(long inControlIndex, long * outValue) +long DfxPlugin::GetControlDefaultValue(long inControlIndex, long* outValue) { return static_cast(CProcess::GetControlDefaultValue(inControlIndex, outValue)); } @@ -778,7 +814,7 @@ int DfxPlugin::ProcessReleaseControl(long inControlIndex) //----------------------------------------------------------------------------- void DfxPlugin::ProcessDoIdle() { - this->DoIdle(NULL); + this->DoIdle(nullptr); gProcessGroup->YieldCriticalSection(); } @@ -800,17 +836,19 @@ ComponentResult DfxPlugin::SetControlHighliteInfo(long inControlIndex, short inI } //----------------------------------------------------------------------------- -ComponentResult DfxPlugin::ChooseControl(Point inLocalCoord, long * outControlIndex) +ComponentResult DfxPlugin::ChooseControl(Point inLocalCoord, long* outControlIndex) { - if (outControlIndex != NULL) + if (outControlIndex == nullptr) { - *outControlIndex = 0; - if (mCustomUI_p) - mCustomUI_p->GetControlIndexFromPoint(inLocalCoord.h, inLocalCoord.v, outControlIndex); - return noErr; - } - else return paramErr; + } + + *outControlIndex = 0; + if (mCustomUI_p) + { + mCustomUI_p->GetControlIndexFromPoint(inLocalCoord.h, inLocalCoord.v, outControlIndex); + } + return noErr; } #ifdef TARGET_API_AUDIOSUITE @@ -853,7 +891,7 @@ enum #endif //----------------------------------------------------------------------------- -CProcessGroupInterface * CProcessGroup::CreateProcessGroup() +CProcessGroupInterface* CProcessGroup::CreateProcessGroup() { return new DfxEffectGroup; } @@ -881,7 +919,7 @@ void DfxEffectGroup::CreateEffectTypes() for (int i = static_cast(ePlugIn_StemFormat_FirstExplicitChoice) - 1; i <= static_cast(ePlugIn_StemFormat_LastExplicitChoice); i++) { effectTypeFourCharID = DFX_IterateAlphaNumericFourCharCode(effectTypeFourCharID); - CEffectType * effectType; + CEffectType* effectType {}; if (i < static_cast(ePlugIn_StemFormat_FirstExplicitChoice)) { effectType = new CEffectTypeAS(effectTypeFourCharID, PLUGIN_ID, PLUGIN_CATEGORY_RTAS); @@ -923,7 +961,7 @@ void DfxEffectGroup::Initialize() } //----------------------------------------------------------------------------- -void DfxEffectGroup::dfx_AddEffectType(CEffectType * inEffectType) +void DfxEffectGroup::dfx_AddEffectType(CEffectType* inEffectType) { inEffectType->DefineTypeNames(PLUGIN_NAME_STRING); inEffectType->DefineSampleRateSupport(eSupports48kAnd96kAnd192k); diff --git a/dfx-library/dfxplugin-vst.cpp b/dfx-library/dfxplugin-vst.cpp index 9326bbb3..62aa2259 100644 --- a/dfx-library/dfxplugin-vst.cpp +++ b/dfx-library/dfxplugin-vst.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our class for E-Z plugin-making and E-Z multiple-API support. @@ -168,7 +168,7 @@ bool DfxPlugin::getEffectName(char* outText) VstInt32 DfxPlugin::getVendorVersion() { - return getpluginversion(); + return static_cast(getpluginversion()); } bool DfxPlugin::getVendorString(char* outText) @@ -362,13 +362,13 @@ VstInt32 DfxPlugin::setChunk(void* data, VstInt32 byteSize, bool isPreset) //----------------------------------------------------------------------------- void DfxPlugin::setParameter(VstInt32 index, float value) { - setparameter_gen(index, value); + setparameter_gen(dfx::ParameterID_FromVST(index), value); } //----------------------------------------------------------------------------- float DfxPlugin::getParameter(VstInt32 index) { - return getparameter_gen(index); + return getparameter_gen(dfx::ParameterID_FromVST(index)); } //----------------------------------------------------------------------------- @@ -379,10 +379,10 @@ void DfxPlugin::getParameterName(VstInt32 index, char* name) { // kVstMaxParamStrLen is absurdly short for parameter names at 8-characters, // and given that exceding that length is common, hosts prepare for that, - // and even the Vst2Wrapper in the VST3 SDK acknowleges as much by defining + // and even the Vst2Wrapper in the VST3 SDK acknowledges as much by defining // the following "extended" constant to use instead constexpr size_t kVstExtMaxParamStrLen = 32; - vst_strncpy(name, getparametername(index).c_str(), kVstExtMaxParamStrLen); + vst_strncpy(name, getparametername(dfx::ParameterID_FromVST(index)).c_str(), kVstExtMaxParamStrLen); } } @@ -395,22 +395,23 @@ void DfxPlugin::getParameterDisplay(VstInt32 index, char* text) return; } - if (getparameterusevaluestrings(index)) + auto const parameterID = dfx::ParameterID_FromVST(index); + if (getparameterusevaluestrings(parameterID)) { - vst_strncpy(text, getparametervaluestring(index, getparameter_i(index)).value_or("").c_str(), kVstMaxParamStrLen); + vst_strncpy(text, getparametervaluestring(parameterID, getparameter_i(parameterID)).value_or("").c_str(), kVstMaxParamStrLen); return; } - switch (getparametervaluetype(index)) + switch (getparametervaluetype(parameterID)) { case DfxParam::ValueType::Float: - snprintf(text, kVstMaxParamStrLen + 1, "%.3f", getparameter_f(index)); + snprintf(text, kVstMaxParamStrLen + 1, "%.3f", getparameter_f(parameterID)); break; case DfxParam::ValueType::Int: - snprintf(text, kVstMaxParamStrLen + 1, "%" PRIi64, getparameter_i(index)); + snprintf(text, kVstMaxParamStrLen + 1, "%" PRIi64, getparameter_i(parameterID)); break; case DfxParam::ValueType::Boolean: - vst_strncpy(text, getparameter_b(index) ? "on" : "off", kVstMaxParamStrLen); + vst_strncpy(text, getparameter_b(parameterID) ? "on" : "off", kVstMaxParamStrLen); break; default: assert(false); @@ -424,7 +425,7 @@ void DfxPlugin::getParameterLabel(VstInt32 index, char* label) { if (label) { - vst_strncpy(label, getparameterunitstring(index).c_str(), kVstMaxParamStrLen); + vst_strncpy(label, getparameterunitstring(dfx::ParameterID_FromVST(index)).c_str(), kVstMaxParamStrLen); } } @@ -436,30 +437,31 @@ bool DfxPlugin::getParameterProperties(VstInt32 index, VstParameterProperties* p return false; } *properties = {}; + auto const parameterID = dfx::ParameterID_FromVST(index); // note that kVstMax* are specified as "number of characters excluding the null terminator", // and vst_strncpy behaves accordingly and writes null at array[N], however the static arrays // in struct types (like VstParameterProperties here) size the arrays by N, meaning that // array[N] is out of range, so we call vst_strncpy in these cases passing N-1 as max length - vst_strncpy(properties->label, getparametername(index).c_str(), kVstMaxLabelLen - 1); + vst_strncpy(properties->label, getparametername(parameterID).c_str(), kVstMaxLabelLen - 1); constexpr size_t recommendedShortLabelLength = 6; // per the VST header comment static_assert(recommendedShortLabelLength < kVstMaxShortLabelLen); - auto const shortName = getparametername(index, recommendedShortLabelLength); + auto const shortName = getparametername(parameterID, recommendedShortLabelLength); vst_strncpy(properties->shortLabel, shortName.c_str(), kVstMaxShortLabelLen - 1); - auto const isVisible = [this](long parameterID) + auto const isVisible = [this](dfx::ParameterID parameterID) { return !hasparameterattribute(parameterID, DfxParam::kAttribute_Unused) && !hasparameterattribute(parameterID, DfxParam::kAttribute_Hidden); }; - if (isVisible(index)) + if (isVisible(parameterID)) { - properties->displayIndex = [index, isVisible] + properties->displayIndex = [parameterID, isVisible] { VstInt16 result = 0; - for (VstInt16 parameterID = 0; parameterID <= index; parameterID++) + for (dfx::ParameterID i = 0; i <= parameterID; i++) { - if (isVisible(parameterID)) + if (isVisible(i)) { assert(result < std::numeric_limits::max()); result++; @@ -470,21 +472,21 @@ bool DfxPlugin::getParameterProperties(VstInt32 index, VstParameterProperties* p properties->flags |= kVstParameterSupportsDisplayIndex; } - switch (getparametervaluetype(index)) + switch (getparametervaluetype(parameterID)) { case DfxParam::ValueType::Boolean: properties->flags |= kVstParameterIsSwitch; break; case DfxParam::ValueType::Int: - properties->minInteger = getparametermin_i(index); - properties->maxInteger = getparametermax_i(index); + properties->minInteger = getparametermin_i(parameterID); + properties->maxInteger = getparametermax_i(parameterID); properties->flags |= kVstParameterUsesIntegerMinMax; break; default: break; } - if (auto const groupIndex = getparametergroup(index)) + if (auto const groupIndex = getparametergroup(parameterID)) { auto const downcastWithValidation = [](auto& destination, auto const& source) { @@ -547,7 +549,7 @@ void DfxPlugin::processReplacing(float** inputs, float** outputs, VstInt32 sampl if (ch == 0) { assert(mAsymmetricalInputAudioBuffer.size() >= static_cast(sampleFrames)); - std::copy_n(mInputAudioStreams[ch], sampleFrames, mAsymmetricalInputAudioBuffer.data()); + std::copy_n(mInputAudioStreams[ch], dfx::math::ToUnsigned(sampleFrames), mAsymmetricalInputAudioBuffer.data()); } inputAudio = mAsymmetricalInputAudioBuffer.data(); } diff --git a/dfx-library/dfxplugin.cpp b/dfx-library/dfxplugin.cpp index 54dbb0d3..31179ae6 100644 --- a/dfx-library/dfxplugin.cpp +++ b/dfx-library/dfxplugin.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our class for E-Z plugin-making and E-Z multiple-API support. @@ -427,15 +427,15 @@ void DfxPlugin::do_reset() #pragma mark parameters //----------------------------------------------------------------------------- -void DfxPlugin::initparameter_f(long inParameterIndex, std::vector const& initNames, +void DfxPlugin::initparameter_f(dfx::ParameterID inParameterID, std::vector const& initNames, double initValue, double initDefaultValue, double initMin, double initMax, DfxParam::Unit initUnit, DfxParam::Curve initCurve, std::string_view initCustomUnitString) { - auto& parameter = getparameterobject(inParameterIndex); + auto& parameter = getparameterobject(inParameterID); parameter.init_f(initNames, initValue, initDefaultValue, initMin, initMax, initUnit, initCurve); - initpresetsparameter(inParameterIndex); // default empty presets with this value + initpresetsparameter(inParameterID); // default empty presets with this value if (!initCustomUnitString.empty()) { parameter.setcustomunitstring(initCustomUnitString); @@ -443,15 +443,15 @@ void DfxPlugin::initparameter_f(long inParameterIndex, std::vector const& initNames, +void DfxPlugin::initparameter_i(dfx::ParameterID inParameterID, std::vector const& initNames, int64_t initValue, int64_t initDefaultValue, int64_t initMin, int64_t initMax, DfxParam::Unit initUnit, DfxParam::Curve initCurve, std::string_view initCustomUnitString) { - auto& parameter = getparameterobject(inParameterIndex); + auto& parameter = getparameterobject(inParameterID); parameter.init_i(initNames, initValue, initDefaultValue, initMin, initMax, initUnit, initCurve); - initpresetsparameter(inParameterIndex); // default empty presets with this value + initpresetsparameter(inParameterID); // default empty presets with this value if (!initCustomUnitString.empty()) { parameter.setcustomunitstring(initCustomUnitString); @@ -459,33 +459,33 @@ void DfxPlugin::initparameter_i(long inParameterIndex, std::vector const& initNames, +void DfxPlugin::initparameter_b(dfx::ParameterID inParameterID, std::vector const& initNames, bool initValue, bool initDefaultValue, DfxParam::Unit initUnit) { - getparameterobject(inParameterIndex).init_b(initNames, initValue, initDefaultValue, initUnit); - initpresetsparameter(inParameterIndex); // default empty presets with this value + getparameterobject(inParameterID).init_b(initNames, initValue, initDefaultValue, initUnit); + initpresetsparameter(inParameterID); // default empty presets with this value } //----------------------------------------------------------------------------- -void DfxPlugin::initparameter_b(long inParameterIndex, std::vector const& initNames, +void DfxPlugin::initparameter_b(dfx::ParameterID inParameterID, std::vector const& initNames, bool initDefaultValue, DfxParam::Unit initUnit) { - initparameter_b(inParameterIndex, initNames, initDefaultValue, initDefaultValue, initUnit); + initparameter_b(inParameterID, initNames, initDefaultValue, initDefaultValue, initUnit); } //----------------------------------------------------------------------------- // this is a shorcut for initializing a parameter that uses integer indexes // into an array, with an array of strings representing its values -void DfxPlugin::initparameter_list(long inParameterIndex, std::vector const& initNames, +void DfxPlugin::initparameter_list(dfx::ParameterID inParameterID, std::vector const& initNames, int64_t initValue, int64_t initDefaultValue, int64_t initNumItems, DfxParam::Unit initUnit, std::string_view initCustomUnitString) { - auto& parameter = getparameterobject(inParameterIndex); + auto& parameter = getparameterobject(inParameterID); parameter.init_i(initNames, initValue, initDefaultValue, 0, initNumItems - 1, initUnit, DfxParam::Curve::Stepped); parameter.setusevaluestrings(true); // indicate that we will use custom value display strings - initpresetsparameter(inParameterIndex); // default empty presets with this value + initpresetsparameter(inParameterID); // default empty presets with this value if (!initCustomUnitString.empty()) { parameter.setcustomunitstring(initCustomUnitString); @@ -493,94 +493,94 @@ void DfxPlugin::initparameter_list(long inParameterIndex, std::vector()); @@ -597,8 +597,8 @@ void DfxPlugin::randomizeparameter(long inParameterIndex) break; } - update_parameter(inParameterIndex); // make the host aware of the parameter change - postupdate_parameter(inParameterIndex); // inform any parameter listeners of the changes + update_parameter(inParameterID); // make the host aware of the parameter change + postupdate_parameter(inParameterID); // inform any parameter listeners of the changes } } @@ -606,7 +606,7 @@ void DfxPlugin::randomizeparameter(long inParameterIndex) // randomize all of the parameters at once void DfxPlugin::randomizeparameters() { - for (long i = 0; i < getnumparameters(); i++) + for (dfx::ParameterID i = 0; i < getnumparameters(); i++) { if (!hasparameterattribute(i, DfxParam::kAttribute_OmitFromRandomizeAll) && !hasparameterattribute(i, DfxParam::kAttribute_Unused)) { @@ -617,44 +617,44 @@ void DfxPlugin::randomizeparameters() //----------------------------------------------------------------------------- // do stuff necessary to inform the host of changes, etc. -void DfxPlugin::update_parameter(long inParameterIndex) +void DfxPlugin::update_parameter(dfx::ParameterID inParameterID) { - if (!parameterisvalid(inParameterIndex) || hasparameterattribute(inParameterIndex, DfxParam::kAttribute_Unused)) + if (!parameterisvalid(inParameterID) || hasparameterattribute(inParameterID, DfxParam::kAttribute_Unused)) { return; } #ifdef TARGET_API_AUDIOUNIT // make the global-scope element aware of the parameter's value - TARGET_API_BASE_CLASS::SetParameter(inParameterIndex, kAudioUnitScope_Global, AudioUnitElement(0), getparameter_f(inParameterIndex), 0); + TARGET_API_BASE_CLASS::SetParameter(inParameterID, kAudioUnitScope_Global, AudioUnitElement(0), getparameter_f(inParameterID), 0); #endif #ifdef TARGET_API_VST auto const vstPresetIndex = getProgram(); if ((vstPresetIndex >= 0) && presetisvalid(dfx::math::ToIndex(vstPresetIndex))) { - setpresetparameter(dfx::math::ToIndex(vstPresetIndex), inParameterIndex, getparameter(inParameterIndex)); + setpresetparameter(dfx::math::ToIndex(vstPresetIndex), inParameterID, getparameter(inParameterID)); } #if TARGET_PLUGIN_HAS_GUI // the VST2 editor interface has no real listener mechanism for parameters and therefore // always needs notification pushed in any circumstance where a parameter value changes - postupdate_parameter(inParameterIndex); + postupdate_parameter(inParameterID); #endif #endif #ifdef TARGET_API_RTAS - SetControlValue(dfx::ParameterID_ToRTAS(inParameterIndex), ConvertToDigiValue(getparameter_gen(inParameterIndex))); // XXX yeah do this? + SetControlValue(dfx::ParameterID_ToRTAS(inParameterID), ConvertToDigiValue(getparameter_gen(inParameterID))); // XXX yeah do this? #endif - parameterChanged(inParameterIndex); + parameterChanged(inParameterID); } //----------------------------------------------------------------------------- // this will broadcast a notification to anyone interested (host, GUI, etc.) // about a parameter change -void DfxPlugin::postupdate_parameter(long inParameterIndex) +void DfxPlugin::postupdate_parameter(dfx::ParameterID inParameterID) { - if (!parameterisvalid(inParameterIndex) || hasparameterattribute(inParameterIndex, DfxParam::kAttribute_Unused)) + if (!parameterisvalid(inParameterID) || hasparameterattribute(inParameterID, DfxParam::kAttribute_Unused)) { return; } @@ -663,19 +663,19 @@ void DfxPlugin::postupdate_parameter(long inParameterIndex) if (std::this_thread::get_id() == mAudioRenderThreadID) { // defer listener notification to later, off the realtime thread - mParametersChangedInProcessHavePosted[inParameterIndex].clear(std::memory_order_relaxed); + mParametersChangedInProcessHavePosted[inParameterID].clear(std::memory_order_relaxed); return; } #ifdef TARGET_API_AUDIOUNIT - AUParameterChange_TellListeners(GetComponentInstance(), inParameterIndex); + AUParameterChange_TellListeners(GetComponentInstance(), inParameterID); #endif #ifdef TARGET_API_VST #if TARGET_PLUGIN_HAS_GUI if (auto const guiEditor = dynamic_cast(getEditor())) { - guiEditor->setParameter(inParameterIndex, getparameter_gen(inParameterIndex)); + guiEditor->setParameter(dfx::ParameterID_ToVST(inParameterID), getparameter_gen(inParameterID)); } #endif #endif @@ -686,28 +686,28 @@ void DfxPlugin::postupdate_parameter(long inParameterIndex) } //----------------------------------------------------------------------------- -DfxParam::Value DfxPlugin::getparameter(long inParameterIndex) const +DfxParam::Value DfxPlugin::getparameter(dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].get(); + return mParameters[inParameterID].get(); } return {}; } //----------------------------------------------------------------------------- // return a (hopefully) 0 to 1 scalar version of the parameter's current value -double DfxPlugin::getparameter_scalar(long inParameterIndex) const +double DfxPlugin::getparameter_scalar(dfx::ParameterID inParameterID) const { - return getparameter_scalar(inParameterIndex, getparameter_f(inParameterIndex)); + return getparameter_scalar(inParameterID, getparameter_f(inParameterID)); } //----------------------------------------------------------------------------- -double DfxPlugin::getparameter_scalar(long inParameterIndex, double inValue) const +double DfxPlugin::getparameter_scalar(dfx::ParameterID inParameterID, double inValue) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - switch (getparameterunit(inParameterIndex)) + switch (getparameterunit(inParameterID)) { case DfxParam::Unit::Percent: case DfxParam::Unit::DryWetMix: @@ -716,138 +716,138 @@ double DfxPlugin::getparameter_scalar(long inParameterIndex, double inValue) con return inValue; // XXX should we not just use contractparametervalue() here? default: - return inValue / mParameters[inParameterIndex].getmax_f(); + return inValue / mParameters[inParameterID].getmax_f(); } } return 0.0; } //----------------------------------------------------------------------------- -std::optional DfxPlugin::getparameterifchanged_f(long inParameterIndex) const +std::optional DfxPlugin::getparameterifchanged_f(dfx::ParameterID inParameterID) const { - if (getparameterchanged(inParameterIndex)) + if (getparameterchanged(inParameterID)) { - return getparameter_f(inParameterIndex); + return getparameter_f(inParameterID); } return {}; } //----------------------------------------------------------------------------- -std::optional DfxPlugin::getparameterifchanged_i(long inParameterIndex) const +std::optional DfxPlugin::getparameterifchanged_i(dfx::ParameterID inParameterID) const { - if (getparameterchanged(inParameterIndex)) + if (getparameterchanged(inParameterID)) { - return getparameter_i(inParameterIndex); + return getparameter_i(inParameterID); } return {}; } //----------------------------------------------------------------------------- -std::optional DfxPlugin::getparameterifchanged_b(long inParameterIndex) const +std::optional DfxPlugin::getparameterifchanged_b(dfx::ParameterID inParameterID) const { - if (getparameterchanged(inParameterIndex)) + if (getparameterchanged(inParameterID)) { - return getparameter_b(inParameterIndex); + return getparameter_b(inParameterID); } return {}; } //----------------------------------------------------------------------------- -std::optional DfxPlugin::getparameterifchanged_scalar(long inParameterIndex) const +std::optional DfxPlugin::getparameterifchanged_scalar(dfx::ParameterID inParameterID) const { - if (getparameterchanged(inParameterIndex)) + if (getparameterchanged(inParameterID)) { - return getparameter_scalar(inParameterIndex); + return getparameter_scalar(inParameterID); } return {}; } //----------------------------------------------------------------------------- -std::optional DfxPlugin::getparameterifchanged_gen(long inParameterIndex) const +std::optional DfxPlugin::getparameterifchanged_gen(dfx::ParameterID inParameterID) const { - if (getparameterchanged(inParameterIndex)) + if (getparameterchanged(inParameterID)) { - return getparameter_gen(inParameterIndex); + return getparameter_gen(inParameterID); } return {}; } //----------------------------------------------------------------------------- -std::string DfxPlugin::getparametername(long inParameterIndex) const +std::string DfxPlugin::getparametername(dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].getname(); + return mParameters[inParameterID].getname(); } return {}; } //----------------------------------------------------------------------------- -std::string DfxPlugin::getparametername(long inParameterIndex, size_t inMaxLength) const +std::string DfxPlugin::getparametername(dfx::ParameterID inParameterID, size_t inMaxLength) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].getname(inMaxLength); + return mParameters[inParameterID].getname(inMaxLength); } return {}; } //----------------------------------------------------------------------------- -DfxParam::ValueType DfxPlugin::getparametervaluetype(long inParameterIndex) const +DfxParam::ValueType DfxPlugin::getparametervaluetype(dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].getvaluetype(); + return mParameters[inParameterID].getvaluetype(); } return DfxParam::ValueType::Float; } //----------------------------------------------------------------------------- -DfxParam::Unit DfxPlugin::getparameterunit(long inParameterIndex) const +DfxParam::Unit DfxPlugin::getparameterunit(dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].getunit(); + return mParameters[inParameterID].getunit(); } return DfxParam::Unit::Generic; } //----------------------------------------------------------------------------- -bool DfxPlugin::setparametervaluestring(long inParameterIndex, int64_t inStringIndex, std::string_view inText) +bool DfxPlugin::setparametervaluestring(dfx::ParameterID inParameterID, int64_t inStringIndex, std::string_view inText) { - return getparameterobject(inParameterIndex).setvaluestring(inStringIndex, inText); + return getparameterobject(inParameterID).setvaluestring(inStringIndex, inText); } //----------------------------------------------------------------------------- -std::optional DfxPlugin::getparametervaluestring(long inParameterIndex, int64_t inStringIndex) const +std::optional DfxPlugin::getparametervaluestring(dfx::ParameterID inParameterID, int64_t inStringIndex) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].getvaluestring(inStringIndex); + return mParameters[inParameterID].getvaluestring(inStringIndex); } return {}; } //----------------------------------------------------------------------------- -void DfxPlugin::addparametergroup(std::string const& inName, std::vector const& inParameterIndices) +void DfxPlugin::addparametergroup(std::string const& inName, std::vector const& inParameterIndices) { assert(!inName.empty()); assert(!inParameterIndices.empty()); assert(std::none_of(mParameterGroups.cbegin(), mParameterGroups.cend(), [&inName](auto const& item){ return (item.first == inName); })); assert(std::none_of(inParameterIndices.cbegin(), inParameterIndices.cend(), [this](auto index){ return getparametergroup(index).has_value(); })); assert(std::all_of(inParameterIndices.cbegin(), inParameterIndices.cend(), std::bind_front(&DfxPlugin::parameterisvalid, this))); - assert(std::unordered_set(inParameterIndices.cbegin(), inParameterIndices.cend()).size() == inParameterIndices.size()); + assert(std::unordered_set(inParameterIndices.cbegin(), inParameterIndices.cend()).size() == inParameterIndices.size()); - mParameterGroups.emplace_back(inName, std::set(inParameterIndices.cbegin(), inParameterIndices.cend())); + mParameterGroups.emplace_back(inName, std::set(inParameterIndices.cbegin(), inParameterIndices.cend())); } //----------------------------------------------------------------------------- -std::optional DfxPlugin::getparametergroup(long inParameterIndex) const +std::optional DfxPlugin::getparametergroup(dfx::ParameterID inParameterID) const { - auto const foundGroup = std::find_if(mParameterGroups.cbegin(), mParameterGroups.cend(), [inParameterIndex](auto const& group) + auto const foundGroup = std::find_if(mParameterGroups.cbegin(), mParameterGroups.cend(), [inParameterID](auto const& group) { auto const& indices = group.second; - return (indices.find(inParameterIndex) != indices.cend()); + return (indices.find(inParameterID) != indices.cend()); }); if (foundGroup != mParameterGroups.cend()) { @@ -867,67 +867,67 @@ std::string DfxPlugin::getparametergroupname(size_t inGroupIndex) const } //----------------------------------------------------------------------------- -bool DfxPlugin::getparameterchanged(long inParameterIndex) const +bool DfxPlugin::getparameterchanged(dfx::ParameterID inParameterID) const { assert(std::this_thread::get_id() == mAudioRenderThreadID); // only valid during audio rendering - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParametersChangedAsOfPreProcess[inParameterIndex]; + return mParametersChangedAsOfPreProcess[inParameterID]; } return false; } //----------------------------------------------------------------------------- -bool DfxPlugin::getparametertouched(long inParameterIndex) const +bool DfxPlugin::getparametertouched(dfx::ParameterID inParameterID) const { assert(std::this_thread::get_id() == mAudioRenderThreadID); // only valid during audio rendering - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParametersTouchedAsOfPreProcess[inParameterIndex]; + return mParametersTouchedAsOfPreProcess[inParameterID]; } return false; } //----------------------------------------------------------------------------- -bool DfxPlugin::hasparameterattribute(long inParameterIndex, DfxParam::Attribute inFlag) const +bool DfxPlugin::hasparameterattribute(dfx::ParameterID inParameterID, DfxParam::Attribute inFlag) const { assert(std::bitset(inFlag).count() == 1); - return getparameterattributes(inParameterIndex) & inFlag; + return getparameterattributes(inParameterID) & inFlag; } //----------------------------------------------------------------------------- -void DfxPlugin::addparameterattributes(long inParameterIndex, DfxParam::Attribute inFlags) +void DfxPlugin::addparameterattributes(dfx::ParameterID inParameterID, DfxParam::Attribute inFlags) { - auto& parameter = getparameterobject(inParameterIndex); + auto& parameter = getparameterobject(inParameterID); parameter.setattributes(parameter.getattributes() | inFlags); } //----------------------------------------------------------------------------- // convenience methods for expanding and contracting parameter values // using the min/max/curvetype/curvespec/etc. settings of a given parameter -double DfxPlugin::expandparametervalue(long inParameterIndex, double genValue) const +double DfxPlugin::expandparametervalue(dfx::ParameterID inParameterID, double genValue) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].expand(genValue); + return mParameters[inParameterID].expand(genValue); } return 0.0; } //----------------------------------------------------------------------------- -double DfxPlugin::contractparametervalue(long inParameterIndex, double realValue) const +double DfxPlugin::contractparametervalue(dfx::ParameterID inParameterID, double realValue) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return mParameters[inParameterIndex].contract(realValue); + return mParameters[inParameterID].contract(realValue); } return 0.0; } //----------------------------------------------------------------------------- -DfxParam& DfxPlugin::getparameterobject(long inParameterIndex) +DfxParam& DfxPlugin::getparameterobject(dfx::ParameterID inParameterID) { - assert(parameterisvalid(inParameterIndex)); - return mParameters.at(inParameterIndex); + assert(parameterisvalid(inParameterID)); + return mParameters.at(inParameterID); } @@ -977,7 +977,7 @@ bool DfxPlugin::loadpreset(size_t inPresetIndex) TARGET_API_BASE_CLASS::setProgram(dfx::math::ToSigned(inPresetIndex)); #endif - for (long i = 0; i < getnumparameters(); i++) + for (dfx::ParameterID i = 0; i < getnumparameters(); i++) { setparameter(i, getpresetparameter(inPresetIndex, i)); postupdate_parameter(i); // inform any parameter listeners of the changes @@ -1028,7 +1028,7 @@ void DfxPlugin::postupdate_preset() //----------------------------------------------------------------------------- // default all empty (no name) presets with the current value of a parameter -void DfxPlugin::initpresetsparameter(long inParameterIndex) +void DfxPlugin::initpresetsparameter(dfx::ParameterID inParameterID) { // first fill in the presets with the init settings // so that there are no "stale" unset values @@ -1036,97 +1036,97 @@ void DfxPlugin::initpresetsparameter(long inParameterIndex) { if (!presetnameisvalid(i)) // only if it's an "empty" preset { - setpresetparameter(i, inParameterIndex, getparameter(inParameterIndex)); + setpresetparameter(i, inParameterID, getparameter(inParameterID)); } } } //----------------------------------------------------------------------------- -DfxParam::Value DfxPlugin::getpresetparameter(size_t inPresetIndex, long inParameterIndex) const +DfxParam::Value DfxPlugin::getpresetparameter(size_t inPresetIndex, dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - return mPresets[inPresetIndex].getvalue(inParameterIndex); + return mPresets[inPresetIndex].getvalue(inParameterID); } return {}; } //----------------------------------------------------------------------------- -double DfxPlugin::getpresetparameter_f(size_t inPresetIndex, long inParameterIndex) const +double DfxPlugin::getpresetparameter_f(size_t inPresetIndex, dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - return mParameters[inParameterIndex].derive_f(mPresets[inPresetIndex].getvalue(inParameterIndex)); + return mParameters[inParameterID].derive_f(mPresets[inPresetIndex].getvalue(inParameterID)); } return 0.0; } //----------------------------------------------------------------------------- -int64_t DfxPlugin::getpresetparameter_i(size_t inPresetIndex, long inParameterIndex) const +int64_t DfxPlugin::getpresetparameter_i(size_t inPresetIndex, dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - return mParameters[inParameterIndex].derive_i(mPresets[inPresetIndex].getvalue(inParameterIndex)); + return mParameters[inParameterID].derive_i(mPresets[inPresetIndex].getvalue(inParameterID)); } return 0; } //----------------------------------------------------------------------------- -bool DfxPlugin::getpresetparameter_b(size_t inPresetIndex, long inParameterIndex) const +bool DfxPlugin::getpresetparameter_b(size_t inPresetIndex, dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - return mParameters[inParameterIndex].derive_b(mPresets[inPresetIndex].getvalue(inParameterIndex)); + return mParameters[inParameterID].derive_b(mPresets[inPresetIndex].getvalue(inParameterID)); } return false; } //----------------------------------------------------------------------------- -void DfxPlugin::setpresetparameter(size_t inPresetIndex, long inParameterIndex, DfxParam::Value inValue) +void DfxPlugin::setpresetparameter(size_t inPresetIndex, dfx::ParameterID inParameterID, DfxParam::Value inValue) { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - mPresets[inPresetIndex].setvalue(inParameterIndex, inValue); + mPresets[inPresetIndex].setvalue(inParameterID, inValue); } } //----------------------------------------------------------------------------- -void DfxPlugin::setpresetparameter_f(size_t inPresetIndex, long inParameterIndex, double inValue) +void DfxPlugin::setpresetparameter_f(size_t inPresetIndex, dfx::ParameterID inParameterID, double inValue) { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - auto const paramValue = mParameters[inParameterIndex].pack_f(inValue); - mPresets[inPresetIndex].setvalue(inParameterIndex, paramValue); + auto const paramValue = mParameters[inParameterID].pack_f(inValue); + mPresets[inPresetIndex].setvalue(inParameterID, paramValue); } } //----------------------------------------------------------------------------- -void DfxPlugin::setpresetparameter_i(size_t inPresetIndex, long inParameterIndex, int64_t inValue) +void DfxPlugin::setpresetparameter_i(size_t inPresetIndex, dfx::ParameterID inParameterID, int64_t inValue) { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - auto const paramValue = mParameters[inParameterIndex].pack_i(inValue); - mPresets[inPresetIndex].setvalue(inParameterIndex, paramValue); + auto const paramValue = mParameters[inParameterID].pack_i(inValue); + mPresets[inPresetIndex].setvalue(inParameterID, paramValue); } } //----------------------------------------------------------------------------- -void DfxPlugin::setpresetparameter_b(size_t inPresetIndex, long inParameterIndex, bool inValue) +void DfxPlugin::setpresetparameter_b(size_t inPresetIndex, dfx::ParameterID inParameterID, bool inValue) { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - auto const paramValue = mParameters[inParameterIndex].pack_b(inValue); - mPresets[inPresetIndex].setvalue(inParameterIndex, paramValue); + auto const paramValue = mParameters[inParameterID].pack_b(inValue); + mPresets[inPresetIndex].setvalue(inParameterID, paramValue); } } //----------------------------------------------------------------------------- -void DfxPlugin::setpresetparameter_gen(size_t inPresetIndex, long inParameterIndex, double inValue) +void DfxPlugin::setpresetparameter_gen(size_t inPresetIndex, dfx::ParameterID inParameterID, double inValue) { - if (parameterisvalid(inParameterIndex) && presetisvalid(inPresetIndex)) + if (parameterisvalid(inParameterID) && presetisvalid(inPresetIndex)) { - auto const paramValue = mParameters[inParameterIndex].pack_f(expandparametervalue(inParameterIndex, inValue)); - mPresets[inPresetIndex].setvalue(inParameterIndex, paramValue); + auto const paramValue = mParameters[inParameterID].pack_f(expandparametervalue(inParameterID, inValue)); + mPresets[inPresetIndex].setvalue(inParameterID, paramValue); } } @@ -1988,21 +1988,21 @@ void DfxPlugin::do_processparameters() #if TARGET_PLUGIN_USES_DSPCORE //----------------------------------------------------------------------------- -double DfxPlugin::getdspcoreparameter_gen(long inParameterIndex) const +double DfxPlugin::getdspcoreparameter_gen(dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - return contractparametervalue(inParameterIndex, mParameters[inParameterIndex].derive_f(mDSPCoreParameterValuesCache[inParameterIndex])); + return contractparametervalue(inParameterID, mParameters[inParameterID].derive_f(mDSPCoreParameterValuesCache[inParameterID])); } return 0.; } //----------------------------------------------------------------------------- -double DfxPlugin::getdspcoreparameter_scalar(long inParameterIndex) const +double DfxPlugin::getdspcoreparameter_scalar(dfx::ParameterID inParameterID) const { - if (parameterisvalid(inParameterIndex)) + if (parameterisvalid(inParameterID)) { - getparameter_scalar(inParameterIndex, mParameters[inParameterIndex].derive_f(mDSPCoreParameterValuesCache[inParameterIndex])); + getparameter_scalar(inParameterID, mParameters[inParameterID].derive_f(mDSPCoreParameterValuesCache[inParameterID])); } return 0.; } @@ -2108,27 +2108,27 @@ fprintf(stderr, "program change: program num = %d, channel = %d, sample offset } //----------------------------------------------------------------------------- -void DfxPlugin::setmidilearner(long inParameterIndex) +void DfxPlugin::setmidilearner(dfx::ParameterID inParameterID) { - if (auto const assignmentData = settings_getLearningAssignData(inParameterIndex)) + if (auto const assignmentData = settings_getLearningAssignData(inParameterID)) { - mDfxSettings->setLearner(inParameterIndex, assignmentData->mEventBehaviorFlags, + mDfxSettings->setLearner(inParameterID, assignmentData->mEventBehaviorFlags, assignmentData->mDataInt1, assignmentData->mDataInt2, assignmentData->mDataFloat1, assignmentData->mDataFloat2); } - else if (getparametervaluetype(inParameterIndex) == DfxParam::ValueType::Float) + else if (getparametervaluetype(inParameterID) == DfxParam::ValueType::Float) { - mDfxSettings->setLearner(inParameterIndex); + mDfxSettings->setLearner(inParameterID); } else { - auto const numStates = getparametermax_i(inParameterIndex) - getparametermin_i(inParameterIndex) + 1; - mDfxSettings->setLearner(inParameterIndex, dfx::kMidiEventBehaviorFlag_Toggle, numStates); + auto const numStates = getparametermax_i(inParameterID) - getparametermin_i(inParameterID) + 1; + mDfxSettings->setLearner(inParameterID, dfx::kMidiEventBehaviorFlag_Toggle, numStates); } } //----------------------------------------------------------------------------- -long DfxPlugin::getmidilearner() const +dfx::ParameterID DfxPlugin::getmidilearner() const { return mDfxSettings->getLearner(); } @@ -2152,26 +2152,26 @@ void DfxPlugin::resetmidilearn() } //----------------------------------------------------------------------------- -void DfxPlugin::setparametermidiassignment(long inParameterIndex, dfx::ParameterAssignment const& inAssignment) +void DfxPlugin::setparametermidiassignment(dfx::ParameterID inParameterID, dfx::ParameterAssignment const& inAssignment) { if (inAssignment.mEventType == dfx::MidiEventType::None) { - mDfxSettings->unassignParam(inParameterIndex); + mDfxSettings->unassignParameter(inParameterID); } else { - mDfxSettings->assignParam(inParameterIndex, inAssignment.mEventType, inAssignment.mEventChannel, - inAssignment.mEventNum, inAssignment.mEventNum2, - inAssignment.mEventBehaviorFlags, - inAssignment.mDataInt1, inAssignment.mDataInt2, - inAssignment.mDataFloat1, inAssignment.mDataFloat2); + mDfxSettings->assignParameter(inParameterID, inAssignment.mEventType, inAssignment.mEventChannel, + inAssignment.mEventNum, inAssignment.mEventNum2, + inAssignment.mEventBehaviorFlags, + inAssignment.mDataInt1, inAssignment.mDataInt2, + inAssignment.mDataFloat1, inAssignment.mDataFloat2); } } //----------------------------------------------------------------------------- -dfx::ParameterAssignment DfxPlugin::getparametermidiassignment(long inParameterIndex) const +dfx::ParameterAssignment DfxPlugin::getparametermidiassignment(dfx::ParameterID inParameterID) const { - return mDfxSettings->getParameterAssignment(inParameterIndex); + return mDfxSettings->getParameterAssignment(inParameterID); } //----------------------------------------------------------------------------- diff --git a/dfx-library/dfxplugin.h b/dfx-library/dfxplugin.h index 09b0b34e..a0fc4cb0 100644 --- a/dfx-library/dfxplugin.h +++ b/dfx-library/dfxplugin.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our class for E-Z plugin-making and E-Z multiple-API support. @@ -212,7 +212,7 @@ class DfxPlugin : public TARGET_API_BASE_CLASS double mSamplesToNextBar = 0.; bool mSamplesToNextBarIsValid = false; - bool mPlaybackChanged = false; // whether or not the playback state or position just changed + bool mPlaybackChanged = false; // whether the playback state or position changed since the last audio render cycle bool mPlaybackIsOccurring = false; }; @@ -264,186 +264,186 @@ class DfxPlugin : public TARGET_API_BASE_CLASS { return mPresets.size(); } - bool parameterisvalid(long inParameterIndex) const noexcept + bool parameterisvalid(dfx::ParameterID inParameterID) const noexcept { - return (inParameterIndex >= 0) && (static_cast(inParameterIndex) < getnumparameters()); + return (inParameterID != dfx::kParameterID_Invalid) && (inParameterID < getnumparameters()); } // Initialize parameters of double, int64, bool, or list type. (See dfxparameter.h) // initNames gives different names for the parameter (not the values); each name must // be a different length and could be used in different contexts (e.g. a control surface // may only have room for 4 characters). The longest one is assumed to be the best name. - void initparameter_f(long inParameterIndex, std::vector const& initNames, + void initparameter_f(dfx::ParameterID inParameterID, std::vector const& initNames, double initValue, double initDefaultValue, double initMin, double initMax, DfxParam::Unit initUnit = DfxParam::Unit::Generic, DfxParam::Curve initCurve = DfxParam::Curve::Linear, std::string_view initCustomUnitString = {}); - void initparameter_i(long inParameterIndex, std::vector const& initNames, + void initparameter_i(dfx::ParameterID inParameterID, std::vector const& initNames, int64_t initValue, int64_t initDefaultValue, int64_t initMin, int64_t initMax, DfxParam::Unit initUnit = DfxParam::Unit::Generic, DfxParam::Curve initCurve = DfxParam::Curve::Stepped, std::string_view initCustomUnitString = {}); - void initparameter_b(long inParameterIndex, std::vector const& initNames, + void initparameter_b(dfx::ParameterID inParameterID, std::vector const& initNames, bool initValue, bool initDefaultValue, DfxParam::Unit initUnit = DfxParam::Unit::Generic); - void initparameter_b(long inParameterIndex, std::vector const& initNames, + void initparameter_b(dfx::ParameterID inParameterID, std::vector const& initNames, bool initDefaultValue, DfxParam::Unit initUnit = DfxParam::Unit::Generic); - void initparameter_list(long inParameterIndex, std::vector const& initNames, + void initparameter_list(dfx::ParameterID inParameterID, std::vector const& initNames, int64_t initValue, int64_t initDefaultValue, int64_t initNumItems, DfxParam::Unit initUnit = DfxParam::Unit::List, std::string_view initCustomUnitString = {}); - void setparameterusevaluestrings(long inParameterIndex, bool inMode = true) + void setparameterusevaluestrings(dfx::ParameterID inParameterID, bool inMode = true) { - getparameterobject(inParameterIndex).setusevaluestrings(inMode); + getparameterobject(inParameterID).setusevaluestrings(inMode); } - bool getparameterusevaluestrings(long inParameterIndex) const + bool getparameterusevaluestrings(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getusevaluestrings() : false; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getusevaluestrings() : false; } - bool setparametervaluestring(long inParameterIndex, int64_t inStringIndex, std::string_view inText); - std::optional getparametervaluestring(long inParameterIndex, int64_t inStringIndex) const; - std::string getparameterunitstring(long inParameterIndex) const + bool setparametervaluestring(dfx::ParameterID inParameterID, int64_t inStringIndex, std::string_view inText); + std::optional getparametervaluestring(dfx::ParameterID inParameterID, int64_t inStringIndex) const; + std::string getparameterunitstring(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getunitstring() : std::string{}; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getunitstring() : std::string{}; } - void setparametercustomunitstring(long inParameterIndex, std::string_view inText) + void setparametercustomunitstring(dfx::ParameterID inParameterID, std::string_view inText) { - getparameterobject(inParameterIndex).setcustomunitstring(inText); + getparameterobject(inParameterID).setcustomunitstring(inText); } #ifdef TARGET_API_AUDIOUNIT - CFStringRef getparametervaluecfstring(long inParameterIndex, int64_t inStringIndex) const + CFStringRef getparametervaluecfstring(dfx::ParameterID inParameterID, int64_t inStringIndex) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getvaluecfstring(inStringIndex) : nullptr; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getvaluecfstring(inStringIndex) : nullptr; } #endif - void addparametergroup(std::string const& inName, std::vector const& inParameterIndices); // TODO: C++23 use std::span? - std::optional getparametergroup(long inParameterIndex) const; + void addparametergroup(std::string const& inName, std::vector const& inParameterIndices); // TODO: C++23 use std::span? + std::optional getparametergroup(dfx::ParameterID inParameterID) const; std::string getparametergroupname(size_t inGroupIndex) const; - void setparameter_f(long inParameterIndex, double inValue); - void setparameter_i(long inParameterIndex, int64_t inValue); - void setparameter_b(long inParameterIndex, bool inValue); - void setparameter_gen(long inParameterIndex, double inValue); - void setparameterquietly_f(long inParameterIndex, double inValue); - void setparameterquietly_i(long inParameterIndex, int64_t inValue); - void setparameterquietly_b(long inParameterIndex, bool inValue); - virtual void parameterChanged(long inParameterIndex) {} + void setparameter_f(dfx::ParameterID inParameterID, double inValue); + void setparameter_i(dfx::ParameterID inParameterID, int64_t inValue); + void setparameter_b(dfx::ParameterID inParameterID, bool inValue); + void setparameter_gen(dfx::ParameterID inParameterID, double inValue); + void setparameterquietly_f(dfx::ParameterID inParameterID, double inValue); + void setparameterquietly_i(dfx::ParameterID inParameterID, int64_t inValue); + void setparameterquietly_b(dfx::ParameterID inParameterID, bool inValue); + virtual void parameterChanged(dfx::ParameterID inParameterID) {} // *** - virtual void randomizeparameter(long inParameterIndex); + virtual void randomizeparameter(dfx::ParameterID inParameterID); // Randomize all parameters at once. Default implementation just loops over the // eligible parameters and calls randomizeparameter(), but this could also be // smarter (e.g. keeping the total output volume the same). virtual void randomizeparameters(); // broadcast changes to listeners (like GUI) - void postupdate_parameter(long inParameterIndex); + void postupdate_parameter(dfx::ParameterID inParameterID); - double getparameter_f(long inParameterIndex) const + double getparameter_f(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].get_f() : 0.0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].get_f() : 0.0; } - int64_t getparameter_i(long inParameterIndex) const + int64_t getparameter_i(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].get_i() : 0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].get_i() : 0; } - bool getparameter_b(long inParameterIndex) const + bool getparameter_b(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].get_b() : false; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].get_b() : false; } - double getparameter_gen(long inParameterIndex) const + double getparameter_gen(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].get_gen() : 0.0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].get_gen() : 0.0; } // return a (hopefully) 0 to 1 scalar version of the parameter's current value - double getparameter_scalar(long inParameterIndex) const; - std::optional getparameterifchanged_f(long inParameterIndex) const; - std::optional getparameterifchanged_i(long inParameterIndex) const; - std::optional getparameterifchanged_b(long inParameterIndex) const; - std::optional getparameterifchanged_scalar(long inParameterIndex) const; - std::optional getparameterifchanged_gen(long inParameterIndex) const; + double getparameter_scalar(dfx::ParameterID inParameterID) const; + std::optional getparameterifchanged_f(dfx::ParameterID inParameterID) const; + std::optional getparameterifchanged_i(dfx::ParameterID inParameterID) const; + std::optional getparameterifchanged_b(dfx::ParameterID inParameterID) const; + std::optional getparameterifchanged_scalar(dfx::ParameterID inParameterID) const; + std::optional getparameterifchanged_gen(dfx::ParameterID inParameterID) const; - double getparametermin_f(long inParameterIndex) const + double getparametermin_f(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getmin_f() : 0.0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getmin_f() : 0.0; } - int64_t getparametermin_i(long inParameterIndex) const + int64_t getparametermin_i(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getmin_i() : 0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getmin_i() : 0; } - double getparametermax_f(long inParameterIndex) const + double getparametermax_f(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getmax_f() : 0.0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getmax_f() : 0.0; } - int64_t getparametermax_i(long inParameterIndex) const + int64_t getparametermax_i(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getmax_i() : 0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getmax_i() : 0; } - double getparameterdefault_f(long inParameterIndex) const + double getparameterdefault_f(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getdefault_f() : 0.0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getdefault_f() : 0.0; } - int64_t getparameterdefault_i(long inParameterIndex) const + int64_t getparameterdefault_i(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getdefault_i() : 0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getdefault_i() : 0; } - bool getparameterdefault_b(long inParameterIndex) const + bool getparameterdefault_b(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getdefault_b() : false; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getdefault_b() : false; } - std::string getparametername(long inParameterIndex) const; - std::string getparametername(long inParameterIndex, size_t inMaxLength) const; + std::string getparametername(dfx::ParameterID inParameterID) const; + std::string getparametername(dfx::ParameterID inParameterID, size_t inMaxLength) const; #ifdef TARGET_API_AUDIOUNIT - CFStringRef getparametercfname(long inParameterIndex) const + CFStringRef getparametercfname(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getcfname() : nullptr; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getcfname() : nullptr; } #endif - DfxParam::ValueType getparametervaluetype(long inParameterIndex) const; - DfxParam::Unit getparameterunit(long inParameterIndex) const; - bool getparameterchanged(long inParameterIndex) const; // only reliable when called during processaudio - bool getparametertouched(long inParameterIndex) const; // only reliable when called during processaudio - DfxParam::Curve getparametercurve(long inParameterIndex) const + DfxParam::ValueType getparametervaluetype(dfx::ParameterID inParameterID) const; + DfxParam::Unit getparameterunit(dfx::ParameterID inParameterID) const; + bool getparameterchanged(dfx::ParameterID inParameterID) const; // only reliable when called during processaudio + bool getparametertouched(dfx::ParameterID inParameterID) const; // only reliable when called during processaudio + DfxParam::Curve getparametercurve(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getcurve() : DfxParam::Curve::Linear; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getcurve() : DfxParam::Curve::Linear; } - void setparametercurve(long inParameterIndex, DfxParam::Curve inCurve) + void setparametercurve(dfx::ParameterID inParameterID, DfxParam::Curve inCurve) { - getparameterobject(inParameterIndex).setcurve(inCurve); + getparameterobject(inParameterID).setcurve(inCurve); } - double getparametercurvespec(long inParameterIndex) const + double getparametercurvespec(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getcurvespec() : 0.0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getcurvespec() : 0.0; } - void setparametercurvespec(long inParameterIndex, double inCurveSpec) + void setparametercurvespec(dfx::ParameterID inParameterID, double inCurveSpec) { - getparameterobject(inParameterIndex).setcurvespec(inCurveSpec); + getparameterobject(inParameterID).setcurvespec(inCurveSpec); } - bool getparameterenforcevaluelimits(long inParameterIndex) const + bool getparameterenforcevaluelimits(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].GetEnforceValueLimits() : false; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].GetEnforceValueLimits() : false; } - void setparameterenforcevaluelimits(long inParameterIndex, bool inMode) + void setparameterenforcevaluelimits(dfx::ParameterID inParameterID, bool inMode) { - getparameterobject(inParameterIndex).SetEnforceValueLimits(inMode); + getparameterobject(inParameterID).SetEnforceValueLimits(inMode); } - DfxParam::Attribute getparameterattributes(long inParameterIndex) const + DfxParam::Attribute getparameterattributes(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].getattributes() : 0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].getattributes() : 0; } - bool hasparameterattribute(long inParameterIndex, DfxParam::Attribute inFlag) const; - void setparameterattributes(long inParameterIndex, DfxParam::Attribute inFlags) + bool hasparameterattribute(dfx::ParameterID inParameterID, DfxParam::Attribute inFlag) const; + void setparameterattributes(dfx::ParameterID inParameterID, DfxParam::Attribute inFlags) { - getparameterobject(inParameterIndex).setattributes(inFlags); + getparameterobject(inParameterID).setattributes(inFlags); } - void addparameterattributes(long inParameterIndex, DfxParam::Attribute inFlags); + void addparameterattributes(dfx::ParameterID inParameterID, DfxParam::Attribute inFlags); // convenience methods for expanding and contracting parameter values // using the min/max/curvetype/curvespec/etc. settings of a given parameter - double expandparametervalue(long inParameterIndex, double genValue) const; - double contractparametervalue(long inParameterIndex, double realValue) const; + double expandparametervalue(dfx::ParameterID inParameterID, double genValue) const; + double contractparametervalue(dfx::ParameterID inParameterID, double realValue) const; // whether or not the index is a valid preset bool presetisvalid(size_t inPresetIndex) const noexcept; @@ -453,7 +453,7 @@ class DfxPlugin : public TARGET_API_BASE_CLASS virtual bool loadpreset(size_t inPresetIndex); // set a parameter value in all of the empty (no name) presets // to the current value of that parameter - void initpresetsparameter(long inParameterIndex); + void initpresetsparameter(dfx::ParameterID inParameterID); // set the text of a preset name void setpresetname(size_t inPresetIndex, std::string_view inText); // get a copy of the text of a preset name @@ -465,14 +465,14 @@ class DfxPlugin : public TARGET_API_BASE_CLASS { return mCurrentPresetNum; } - void setpresetparameter_f(size_t inPresetIndex, long inParameterIndex, double inValue); - void setpresetparameter_i(size_t inPresetIndex, long inParameterIndex, int64_t inValue); - void setpresetparameter_b(size_t inPresetIndex, long inParameterIndex, bool inValue); - void setpresetparameter_gen(size_t inPresetIndex, long inParameterIndex, double inValue); + void setpresetparameter_f(size_t inPresetIndex, dfx::ParameterID inParameterID, double inValue); + void setpresetparameter_i(size_t inPresetIndex, dfx::ParameterID inParameterID, int64_t inValue); + void setpresetparameter_b(size_t inPresetIndex, dfx::ParameterID inParameterID, bool inValue); + void setpresetparameter_gen(size_t inPresetIndex, dfx::ParameterID inParameterID, double inValue); void postupdate_preset(); - double getpresetparameter_f(size_t inPresetIndex, long inParameterIndex) const; - int64_t getpresetparameter_i(size_t inPresetIndex, long inParameterIndex) const; - bool getpresetparameter_b(size_t inPresetIndex, long inParameterIndex) const; + double getpresetparameter_f(size_t inPresetIndex, dfx::ParameterID inParameterID) const; + int64_t getpresetparameter_i(size_t inPresetIndex, dfx::ParameterID inParameterID) const; + bool getpresetparameter_b(size_t inPresetIndex, dfx::ParameterID inParameterID) const; bool settingsMinimalValidate(void const* inData, size_t inBufferSize) const noexcept; @@ -582,13 +582,13 @@ class DfxPlugin : public TARGET_API_BASE_CLASS virtual void handlemidi_cc(int inChannel, int inControllerNum, int inValue, size_t inOffsetFrames); virtual void handlemidi_programchange(int inChannel, int inProgramNum, size_t inOffsetFrames); - void setmidilearner(long inParameterIndex); - long getmidilearner() const; + void setmidilearner(dfx::ParameterID inParameterID); + dfx::ParameterID getmidilearner() const; void setmidilearning(bool inLearnMode); bool getmidilearning() const; void resetmidilearn(); - void setparametermidiassignment(long inParameterIndex, dfx::ParameterAssignment const& inAssignment); - dfx::ParameterAssignment getparametermidiassignment(long inParameterIndex) const; + void setparametermidiassignment(dfx::ParameterID inParameterID, dfx::ParameterAssignment const& inAssignment); + dfx::ParameterAssignment getparametermidiassignment(dfx::ParameterID inParameterID) const; void setMidiAssignmentsUseChannel(bool inEnable); bool getMidiAssignmentsUseChannel() const; void setMidiAssignmentsSteal(bool inEnable); @@ -621,17 +621,17 @@ class DfxPlugin : public TARGET_API_BASE_CLASS // it's the version number of the plugin that created the data) // (presetNum of -1 indicates that we're just working with the current // state of the plugin) - virtual void settings_doChunkRestoreSetParameterStuff(long tag, float value, unsigned int dataVersion, std::optional presetIndex) {} + virtual void settings_doChunkRestoreSetParameterStuff(dfx::ParameterID parameterID, float value, unsigned int dataVersion, std::optional presetIndex) {} // // these can be overridden to do something and extend the MIDI event processing - virtual void settings_doLearningAssignStuff(long tag, dfx::MidiEventType eventType, int eventChannel, + virtual void settings_doLearningAssignStuff(dfx::ParameterID parameterID, dfx::MidiEventType eventType, int eventChannel, int eventNum, size_t offsetFrames, int eventNum2 = 0, dfx::MidiEventBehaviorFlags eventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None, int data1 = 0, int data2 = 0, float fdata1 = 0.0f, float fdata2 = 0.0f) {} - virtual void settings_doMidiAutomatedSetParameterStuff(long tag, float value, size_t offsetFrames) {} + virtual void settings_doMidiAutomatedSetParameterStuff(dfx::ParameterID parameterID, float value, size_t offsetFrames) {} // HACK: the return type is overloaded for this purpose, contains more data than used in this context - virtual std::optional settings_getLearningAssignData(long inParameterIndex) const + virtual std::optional settings_getLearningAssignData(dfx::ParameterID inParameterID) const { return {}; } @@ -642,20 +642,20 @@ class DfxPlugin : public TARGET_API_BASE_CLASS #endif #if TARGET_PLUGIN_USES_DSPCORE - double getdspcoreparameter_f(long inParameterIndex) const + double getdspcoreparameter_f(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].derive_f(mDSPCoreParameterValuesCache[inParameterIndex]) : 0.; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].derive_f(mDSPCoreParameterValuesCache[inParameterID]) : 0.; } - int64_t getdspcoreparameter_i(long inParameterIndex) const + int64_t getdspcoreparameter_i(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].derive_i(mDSPCoreParameterValuesCache[inParameterIndex]) : 0; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].derive_i(mDSPCoreParameterValuesCache[inParameterID]) : 0; } - bool getdspcoreparameter_b(long inParameterIndex) const + bool getdspcoreparameter_b(dfx::ParameterID inParameterID) const { - return parameterisvalid(inParameterIndex) ? mParameters[inParameterIndex].derive_b(mDSPCoreParameterValuesCache[inParameterIndex]) : false; + return parameterisvalid(inParameterID) ? mParameters[inParameterID].derive_b(mDSPCoreParameterValuesCache[inParameterID]) : false; } - double getdspcoreparameter_gen(long inParameterIndex) const; - double getdspcoreparameter_scalar(long inParameterIndex) const; + double getdspcoreparameter_gen(dfx::ParameterID inParameterID) const; + double getdspcoreparameter_scalar(dfx::ParameterID inParameterID) const; #endif // handling of AU properties specific to Logic @@ -753,16 +753,16 @@ class DfxPlugin : public TARGET_API_BASE_CLASS private: - DfxParam& getparameterobject(long inParameterIndex); + DfxParam& getparameterobject(dfx::ParameterID inParameterID); - void setparameter(long inParameterIndex, DfxParam::Value inValue); - DfxParam::Value getparameter(long inParameterIndex) const; - double getparameter_scalar(long inParameterIndex, double inValue) const; + void setparameter(dfx::ParameterID inParameterID, DfxParam::Value inValue); + DfxParam::Value getparameter(dfx::ParameterID inParameterID) const; + double getparameter_scalar(dfx::ParameterID inParameterID, double inValue) const; // synchronize the underlying API/preset/etc. parameter value representation to the current value in DfxPlugin - void update_parameter(long inParameterIndex); + void update_parameter(dfx::ParameterID inParameterID); - void setpresetparameter(size_t inPresetIndex, long inParameterIndex, DfxParam::Value inValue); - DfxParam::Value getpresetparameter(size_t inPresetIndex, long inParameterIndex) const; + void setpresetparameter(size_t inPresetIndex, dfx::ParameterID inParameterID, DfxParam::Value inValue); + DfxParam::Value getpresetparameter(size_t inPresetIndex, dfx::ParameterID inParameterID) const; bool ischannelcountsupported(size_t inNumInputs, size_t inNumOutputs) const; @@ -772,7 +772,7 @@ class DfxPlugin : public TARGET_API_BASE_CLASS // the effect owns a single random engine shared by all parameters rather than each parameter owning its own for efficiency, because its state data can be quite large dfx::math::RandomEngine mParameterRandomEngine {dfx::math::RandomSeed::Entropic}; dfx::SpinLock mParameterRandomEngineLock; - std::vector>> mParameterGroups; + std::vector>> mParameterGroups; std::vector mPresets; std::atomic_flag mPresetChangedInProcessHasPosted; @@ -1043,9 +1043,9 @@ class DfxPlugin : public TARGET_API_BASE_CLASS #endif // AU->RTAS glue convenience functions - double GetParameter_f_FromRTAS(long inParameterID); - int64_t GetParameter_i_FromRTAS(long inParameterID); - bool GetParameter_b_FromRTAS(long inParameterID); + double GetParameter_f_FromRTAS(dfx::ParameterID inParameterID); + int64_t GetParameter_i_FromRTAS(dfx::ParameterID inParameterID); + bool GetParameter_b_FromRTAS(dfx::ParameterID inParameterID); #if TARGET_PLUGIN_HAS_GUI void SetViewPort(GrafPtr inPort) final; @@ -1153,65 +1153,65 @@ class DfxPluginCore { return static_cast(mSampleRate); } - double getparameter_f(long inParameterIndex) const + double getparameter_f(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getdspcoreparameter_f(inParameterIndex); + return mDfxPlugin->getdspcoreparameter_f(inParameterID); } - int64_t getparameter_i(long inParameterIndex) const + int64_t getparameter_i(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getdspcoreparameter_i(inParameterIndex); + return mDfxPlugin->getdspcoreparameter_i(inParameterID); } - bool getparameter_b(long inParameterIndex) const + bool getparameter_b(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getdspcoreparameter_b(inParameterIndex); + return mDfxPlugin->getdspcoreparameter_b(inParameterID); } - double getparameter_scalar(long inParameterIndex) const + double getparameter_scalar(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getdspcoreparameter_scalar(inParameterIndex); + return mDfxPlugin->getdspcoreparameter_scalar(inParameterID); } - double getparameter_gen(long inParameterIndex) const + double getparameter_gen(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getdspcoreparameter_gen(inParameterIndex); + return mDfxPlugin->getdspcoreparameter_gen(inParameterID); } - std::optional getparameterifchanged_f(long inParameterIndex) const + std::optional getparameterifchanged_f(dfx::ParameterID inParameterID) const { - return getparameterchanged(inParameterIndex) ? std::make_optional(getparameter_f(inParameterIndex)) : std::nullopt; + return getparameterchanged(inParameterID) ? std::make_optional(getparameter_f(inParameterID)) : std::nullopt; } - std::optional getparameterifchanged_i(long inParameterIndex) const + std::optional getparameterifchanged_i(dfx::ParameterID inParameterID) const { - return getparameterchanged(inParameterIndex) ? std::make_optional(getparameter_i(inParameterIndex)) : std::nullopt; + return getparameterchanged(inParameterID) ? std::make_optional(getparameter_i(inParameterID)) : std::nullopt; } - std::optional getparameterifchanged_b(long inParameterIndex) const + std::optional getparameterifchanged_b(dfx::ParameterID inParameterID) const { - return getparameterchanged(inParameterIndex) ? std::make_optional(getparameter_b(inParameterIndex)) : std::nullopt; + return getparameterchanged(inParameterID) ? std::make_optional(getparameter_b(inParameterID)) : std::nullopt; } - std::optional getparameterifchanged_gen(long inParameterIndex) const + std::optional getparameterifchanged_gen(dfx::ParameterID inParameterID) const { - return getparameterchanged(inParameterIndex) ? std::make_optional(getparameter_gen(inParameterIndex)) : std::nullopt; + return getparameterchanged(inParameterID) ? std::make_optional(getparameter_gen(inParameterID)) : std::nullopt; } - std::optional getparameterifchanged_scalar(long inParameterIndex) const + std::optional getparameterifchanged_scalar(dfx::ParameterID inParameterID) const { - return getparameterchanged(inParameterIndex) ? std::make_optional(getparameter_scalar(inParameterIndex)) : std::nullopt; + return getparameterchanged(inParameterID) ? std::make_optional(getparameter_scalar(inParameterID)) : std::nullopt; } - double getparametermin_f(long inParameterIndex) const + double getparametermin_f(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getparametermin_f(inParameterIndex); + return mDfxPlugin->getparametermin_f(inParameterID); } - int64_t getparametermin_i(long inParameterIndex) const + int64_t getparametermin_i(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getparametermin_i(inParameterIndex); + return mDfxPlugin->getparametermin_i(inParameterID); } - double getparametermax_f(long inParameterIndex) const + double getparametermax_f(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getparametermax_f(inParameterIndex); + return mDfxPlugin->getparametermax_f(inParameterID); } - int64_t getparametermax_i(long inParameterIndex) const + int64_t getparametermax_i(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getparametermax_i(inParameterIndex); + return mDfxPlugin->getparametermax_i(inParameterID); } - bool getparameterchanged(long inParameterIndex) const + bool getparameterchanged(dfx::ParameterID inParameterID) const { - return mDfxPlugin->getparameterchanged(inParameterIndex); + return mDfxPlugin->getparameterchanged(inParameterID); } void registerSmoothedAudioValue(dfx::ISmoothedValue* smoothedValue) { diff --git a/dfx-library/dfxsettings.cpp b/dfx-library/dfxsettings.cpp index cc67383e..e0fe7af6 100644 --- a/dfx-library/dfxsettings.cpp +++ b/dfx-library/dfxsettings.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. Welcome to our settings persistence mess. @@ -59,17 +59,17 @@ DfxSettings::DfxSettings(uint32_t inMagic, DfxPlugin* inPlugin, size_t inSizeofE mNumParameters(std::max(inPlugin->getnumparameters(), size_t(1))), // we need at least one parameter mNumPresets(std::max(inPlugin->getnumpresets(), size_t(1))), // we need at least one set of parameters mSizeOfExtendedData(inSizeofExtendedData), - mParameterIDs(mNumParameters, dfx::kParameterID_Invalid), + mParameterIDMap(mNumParameters, dfx::kParameterID_Invalid), mParameterAssignments(mNumParameters) { assert(inPlugin); // default to each parameter having its ID equal its index - std::iota(mParameterIDs.begin(), mParameterIDs.end(), 0); + std::iota(mParameterIDMap.begin(), mParameterIDMap.end(), 0); // calculate some data sizes that are useful to know mSizeOfPreset = sizeof(GenPreset) + (sizeof(*GenPreset::mParameterValues) * mNumParameters) - sizeof(GenPreset::mParameterValues); - mSizeOfParameterIDs = sizeof(mParameterIDs.front()) * mNumParameters; + mSizeOfParameterIDs = sizeof(mParameterIDMap.front()) * mNumParameters; mSizeOfPresetChunk = mSizeOfPreset // 1 preset + sizeof(SettingsInfo) // the special data header info + mSizeOfParameterIDs // the table of parameter IDs @@ -131,13 +131,13 @@ std::vector DfxSettings::save(bool inIsPreset) sharedChunk->mGlobalBehaviorFlags = mSettingsInfo.mGlobalBehaviorFlags; // store the parameters' IDs - std::copy(mParameterIDs.cbegin(), mParameterIDs.cend(), firstSharedParameterID); + std::copy(mParameterIDMap.cbegin(), mParameterIDMap.cend(), firstSharedParameterID); // store only one preset setting if inIsPreset is true if (inIsPreset) { dfx::StrLCpy(firstSharedPreset->mName, mPlugin->getpresetname(mPlugin->getcurrentpresetnum()), std::size(firstSharedPreset->mName)); - for (size_t i = 0; i < mNumParameters; i++) + for (dfx::ParameterID i = 0; i < mNumParameters; i++) { firstSharedPreset->mParameterValues[i] = mPlugin->getparameter_f(i); } @@ -151,7 +151,7 @@ std::vector DfxSettings::save(bool inIsPreset) // copy the preset name to the chunk dfx::StrLCpy(tempSharedPresets->mName, mPlugin->getpresetname(j), std::size(tempSharedPresets->mName)); // copy all of the parameters for this preset to the chunk - for (size_t i = 0; i < mNumParameters; i++) + for (dfx::ParameterID i = 0; i < mNumParameters; i++) { tempSharedPresets->mParameterValues[i] = mPlugin->getpresetparameter_f(j, i); } @@ -319,12 +319,12 @@ try validateRange(newParameterIDs, sizeOfStoredParameterIDs, "parameter IDs"); // create a mapping table for corresponding the incoming parameters to the // destination parameters (in case the parameter IDs don't all match up) - // [ the index of paramMap is the same as our parameter tag/index and the value + // [ the index of parameterMap is the same as our parameter tag/index and the value // is the tag/index of the incoming parameter that corresponds, if any ] - std::vector paramMap(mNumParameters, dfx::kParameterID_Invalid); - for (size_t tag = 0; tag < mParameterIDs.size(); tag++) + std::vector parameterMap(mNumParameters, dfx::kParameterID_Invalid); + for (size_t i = 0; i < mParameterIDMap.size(); i++) { - paramMap[tag] = getParameterTagFromID(mParameterIDs[tag], {newParameterIDs, numStoredParameters}); + parameterMap[i] = getParameterIndexFromMap(mParameterIDMap[i], {newParameterIDs, numStoredParameters}); } // point to the next data element after the parameter IDs: the first preset name @@ -355,24 +355,24 @@ try } #endif // copy all of the parameters that we can for this preset from the chunk - for (size_t i = 0; i < paramMap.size(); i++) + for (dfx::ParameterID i = 0; i < parameterMap.size(); i++) { - auto const mappedTag = paramMap[i]; - if (mappedTag != dfx::kParameterID_Invalid) + auto const mappedParameterID = parameterMap[i]; + if ((mappedParameterID != dfx::kParameterID_Invalid) && (mappedParameterID < numStoredParameters)) { #ifdef DFX_SUPPORT_OLD_VST_SETTINGS // handle old-style generic VST 0.0 to 1.0 parameter values if (oldVST) { - mPlugin->setparameter_gen(i, newPreset->mParameterValues[mappedTag]); + mPlugin->setparameter_gen(i, newPreset->mParameterValues[mappedParameterID]); } else #endif { - mPlugin->setparameter_f(i, newPreset->mParameterValues[mappedTag]); + mPlugin->setparameter_f(i, newPreset->mParameterValues[mappedParameterID]); } // allow for additional tweaking of the stored parameter setting - mPlugin->settings_doChunkRestoreSetParameterStuff(i, newPreset->mParameterValues[mappedTag], newSettingsInfo->mVersion, {}); + mPlugin->settings_doChunkRestoreSetParameterStuff(i, newPreset->mParameterValues[mappedParameterID], newSettingsInfo->mVersion, {}); } } // point past the preset @@ -395,24 +395,24 @@ try } #endif // copy all of the parameters that we can for this preset from the chunk - for (size_t i = 0; i < paramMap.size(); i++) + for (dfx::ParameterID i = 0; i < parameterMap.size(); i++) { - auto const mappedTag = paramMap[i]; - if (mappedTag != dfx::kParameterID_Invalid) + auto const mappedParameterID = parameterMap[i]; + if ((mappedParameterID != dfx::kParameterID_Invalid) && (mappedParameterID < numStoredParameters)) { #ifdef DFX_SUPPORT_OLD_VST_SETTINGS // handle old-style generic VST 0.0 to 1.0 parameter values if (oldVST) { - mPlugin->setpresetparameter_gen(j, i, newPreset->mParameterValues[mappedTag]); + mPlugin->setpresetparameter_gen(j, i, newPreset->mParameterValues[mappedParameterID]); } else #endif { - mPlugin->setpresetparameter_f(j, i, newPreset->mParameterValues[mappedTag]); + mPlugin->setpresetparameter_f(j, i, newPreset->mParameterValues[mappedParameterID]); } // allow for additional tweaking of the stored parameter setting - mPlugin->settings_doChunkRestoreSetParameterStuff(i, newPreset->mParameterValues[mappedTag], newSettingsInfo->mVersion, j); + mPlugin->settings_doChunkRestoreSetParameterStuff(i, newPreset->mParameterValues[mappedParameterID], newSettingsInfo->mVersion, j); } } // point to the next preset in the received data array @@ -434,13 +434,13 @@ if (!(oldVST && inIsPreset)) sizeOfStoredParameterAssignments = storedParameterAssignmentSize * numStoredParameters; validateRange(newParameterAssignments, sizeOfStoredParameterAssignments, "parameter assignments"); // and load up as many of them as we can - for (size_t i = 0; i < std::min(paramMap.size(), mParameterAssignments.size()); i++) + for (size_t i = 0; i < std::min(parameterMap.size(), mParameterAssignments.size()); i++) { - auto const mappedTag = paramMap[i]; - if ((mappedTag != dfx::kParameterID_Invalid) && (mappedTag >= 0) && (dfx::math::ToUnsigned(mappedTag) < numStoredParameters)) + auto const mappedParameterID = parameterMap[i]; + if ((mappedParameterID != dfx::kParameterID_Invalid) && (mappedParameterID < numStoredParameters)) { memcpy(&(mParameterAssignments[i]), - newParameterAssignments + (dfx::math::ToUnsigned(mappedTag) * storedParameterAssignmentSize), + newParameterAssignments + (mappedParameterID * storedParameterAssignmentSize), copyParameterAssignmentSize); } } @@ -724,7 +724,7 @@ bool DfxSettings::saveMidiAssignmentsToDictionary(CFMutableDictionaryRef inDicti } size_t assignmentsFoundCount = 0; - for (long i = 0; i < static_cast(mNumParameters); i++) + for (dfx::ParameterID i = 0; i < mNumParameters; i++) { if (getParameterAssignmentType(i) != dfx::MidiEventType::None) { @@ -743,16 +743,16 @@ bool DfxSettings::saveMidiAssignmentsToDictionary(CFMutableDictionaryRef inDicti return false; } - for (size_t i = 0; i < mNumParameters; i++) + for (dfx::ParameterID i = 0; i < mNumParameters; i++) { auto const assignmentCFDictionary = dfx::MakeUniqueCFType(CFDictionaryCreateMutable(kCFAllocatorDefault, 10, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); if (assignmentCFDictionary) { - if (getParameterID(i) == dfx::kParameterID_Invalid) + if (getMappedParameterID(i) == dfx::kParameterID_Invalid) { continue; } - DFX_AddNumberToCFDictionary_i(getParameterID(i), assignmentCFDictionary.get(), kDfxSettings_ParameterIDKey); + DFX_AddNumberToCFDictionary_i(getMappedParameterID(i), assignmentCFDictionary.get(), kDfxSettings_ParameterIDKey); DFX_AddNumberToCFDictionary_i(static_cast(mParameterAssignments[i].mEventType), assignmentCFDictionary.get(), kDfxSettings_MidiAssignment_mEventTypeKey); #define ADD_ASSIGNMENT_VALUE_TO_DICT(inMember, inTypeSuffix) \ @@ -807,27 +807,27 @@ bool DfxSettings::restoreMidiAssignmentsFromDictionary(CFDictionaryRef inDiction auto const assignmentCFDictionary = static_cast(CFArrayGetValueAtIndex(assignmentsCFArray, i)); if (assignmentCFDictionary) { - auto const paramID_optional = DFX_GetNumberFromCFDictionary_i(assignmentCFDictionary, kDfxSettings_ParameterIDKey); - if (!paramID_optional) + auto const parameterID_optional = DFX_GetNumberFromCFDictionary_i(assignmentCFDictionary, kDfxSettings_ParameterIDKey); + if (!parameterID_optional) { continue; } - auto const paramTag = getParameterTagFromID(*paramID_optional); - if (!paramTagIsValid(paramTag)) + auto const parameterID = getParameterIndexFromMap(*parameterID_optional); + if (!isValidParameterID(parameterID)) { continue; } #define GET_ASSIGNMENT_VALUE_FROM_DICT(inMember, inTypeSuffix) \ { \ auto const optionalValue = DFX_GetNumberFromCFDictionary_##inTypeSuffix(assignmentCFDictionary, kDfxSettings_MidiAssignment_##inMember##Key); \ - mParameterAssignments[paramTag].inMember = static_cast(optionalValue.value_or(0)); \ - numberSuccess = optionalValue ? true : false; \ + mParameterAssignments[parameterID].inMember = static_cast(optionalValue.value_or(0)); \ + numberSuccess = optionalValue.has_value(); \ } bool numberSuccess = false; GET_ASSIGNMENT_VALUE_FROM_DICT(mEventType, i) if (!numberSuccess) { - unassignParam(paramTag); + unassignParameter(parameterID); continue; } GET_ASSIGNMENT_VALUE_FROM_DICT(mEventChannel, i) @@ -863,8 +863,8 @@ void DfxSettings::handleCC(int inMidiChannel, int inControllerNumber, int inValu return; } - handleMidi_assignParam(dfx::MidiEventType::CC, inMidiChannel, inControllerNumber, inOffsetFrames); - handleMidi_automateParams(dfx::MidiEventType::CC, inMidiChannel, inControllerNumber, inValue, inOffsetFrames); + handleMidi_assignParameter(dfx::MidiEventType::CC, inMidiChannel, inControllerNumber, inOffsetFrames); + handleMidi_automateParameters(dfx::MidiEventType::CC, inMidiChannel, inControllerNumber, inValue, inOffsetFrames); } //----------------------------------------------------------------------------------------- @@ -876,9 +876,9 @@ void DfxSettings::handleChannelAftertouch(int inMidiChannel, int inValue, size_t } constexpr int fakeEventNum = 0; // not used for this type of event - handleMidi_assignParam(dfx::MidiEventType::ChannelAftertouch, inMidiChannel, fakeEventNum, inOffsetFrames); + handleMidi_assignParameter(dfx::MidiEventType::ChannelAftertouch, inMidiChannel, fakeEventNum, inOffsetFrames); constexpr int fakeByte2 = 0; // not used for this type of event - handleMidi_automateParams(dfx::MidiEventType::ChannelAftertouch, inMidiChannel, inValue, fakeByte2, inOffsetFrames); + handleMidi_automateParameters(dfx::MidiEventType::ChannelAftertouch, inMidiChannel, inValue, fakeByte2, inOffsetFrames); } //----------------------------------------------------------------------------------------- @@ -893,8 +893,8 @@ void DfxSettings::handlePitchBend(int inMidiChannel, int inValueLSB, int inValue // type for pitchbend as it does for some other events, // and stuff below assumes that byte 2 means that constexpr int fakeEventNum = 0; - handleMidi_assignParam(dfx::MidiEventType::PitchBend, inMidiChannel, fakeEventNum, inOffsetFrames); - handleMidi_automateParams(dfx::MidiEventType::PitchBend, inMidiChannel, inValueLSB, inValueMSB, inOffsetFrames); + handleMidi_assignParameter(dfx::MidiEventType::PitchBend, inMidiChannel, fakeEventNum, inOffsetFrames); + handleMidi_automateParameters(dfx::MidiEventType::PitchBend, inMidiChannel, inValueLSB, inValueMSB, inOffsetFrames); } //----------------------------------------------------------------------------------------- @@ -905,8 +905,8 @@ void DfxSettings::handleNoteOn(int inMidiChannel, int inNoteNumber, int inVeloci return; } - handleMidi_assignParam(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inOffsetFrames); - handleMidi_automateParams(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inVelocity, inOffsetFrames, true); + handleMidi_assignParameter(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inOffsetFrames); + handleMidi_automateParameters(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inVelocity, inOffsetFrames, true); } //----------------------------------------------------------------------------------------- @@ -932,9 +932,9 @@ void DfxSettings::handleNoteOff(int inMidiChannel, int inNoteNumber, int inVeloc if (allowAssignment) { - handleMidi_assignParam(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inOffsetFrames); + handleMidi_assignParameter(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inOffsetFrames); } - handleMidi_automateParams(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inVelocity, inOffsetFrames, false); + handleMidi_automateParameters(dfx::MidiEventType::Note, inMidiChannel, inNoteNumber, inVelocity, inOffsetFrames, false); } //----------------------------------------------------------------------------------------- @@ -947,16 +947,16 @@ void DfxSettings::handleAllNotesOff(int inMidiChannel, size_t inOffsetFrames) for (int i = 0; i < DfxMidi::kNumNotes; i++) { - handleMidi_automateParams(dfx::MidiEventType::Note, inMidiChannel, i, 0, inOffsetFrames, false); + handleMidi_automateParameters(dfx::MidiEventType::Note, inMidiChannel, i, 0, inOffsetFrames, false); } } //----------------------------------------------------------------------------------------- // assign an incoming MIDI event to the learner parameter -void DfxSettings::handleMidi_assignParam(dfx::MidiEventType inEventType, int inMidiChannel, int inByte1, size_t inOffsetFrames) +void DfxSettings::handleMidi_assignParameter(dfx::MidiEventType inEventType, int inMidiChannel, int inByte1, size_t inOffsetFrames) { // we don't need to make an assignment to a parameter if MIDI learning is off - if (!mMidiLearn || !paramTagIsValid(mLearner)) + if (!mMidiLearn || !isValidParameterID(mLearner)) { return; } @@ -964,15 +964,15 @@ void DfxSettings::handleMidi_assignParam(dfx::MidiEventType inEventType, int inM auto const handleAssignment = [this, inEventType, inMidiChannel, inOffsetFrames](int eventNum, int eventNum2) { // assign the learner parameter to the event that sent the message - assignParam(mLearner, inEventType, inMidiChannel, eventNum, eventNum2, - mLearnerEventBehaviorFlags, mLearnerDataInt1, mLearnerDataInt2, - mLearnerDataFloat1, mLearnerDataFloat2); + assignParameter(mLearner, inEventType, inMidiChannel, eventNum, eventNum2, + mLearnerEventBehaviorFlags, mLearnerDataInt1, mLearnerDataInt2, + mLearnerDataFloat1, mLearnerDataFloat2); // this is an invitation to do something more, if necessary mPlugin->settings_doLearningAssignStuff(mLearner, inEventType, inMidiChannel, eventNum, inOffsetFrames, eventNum2, mLearnerEventBehaviorFlags, mLearnerDataInt1, mLearnerDataInt2, mLearnerDataFloat1, mLearnerDataFloat2); // and then deactivate the current learner, the learning is complete - setLearner(kNoLearner); + setLearner(dfx::kParameterID_Invalid); if (getDeactivateLearningUponLearnt()) { setLearning(false); @@ -1017,7 +1017,8 @@ void DfxSettings::handleMidi_assignParam(dfx::MidiEventType inEventType, int inM //----------------------------------------------------------------------------------------- // automate assigned parameters in response to a MIDI event -void DfxSettings::handleMidi_automateParams(dfx::MidiEventType inEventType, int inMidiChannel, int inByte1, int inByte2, size_t inOffsetFrames, bool inIsNoteOn) +void DfxSettings::handleMidi_automateParameters(dfx::MidiEventType inEventType, int inMidiChannel, + int inByte1, int inByte2, size_t inOffsetFrames, bool inIsNoteOn) { float valueNormalized = static_cast(inByte2) * DfxMidi::kValueScalar; if (inEventType == dfx::MidiEventType::ChannelAftertouch) @@ -1045,9 +1046,9 @@ void DfxSettings::handleMidi_automateParams(dfx::MidiEventType inEventType, int // search for parameters that have this MIDI event assigned to them and, // if any are found, automate them with the event message's value - for (size_t tag = 0; tag < mNumParameters; tag++) + for (dfx::ParameterID parameterID = 0; parameterID < mNumParameters; parameterID++) { - auto const& pa = mParameterAssignments.at(tag); + auto const& pa = mParameterAssignments.at(parameterID); // if the event type doesn't match what this parameter has assigned to it, // skip to the next parameter parameter @@ -1097,7 +1098,7 @@ void DfxSettings::handleMidi_automateParams(dfx::MidiEventType inEventType, int maxSteps = numSteps; } // get the current state of the parameter - auto currentStep = static_cast(mPlugin->getparameter_gen(tag) * (static_cast(numSteps) - 0.01f)); + auto currentStep = static_cast(mPlugin->getparameter_gen(parameterID) * (static_cast(numSteps) - 0.01f)); // cycle to the next state, wraparound if necessary (using maxSteps) currentStep = (currentStep + 1) % maxSteps; // get the 0.0 to 1.0 parameter value version of that state @@ -1143,10 +1144,10 @@ void DfxSettings::handleMidi_automateParams(dfx::MidiEventType inEventType, int } // automate the parameter with the value if we've reached this point - mPlugin->setparameter_gen(tag, valueNormalized); - mPlugin->postupdate_parameter(tag); // notify listeners of internal parameter change + mPlugin->setparameter_gen(parameterID, valueNormalized); + mPlugin->postupdate_parameter(parameterID); // notify listeners of internal parameter change // this is an invitation to do something more, if necessary - mPlugin->settings_doMidiAutomatedSetParameterStuff(tag, valueNormalized, inOffsetFrames); + mPlugin->settings_doMidiAutomatedSetParameterStuff(parameterID, valueNormalized, inOffsetFrames); } // end of parameters loop (for automation) } @@ -1157,20 +1158,20 @@ void DfxSettings::handleMidi_automateParams(dfx::MidiEventType inEventType, int // clear all parameter assignments from the the CCs void DfxSettings::clearAssignments() { - for (long i = 0; i < static_cast(mNumParameters); i++) + for (dfx::ParameterID i = 0; i < mNumParameters; i++) { - unassignParam(i); + unassignParameter(i); } } //----------------------------------------------------------------------------- // assign a CC to a parameter -void DfxSettings::assignParam(long inParamTag, dfx::MidiEventType inEventType, long inEventChannel, long inEventNum, - long inEventNum2, dfx::MidiEventBehaviorFlags inEventBehaviorFlags, - int inDataInt1, int inDataInt2, float inDataFloat1, float inDataFloat2) +void DfxSettings::assignParameter(dfx::ParameterID inParameterID, dfx::MidiEventType inEventType, int inEventChannel, + int inEventNum, int inEventNum2, dfx::MidiEventBehaviorFlags inEventBehaviorFlags, + int inDataInt1, int inDataInt2, float inDataFloat1, float inDataFloat2) { // bail if the parameter index is not valid - if (!paramTagIsValid(inParamTag)) + if (!isValidParameterID(inParameterID)) { return; } @@ -1190,7 +1191,7 @@ void DfxSettings::assignParam(long inParamTag, dfx::MidiEventType inEventType, l // parameter assignment(s) if using stealing if (mStealAssignments) { - for (size_t i = 0; i < mNumParameters; i++) + for (dfx::ParameterID i = 0; i < mNumParameters; i++) { auto const& pa = mParameterAssignments.at(i); // skip this parameter if the event type doesn't match @@ -1211,17 +1212,17 @@ void DfxSettings::assignParam(long inParamTag, dfx::MidiEventType inEventType, l // lower note overlaps with existing note assignment if ((pa.mEventNum >= inEventNum) && (pa.mEventNum <= inEventNum2)) { - unassignParam(i); + unassignParameter(i); } // upper note overlaps with existing note assignment else if ((pa.mEventNum2 >= inEventNum) && (pa.mEventNum2 <= inEventNum2)) { - unassignParam(i); + unassignParameter(i); } // current note range consumes the entire existing assignment else if ((pa.mEventNum <= inEventNum) && (pa.mEventNum2 >= inEventNum2)) { - unassignParam(i); + unassignParameter(i); } } @@ -1229,43 +1230,43 @@ void DfxSettings::assignParam(long inParamTag, dfx::MidiEventType inEventType, l // just delete the assignment if the event number matches else if (pa.mEventNum == inEventNum) { - unassignParam(i); + unassignParameter(i); } } } // then assign the event to the desired parameter - mParameterAssignments[inParamTag].mEventType = inEventType; - mParameterAssignments[inParamTag].mEventChannel = inEventChannel; - mParameterAssignments[inParamTag].mEventNum = inEventNum; - mParameterAssignments[inParamTag].mEventNum2 = inEventNum2; - mParameterAssignments[inParamTag].mEventBehaviorFlags = inEventBehaviorFlags; - mParameterAssignments[inParamTag].mDataInt1 = inDataInt1; - mParameterAssignments[inParamTag].mDataInt2 = inDataInt2; - mParameterAssignments[inParamTag].mDataFloat1 = inDataFloat1; - mParameterAssignments[inParamTag].mDataFloat2 = inDataFloat2; + mParameterAssignments[inParameterID].mEventType = inEventType; + mParameterAssignments[inParameterID].mEventChannel = inEventChannel; + mParameterAssignments[inParameterID].mEventNum = inEventNum; + mParameterAssignments[inParameterID].mEventNum2 = inEventNum2; + mParameterAssignments[inParameterID].mEventBehaviorFlags = inEventBehaviorFlags; + mParameterAssignments[inParameterID].mDataInt1 = inDataInt1; + mParameterAssignments[inParameterID].mDataInt2 = inDataInt2; + mParameterAssignments[inParameterID].mDataFloat1 = inDataFloat1; + mParameterAssignments[inParameterID].mDataFloat2 = inDataFloat2; } //----------------------------------------------------------------------------- // remove any MIDI event assignment that a parameter might have -void DfxSettings::unassignParam(long inParamTag) +void DfxSettings::unassignParameter(dfx::ParameterID inParameterID) { // return if what we got is not a valid parameter index - if (!paramTagIsValid(inParamTag)) + if (!isValidParameterID(inParameterID)) { return; } // clear the MIDI event assignment for this parameter - mParameterAssignments[inParamTag].mEventType = dfx::MidiEventType::None; - mParameterAssignments[inParamTag].mEventChannel = 0; - mParameterAssignments[inParamTag].mEventNum = 0; - mParameterAssignments[inParamTag].mEventNum2 = 0; - mParameterAssignments[inParamTag].mEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None; - mParameterAssignments[inParamTag].mDataInt1 = 0; - mParameterAssignments[inParamTag].mDataInt2 = 0; - mParameterAssignments[inParamTag].mDataFloat1 = 0.0f; - mParameterAssignments[inParamTag].mDataFloat2 = 0.0f; + mParameterAssignments[inParameterID].mEventType = dfx::MidiEventType::None; + mParameterAssignments[inParameterID].mEventChannel = 0; + mParameterAssignments[inParameterID].mEventNum = 0; + mParameterAssignments[inParameterID].mEventNum2 = 0; + mParameterAssignments[inParameterID].mEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None; + mParameterAssignments[inParameterID].mDataInt1 = 0; + mParameterAssignments[inParameterID].mDataInt2 = 0; + mParameterAssignments[inParameterID].mDataFloat1 = 0.0f; + mParameterAssignments[inParameterID].mDataFloat2 = 0.0f; } //----------------------------------------------------------------------------- @@ -1275,12 +1276,12 @@ void DfxSettings::setLearning(bool inLearnMode) // erase the current learner if the state of MIDI learn is being toggled if (inLearnMode != mMidiLearn) { - setLearner(kNoLearner); + setLearner(dfx::kParameterID_Invalid); } // or if it's being asked to be turned off, irregardless else if (!inLearnMode) { - setLearner(kNoLearner); + setLearner(dfx::kParameterID_Invalid); } mMidiLearn = inLearnMode; @@ -1288,33 +1289,27 @@ void DfxSettings::setLearning(bool inLearnMode) mPlugin->postupdate_midilearn(); } -//----------------------------------------------------------------------------- -// just an easy way to check if a particular parameter is currently a learner -bool DfxSettings::isLearner(long inParamTag) const noexcept -{ - return (inParamTag == getLearner()); -} - //----------------------------------------------------------------------------- // define the actively learning parameter during MIDI learn mode -void DfxSettings::setLearner(long inParamTag, dfx::MidiEventBehaviorFlags inEventBehaviorFlags, +void DfxSettings::setLearner(dfx::ParameterID inParameterID, dfx::MidiEventBehaviorFlags inEventBehaviorFlags, int inDataInt1, int inDataInt2, float inDataFloat1, float inDataFloat2) { // allow this invalid parameter tag, and then exit - if (inParamTag == kNoLearner) + if (inParameterID == dfx::kParameterID_Invalid) { - mLearner = kNoLearner; + mLearner = inParameterID; + mLearnerEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None; } else { // return if what we got is not a valid parameter index - if (!paramTagIsValid(inParamTag)) + if (!isValidParameterID(inParameterID)) { return; } // cancel note range assignment if we're switching to a new learner - if (mLearner != inParamTag) + if (mLearner != inParameterID) { mNoteRangeHalfwayDone = false; } @@ -1322,19 +1317,13 @@ void DfxSettings::setLearner(long inParamTag, dfx::MidiEventBehaviorFlags inEven // only set the learner if MIDI learn is on if (mMidiLearn) { - mLearner = inParamTag; + mLearner = inParameterID; mLearnerEventBehaviorFlags = inEventBehaviorFlags; mLearnerDataInt1 = inDataInt1; mLearnerDataInt2 = inDataInt2; mLearnerDataFloat1 = inDataFloat1; mLearnerDataFloat2 = inDataFloat2; } - // unless we're making it so that there's no learner, that's okay - else if (inParamTag == kNoLearner) - { - mLearner = inParamTag; - mLearnerEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None; - } } mPlugin->postupdate_midilearner(); @@ -1355,10 +1344,10 @@ void DfxSettings::setParameterMidiReset() { // if we're in MIDI learn mode and a parameter has been selected, // then erase its MIDI event assigment (if it has one) - if (mMidiLearn && (mLearner != kNoLearner)) + if (mMidiLearn && (mLearner != dfx::kParameterID_Invalid)) { - unassignParam(mLearner); - setLearner(kNoLearner); + unassignParameter(mLearner); + setLearner(dfx::kParameterID_Invalid); } // otherwise erase all of the MIDI event assignments else @@ -1375,34 +1364,34 @@ void DfxSettings::setParameterMidiReset() //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //----------------------------------------------------------------------------- -dfx::ParameterAssignment DfxSettings::getParameterAssignment(long inParamTag) const +dfx::ParameterAssignment DfxSettings::getParameterAssignment(dfx::ParameterID inParameterID) const { // return a no-assignment structure if what we got is not a valid parameter index - if (!paramTagIsValid(inParamTag)) + if (!isValidParameterID(inParameterID)) { return {}; } - return mParameterAssignments[inParamTag]; + return mParameterAssignments[inParameterID]; } //----------------------------------------------------------------------------- -dfx::MidiEventType DfxSettings::getParameterAssignmentType(long inParamTag) const +dfx::MidiEventType DfxSettings::getParameterAssignmentType(dfx::ParameterID inParameterID) const { // return no-assignment if what we got is not a valid parameter index - if (!paramTagIsValid(inParamTag)) + if (!isValidParameterID(inParameterID)) { return dfx::MidiEventType::None; } - return mParameterAssignments[inParamTag].mEventType; + return mParameterAssignments[inParameterID].mEventType; } //----------------------------------------------------------------------------- // given a parameter ID, find the tag (index) for that parameter in a table of parameter IDs -long DfxSettings::getParameterTagFromID(long inParamID, std::span inSearchIDs) +dfx::ParameterID DfxSettings::getParameterIndexFromMap(dfx::ParameterID inParameterID, std::span inSearchIDs) { - auto const foundID = std::find(inSearchIDs.begin(), inSearchIDs.end(), inParamID); + auto const foundID = std::find(inSearchIDs.begin(), inSearchIDs.end(), inParameterID); if (foundID != inSearchIDs.end()) { return std::distance(inSearchIDs.begin(), foundID); @@ -1412,9 +1401,9 @@ long DfxSettings::getParameterTagFromID(long inParamID, std::span //----------------------------------------------------------------------------- // search using the internal table -long DfxSettings::getParameterTagFromID(long inParamID) const +dfx::ParameterID DfxSettings::getParameterIndexFromMap(dfx::ParameterID inParameterID) const { - return getParameterTagFromID(inParamID, mParameterIDs); + return getParameterIndexFromMap(inParameterID, mParameterIDMap); } diff --git a/dfx-library/dfxsettings.h b/dfx-library/dfxsettings.h index 07aca9f6..17b85581 100644 --- a/dfx-library/dfxsettings.h +++ b/dfx-library/dfxsettings.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7. This is our Destroy FX plugin data storage stuff @@ -95,8 +95,6 @@ class DfxPlugin; class DfxSettings { public: - static constexpr long kNoLearner = -3; // for when no parameter is activated for learning - enum class CrisisBehavior { // crisis behaviors (what to do when restore sends an unexpected buffer size) @@ -161,23 +159,22 @@ class DfxSettings // remove MIDI event assignments from all parameters void clearAssignments(); // assign a MIDI event to a parameter - void assignParam(long inParamTag, dfx::MidiEventType inEventType, long inEventChannel, - long inEventNum, long inEventNum2 = 0, - dfx::MidiEventBehaviorFlags inEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None, - int inDataInt1 = 0, int inDataInt2 = 0, - float inDataFloat1 = 0.0f, float inDataFloat2 = 0.0f); + void assignParameter(dfx::ParameterID inParameterID, dfx::MidiEventType inEventType, int inEventChannel, + int inEventNum, int inEventNum2 = 0, + dfx::MidiEventBehaviorFlags inEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None, + int inDataInt1 = 0, int inDataInt2 = 0, + float inDataFloat1 = 0.0f, float inDataFloat2 = 0.0f); // remove a parameter's MIDI event assignment - void unassignParam(long inParamTag); + void unassignParameter(dfx::ParameterID inParameterID); // define or report the actively learning parameter during MIDI learn mode - void setLearner(long inParamTag, dfx::MidiEventBehaviorFlags inEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None, + void setLearner(dfx::ParameterID inParameterID, dfx::MidiEventBehaviorFlags inEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_None, int inDataInt1 = 0, int inDataInt2 = 0, float inDataFloat1 = 0.0f, float inDataFloat2 = 0.0f); auto getLearner() const noexcept { return mLearner.load(); } - bool isLearner(long inParamTag) const noexcept; // turn MIDI learning on or off void setLearning(bool inLearnMode); @@ -192,8 +189,8 @@ class DfxSettings void setParameterMidiReset(); // potentially useful accessors - dfx::ParameterAssignment getParameterAssignment(long inParamTag) const; - dfx::MidiEventType getParameterAssignmentType(long inParamTag) const; + dfx::ParameterAssignment getParameterAssignment(dfx::ParameterID inParameterID) const; + dfx::MidiEventType getParameterAssignmentType(dfx::ParameterID inParameterID) const; #endif // TARGET_PLUGIN_USES_MIDI @@ -225,16 +222,16 @@ class DfxSettings // creating the DfxSettings object, or at least before your plugin's // constructor returns, because you don't want any set or save calls // made before you have your parameter ID map finalized. - void setParameterID(long inParamTag, long inNewID) + void setMappedParameterID(dfx::ParameterID inParameterIndex, dfx::ParameterID inMappedParameterID) { - if (paramTagIsValid(inParamTag)) + if (isValidParameterID(inParameterIndex)) { - mParameterIDs[inParamTag] = inNewID; + mParameterIDMap[inParameterIndex] = inMappedParameterID; } } - long getParameterID(long inParamTag) const + dfx::ParameterID getMappedParameterID(dfx::ParameterID inParameterIndex) const { - return (paramTagIsValid(inParamTag)) ? mParameterIDs[inParamTag] : dfx::kParameterID_Invalid; + return (isValidParameterID(inParameterIndex)) ? mParameterIDMap[inParameterIndex] : dfx::kParameterID_Invalid; } @@ -389,17 +386,17 @@ class DfxSettings void debugAlertCorruptData(char const* inDataItemName, size_t inDataItemSize, size_t inDataTotalSize) const; // a simple but handy check to see if a parameter tag is valid - bool paramTagIsValid(long inParamTag) const noexcept + bool isValidParameterID(dfx::ParameterID inParameterID) const noexcept { - return (inParamTag >= 0) && (static_cast(inParamTag) < mNumParameters); + return (inParameterID < mNumParameters); } - static long getParameterTagFromID(long inParamID, std::span inSearchIDs); - long getParameterTagFromID(long inParamID) const; + static dfx::ParameterID getParameterIndexFromMap(dfx::ParameterID inParameterID, std::span inSearchIDs); + dfx::ParameterID getParameterIndexFromMap(dfx::ParameterID inParameterID) const; #if TARGET_PLUGIN_USES_MIDI - void handleMidi_assignParam(dfx::MidiEventType inEventType, int inMidiChannel, int inByte1, size_t inOffsetFrames); - void handleMidi_automateParams(dfx::MidiEventType inEventType, int inMidiChannel, int inByte1, int inByte2, size_t inOffsetFrames, bool inIsNoteOn = false); + void handleMidi_assignParameter(dfx::MidiEventType inEventType, int inMidiChannel, int inByte1, size_t inOffsetFrames); + void handleMidi_automateParameters(dfx::MidiEventType inEventType, int inMidiChannel, int inByte1, int inByte2, size_t inOffsetFrames, bool inIsNoteOn = false); #endif // TARGET_PLUGIN_USES_MIDI @@ -425,14 +422,14 @@ class DfxSettings // an ordered table of IDs for each parameter stored in each preset // (this is so that non-parameter-compatible plugin versions can load // settings and know which stored parameters correspond to theirs) - std::vector mParameterIDs; + std::vector mParameterIDMap; // what to do if restore() sends data with a mismatched byte size CrisisBehavior mCrisisBehavior = CrisisBehavior::LoadWhatYouCan; #if TARGET_PLUGIN_USES_MIDI std::atomic mMidiLearn {false}; // switch value for MIDI learn mode - std::atomic mLearner {kNoLearner}; // the parameter currently selected for MIDI learning + std::atomic mLearner {dfx::kParameterID_Invalid}; // the parameter currently selected for MIDI learning // the array of which MIDI event, if any, is assigned to each parameter std::vector mParameterAssignments; diff --git a/dfxgui/dfxguibutton.cpp b/dfxgui/dfxguibutton.cpp index c25d9ac1..11584a12 100644 --- a/dfxgui/dfxguibutton.cpp +++ b/dfxgui/dfxguibutton.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "dfxguibutton.h" @@ -39,9 +39,9 @@ using namespace std::placeholders; //----------------------------------------------------------------------------- // DGButton //----------------------------------------------------------------------------- -DGButton::DGButton(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, DGImage* inImage, +DGButton::DGButton(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, DGImage* inImage, Mode inMode, bool inDrawMomentaryState) -: DGControl(inRegion, inOwnerEditor, inParamID, inImage), +: DGControl(inRegion, inOwnerEditor, dfx::ParameterID_ToVST(inParameterID), inImage), mMode(inMode), mDrawMomentaryState(inDrawMomentaryState), mWraparoundValues((mMode == Mode::Increment) || (mMode == Mode::Decrement)) @@ -395,7 +395,7 @@ long DGButton::getRange() const // Toggle Button //----------------------------------------------------------------------------- DGToggleImageButton::DGToggleImageButton(DfxGuiEditor* inOwnerEditor, - long inParameterID, + dfx::ParameterID inParameterID, VSTGUI::CCoord inXpos, VSTGUI::CCoord inYpos, DGImage* inImage, bool inDrawMomentaryState) @@ -435,11 +435,11 @@ DGRect DGToggleImageButton::makeRegion(VSTGUI::CCoord inXpos, VSTGUI::CCoord inY // Fine-tune Button //----------------------------------------------------------------------------- DGFineTuneButton::DGFineTuneButton(DfxGuiEditor* inOwnerEditor, - long inParameterID, - DGRect const& inRegion, - DGImage* inImage, - float inValueChangeAmount) -: DGControl(inRegion, inOwnerEditor, inParameterID, inImage), + dfx::ParameterID inParameterID, + DGRect const& inRegion, + DGImage* inImage, + float inValueChangeAmount) +: DGControl(inRegion, inOwnerEditor, dfx::ParameterID_ToVST(inParameterID), inImage), mValueChangeAmount(inValueChangeAmount) { } @@ -554,13 +554,13 @@ void DGFineTuneButton::onMouseCancelEvent(VSTGUI::MouseCancelEvent& ioEvent) //----------------------------------------------------------------------------- // DGValueSpot //----------------------------------------------------------------------------- -DGValueSpot::DGValueSpot(DfxGuiEditor* inOwnerEditor, - long inParamID, - DGRect const& inRegion, - DGImage* inImage, - double inValue) -: DGControl(inRegion, inOwnerEditor, inParamID, inImage), - mValueToSet(inOwnerEditor->dfxgui_ContractParameterValue(inParamID, inValue)) +DGValueSpot::DGValueSpot(DfxGuiEditor* inOwnerEditor, + dfx::ParameterID inParameterID, + DGRect const& inRegion, + DGImage* inImage, + double inValue) +: DGControl(inRegion, inOwnerEditor, dfx::ParameterID_ToVST(inParameterID), inImage), + mValueToSet(inOwnerEditor->dfxgui_ContractParameterValue(inParameterID, inValue)) { setTransparency(true); } @@ -763,7 +763,7 @@ void DGWebLink::onMouseCancelEvent(VSTGUI::MouseCancelEvent& ioEvent) DGSplashScreen::DGSplashScreen(DfxGuiEditor* inOwnerEditor, DGRect const& inClickRegion, DGImage* inSplashImage) -: DGControl(inClickRegion, inOwnerEditor, dfx::kParameterID_Invalid, inSplashImage, inClickRegion) +: DGControl(inClickRegion, inOwnerEditor, dfx::ParameterID_ToVST(dfx::kParameterID_Invalid), inSplashImage, inClickRegion) { setTransparency(true); diff --git a/dfxgui/dfxguibutton.h b/dfxgui/dfxguibutton.h index 92836608..7e63d99f 100644 --- a/dfxgui/dfxguibutton.h +++ b/dfxgui/dfxguibutton.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -45,7 +45,7 @@ class DGButton : public DGControl PictureReel }; - DGButton(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, DGImage* inImage, + DGButton(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, DGImage* inImage, Mode inMode, bool inDrawMomentaryState = false); DGButton(DfxGuiEditor* inOwnerEditor, DGRect const& inRegion, DGImage* inImage, size_t inNumStates, Mode inMode, bool inDrawMomentaryState = false); @@ -107,7 +107,7 @@ class DGButton : public DGControl class DGToggleImageButton : public DGButton { public: - DGToggleImageButton(DfxGuiEditor* inOwnerEditor, long inParameterID, VSTGUI::CCoord inXpos, VSTGUI::CCoord inYpos, + DGToggleImageButton(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, VSTGUI::CCoord inXpos, VSTGUI::CCoord inYpos, DGImage* inImage, bool inDrawMomentaryState = false); DGToggleImageButton(DfxGuiEditor* inOwnerEditor, VSTGUI::CCoord inXpos, VSTGUI::CCoord inYpos, DGImage* inImage, bool inDrawMomentaryState = false); @@ -126,7 +126,7 @@ class DGToggleImageButton : public DGButton class DGFineTuneButton : public DGControl { public: - DGFineTuneButton(DfxGuiEditor* inOwnerEditor, long inParameterID, DGRect const& inRegion, + DGFineTuneButton(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, DGImage* inImage, float inValueChangeAmount = 0.0001f); void draw(VSTGUI::CDrawContext* inContext) override; @@ -149,7 +149,7 @@ class DGFineTuneButton : public DGControl class DGValueSpot : public DGControl { public: - DGValueSpot(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, DGImage* inImage, double inValue); + DGValueSpot(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, DGImage* inImage, double inValue); void draw(VSTGUI::CDrawContext* inContext) override; void onMouseDownEvent(VSTGUI::MouseDownEvent& ioEvent) override; diff --git a/dfxgui/dfxguicontrol.cpp b/dfxgui/dfxguicontrol.cpp index 3e1149bf..b83f804b 100644 --- a/dfxgui/dfxguicontrol.cpp +++ b/dfxgui/dfxguicontrol.cpp @@ -18,11 +18,13 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "dfxguicontrol.h" +#include "dfxplugin-base.h" + //----------------------------------------------------------------------------- @@ -55,7 +57,7 @@ void detail::onMouseWheelEvent(IDGControl* inControl, VSTGUI::MouseWheelEvent& i //----------------------------------------------------------------------------- DGNullControl::DGNullControl(DfxGuiEditor* inOwnerEditor, DGRect const& inRegion, DGImage* inBackgroundImage) -: DGControl(inRegion, inOwnerEditor, dfx::kParameterID_Invalid, inBackgroundImage) +: DGControl(inRegion, inOwnerEditor, dfx::ParameterID_ToVST(dfx::kParameterID_Invalid), inBackgroundImage) { setMouseEnabled(false); } diff --git a/dfxgui/dfxguicontrol.h b/dfxgui/dfxguicontrol.h index e474c951..c1819bb2 100644 --- a/dfxgui/dfxguicontrol.h +++ b/dfxgui/dfxguicontrol.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -72,8 +72,8 @@ class DGControl : public IDGControl, public T void redraw() final; - long getParameterID() const final; - void setParameterID(long inParameterID) final; + dfx::ParameterID getParameterID() const final; + void setParameterID(dfx::ParameterID inParameterID) final; bool isParameterAttached() const final; size_t getNumStates() const final @@ -230,12 +230,12 @@ class DGMultiControl : /*public IDGMultiControl,*/ public DGControl void endEdit_all(); bool isEditing_any() const; - IDGControl* getControlByParameterID(long inParameterID); + IDGControl* getControlByParameterID(dfx::ParameterID inParameterID); protected: - IDGControl* addChild(long inParameterID); + IDGControl* addChild(dfx::ParameterID inParameterID); // TODO: C++23 use std::span? - void addChildren(std::vector const& inParameterID); + void addChildren(std::vector const& inParameterID); template void forEachChild(Proc inProc); @@ -246,7 +246,7 @@ class DGMultiControl : /*public IDGMultiControl,*/ public DGControl class DGMultiControlChild final : public DGControl { public: - DGMultiControlChild(DfxGuiEditor* inOwnerEditor, DGRect const& inRegion, long inParameterID); + DGMultiControlChild(DfxGuiEditor* inOwnerEditor, DGRect const& inRegion, dfx::ParameterID inParameterID); void draw(VSTGUI::CDrawContext*) override {} CLASS_METHODS(DGMultiControlChild, VSTGUI::CControl) }; diff --git a/dfxgui/dfxguicontrol.hpp b/dfxgui/dfxguicontrol.hpp index c239dba2..9831ce2c 100644 --- a/dfxgui/dfxguicontrol.hpp +++ b/dfxgui/dfxguicontrol.hpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include @@ -29,6 +29,7 @@ To contact the author, use the contact form at http://destroyfx.org/ #include "dfxguieditor.h" #include "dfxmisc.h" +#include "dfxplugin-base.h" @@ -122,18 +123,18 @@ void DGControl::redraw() //----------------------------------------------------------------------------- template -long DGControl::getParameterID() const +dfx::ParameterID DGControl::getParameterID() const { - return T::getTag(); + return dfx::ParameterID_FromVST(T::getTag()); } //----------------------------------------------------------------------------- template -void DGControl::setParameterID(long inParameterID) +void DGControl::setParameterID(dfx::ParameterID inParameterID) { if (inParameterID != getParameterID()) { - T::setTag(inParameterID); + T::setTag(dfx::ParameterID_ToVST(inParameterID)); initValues(); T::invalidRect(T::getViewSize()); } @@ -143,7 +144,7 @@ void DGControl::setParameterID(long inParameterID) template bool DGControl::isParameterAttached() const { - return (getParameterID() >= 0); + return (getParameterID() != dfx::kParameterID_Invalid); } //----------------------------------------------------------------------------- @@ -269,10 +270,10 @@ void DGControl::pullNumStatesFromParameter() if (isParameterAttached() && mOwnerEditor) { size_t numStates = 0; - auto const paramID = getParameterID(); - if (mOwnerEditor->GetParameterValueType(paramID) != DfxParam::ValueType::Float) + auto const parameterID = getParameterID(); + if (mOwnerEditor->GetParameterValueType(parameterID) != DfxParam::ValueType::Float) { - auto const valueRange = mOwnerEditor->GetParameter_maxValue(paramID) - mOwnerEditor->GetParameter_minValue(paramID); + auto const valueRange = mOwnerEditor->GetParameter_maxValue(parameterID) - mOwnerEditor->GetParameter_minValue(parameterID); numStates = static_cast(std::max(std::lround(valueRange), 0L) + 1); } setNumStates(numStates); @@ -346,7 +347,7 @@ bool DGMultiControl::isEditing_any() const //----------------------------------------------------------------------------- template -IDGControl* DGMultiControl::getControlByParameterID(long inParameterID) +IDGControl* DGMultiControl::getControlByParameterID(dfx::ParameterID inParameterID) { if (DGControl::getParameterID() == inParameterID) { @@ -359,9 +360,9 @@ IDGControl* DGMultiControl::getControlByParameterID(long inParameterID) //----------------------------------------------------------------------------- template -IDGControl* DGMultiControl::addChild(long inParameterID) +IDGControl* DGMultiControl::addChild(dfx::ParameterID inParameterID) { - assert(inParameterID >= 0); + assert(inParameterID != dfx::kParameterID_Invalid); assert(inParameterID != this->getParameterID()); auto child = std::make_unique(DGControl::getOwnerEditor(), DGControl::getViewSize(), inParameterID); [[maybe_unused]] auto const [element, inserted] = mChildren.insert(child.get()); @@ -376,9 +377,9 @@ IDGControl* DGMultiControl::addChild(long inParameterID) //----------------------------------------------------------------------------- template -void DGMultiControl::addChildren(std::vector const& inParameterIDs) +void DGMultiControl::addChildren(std::vector const& inParameterIDs) { - assert(std::unordered_set(inParameterIDs.cbegin(), inParameterIDs.cend()).size() == inParameterIDs.size()); + assert(std::unordered_set(inParameterIDs.cbegin(), inParameterIDs.cend()).size() == inParameterIDs.size()); std::for_each(inParameterIDs.cbegin(), inParameterIDs.cend(), [this](auto parameterID){ addChild(parameterID); }); } @@ -417,7 +418,7 @@ void DGMultiControl::notifyIfChanged_all() template DGMultiControl::DGMultiControlChild::DGMultiControlChild(DfxGuiEditor* inOwnerEditor, DGRect const& inRegion, - long inParameterID) -: DGControl(inRegion, inOwnerEditor, inParameterID) + dfx::ParameterID inParameterID) +: DGControl(inRegion, inOwnerEditor, dfx::ParameterID_ToVST(inParameterID)) { } diff --git a/dfxgui/dfxguidialog.cpp b/dfxgui/dfxguidialog.cpp index bfa4ec09..41e73c92 100644 --- a/dfxgui/dfxguidialog.cpp +++ b/dfxgui/dfxguidialog.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "dfxguidialog.h" @@ -29,6 +29,8 @@ To contact the author, use the contact form at http://destroyfx.org/ #include #include +#include "dfxplugin-base.h" + //----------------------------------------------------------------------------- constexpr VSTGUI::CCoord kContentMargin = 20.0; @@ -77,7 +79,7 @@ class DGDialogButton final : public VSTGUI::CTextButton { public: DGDialogButton(VSTGUI::IControlListener* inListener, DGRect const& inRegion, DGDialog::Selection inSelection, VSTGUI::UTF8StringPtr inTitle) - : VSTGUI::CTextButton(inRegion, inListener, dfx::kParameterID_Invalid, inTitle, VSTGUI::CTextButton::kKickStyle), + : VSTGUI::CTextButton(inRegion, inListener, dfx::ParameterID_ToVST(dfx::kParameterID_Invalid), inTitle, VSTGUI::CTextButton::kKickStyle), mSelection(inSelection), mIsDefaultButton(inSelection == DGDialog::kSelection_OK) { @@ -177,7 +179,7 @@ class DGDialogTextEdit final : public VSTGUI::CTextEdit { public: DGDialogTextEdit(VSTGUI::CRect const& inRegion, VSTGUI::IControlListener* inListener) - : VSTGUI::CTextEdit(inRegion, inListener, dfx::kParameterID_Invalid) + : VSTGUI::CTextEdit(inRegion, inListener, dfx::ParameterID_ToVST(dfx::kParameterID_Invalid)) { setFontColor(DGColor::getSystem(DGColor::System::Text)); setBackColor(DGColor::getSystem(DGColor::System::TextBackground)); @@ -527,11 +529,11 @@ VSTGUI::CTextButton* DGDialog::getButton(Selection inSelection) const //----------------------------------------------------------------------------- // Text-Entry Dialog //----------------------------------------------------------------------------- -DGTextEntryDialog::DGTextEntryDialog(long inParamID, std::string const& inMessage, +DGTextEntryDialog::DGTextEntryDialog(dfx::ParameterID inParameterID, std::string const& inMessage, char const* inTextEntryLabel, Buttons inButtons, char const* inOkButtonTitle, char const* inCancelButtonTitle, char const* inOtherButtonTitle) : DGDialog(DGRect(0.0, 0.0, 247.0, 134.0), inMessage, inButtons, inOkButtonTitle, inCancelButtonTitle, inOtherButtonTitle), - mParameterID(inParamID) + mParameterID(inParameterID) { constexpr VSTGUI::CCoord labelEditHeightOffset = (kTextEditHeight - kTextLabelHeight) / 2.0; @@ -607,7 +609,7 @@ std::string DGTextEntryDialog::getText() const } //----------------------------------------------------------------------------- -long DGTextEntryDialog::getParameterID() const noexcept +dfx::ParameterID DGTextEntryDialog::getParameterID() const noexcept { return mParameterID; } diff --git a/dfxgui/dfxguidialog.h b/dfxgui/dfxguidialog.h index e50ce10f..224d2359 100644 --- a/dfxgui/dfxguidialog.h +++ b/dfxgui/dfxguidialog.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -115,7 +115,7 @@ class DGDialog : public VSTGUI::CViewContainer, public VSTGUI::IControlListener class DGTextEntryDialog : public DGDialog { public: - DGTextEntryDialog(long inParamID, std::string const& inMessage, + DGTextEntryDialog(dfx::ParameterID inParameterID, std::string const& inMessage, char const* inTextEntryLabel = nullptr, Buttons inButtons = kButtons_OKCancel, char const* inOkButtonTitle = nullptr, char const* inCancelButtonTitle = nullptr, char const* inOtherButtonTitle = nullptr); explicit DGTextEntryDialog(std::string const& inMessage, @@ -128,12 +128,12 @@ class DGTextEntryDialog : public DGDialog void setText(std::string const& inText); std::string getText() const; - long getParameterID() const noexcept; + dfx::ParameterID getParameterID() const noexcept; CLASS_METHODS(DGTextEntryDialog, DGDialog) private: - long const mParameterID; + dfx::ParameterID const mParameterID; VSTGUI::CTextEdit* mTextEdit = nullptr; }; diff --git a/dfxgui/dfxguieditor.cpp b/dfxgui/dfxguieditor.cpp index fa88c516..261841b4 100644 --- a/dfxgui/dfxguieditor.cpp +++ b/dfxgui/dfxguieditor.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "dfxguieditor.h" @@ -293,40 +293,40 @@ void DfxGuiEditor::setParameter(TARGET_API_EDITOR_INDEX_TYPE inParameterIndex, f return; } - updateParameterControls(inParameterIndex, inValue); + updateParameterControls(dfx::ParameterID_FromVST(inParameterIndex), inValue); } //----------------------------------------------------------------------------- -void DfxGuiEditor::updateParameterControls(long inParameterIndex, float inValue, VSTGUI::CControl* inSendingControl) +void DfxGuiEditor::updateParameterControls(dfx::ParameterID inParameterID, float inValue, VSTGUI::CControl* inSendingControl) { for (auto& control : mControlsList) { - if ((control->getParameterID() == inParameterIndex) && (control->asCControl() != inSendingControl)) + if ((control->getParameterID() == inParameterID) && (control->asCControl() != inSendingControl)) { control->setValue_gen(inValue); control->redraw(); // TODO: why is this also necessary? redraws are sometimes dropped without it } } - parameterChanged(inParameterIndex); + parameterChanged(inParameterID); } //----------------------------------------------------------------------------- void DfxGuiEditor::valueChanged(VSTGUI::CControl* inControl) { - auto const paramIndex = inControl->getTag(); - auto const paramValue_norm = inControl->getValueNormalized(); + auto const parameterID = dfx::ParameterID_FromVST(inControl->getTag()); + auto const parameterValue_norm = inControl->getValueNormalized(); - if (dfxgui_IsValidParamID(paramIndex)) + if (dfxgui_IsValidParameterID(parameterID)) { #ifdef TARGET_API_AUDIOUNIT - auto const paramValue_literal = dfxgui_ExpandParameterValue(paramIndex, paramValue_norm); + auto const parameterValue_literal = dfxgui_ExpandParameterValue(parameterID, parameterValue_norm); // XXX or should I call setparameter_f()? - auto const auParam = dfxgui_MakeAudioUnitParameter(paramIndex); - AUParameterSet(mAUEventListener.get(), inControl, &auParam, paramValue_literal, 0); + auto const auParam = dfxgui_MakeAudioUnitParameter(parameterID); + AUParameterSet(mAUEventListener.get(), inControl, &auParam, parameterValue_literal, 0); #endif #ifdef TARGET_API_VST - getEffect()->setParameterAutomated(paramIndex, paramValue_norm); + getEffect()->setParameterAutomated(dfx::ParameterID_ToVST(parameterID), parameterValue_norm); #endif #ifdef TARGET_API_RTAS // XXX though the model of calling SetControlValue might make more seem like @@ -335,8 +335,8 @@ void DfxGuiEditor::valueChanged(VSTGUI::CControl* inControl) // the next call to UpdateControlInAlgorithm which be deferred until the start of // the next audio render call, which means that in the meantime getparameter_* // methods will return the previous rather than current value -// dfxgui_GetEffectInstance()->SetControlValue(dfx::ParameterID_ToRTAS(paramIndex), ConvertToDigiValue(paramValue_norm)); - dfxgui_GetEffectInstance()->setparameter_gen(paramIndex, paramValue_norm); +// dfxgui_GetEffectInstance()->SetControlValue(dfx::ParameterID_ToRTAS(parameterID), ConvertToDigiValue(parameterValue_norm)); + dfxgui_GetEffectInstance()->setparameter_gen(parameterID, parameterValue_norm); #endif } } @@ -345,18 +345,18 @@ void DfxGuiEditor::valueChanged(VSTGUI::CControl* inControl) //----------------------------------------------------------------------------- void DfxGuiEditor::beginEdit(int32_t inParameterIndex) { - if (dfxgui_IsValidParamID(inParameterIndex)) + if (auto const parameterID = dfx::ParameterID_FromVST(inParameterIndex); dfxgui_IsValidParameterID(parameterID)) { - automationgesture_begin(inParameterIndex); + automationgesture_begin(parameterID); } } //----------------------------------------------------------------------------- void DfxGuiEditor::endEdit(int32_t inParameterIndex) { - if (dfxgui_IsValidParamID(inParameterIndex)) + if (auto const parameterID = dfx::ParameterID_FromVST(inParameterIndex); dfxgui_IsValidParameterID(parameterID)) { - automationgesture_end(inParameterIndex); + automationgesture_end(parameterID); } } #endif // !TARGET_API_VST @@ -420,7 +420,7 @@ IDGControl* DfxGuiEditor::addControl(IDGControl* inControl) assert(inControl); // XXX only add it to our controls list if it is attached to a parameter (?) - if (dfxgui_IsValidParamID(inControl->getParameterID())) + if (dfxgui_IsValidParameterID(inControl->getParameterID())) { assert(std::find(mControlsList.cbegin(), mControlsList.cend(), inControl) == mControlsList.cend()); mControlsList.push_back(inControl); @@ -451,7 +451,7 @@ void DfxGuiEditor::removeControl(IDGControl* inControl) } //----------------------------------------------------------------------------- -long DfxGuiEditor::GetWidth() +int DfxGuiEditor::GetWidth() { ERect* editorRect = nullptr; if (getRect(&editorRect) && editorRect) @@ -462,7 +462,7 @@ long DfxGuiEditor::GetWidth() } //----------------------------------------------------------------------------- -long DfxGuiEditor::GetHeight() +int DfxGuiEditor::GetHeight() { ERect* editorRect = nullptr; if (getRect(&editorRect) && editorRect) @@ -505,14 +505,14 @@ OSStatus DfxGuiEditor::SendAUParameterEvent(AudioUnitParameterID inParameterID, #endif //----------------------------------------------------------------------------- -void DfxGuiEditor::automationgesture_begin(long inParameterID) +void DfxGuiEditor::automationgesture_begin(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - SendAUParameterEvent(static_cast(inParameterID), kAudioUnitEvent_BeginParameterChangeGesture); + SendAUParameterEvent(inParameterID, kAudioUnitEvent_BeginParameterChangeGesture); #endif #ifdef TARGET_API_VST - TARGET_API_EDITOR_BASE_CLASS::beginEdit(inParameterID); + TARGET_API_EDITOR_BASE_CLASS::beginEdit(dfx::ParameterID_ToVST(inParameterID)); #endif #ifdef TARGET_API_RTAS @@ -523,14 +523,14 @@ void DfxGuiEditor::automationgesture_begin(long inParameterID) } //----------------------------------------------------------------------------- -void DfxGuiEditor::automationgesture_end(long inParameterID) +void DfxGuiEditor::automationgesture_end(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - SendAUParameterEvent(static_cast(inParameterID), kAudioUnitEvent_EndParameterChangeGesture); + SendAUParameterEvent(inParameterID, kAudioUnitEvent_EndParameterChangeGesture); #endif #ifdef TARGET_API_VST - TARGET_API_EDITOR_BASE_CLASS::endEdit(inParameterID); + TARGET_API_EDITOR_BASE_CLASS::endEdit(dfx::ParameterID_ToVST(inParameterID)); #endif #ifdef TARGET_API_RTAS @@ -540,7 +540,7 @@ void DfxGuiEditor::automationgesture_end(long inParameterID) } //----------------------------------------------------------------------------- -void DfxGuiEditor::randomizeparameter(long inParameterID, bool inWriteAutomation) +void DfxGuiEditor::randomizeparameter(dfx::ParameterID inParameterID, bool inWriteAutomation) { if (inWriteAutomation) { @@ -556,7 +556,7 @@ void DfxGuiEditor::randomizeparameter(long inParameterID, bool inWriteAutomation dfxgui_GetEffectInstance()->randomizeparameter(inParameterID); if (inWriteAutomation) { - getEffect()->setParameterAutomated(inParameterID, getparameter_gen(inParameterID)); + getEffect()->setParameterAutomated(dfx::ParameterID_ToVST(inParameterID), getparameter_gen(inParameterID)); } #endif @@ -609,7 +609,7 @@ void DfxGuiEditor::randomizeparameters(bool inWriteAutomation) for (auto const parameterID : parameterList) { #ifdef TARGET_API_VST - getEffect()->setParameterAutomated(parameterID, getparameter_gen(parameterID)); + getEffect()->setParameterAutomated(dfx::ParameterID_ToVST(parameterID), getparameter_gen(parameterID)); #endif automationgesture_end(parameterID); } @@ -617,7 +617,7 @@ void DfxGuiEditor::randomizeparameters(bool inWriteAutomation) } //----------------------------------------------------------------------------- -void DfxGuiEditor::GenerateParameterAutomationSnapshot(long inParameterID) +void DfxGuiEditor::GenerateParameterAutomationSnapshot(dfx::ParameterID inParameterID) { setparameter_f(inParameterID, getparameter_f(inParameterID), true); } @@ -632,7 +632,7 @@ void DfxGuiEditor::GenerateParametersAutomationSnapshot() } //----------------------------------------------------------------------------- -std::optional DfxGuiEditor::dfxgui_GetParameterValueFromString_f(long inParameterID, std::string const& inText) +std::optional DfxGuiEditor::dfxgui_GetParameterValueFromString_f(dfx::ParameterID inParameterID, std::string const& inText) { if (GetParameterValueType(inParameterID) == DfxParam::ValueType::Float) { @@ -655,17 +655,17 @@ std::optional DfxGuiEditor::dfxgui_GetParameterValueFromString_f(long in } //----------------------------------------------------------------------------- -std::optional DfxGuiEditor::dfxgui_GetParameterValueFromString_i(long inParameterID, std::string const& inText) +std::optional DfxGuiEditor::dfxgui_GetParameterValueFromString_i(dfx::ParameterID inParameterID, std::string const& inText) { if (GetParameterValueType(inParameterID) == DfxParam::ValueType::Float) { if (auto const newValue_f = dfxgui_GetParameterValueFromString_f(inParameterID, inText)) { - DfxParam param; - param.init_f({""}, 0.0, 0.0, -1.0, 1.0); - DfxParam::Value paramValue {}; - paramValue.f = *newValue_f; - return param.derive_i(paramValue); + DfxParam parameter; + parameter.init_f({""}, 0.0, 0.0, -1.0, 1.0); + DfxParam::Value parameterValue {}; + parameterValue.f = *newValue_f; + return parameter.derive_i(parameterValue); } } else @@ -682,9 +682,9 @@ std::optional DfxGuiEditor::dfxgui_GetParameterValueFromString_i(long inPa } //----------------------------------------------------------------------------- -bool DfxGuiEditor::dfxgui_SetParameterValueWithString(long inParameterID, std::string const& inText) +bool DfxGuiEditor::dfxgui_SetParameterValueWithString(dfx::ParameterID inParameterID, std::string const& inText) { - if (dfxgui_IsValidParamID(inParameterID)) + if (dfxgui_IsValidParameterID(inParameterID)) { constexpr bool automationGesture = true; if (GetParameterValueType(inParameterID) == DfxParam::ValueType::Float) @@ -709,7 +709,7 @@ bool DfxGuiEditor::dfxgui_SetParameterValueWithString(long inParameterID, std::s } //----------------------------------------------------------------------------- -bool DfxGuiEditor::dfxgui_IsValidParamID(long inParameterID) +bool DfxGuiEditor::dfxgui_IsValidParameterID(dfx::ParameterID inParameterID) { if ((inParameterID == dfx::kParameterID_Invalid) || (inParameterID < 0)) { @@ -717,14 +717,14 @@ bool DfxGuiEditor::dfxgui_IsValidParamID(long inParameterID) } #ifdef TARGET_API_AUDIOUNIT // TODO: actually search parameter ID list to ensure that this ID is present? - return (static_cast(inParameterID) <= mAUMaxParameterID); + return (inParameterID <= mAUMaxParameterID); #else return (inParameterID < GetNumParameters()); #endif } //----------------------------------------------------------------------------- -void DfxGuiEditor::TextEntryForParameterValue(long inParameterID) +void DfxGuiEditor::TextEntryForParameterValue(dfx::ParameterID inParameterID) { if (!getFrame()) { @@ -764,7 +764,7 @@ void DfxGuiEditor::TextEntryForParameterValue(long inParameterID) } //----------------------------------------------------------------------------- -void DfxGuiEditor::SetParameterHelpText(long inParameterID, char const* inText) +void DfxGuiEditor::SetParameterHelpText(dfx::ParameterID inParameterID, char const* inText) { for (auto& control : mControlsList) { @@ -776,7 +776,7 @@ void DfxGuiEditor::SetParameterHelpText(long inParameterID, char const* inText) } //----------------------------------------------------------------------------- -void DfxGuiEditor::SetParameterAlpha(long inParameterID, float inAlpha) +void DfxGuiEditor::SetParameterAlpha(dfx::ParameterID inParameterID, float inAlpha) { for (auto& control : mControlsList) { @@ -906,7 +906,7 @@ void DfxGuiEditor::viewOnEvent(VSTGUI::CView* inView, VSTGUI::Event& ioEvent) } //----------------------------------------------------------------------------- -double DfxGuiEditor::getparameter_f(long inParameterID) +double DfxGuiEditor::getparameter_f(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT dfx::ParameterValueRequest request; @@ -927,7 +927,7 @@ double DfxGuiEditor::getparameter_f(long inParameterID) } //----------------------------------------------------------------------------- -long DfxGuiEditor::getparameter_i(long inParameterID) +long DfxGuiEditor::getparameter_i(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT dfx::ParameterValueRequest request; @@ -948,7 +948,7 @@ long DfxGuiEditor::getparameter_i(long inParameterID) } //----------------------------------------------------------------------------- -bool DfxGuiEditor::getparameter_b(long inParameterID) +bool DfxGuiEditor::getparameter_b(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT dfx::ParameterValueRequest request; @@ -969,18 +969,18 @@ bool DfxGuiEditor::getparameter_b(long inParameterID) } //----------------------------------------------------------------------------- -double DfxGuiEditor::getparameter_gen(long inParameterIndex) +double DfxGuiEditor::getparameter_gen(dfx::ParameterID inParameterID) { #ifdef TARGET_API_VST - return getEffect()->getParameter(inParameterIndex); + return getEffect()->getParameter(dfx::ParameterID_ToVST(inParameterID)); #else - double currentValue = getparameter_f(inParameterIndex); - return dfxgui_ContractParameterValue(inParameterIndex, currentValue); + double currentValue = getparameter_f(inParameterID); + return dfxgui_ContractParameterValue(inParameterID, currentValue); #endif } //----------------------------------------------------------------------------- -void DfxGuiEditor::setparameter_f(long inParameterID, double inValue, bool inWrapWithAutomationGesture) +void DfxGuiEditor::setparameter_f(dfx::ParameterID inParameterID, double inValue, bool inWrapWithAutomationGesture) { if (inWrapWithAutomationGesture) { @@ -998,7 +998,7 @@ void DfxGuiEditor::setparameter_f(long inParameterID, double inValue, bool inWra #ifdef TARGET_API_VST auto const value_norm = dfxgui_ContractParameterValue(inParameterID, inValue); - getEffect()->setParameterAutomated(inParameterID, value_norm); + getEffect()->setParameterAutomated(dfx::ParameterID_ToVST(inParameterID), value_norm); #endif #ifdef TARGET_API_RTAS @@ -1013,7 +1013,7 @@ void DfxGuiEditor::setparameter_f(long inParameterID, double inValue, bool inWra } //----------------------------------------------------------------------------- -void DfxGuiEditor::setparameter_i(long inParameterID, long inValue, bool inWrapWithAutomationGesture) +void DfxGuiEditor::setparameter_i(dfx::ParameterID inParameterID, long inValue, bool inWrapWithAutomationGesture) { if (inWrapWithAutomationGesture) { @@ -1031,7 +1031,7 @@ void DfxGuiEditor::setparameter_i(long inParameterID, long inValue, bool inWrapW #ifdef TARGET_API_VST auto const value_norm = dfxgui_ContractParameterValue(inParameterID, inValue); - getEffect()->setParameterAutomated(inParameterID, value_norm); + getEffect()->setParameterAutomated(dfx::ParameterID_ToVST(inParameterID), value_norm); #endif #ifdef TARGET_API_RTAS @@ -1046,7 +1046,7 @@ void DfxGuiEditor::setparameter_i(long inParameterID, long inValue, bool inWrapW } //----------------------------------------------------------------------------- -void DfxGuiEditor::setparameter_b(long inParameterID, bool inValue, bool inWrapWithAutomationGesture) +void DfxGuiEditor::setparameter_b(dfx::ParameterID inParameterID, bool inValue, bool inWrapWithAutomationGesture) { if (inWrapWithAutomationGesture) { @@ -1063,7 +1063,7 @@ void DfxGuiEditor::setparameter_b(long inParameterID, bool inValue, bool inWrapW #endif #ifdef TARGET_API_VST - getEffect()->setParameterAutomated(inParameterID, inValue ? 1.0f : 0.0f); + getEffect()->setParameterAutomated(dfx::ParameterID_ToVST(inParameterID), inValue ? 1.f : 0.f); #endif #ifdef TARGET_API_RTAS @@ -1078,7 +1078,7 @@ void DfxGuiEditor::setparameter_b(long inParameterID, bool inValue, bool inWrapW } //----------------------------------------------------------------------------- -void DfxGuiEditor::setparameter_default(long inParameterID, bool inWrapWithAutomationGesture) +void DfxGuiEditor::setparameter_default(dfx::ParameterID inParameterID, bool inWrapWithAutomationGesture) { #ifdef TARGET_API_AUDIOUNIT if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterID)) @@ -1102,7 +1102,7 @@ void DfxGuiEditor::setparameter_default(long inParameterID, bool inWrapWithAutom #ifdef TARGET_API_VST auto const defaultValue = GetParameter_defaultValue(inParameterID); auto const defaultValue_norm = dfxgui_ContractParameterValue(inParameterID, defaultValue); - getEffect()->setParameterAutomated(inParameterID, defaultValue_norm); + getEffect()->setParameterAutomated(dfx::ParameterID_ToVST(inParameterID), defaultValue_norm); #endif #ifdef TARGET_API_RTAS @@ -1121,13 +1121,13 @@ void DfxGuiEditor::setparameters_default(bool inWrapWithAutomationGesture) } //----------------------------------------------------------------------------- -std::optional DfxGuiEditor::getparametervaluestring(long inParameterID) +std::optional DfxGuiEditor::getparametervaluestring(dfx::ParameterID inParameterID) { return getparametervaluestring(inParameterID, getparameter_i(inParameterID)); } //----------------------------------------------------------------------------- -std::optional DfxGuiEditor::getparametervaluestring(long inParameterID, int64_t inStringIndex) +std::optional DfxGuiEditor::getparametervaluestring(dfx::ParameterID inParameterID, int64_t inStringIndex) { #ifdef TARGET_API_AUDIOUNIT dfx::ParameterValueStringRequest request; @@ -1146,51 +1146,51 @@ std::optional DfxGuiEditor::getparametervaluestring(long inParamete } //----------------------------------------------------------------------------- -std::string DfxGuiEditor::getparameterunitstring(long inParameterIndex) +std::string DfxGuiEditor::getparameterunitstring(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT std::array unitLabel {}; size_t dataSize = unitLabel.size() * sizeof(unitLabel.front()); auto const status = dfxgui_GetProperty(dfx::kPluginProperty_ParameterUnitLabel, dfx::kScope_Global, - inParameterIndex, unitLabel.data(), dataSize); + inParameterID, unitLabel.data(), dataSize); if (status == noErr) { return unitLabel.data(); } return {}; #else - return dfxgui_GetEffectInstance()->getparameterunitstring(inParameterIndex); + return dfxgui_GetEffectInstance()->getparameterunitstring(inParameterID); #endif } //----------------------------------------------------------------------------- -bool DfxGuiEditor::GetParameterUseValueStrings(long inParameterIndex) +bool DfxGuiEditor::GetParameterUseValueStrings(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - return dfxgui_GetProperty(dfx::kPluginProperty_ParameterUseValueStrings, dfx::kScope_Global, inParameterIndex).value_or(false); + return dfxgui_GetProperty(dfx::kPluginProperty_ParameterUseValueStrings, dfx::kScope_Global, inParameterID).value_or(false); #else - return dfxgui_GetEffectInstance()->getparameterusevaluestrings(inParameterIndex); + return dfxgui_GetEffectInstance()->getparameterusevaluestrings(inParameterID); #endif } //----------------------------------------------------------------------------- -bool DfxGuiEditor::HasParameterAttribute(long inParameterIndex, DfxParam::Attribute inFlag) +bool DfxGuiEditor::HasParameterAttribute(dfx::ParameterID inParameterID, DfxParam::Attribute inFlag) { assert(inFlag); #ifdef TARGET_API_AUDIOUNIT - return dfxgui_GetProperty(dfx::kPluginProperty_ParameterAttributes, dfx::kScope_Global, inParameterIndex).value_or(0) & inFlag; + return dfxgui_GetProperty(dfx::kPluginProperty_ParameterAttributes, dfx::kScope_Global, inParameterID).value_or(0) & inFlag; #else - return dfxgui_GetEffectInstance()->hasparameterattribute(inParameterIndex, inFlag); + return dfxgui_GetEffectInstance()->hasparameterattribute(inParameterID, inFlag); #endif } //----------------------------------------------------------------------------- -std::optional DfxGuiEditor::GetParameterGroup(long inParameterIndex) +std::optional DfxGuiEditor::GetParameterGroup(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - return dfxgui_GetProperty(dfx::kPluginProperty_ParameterGroup, dfx::kScope_Global, inParameterIndex); + return dfxgui_GetProperty(dfx::kPluginProperty_ParameterGroup, dfx::kScope_Global, inParameterID); #else - return dfxgui_GetEffectInstance()->getparametergroup(inParameterIndex); + return dfxgui_GetEffectInstance()->getparametergroup(inParameterID); #endif } @@ -1213,7 +1213,7 @@ std::string DfxGuiEditor::GetParameterGroupName(size_t inGroupIndex) } //----------------------------------------------------------------------------- -std::string DfxGuiEditor::getparametername(long inParameterID) +std::string DfxGuiEditor::getparametername(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterID)) @@ -1234,7 +1234,7 @@ std::string DfxGuiEditor::getparametername(long inParameterID) } //----------------------------------------------------------------------------- -float DfxGuiEditor::dfxgui_ExpandParameterValue(long inParameterIndex, float inValue) +float DfxGuiEditor::dfxgui_ExpandParameterValue(dfx::ParameterID inParameterID, float inValue) { #ifdef TARGET_API_AUDIOUNIT dfx::ParameterValueConversionRequest request; @@ -1242,23 +1242,24 @@ float DfxGuiEditor::dfxgui_ExpandParameterValue(long inParameterIndex, float inV request.inValue = inValue; size_t dataSize = sizeof(request); auto const status = dfxgui_GetProperty(dfx::kPluginProperty_ParameterValueConversion, dfx::kScope_Global, - inParameterIndex, &request, dataSize); + inParameterID, &request, dataSize); if (status == noErr) { return request.outValue; } else { - auto const auParam = dfxgui_MakeAudioUnitParameter(inParameterIndex); + assert(false); // really the above should not be failing + auto const auParam = dfxgui_MakeAudioUnitParameter(inParameterID); return AUParameterValueFromLinear(inValue, &auParam); } #else - return dfxgui_GetEffectInstance()->expandparametervalue(inParameterIndex, inValue); + return dfxgui_GetEffectInstance()->expandparametervalue(inParameterID, inValue); #endif } //----------------------------------------------------------------------------- -float DfxGuiEditor::dfxgui_ContractParameterValue(long inParameterIndex, float inValue) +float DfxGuiEditor::dfxgui_ContractParameterValue(dfx::ParameterID inParameterID, float inValue) { #ifdef TARGET_API_AUDIOUNIT dfx::ParameterValueConversionRequest request; @@ -1266,7 +1267,7 @@ float DfxGuiEditor::dfxgui_ContractParameterValue(long inParameterIndex, float i request.inValue = inValue; size_t dataSize = sizeof(request); auto const status = dfxgui_GetProperty(dfx::kPluginProperty_ParameterValueConversion, dfx::kScope_Global, - inParameterIndex, &request, dataSize); + inParameterID, &request, dataSize); if (status == noErr) { return request.outValue; @@ -1274,77 +1275,77 @@ float DfxGuiEditor::dfxgui_ContractParameterValue(long inParameterIndex, float i else { assert(false); // really the above should not be failing - auto const auParam = dfxgui_MakeAudioUnitParameter(inParameterIndex); + auto const auParam = dfxgui_MakeAudioUnitParameter(inParameterID); return AUParameterValueToLinear(inValue, &auParam); } #else - return dfxgui_GetEffectInstance()->contractparametervalue(inParameterIndex, inValue); + return dfxgui_GetEffectInstance()->contractparametervalue(inParameterID, inValue); #endif } //----------------------------------------------------------------------------- -float DfxGuiEditor::GetParameter_minValue(long inParameterIndex) +float DfxGuiEditor::GetParameter_minValue(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterIndex)) + if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterID)) { return parameterInfo->minValue; } + return 0.f; #else - return dfxgui_GetEffectInstance()->getparametermin_f(inParameterIndex); + return dfxgui_GetEffectInstance()->getparametermin_f(inParameterID); #endif - return 0.0f; } //----------------------------------------------------------------------------- -float DfxGuiEditor::GetParameter_maxValue(long inParameterIndex) +float DfxGuiEditor::GetParameter_maxValue(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterIndex)) + if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterID)) { return parameterInfo->maxValue; } + return 0.f; #else - return dfxgui_GetEffectInstance()->getparametermax_f(inParameterIndex); + return dfxgui_GetEffectInstance()->getparametermax_f(inParameterID); #endif - return 0.0f; } //----------------------------------------------------------------------------- -float DfxGuiEditor::GetParameter_defaultValue(long inParameterIndex) +float DfxGuiEditor::GetParameter_defaultValue(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterIndex)) + if (auto const parameterInfo = dfxgui_GetParameterInfo(inParameterID)) { return parameterInfo->defaultValue; } + return 0.f; #else - return dfxgui_GetEffectInstance()->getparameterdefault_f(inParameterIndex); + return dfxgui_GetEffectInstance()->getparameterdefault_f(inParameterID); #endif - return 0.0f; } //----------------------------------------------------------------------------- -DfxParam::ValueType DfxGuiEditor::GetParameterValueType(long inParameterIndex) +DfxParam::ValueType DfxGuiEditor::GetParameterValueType(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT return dfxgui_GetProperty(dfx::kPluginProperty_ParameterValueType, dfx::kScope_Global, - inParameterIndex).value_or(DfxParam::ValueType::Float); + inParameterID).value_or(DfxParam::ValueType::Float); #else - return dfxgui_GetEffectInstance()->getparametervaluetype(inParameterIndex); + return dfxgui_GetEffectInstance()->getparametervaluetype(inParameterID); #endif } //----------------------------------------------------------------------------- -DfxParam::Unit DfxGuiEditor::GetParameterUnit(long inParameterIndex) +DfxParam::Unit DfxGuiEditor::GetParameterUnit(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT return dfxgui_GetProperty(dfx::kPluginProperty_ParameterUnit, dfx::kScope_Global, - inParameterIndex).value_or(DfxParam::Unit::Generic); + inParameterID).value_or(DfxParam::Unit::Generic); #else - return dfxgui_GetEffectInstance()->getparameterunit(inParameterIndex); + return dfxgui_GetEffectInstance()->getparameterunit(inParameterID); #endif } @@ -1382,7 +1383,7 @@ size_t DfxGuiEditor::GetNumParameters() } //----------------------------------------------------------------------------- -std::vector DfxGuiEditor::GetParameterList() +std::vector DfxGuiEditor::GetParameterList() const { #ifdef TARGET_API_AUDIOUNIT std::lock_guard const guard(mParameterListLock); @@ -1403,7 +1404,7 @@ AudioUnitParameter DfxGuiEditor::dfxgui_MakeAudioUnitParameter(AudioUnitParamete } //----------------------------------------------------------------------------- -std::vector DfxGuiEditor::CreateParameterList(AudioUnitScope inScope) +std::vector DfxGuiEditor::CreateParameterList(AudioUnitScope inScope) { size_t dataSize {}; dfx::PropertyFlags propFlags {}; @@ -1434,7 +1435,7 @@ std::vector DfxGuiEditor::CreateParameterList(AudioUnitScope inScope) mAUMaxParameterID = *std::max_element(parameterList.cbegin(), parameterList.cend()); - return std::vector(parameterList.cbegin(), parameterList.cend()); + return std::vector(parameterList.cbegin(), parameterList.cend()); } #endif @@ -1729,71 +1730,66 @@ void DfxGuiEditor::resetmidilearn() } //----------------------------------------------------------------------------- -void DfxGuiEditor::setmidilearner(long inParameterIndex) +void DfxGuiEditor::setmidilearner(dfx::ParameterID inParameterID) { - if (dfxgui_IsValidParamID(inParameterIndex) && !getmidilearning()) + if (dfxgui_IsValidParameterID(inParameterID) && !getmidilearning()) { setmidilearning(true); } #ifdef TARGET_API_AUDIOUNIT - dfxgui_SetProperty(dfx::kPluginProperty_MidiLearner, static_cast(inParameterIndex)); + dfxgui_SetProperty(dfx::kPluginProperty_MidiLearner, static_cast(inParameterID)); #else - dfxgui_GetEffectInstance()->setmidilearner(inParameterIndex); + dfxgui_GetEffectInstance()->setmidilearner(inParameterID); #endif } //----------------------------------------------------------------------------- -long DfxGuiEditor::getmidilearner() +dfx::ParameterID DfxGuiEditor::getmidilearner() { #ifdef TARGET_API_AUDIOUNIT - return dfxgui_GetProperty(dfx::kPluginProperty_MidiLearner).value_or(dfx::kParameterID_Invalid); + return dfxgui_GetProperty(dfx::kPluginProperty_MidiLearner).value_or(dfx::kParameterID_Invalid); #else return dfxgui_GetEffectInstance()->getmidilearner(); #endif } //----------------------------------------------------------------------------- -bool DfxGuiEditor::ismidilearner(long inParameterIndex) +bool DfxGuiEditor::ismidilearner(dfx::ParameterID inParameterID) { - return (getmidilearner() == inParameterIndex); + return (getmidilearner() == inParameterID); } //----------------------------------------------------------------------------- -void DfxGuiEditor::setparametermidiassignment(long inParameterIndex, dfx::ParameterAssignment const& inAssignment) +void DfxGuiEditor::setparametermidiassignment(dfx::ParameterID inParameterID, dfx::ParameterAssignment const& inAssignment) { #ifdef TARGET_API_AUDIOUNIT - dfxgui_SetProperty(dfx::kPluginProperty_ParameterMidiAssignment, dfx::kScope_Global, inParameterIndex, inAssignment); + dfxgui_SetProperty(dfx::kPluginProperty_ParameterMidiAssignment, dfx::kScope_Global, inParameterID, inAssignment); #else - dfxgui_GetEffectInstance()->setparametermidiassignment(inParameterIndex, inAssignment); + dfxgui_GetEffectInstance()->setparametermidiassignment(inParameterID, inAssignment); #endif } //----------------------------------------------------------------------------- -dfx::ParameterAssignment DfxGuiEditor::getparametermidiassignment(long inParameterIndex) +dfx::ParameterAssignment DfxGuiEditor::getparametermidiassignment(dfx::ParameterID inParameterID) { #ifdef TARGET_API_AUDIOUNIT - auto const opt = dfxgui_GetProperty(dfx::kPluginProperty_ParameterMidiAssignment, - dfx::kScope_Global, - inParameterIndex); - if (opt.has_value()) - { - return *opt; - } - + auto const parameterAssignment = dfxgui_GetProperty(dfx::kPluginProperty_ParameterMidiAssignment, + dfx::kScope_Global, + inParameterID); dfx::ParameterAssignment none; none.mEventType = dfx::MidiEventType::None; - return none; + return parameterAssignment.value_or(none); #else - return dfxgui_GetEffectInstance()->getparametermidiassignment(inParameterIndex); + return dfxgui_GetEffectInstance()->getparametermidiassignment(inParameterID); #endif } //----------------------------------------------------------------------------- -void DfxGuiEditor::parametermidiunassign(long inParameterIndex) +void DfxGuiEditor::parametermidiunassign(dfx::ParameterID inParameterID) { dfx::ParameterAssignment parameterAssignment; parameterAssignment.mEventType = dfx::MidiEventType::None; - setparametermidiassignment(inParameterIndex, parameterAssignment); + setparametermidiassignment(inParameterID, parameterAssignment); } //----------------------------------------------------------------------------- @@ -1837,7 +1833,7 @@ bool DfxGuiEditor::getMidiAssignmentsSteal() } //----------------------------------------------------------------------------- -void DfxGuiEditor::TextEntryForParameterMidiCC(long inParameterID) +void DfxGuiEditor::TextEntryForParameterMidiCC(dfx::ParameterID inParameterID) { if (!getFrame()) { @@ -2035,10 +2031,10 @@ VSTGUI::COptionMenu DfxGuiEditor::createContextualMenu(IDGControl* inControl) { auto const addParameterSubMenu = [this, &resultMenu](IDGControl const* control) { - auto const paramID = control->getParameterID(); - if (auto const parameterSubMenu = createParameterContextualMenu(paramID)) + auto const parameterID = control->getParameterID(); + if (auto const parameterSubMenu = createParameterContextualMenu(parameterID)) { - resultMenu.addEntry(parameterSubMenu, getparametername(paramID)); + resultMenu.addEntry(parameterSubMenu, getparametername(parameterID)); } }; addParameterSubMenu(inControl); @@ -2124,9 +2120,9 @@ VSTGUI::COptionMenu DfxGuiEditor::createContextualMenu(IDGControl* inControl) } //----------------------------------------------------------------------------- -VSTGUI::SharedPointer DfxGuiEditor::createParameterContextualMenu(long inParameterID) +VSTGUI::SharedPointer DfxGuiEditor::createParameterContextualMenu(dfx::ParameterID inParameterID) { - assert(dfxgui_IsValidParamID(inParameterID)); + assert(dfxgui_IsValidParameterID(inParameterID)); auto resultMenu = VSTGUI::makeOwned(); assert(resultMenu.get()); @@ -2179,7 +2175,7 @@ VSTGUI::SharedPointer DfxGuiEditor::createParameterContextu resultMenu->addSeparator(); DFX_AppendCommandItemToMenu(*resultMenu, "MIDI learner", std::bind(&DfxGuiEditor::setmidilearner, this, - ismidilearner(inParameterID) ? DfxSettings::kNoLearner : inParameterID), + ismidilearner(inParameterID) ? dfx::kParameterID_Invalid : inParameterID), true, ismidilearner(inParameterID)); { VSTGUI::UTF8String menuItemText = "Unassign MIDI control"; @@ -3247,15 +3243,15 @@ void DfxGuiEditor::GetControlIndexFromPoint(long inXpos, long inYpos, long* outC // Called by process when a control's highlight has changed void DfxGuiEditor::SetControlHighlight(long inControlIndex, short inIsHighlighted, short inColor) { - inControlIndex = dfx::ParameterID_FromRTAS(inControlIndex); + auto const parameterID = dfx::ParameterID_FromRTAS(inControlIndex); if (!inIsHighlighted) { inColor = eHighlight_None; } - if (dfxgui_IsValidParamID(inControlIndex)) + if (dfxgui_IsValidParameterID(parameterID)) { - mParameterHighlightColors.at(inControlIndex) = inColor; + mParameterHighlightColors.at(parameterID) = inColor; } if (IsOpen()) @@ -3271,14 +3267,14 @@ void DfxGuiEditor::drawControlHighlight(VSTGUI::CDrawContext* inContext, VSTGUI: assert(inContext); assert(inControl); - auto const parameterIndex = inControl->getTag(); - if (!dfxgui_IsValidParamID(parameterIndex)) + auto const parameterID = dfx::ParameterID_FromVST(inControl->getTag()); + if (!dfxgui_IsValidParameterID(parameterID)) { return; } VSTGUI::CColor highlightColor; - switch (mParameterHighlightColors.at(parameterIndex)) + switch (mParameterHighlightColors.at(parameterID)) { case eHighlight_Red: highlightColor = VSTGUI::MakeCColor(255, 0, 0); diff --git a/dfxgui/dfxguieditor.h b/dfxgui/dfxguieditor.h index d06af6f9..e9d410f9 100644 --- a/dfxgui/dfxguieditor.h +++ b/dfxgui/dfxguieditor.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -189,8 +189,8 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, return control; } void removeControl(IDGControl* inControl); - long GetWidth(); - long GetHeight(); + int GetWidth(); + int GetHeight(); auto GetBackgroundImage() const noexcept { return mBackgroundImage.get(); @@ -206,12 +206,12 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, virtual void inputChannelsChanged(size_t inChannelCount) {} virtual void outputChannelsChanged(size_t inChannelCount) {} - void automationgesture_begin(long inParameterID); - void automationgesture_end(long inParameterID); + void automationgesture_begin(dfx::ParameterID inParameterID); + void automationgesture_end(dfx::ParameterID inParameterID); #ifdef TARGET_API_AUDIOUNIT OSStatus SendAUParameterEvent(AudioUnitParameterID inParameterID, AudioUnitEventType inEventType); #endif - virtual void parameterChanged(long inParameterID) {} + virtual void parameterChanged(dfx::ParameterID inParameterID) {} bool IsOpen(); DGEditorListenerInstance dfxgui_GetEffectInstance(); @@ -247,54 +247,53 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, #endif size_t GetNumParameters(); - std::vector GetParameterList(); - long GetNumAudioOutputs(); - float dfxgui_ExpandParameterValue(long inParameterIndex, float inValue); - float dfxgui_ContractParameterValue(long inParameterIndex, float inValue); - float GetParameter_minValue(long inParameterIndex); - float GetParameter_maxValue(long inParameterIndex); - float GetParameter_defaultValue(long inParameterIndex); - DfxParam::ValueType GetParameterValueType(long inParameterIndex); - DfxParam::Unit GetParameterUnit(long inParameterIndex); - bool GetParameterUseValueStrings(long inParameterIndex); - bool HasParameterAttribute(long inParameterIndex, DfxParam::Attribute inFlag); - std::optional GetParameterGroup(long inParameterIndex); + std::vector GetParameterList() const; + float dfxgui_ExpandParameterValue(dfx::ParameterID inParameterID, float inValue); + float dfxgui_ContractParameterValue(dfx::ParameterID inParameterID, float inValue); + float GetParameter_minValue(dfx::ParameterID inParameterID); + float GetParameter_maxValue(dfx::ParameterID inParameterID); + float GetParameter_defaultValue(dfx::ParameterID inParameterID); + DfxParam::ValueType GetParameterValueType(dfx::ParameterID inParameterID); + DfxParam::Unit GetParameterUnit(dfx::ParameterID inParameterID); + bool GetParameterUseValueStrings(dfx::ParameterID inParameterID); + bool HasParameterAttribute(dfx::ParameterID inParameterID, DfxParam::Attribute inFlag); + std::optional GetParameterGroup(dfx::ParameterID inParameterID); std::string GetParameterGroupName(size_t inGroupIndex); // the below methods all handle communication between the GUI component and the audio component - double getparameter_f(long inParameterID); - long getparameter_i(long inParameterID); - bool getparameter_b(long inParameterID); - double getparameter_gen(long inParameterIndex); - void setparameter_f(long inParameterID, double inValue, bool inWrapWithAutomationGesture = false); - void setparameter_i(long inParameterID, long inValue, bool inWrapWithAutomationGesture = false); - void setparameter_b(long inParameterID, bool inValue, bool inWrapWithAutomationGesture = false); - void setparameter_default(long inParameterID, bool inWrapWithAutomationGesture = false); + double getparameter_f(dfx::ParameterID inParameterID); + long getparameter_i(dfx::ParameterID inParameterID); + bool getparameter_b(dfx::ParameterID inParameterID); + double getparameter_gen(dfx::ParameterID inParameterID); + void setparameter_f(dfx::ParameterID inParameterID, double inValue, bool inWrapWithAutomationGesture = false); + void setparameter_i(dfx::ParameterID inParameterID, long inValue, bool inWrapWithAutomationGesture = false); + void setparameter_b(dfx::ParameterID inParameterID, bool inValue, bool inWrapWithAutomationGesture = false); + void setparameter_default(dfx::ParameterID inParameterID, bool inWrapWithAutomationGesture = false); void setparameters_default(bool inWrapWithAutomationGesture = false); - std::optional getparametervaluestring(long inParameterID); - std::optional getparametervaluestring(long inParameterID, int64_t inStringIndex); - std::string getparameterunitstring(long inParameterIndex); - std::string getparametername(long inParameterID); + std::optional getparametervaluestring(dfx::ParameterID inParameterID); + std::optional getparametervaluestring(dfx::ParameterID inParameterID, int64_t inStringIndex); + std::string getparameterunitstring(dfx::ParameterID inParameterID); + std::string getparametername(dfx::ParameterID inParameterID); // Randomize the value of the parameter. If inWriteAutomation is true, then // this saves automation inside a simulated automation gesture. - void randomizeparameter(long inParameterID, bool inWriteAutomation); + void randomizeparameter(dfx::ParameterID inParameterID, bool inWriteAutomation); // Randomize all parameters at the same time. Note that this calls the plugin's // randomizeparameters() function, which may not be the same as just looping over // all the parameters and randomizing them alone. void randomizeparameters(bool inWriteAutomation); - void GenerateParameterAutomationSnapshot(long inParameterID); + void GenerateParameterAutomationSnapshot(dfx::ParameterID inParameterID); void GenerateParametersAutomationSnapshot(); - virtual std::optional dfxgui_GetParameterValueFromString_f(long inParameterID, std::string const& inText); - virtual std::optional dfxgui_GetParameterValueFromString_i(long inParameterID, std::string const& inText); - bool dfxgui_SetParameterValueWithString(long inParameterID, std::string const& inText); - bool dfxgui_IsValidParamID(long inParameterID); - void TextEntryForParameterValue(long inParameterID); - void SetParameterHelpText(long inParameterID, char const* inText); - void SetParameterAlpha(long inParameterID, float inAlpha); + virtual std::optional dfxgui_GetParameterValueFromString_f(dfx::ParameterID inParameterID, std::string const& inText); + virtual std::optional dfxgui_GetParameterValueFromString_i(dfx::ParameterID inParameterID, std::string const& inText); + bool dfxgui_SetParameterValueWithString(dfx::ParameterID inParameterID, std::string const& inText); + bool dfxgui_IsValidParameterID(dfx::ParameterID inParameterID); + void TextEntryForParameterValue(dfx::ParameterID inParameterID); + void SetParameterHelpText(dfx::ParameterID inParameterID, char const* inText); + void SetParameterAlpha(dfx::ParameterID inParameterID, float inAlpha); #ifdef TARGET_API_AUDIOUNIT AudioUnitParameter dfxgui_MakeAudioUnitParameter(AudioUnitParameterID inParameterID, AudioUnitScope inScope = kAudioUnitScope_Global, AudioUnitElement inElement = 0); - std::vector CreateParameterList(AudioUnitScope inScope = kAudioUnitScope_Global); + std::vector CreateParameterList(AudioUnitScope inScope = kAudioUnitScope_Global); #endif long dfxgui_GetPropertyInfo(dfx::PropertyID inPropertyID, dfx::Scope inScope, unsigned int inItemIndex, size_t& outDataSize, dfx::PropertyFlags& outFlags); @@ -342,21 +341,21 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, void setmidilearning(bool inLearnMode); bool getmidilearning(); void resetmidilearn(); - void setmidilearner(long inParameterIndex); - long getmidilearner(); - bool ismidilearner(long inParameterIndex); - void setparametermidiassignment(long inParameterIndex, dfx::ParameterAssignment const& inAssignment); - dfx::ParameterAssignment getparametermidiassignment(long inParameterIndex); - void parametermidiunassign(long inParameterIndex); + void setmidilearner(dfx::ParameterID inParameterID); + dfx::ParameterID getmidilearner(); + bool ismidilearner(dfx::ParameterID inParameterID); + void setparametermidiassignment(dfx::ParameterID inParameterID, dfx::ParameterAssignment const& inAssignment); + dfx::ParameterAssignment getparametermidiassignment(dfx::ParameterID inParameterID); + void parametermidiunassign(dfx::ParameterID inParameterID); void setMidiAssignmentsUseChannel(bool inEnable); bool getMidiAssignmentsUseChannel(); void setMidiAssignmentsSteal(bool inEnable); bool getMidiAssignmentsSteal(); - void TextEntryForParameterMidiCC(long inParameterID); + void TextEntryForParameterMidiCC(dfx::ParameterID inParameterID); void HandleMidiLearnChange(); void HandleMidiLearnerChange(); virtual void midiLearningChanged(bool inLearnMode) {} - virtual void midiLearnerChanged(long inParameterIndex) {} + virtual void midiLearnerChanged(dfx::ParameterID inParameterID) {} DGButton* CreateMidiLearnButton(VSTGUI::CCoord inXpos, VSTGUI::CCoord inYpos, DGImage* inImage, bool inDrawMomentaryState = false); DGButton* CreateMidiResetButton(VSTGUI::CCoord inXpos, VSTGUI::CCoord inYpos, DGImage* inImage); auto GetMidiLearnButton() const noexcept @@ -375,11 +374,11 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, private: // update affected controls of a parameter value change // optional: inSendingControl can specify the originating control to omit it from circular notification - void updateParameterControls(long inParameterIndex, float inValue, VSTGUI::CControl* inSendingControl = nullptr); + void updateParameterControls(dfx::ParameterID inParameterID, float inValue, VSTGUI::CControl* inSendingControl = nullptr); [[nodiscard]] bool handleContextualMenuClick(VSTGUI::CControl* inControl, VSTGUI::MouseEventButtonState inButtonState); VSTGUI::COptionMenu createContextualMenu(IDGControl* inControl); - VSTGUI::SharedPointer createParameterContextualMenu(long inParameterID); + VSTGUI::SharedPointer createParameterContextualMenu(dfx::ParameterID inParameterID); VSTGUI::SharedPointer createParametersContextualMenu(); long initClipboard(); long copySettings(); @@ -424,7 +423,7 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, bool mJustOpened = false; long mEditorOpenErr = dfx::kStatus_NoError; - std::vector mParameterList; + std::vector mParameterList; size_t mNumInputChannels = 0; size_t mNumOutputChannels = 0; @@ -450,7 +449,7 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, #endif #ifdef TARGET_API_AUDIOUNIT - std::mutex mParameterListLock; + std::mutex mutable mParameterListLock; AudioUnitParameterID mAUMaxParameterID = 0; dfx::UniqueOpaqueType mAUEventListener; AudioUnitEvent mStreamFormatPropertyAUEvent {}; @@ -460,7 +459,7 @@ class DfxGuiEditor : public TARGET_API_EDITOR_BASE_CLASS, #endif #ifdef TARGET_API_RTAS - std::vector mParameterHighlightColors; + std::vector mParameterHighlightColors; #endif }; diff --git a/dfxgui/dfxguimisc.h b/dfxgui/dfxguimisc.h index 19b311f1..5bbc15d1 100644 --- a/dfxgui/dfxguimisc.h +++ b/dfxgui/dfxguimisc.h @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------ Destroy FX Library is a collection of foundation code for creating audio processing plug-ins. -Copyright (C) 2002-2021 Sophia Poirier +Copyright (C) 2002-2022 Sophia Poirier This file is part of the Destroy FX Library (version 1.0). @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -85,7 +85,7 @@ class DGRect : public VSTGUI::CRect #ifdef TARGET_API_RTAS //----------------------------------------------------------------------------- -enum +enum : short { eHighlight_None = -1, eHighlight_Red, // = 0, same as what Pro Tools passes in diff --git a/dfxgui/dfxguislider.cpp b/dfxgui/dfxguislider.cpp index 98baa5bc..00cacaf5 100644 --- a/dfxgui/dfxguislider.cpp +++ b/dfxgui/dfxguislider.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "dfxguislider.h" @@ -108,11 +108,11 @@ static void CancelControl(IDGControl* inControl, float inStartValue) #pragma mark DGSlider //----------------------------------------------------------------------------- -DGSlider::DGSlider(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, - dfx::Axis inOrientation, DGImage* inHandleImage, DGImage* inBackgroundImage, long inRangeMargin) +DGSlider::DGSlider(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, + dfx::Axis inOrientation, DGImage* inHandleImage, DGImage* inBackgroundImage, int inRangeMargin) : DGControl(inRegion, inOwnerEditor, - inParamID, + dfx::ParameterID_ToVST(inParameterID), VSTGUI::CPoint((inOrientation & dfx::kAxis_Horizontal) ? inRangeMargin : 0, (inOrientation & dfx::kAxis_Vertical) ? inRangeMargin : 0), (inOrientation & dfx::kAxis_Horizontal) ? (inRegion.getWidth() - (inRangeMargin * 2)) : (inRegion.getHeight() - (inRangeMargin * 2)), @@ -216,14 +216,15 @@ void DGSlider::setMidiLearner(bool inEnable) #pragma mark DGRangeSlider //----------------------------------------------------------------------------- -DGRangeSlider::DGRangeSlider(DfxGuiEditor* inOwnerEditor, long inLowerParamID, long inUpperParamID, DGRect const& inRegion, +DGRangeSlider::DGRangeSlider(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inLowerParameterID, dfx::ParameterID inUpperParameterID, + DGRect const& inRegion, DGImage* inLowerHandleImage, DGImage* inUpperHandleImage, - DGImage* inBackgroundImage, PushStyle inPushStyle, long inOvershoot) + DGImage* inBackgroundImage, PushStyle inPushStyle, int inOvershoot) : DGMultiControl(inRegion, inOwnerEditor, - inUpperParamID, + dfx::ParameterID_ToVST(inUpperParameterID), inBackgroundImage), - mLowerControl(addChild(inLowerParamID)), + mLowerControl(addChild(inLowerParameterID)), mUpperControl(this), mLowerMainHandleImage(inLowerHandleImage), mUpperMainHandleImage(inUpperHandleImage), @@ -543,14 +544,14 @@ void DGRangeSlider::setMidiLearner(bool /*inEnable*/) #pragma mark DGXYBox //----------------------------------------------------------------------------- -DGXYBox::DGXYBox(DfxGuiEditor* inOwnerEditor, long inParamIDX, long inParamIDY, DGRect const& inRegion, - DGImage* inHandleImage, DGImage* inBackgroundImage, int inStyle) +DGXYBox::DGXYBox(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterIDX, dfx::ParameterID inParameterIDY, + DGRect const& inRegion, DGImage* inHandleImage, DGImage* inBackgroundImage, int inStyle) : DGMultiControl(inRegion, inOwnerEditor, - inParamIDX, + dfx::ParameterID_ToVST(inParameterIDX), inBackgroundImage), mControlX(this), - mControlY(addChild(inParamIDY)), + mControlY(addChild(inParameterIDY)), mMainHandleImage(inHandleImage), mStyle(inStyle), mHandleWidth(inHandleImage ? inHandleImage->getWidth() : 1), @@ -820,14 +821,16 @@ float DGXYBox::mapValueY(float inValue) const //----------------------------------------------------------------------------- // DGAnimation //----------------------------------------------------------------------------- -DGAnimation::DGAnimation(DfxGuiEditor* inOwnerEditor, - long inParamID, - DGRect const& inRegion, - DGImage* inAnimationImage, - long inNumAnimationFrames) -: DGControl(inRegion, inOwnerEditor, inParamID, +DGAnimation::DGAnimation(DfxGuiEditor* inOwnerEditor, + dfx::ParameterID inParameterID, + DGRect const& inRegion, + DGImage* inAnimationImage, + size_t inNumAnimationFrames) +: DGControl(inRegion, inOwnerEditor, dfx::ParameterID_ToVST(inParameterID), inNumAnimationFrames, inRegion.getHeight(), inAnimationImage) { + assert(inNumAnimationFrames > 0); + setTransparency(true); setZoomFactor(getFineTuneFactor()); diff --git a/dfxgui/dfxguislider.h b/dfxgui/dfxguislider.h index 4bfe3aef..cd9caf60 100644 --- a/dfxgui/dfxguislider.h +++ b/dfxgui/dfxguislider.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -31,8 +31,8 @@ To contact the author, use the contact form at http://destroyfx.org/ class DGSlider : public DGControl { public: - DGSlider(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, - dfx::Axis inOrientation, DGImage* inHandleImage, DGImage* inBackgroundImage = nullptr, long inRangeMargin = 0); + DGSlider(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, + dfx::Axis inOrientation, DGImage* inHandleImage, DGImage* inBackgroundImage = nullptr, int inRangeMargin = 0); #ifdef TARGET_API_RTAS void draw(VSTGUI::CDrawContext* inContext) override; @@ -71,11 +71,12 @@ class DGRangeSlider : public DGMultiControl Upper }; - DGRangeSlider(DfxGuiEditor* inOwnerEditor, long inLowerParamID, long inUpperParamID, DGRect const& inRegion, + DGRangeSlider(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inLowerParameterID, dfx::ParameterID inUpperParameterID, + DGRect const& inRegion, DGImage* inLowerHandleImage, DGImage* inUpperHandleImage, DGImage* inBackgroundImage = nullptr, PushStyle inPushStyle = PushStyle::Neither, - long inOvershoot = 0); + int inOvershoot = 0); void draw(VSTGUI::CDrawContext* inContext) override; void onMouseDownEvent(VSTGUI::MouseDownEvent& ioEvent) override; @@ -102,7 +103,7 @@ class DGRangeSlider : public DGMultiControl VSTGUI::CCoord const mMaxXPos; // max X position in pixel float const mEffectiveRange; PushStyle const mPushStyle; - long const mOvershoot; // how far (in pixel) you can click outside of being in between the points and still be close enough to be considered in between + int const mOvershoot; // how far (in pixel) you can click outside of being in between the points and still be close enough to be considered in between // mouse-down state bool mClickBetween = false; @@ -125,8 +126,8 @@ class DGRangeSlider : public DGMultiControl class DGXYBox : public DGMultiControl { public: - DGXYBox(DfxGuiEditor* inOwnerEditor, long inParamIDX, long inParamIDY, DGRect const& inRegion, - DGImage* inHandleImage, DGImage* inBackgroundImage = nullptr, + DGXYBox(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterIDX, dfx::ParameterID inParameterIDY, + DGRect const& inRegion, DGImage* inHandleImage, DGImage* inBackgroundImage = nullptr, int inStyle = VSTGUI::CSliderBase::kLeft | VSTGUI::CSliderBase::kBottom); void draw(VSTGUI::CDrawContext* inContext) override; @@ -182,8 +183,8 @@ class DGXYBox : public DGMultiControl class DGAnimation : public DGControl { public: - DGAnimation(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, - DGImage* inAnimationImage, long inNumAnimationFrames); + DGAnimation(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, + DGImage* inAnimationImage, size_t inNumAnimationFrames); #ifdef TARGET_API_RTAS void draw(VSTGUI::CDrawContext* inContext) override; diff --git a/dfxgui/dfxguitextdisplay.cpp b/dfxgui/dfxguitextdisplay.cpp index ee7a14aa..16046dd8 100644 --- a/dfxgui/dfxguitextdisplay.cpp +++ b/dfxgui/dfxguitextdisplay.cpp @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "dfxguitextdisplay.h" @@ -189,7 +189,7 @@ static DGRect DFXGUI_GetTextDrawRegion(DGRect const& inRegion, int inYOffsetTwea // Text Display //----------------------------------------------------------------------------- DGTextDisplay::DGTextDisplay(DfxGuiEditor* inOwnerEditor, - long inParamID, + dfx::ParameterID inParameterID, DGRect const& inRegion, VSTGUI::CParamDisplayValueToStringProc inTextProc, void* inUserData, @@ -198,7 +198,7 @@ DGTextDisplay::DGTextDisplay(DfxGuiEditor* inOwnerEditor, float inFontSize, DGColor inFontColor, char const* inFontName) -: DGControl(inRegion, inOwnerEditor, inParamID, nullptr, inBackgroundImage), +: DGControl(inRegion, inOwnerEditor, dfx::ParameterID_ToVST(inParameterID), nullptr, inBackgroundImage), mValueToTextProc(inTextProc ? inTextProc : valueToTextProc_Generic), mValueToTextUserData(inUserData), mYOffsetTweak(DFXGUI_GetYOffsetTweak(inFontName)), @@ -336,8 +336,8 @@ bool DGTextDisplay::valueToTextProc_LinearToPercent(float inValue, char outTextU //----------------------------------------------------------------------------- std::optional DGTextDisplay::textToValueProc_Generic(std::string const& inText, DGTextDisplay* inTextDisplay) { - auto const paramID = inTextDisplay->getParameterID(); - auto const value_d = inTextDisplay->getOwnerEditor()->dfxgui_GetParameterValueFromString_f(paramID, inText); + auto const parameterID = inTextDisplay->getParameterID(); + auto const value_d = inTextDisplay->getOwnerEditor()->dfxgui_GetParameterValueFromString_f(parameterID, inText); return value_d ? std::make_optional(static_cast(*value_d)) : std::nullopt; } @@ -493,10 +493,10 @@ void DGStaticTextDisplay::drawPlatformText(VSTGUI::CDrawContext* inContext, VSTG //----------------------------------------------------------------------------- // Static Text Display //----------------------------------------------------------------------------- -DGTextArrayDisplay::DGTextArrayDisplay(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, +DGTextArrayDisplay::DGTextArrayDisplay(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, size_t inNumStrings, dfx::TextAlignment inTextAlignment, DGImage* inBackground, float inFontSize, DGColor inFontColor, char const* inFontName) -: DGTextDisplay(inOwnerEditor, inParamID, inRegion, nullptr, nullptr, inBackground, +: DGTextDisplay(inOwnerEditor, inParameterID, inRegion, nullptr, nullptr, inBackground, inTextAlignment, inFontSize, inFontColor, inFontName), // TODO C++23: integer literal suffix UZ mDisplayStrings(std::max(inNumStrings, size_t(1))) diff --git a/dfxgui/dfxguitextdisplay.h b/dfxgui/dfxguitextdisplay.h index 9167fba9..e1cd8dba 100644 --- a/dfxgui/dfxguitextdisplay.h +++ b/dfxgui/dfxguitextdisplay.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -47,7 +47,7 @@ class DGTextDisplay : public DGControl static constexpr size_t kTextMaxLength = 256; // inBackgroundImage may be null - DGTextDisplay(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, + DGTextDisplay(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, VSTGUI::CParamDisplayValueToStringProc inTextProc, void* inUserData, DGImage* inBackgroundImage, dfx::TextAlignment inTextAlignment = dfx::TextAlignment::Left, float inFontSize = 12.0f, DGColor inFontColor = VSTGUI::kBlackCColor, char const* inFontName = nullptr); @@ -139,7 +139,7 @@ class DGStaticTextDisplay : public DGControl class DGTextArrayDisplay : public DGTextDisplay { public: - DGTextArrayDisplay(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, size_t inNumStrings, + DGTextArrayDisplay(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, size_t inNumStrings, dfx::TextAlignment inTextAlignment = dfx::TextAlignment::Left, DGImage* inBackground = nullptr, float inFontSize = 12.0f, DGColor inFontColor = VSTGUI::kBlackCColor, char const* inFontName = nullptr); diff --git a/dfxgui/idfxguicontrol.h b/dfxgui/idfxguicontrol.h index 6d6fb657..3d7cf1e2 100644 --- a/dfxgui/idfxguicontrol.h +++ b/dfxgui/idfxguicontrol.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -26,6 +26,8 @@ To contact the author, use the contact form at http://destroyfx.org/ #include +#include "dfxdefines.h" + //----------------------------------------------------------------------------- @@ -52,8 +54,8 @@ class IDGControl virtual long getValue_i() = 0; virtual void setValue_i(long inValue) = 0; virtual void redraw() = 0; - virtual long getParameterID() const = 0; - virtual void setParameterID(long inParameterID) = 0; + virtual dfx::ParameterID getParameterID() const = 0; + virtual void setParameterID(dfx::ParameterID inParameterID) = 0; virtual bool isParameterAttached() const = 0; virtual size_t getNumStates() const = 0; virtual float getFineTuneFactor() const = 0; diff --git a/eqsync/eqsync.cpp b/eqsync/eqsync.cpp index adf814a1..e6b1dd22 100644 --- a/eqsync/eqsync.cpp +++ b/eqsync/eqsync.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EQ Sync. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "eqsync.h" @@ -41,7 +41,7 @@ EQSync::EQSync(TARGET_API_BASE_INSTANCE_TYPE inInstance) initparameter_f(kSmooth, {"smooth", "Smth"}, 3.0, 33.333, 0.0, 100.0, DfxParam::Unit::Percent); // % of cycle initparameter_f(kTempo, dfx::MakeParameterNames(dfx::kParameterNames_Tempo), 120.0, 120.0, 39.0, 480.0, DfxParam::Unit::BPM); initparameter_b(kTempoAuto, dfx::MakeParameterNames(dfx::kParameterNames_TempoAuto), true); -// for (long i = kA0; i <= kB2; i++) +// for (dfx::ParameterID i = kA0; i <= kB2; i++) { // initparameter_f(i, {""}, 0.5, 0.5, 0.0, 1.0, DfxParam::Unit::Generic); } diff --git a/eqsync/eqsync.h b/eqsync/eqsync.h index cef4ae3c..72762265 100644 --- a/eqsync/eqsync.h +++ b/eqsync/eqsync.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EQ Sync. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -31,7 +31,7 @@ To contact the author, use the contact form at http://destroyfx.org/ //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kRate_Sync, kSmooth, diff --git a/eqsync/gui/eqsynceditor.cpp b/eqsync/gui/eqsynceditor.cpp index 05538098..4f2059bf 100644 --- a/eqsync/gui/eqsynceditor.cpp +++ b/eqsync/gui/eqsynceditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EQ Sync. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "eqsynceditor.h" @@ -85,9 +85,9 @@ static int GetMacOSVersion() class EQSyncSlider final : public DGSlider { public: - EQSyncSlider(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, + EQSyncSlider(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, dfx::Axis inOrientation, DGImage* inHandle, DGImage* inHandleClicked, DGImage* inBackground) - : DGSlider(inOwnerEditor, inParamID, inRegion, inOrientation, inHandle, inBackground), + : DGSlider(inOwnerEditor, inParameterID, inRegion, inOrientation, inHandle, inBackground), mRegularHandle(inHandle), mClickedHandle(inHandleClicked) { } @@ -193,7 +193,7 @@ long EQSyncEditor::OpenEditor() DGRect pos; - for (long i = kRate_Sync; i <= kTempo; i++) + for (dfx::ParameterID i = kRate_Sync; i <= kTempo; i++) { // create the horizontal sliders pos.set(wideFaderX, wideFaderY + (kWideFaderInc * i), horizontalSliderBackgroundImage->getWidth(), horizontalSliderBackgroundImage->getHeight()); @@ -240,7 +240,7 @@ long EQSyncEditor::OpenEditor() } // create the vertical sliders - for (long i = kA0; i <= kB2; i++) + for (dfx::ParameterID i = kA0; i <= kB2; i++) { pos.set(tallFaderX + (kTallFaderInc * (i - kA0)), tallFaderY, verticalSliderBackgroundImage->getWidth(), verticalSliderBackgroundImage->getHeight()); emplaceControl(this, i, pos, dfx::kAxis_Vertical, sliderHandleImage, sliderHandleClickedImage, verticalSliderBackgroundImage); @@ -272,7 +272,7 @@ long EQSyncEditor::OpenEditor() } //----------------------------------------------------------------------------- -void EQSyncEditor::parameterChanged(long inParameterID) +void EQSyncEditor::parameterChanged(dfx::ParameterID inParameterID) { if (inParameterID == kTempoAuto) { diff --git a/eqsync/gui/eqsynceditor.h b/eqsync/gui/eqsynceditor.h index 9875673e..1e0c31da 100644 --- a/eqsync/gui/eqsynceditor.h +++ b/eqsync/gui/eqsynceditor.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------ -Copyright (C) 2001-2021 Sophia Poirier +Copyright (C) 2001-2022 Sophia Poirier This file is part of EQ Sync. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EQ Sync. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -30,7 +30,7 @@ class EQSyncEditor final : public DfxGuiEditor public: explicit EQSyncEditor(DGEditorListenerInstance inInstance); long OpenEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; private: void HandleTempoAutoChange(); diff --git a/exemplar/exemplar.cpp b/exemplar/exemplar.cpp index 71ba96d8..f1a1bdd6 100644 --- a/exemplar/exemplar.cpp +++ b/exemplar/exemplar.cpp @@ -15,27 +15,25 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Exemplar. If not, see . + +To contact the author, use the contact form at http://destroyfx.org + +DFX Exemplar, featuring the Super Destroy FX Windowing System! ------------------------------------------------------------------------*/ #include "exemplar.h" #include +#include #include #include -// #include - -#define DIMENSION 10 #define NORMALIZE 1 -// should be param */ -#define STRIDE 128 -#if defined(TARGET_API_VST) && TARGET_PLUGIN_HAS_GUI - #ifndef _DFX_EXEMPLAREDITOR_H - #include "exemplareditor.hpp" - #endif -#endif +static constexpr int DIMENSION = 10; +// should be param */ +static constexpr int STRIDE = 128; /* this macro does boring entry point stuff for us */ DFX_ENTRY(Exemplar); @@ -63,22 +61,21 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) setparametervaluestring(P_MODE, MODE_MATCH, "match"); setparametervaluestring(P_MODE, MODE_CAPTURE, "capture"); - long i; /* set up values for windowing */ - char bufstr[64]; - for (i=0; i < BUFFERSIZESSIZE; i++) { + std::array bufstr {}; + for (long i=0; i < BUFFERSIZESSIZE; i++) { if (buffersizes[i] > 1000) - sprintf(bufstr, "%ld,%03ld", buffersizes[i]/1000, buffersizes[i]%1000); + snprintf(bufstr.data(), bufstr.size(), "%ld,%03ld", buffersizes[i]/1000, buffersizes[i]%1000); else - sprintf(bufstr, "%ld", buffersizes[i]); - setparametervaluestring(P_BUFSIZE, i, bufstr); + snprintf(bufstr.data(), bufstr.size(), "%ld", buffersizes[i]); + setparametervaluestring(P_BUFSIZE, i, bufstr.data()); } setparametervaluestring(P_SHAPE, WINDOW_TRIANGLE, "linear"); setparametervaluestring(P_SHAPE, WINDOW_ARROW, "arrow"); setparametervaluestring(P_SHAPE, WINDOW_WEDGE, "wedge"); setparametervaluestring(P_SHAPE, WINDOW_COS, "best"); - for (i=NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) + for (int i=NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) setparametervaluestring(P_SHAPE, i, "???"); long delay_samples = buffersizes[getparameter_i(P_BUFSIZE)]; @@ -95,13 +92,6 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) #if !TARGET_PLUGIN_USES_DSPCORE addchannelconfig(1, 1); /* mono */ #endif - -#ifdef TARGET_API_VST - /* if you have a GUI, need an Editor class... */ - #if TARGET_PLUGIN_HAS_GUI - editor = new ExemplarEditor(this); - #endif -#endif } PLUGINCORE::PLUGINCORE(DfxPlugin * inInstance) @@ -110,33 +100,19 @@ PLUGINCORE::PLUGINCORE(DfxPlugin * inInstance) constexpr auto maxframe = *std::max_element(std::cbegin(buffersizes), std::cend(buffersizes)); /* add some leeway? */ - in0 = (float*)malloc(maxframe * sizeof (float)); - out0 = (float*)malloc(maxframe * 2 * sizeof (float)); + in0.assign(maxframe, 0.f); + out0.assign(maxframe * 2, 0.f); /* prevmix is only a single third long */ - prevmix = (float*)malloc((maxframe / 2) * sizeof (float)); - - /* initialize nn stuff */ - capturemode = true; - nntree = 0; - ncapsamples = 0; - npoints = 0; + prevmix.assign(maxframe / 2, 0.f); /* initialize FFT stuff */ - plan = rfftw_create_plan(framesize, FFTW_FORWARD, FFTW_ESTIMATE); - // rplan = rfftw_create_plan(framesize, FFTW_BACKWARD, FFTW_ESTIMATE); + plan.reset(rfftw_create_plan(framesize, FFTW_FORWARD, FFTW_ESTIMATE)); + // rplan.reset(rfftw_create_plan(framesize, FFTW_BACKWARD, FFTW_ESTIMATE)); } -PLUGINCORE::~PLUGINCORE() { - /* windowing buffers */ - free (in0); - free (out0); - - free (prevmix); -} - void PLUGINCORE::reset() { framesize = buffersizes[getparameter_i(P_BUFSIZE)]; @@ -153,7 +129,7 @@ void PLUGINCORE::reset() { capturemode = newcapture; if (capturemode) { /* entering capture mode. discard the existing tree */ - nntree = 0; /* XXX do it... */ + nntree.reset(); /* XXX do it... */ ncapsamples = 0; npoints = 0; @@ -164,15 +140,15 @@ void PLUGINCORE::reset() { int exstart = 0; /* make points */ for (exstart = 0; exstart < (ncapsamples - wsize); exstart += STRIDE) { - /* save which start point this is */ + /* save which start point this is */ cap_index[npoints] = exstart; classify(&(capsamples[exstart]), - cap_scale[npoints], + cap_scale[npoints], cap_point[npoints], wsize); - npoints++; + npoints++; } - nntree = new ANNkd_tree(cap_point, npoints, DIMENSION); + nntree = std::make_unique(cap_point, npoints, DIMENSION); char msg[512]; // sprintf(msg, "ok %p", this); // MessageBoxA(0, "match mode", msg, MB_OK); @@ -192,22 +168,17 @@ void PLUGINCORE::reset() { /* set up buffers. Prevmix and first frame of output are always filled with zeros. XXX memset */ - for (int i = 0; i < third; i ++) { - prevmix[i] = 0.0f; - } + std::fill_n(prevmix.begin(), third, 0.f); + std::fill_n(out0.begin(), framesize, 0.f) - for (int j = 0; j < framesize; j ++) { - out0[j] = 0.0f; - } - /* start input at beginning. Output has a frame of silence. */ insize = 0; outstart = 0; outsize = framesize; /* restore FFT plans */ - plan = rfftw_create_plan(framesize, FFTW_FORWARD, FFTW_ESTIMATE); - // rplan = rfftw_create_plan(framesize, FFTW_BACKWARD, FFTW_ESTIMATE); + plan.reset(rfftw_create_plan(framesize, FFTW_FORWARD, FFTW_ESTIMATE)); + // rplan.reset(rfftw_create_plan(framesize, FFTW_BACKWARD, FFTW_ESTIMATE)); dfxplugin->setlatency_samples(framesize); /* tail is the same as delay, of course */ @@ -217,7 +188,7 @@ void PLUGINCORE::reset() { void PLUGINCORE::processparameters() { /* can safely change this whenever... */ - float erroramount = getparameter_f(P_ERRORAMOUNT); + erroramount = getparameter_f(P_ERRORAMOUNT); #ifdef TARGET_API_VST /* this tells the host to call a suspend()-resume() pair, @@ -232,7 +203,7 @@ void PLUGINCORE::processparameters() { write your DSP, and it will be always called with the same sample size (as long as the block size parameter stays the same) and automatically overlapped. */ -void PLUGINCORE::processw(float * in, float * out, long samples) { +void PLUGINCORE::processw(float const * in, float * out, long samples) { #if 0 /* this sounds pretty neat, actually. */ @@ -328,7 +299,7 @@ void PLUGINCORE::processw(float * in, float * out, long samples) { */ /* assumes samples is a power of two. */ -void PLUGINCORE::classify_haar(float * in, float & scale, +void PLUGINCORE::classify_haar(float const * in, float & scale, ANNpoint & out, long samples) { out = annAllocPt(DIMENSION); @@ -362,10 +333,9 @@ void PLUGINCORE::classify_haar(float * in, float & scale, wavelet degenerates too quickly, because the peaks shrink logarithmically). So, shrink at a smaller factor. */ -#define shrink freq = freq * 4 / 5 for(int d = 0; d < DIMENSION; d++) { - shrink; + freq = freq * 4 / 5; // shrink if (freq) { int i = 0; float prod = 0.0; @@ -399,7 +369,7 @@ void PLUGINCORE::classify_haar(float * in, float & scale, } -void PLUGINCORE::classify_fft(float * in, float & scale, +void PLUGINCORE::classify_fft(float const * in, float & scale, ANNpoint & out, long samples) { out = annAllocPt(DIMENSION); @@ -426,7 +396,7 @@ void PLUGINCORE::classify_fft(float * in, float & scale, # endif /* do the fft */ - rfftw_one(plan, in, fftr); + rfftw_one(plan.get(), in, fftr); /* what we've got now is frequency/amplitude pairs. we want to represent the characteristics of this @@ -471,7 +441,7 @@ void PLUGINCORE::classify_fft(float * in, float & scale, idea 6: classifier is n/2 pairs of (freq, amplitude), where each pair is scaled by a constant determined by its - index. + index. only bad when the n loudest frequencies are close to one another in amplitude. @@ -486,7 +456,7 @@ void PLUGINCORE::classify_fft(float * in, float & scale, collect the DIMENSION highest bins, sorted in descending order. */ - int best[DIMENSION]; + int best[DIMENSION] {}; { for(int j = 0; j < DIMENSION; j ++) best[j] = -1; } @@ -498,7 +468,7 @@ void PLUGINCORE::classify_fft(float * in, float & scale, if (getparameter_i(P_FFTRANGE) == FFTR_AUDIBLE) { /* XXX just a guess. Need to know the sample rate. - But, whatever. */ + But, whatever. */ low = .005 * samples; hi = samples * 0.95; } @@ -511,18 +481,18 @@ void PLUGINCORE::classify_fft(float * in, float & scale, int m = i; /* m will be inserted if larger than fftr[best[j]] - or best[j] == -1 */ + or best[j] == -1 */ for(int j = 0; j < DIMENSION; j ++) { - if (best[j] == -1) { - best[j] = m; break; - } else { - /* better than current best */ - if (fftr[m] > fftr[best[j]]) { - int tmp = best[j]; - best[j] = m; - m = tmp; - } else break; - } + if (best[j] == -1) { + best[j] = m; break; + } else { + /* better than current best */ + if (fftr[m] > fftr[best[j]]) { + int tmp = best[j]; + best[j] = m; + m = tmp; + } else break; + } } } @@ -546,7 +516,7 @@ void PLUGINCORE::classify_fft(float * in, float & scale, } } -void PLUGINCORE::classify(float * in, float & scale, +void PLUGINCORE::classify(float const * in, float & scale, ANNpoint & out, long samples) { classify_fft(in, scale, out, samples); } @@ -598,7 +568,7 @@ void PLUGINCORE::process(const float *tin, float *tout, size_t samples) { /* frame is full! */ /* in0 -> process -> out0(first free space) */ - processw(in0, out0+outstart+outsize, framesize); + processw(in0.data(), out0.data()+outstart+outsize, framesize); float oneDivThird = 1.0f / (float)third; /* apply envelope */ @@ -640,11 +610,11 @@ void PLUGINCORE::process(const float *tin, float *tout, size_t samples) { out0[u+outstart+outsize] += prevmix[u]; /* prevmix becomes out1 */ - memcpy(prevmix, out0 + outstart + outsize + third, third * sizeof (float)); + std::copy_n(std::next(out0.cbegin(), outstart + outsize + third), third, prevmix.begin()); /* copy 2nd third of input over in0 (need to re-use it for next frame), now insize = third */ - memcpy(in0, in0 + third, third * sizeof (float)); + std::copy_n(std::next(in0.cbegin(), third), third, in0.begin()); insize = third; @@ -659,7 +629,7 @@ void PLUGINCORE::process(const float *tin, float *tout, size_t samples) { /* make sure there is always enough room for a frame in out buffer */ if (outstart == third) { - memmove(out0, out0 + outstart, outsize * sizeof (float)); + memmove(out0.data(), out0.data() + outstart, outsize * sizeof (float)); outstart = 0; } } diff --git a/exemplar/exemplar.h b/exemplar/exemplar.h index 9bf41df0..5fd924c9 100644 --- a/exemplar/exemplar.h +++ b/exemplar/exemplar.h @@ -16,14 +16,18 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Exemplar. If not, see . +To contact the author, use the contact form at http://destroyfx.org + DFX Exemplar, starring the Super Destroy FX Windowing System! ------------------------------------------------------------------------*/ #pragma once #include -#include +#include +#include +#include "dfxmisc.h" #include "dfxplugin.h" #include "ANN/ANN.h" #include "rfftw.h" @@ -59,10 +63,10 @@ enum { FFTR_AUDIBLE, NUM_FFTRS, }; /* the names of the parameters */ -enum { P_BUFSIZE, P_SHAPE, - P_MODE, P_FFTRANGE, - P_ERRORAMOUNT, - NUM_PARAMS, +enum : dfx::ParameterID { P_BUFSIZE, P_SHAPE, + P_MODE, P_FFTRANGE, + P_ERRORAMOUNT, + NUM_PARAMS }; @@ -80,7 +84,6 @@ class PLUGIN : public DfxPlugin { class PLUGINCORE : public DfxPluginCore { public: explicit PLUGINCORE(DfxPlugin * inInstance); - ~PLUGINCORE() override; void reset() override; void processparameters() override; @@ -93,46 +96,46 @@ class PLUGINCORE : public DfxPluginCore { /* input and output buffers. out is framesize*2 samples long, in is framesize samples long. (for maximum framesize) */ - float * in0, * out0; + std::vector in0, out0; /* bufsize is 3 * third, framesize is 2 * third bufsize is used for outbuf. */ - long bufsize, framesize, third; + long bufsize = 0, framesize = 0, third = 0; - void processw(float * in, float * out, long samples); + void processw(float const * in, float * out, long samples); - int shape; + int shape = 0; /* third-sized tail of previous processed frame. already has mixing envelope applied. */ - float * prevmix; + std::vector prevmix; /* number of samples in in0 */ - int insize; + int insize = 0; /* number of samples and starting position of valid samples in out0 */ - int outsize; - int outstart; + int outsize = 0; + int outstart = 0; /* Exemplar stuff */ /* classifies a window */ - void classify(float * in, float & scale, ANNpoint & out, long samples); + void classify(float const * in, float & scale, ANNpoint & out, long samples); /* specific classifiers */ - void classify_haar(float * in, float & scale, ANNpoint & out, long samples); - void classify_fft (float * in, float & scale, ANNpoint & out, long samples); + void classify_haar(float const * in, float & scale, ANNpoint & out, long samples); + void classify_fft (float const * in, float & scale, ANNpoint & out, long samples); - bool capturemode; - float erroramount; + bool capturemode = true; + float erroramount = 0.f; static constexpr size_t CAPBUFFER = 500000; /* 1000000 */ - float capsamples[CAPBUFFER]; - int ncapsamples; /* < CAPBUFFER */ + float capsamples[CAPBUFFER] {}; + int ncapsamples = 0; /* < CAPBUFFER */ #if 0 /* an individual capture */ @@ -145,18 +148,17 @@ class PLUGINCORE : public DfxPluginCore { }; #endif - ANNpoint cap_point[CAPBUFFER]; - int cap_index[CAPBUFFER]; - float cap_scale[CAPBUFFER]; - int npoints; + ANNpoint cap_point[CAPBUFFER] {}; + int cap_index[CAPBUFFER] {}; + float cap_scale[CAPBUFFER] {}; + int npoints = 0; - ANNkd_tree * nntree; + std::unique_ptr nntree; /* for FFTW: current analysis plan */ - rfftw_plan plan; - rfftw_plan rplan; + dfx::UniqueOpaqueType plan, rplan; /* result of ffts ( */ - float fftr[*std::max_element(std::cbegin(buffersizes), std::cend(buffersizes))]; + float fftr[*std::max_element(std::cbegin(buffersizes), std::cend(buffersizes))] {}; }; diff --git a/fonttest/fonttest.h b/fonttest/fonttest.h index 0c5d5ae8..5ffba88e 100644 --- a/fonttest/fonttest.h +++ b/fonttest/fonttest.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------ -Copyright (C) 2021 Tom Murphy 7 and Sophia Poirier +Copyright (C) 2021-2022 Tom Murphy 7 and Sophia Poirier This file is part of FontTest. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FontTest. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -30,7 +30,7 @@ class FontTest final : public DfxPlugin { explicit FontTest(TARGET_API_BASE_INSTANCE_TYPE inInstance); private: - enum + enum : dfx::ParameterID { kPlaceholder, kNumParameters diff --git a/geometer/geometer-base.h b/geometer/geometer-base.h index 6645652a..69a4d5b6 100644 --- a/geometer/geometer-base.h +++ b/geometer/geometer-base.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------ -Copyright (C) 2002-2021 Tom Murphy 7 and Sophia Poirier +Copyright (C) 2002-2022 Tom Murphy 7 and Sophia Poirier This file is part of Geometer. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Geometer. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Geometer, starring the Super Destroy FX Windowing System! ------------------------------------------------------------------------*/ @@ -26,6 +26,7 @@ Geometer, starring the Super Destroy FX Windowing System! #include #include +#include "dfxdefines.h" #include "dfxmisc.h" #include "dfxpluginproperties.h" @@ -82,18 +83,18 @@ enum { WINDOW_TRIANGLE, }; /* the names of the parameters */ -enum { P_BUFSIZE, P_SHAPE, - P_POINTSTYLE, - P_POINTPARAMS, - P_INTERPSTYLE = P_POINTPARAMS + MAX_POINTSTYLES, - P_INTERPARAMS, - P_POINTOP1 = P_INTERPARAMS + MAX_INTERPSTYLES, - P_OPPAR1S, - P_POINTOP2 = P_OPPAR1S + MAX_OPS, - P_OPPAR2S, - P_POINTOP3 = P_OPPAR2S + MAX_OPS, - P_OPPAR3S, - NUM_PARAMS = P_OPPAR3S + MAX_OPS +enum : dfx::ParameterID { P_BUFSIZE, P_SHAPE, + P_POINTSTYLE, + P_POINTPARAMS, + P_INTERPSTYLE = P_POINTPARAMS + MAX_POINTSTYLES, + P_INTERPARAMS, + P_POINTOP1 = P_INTERPARAMS + MAX_INTERPSTYLES, + P_OPPAR1S, + P_POINTOP2 = P_OPPAR1S + MAX_OPS, + P_OPPAR2S, + P_POINTOP3 = P_OPPAR2S + MAX_OPS, + P_OPPAR3S, + NUM_PARAMS = P_OPPAR3S + MAX_OPS }; enum : dfx::PropertyID { PROP_LAST_WINDOW_TIMESTAMP = dfx::kPluginProperty_EndOfList, diff --git a/geometer/geometer.cpp b/geometer/geometer.cpp index 4f1fd0f2..ecb0821c 100644 --- a/geometer/geometer.cpp +++ b/geometer/geometer.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Geometer. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Geometer, Featuring the Super Destroy FX Windowing System! @@ -57,7 +57,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) initparameter_f(P_POINTPARAMS + POINT_DYDX, {"point:dydx", "PntDyDx", "PDyDx", "PDyx"}, 0.50, 0.50, 0.0, 1.0, DfxParam::Unit::Custom, DfxParam::Curve::Linear, "gap"); initparameter_f(P_POINTPARAMS + POINT_LEVEL, {"point:level", "PntLevl", "PLevel" "PLvl"}, 0.50, 0.50, 0.0, 1.0, DfxParam::Unit::Custom, DfxParam::Curve::Linear, "level"); - for(int pp = NUM_POINTSTYLES; pp < MAX_POINTSTYLES; pp++) { + for(dfx::ParameterID pp = NUM_POINTSTYLES; pp < MAX_POINTSTYLES; pp++) { initparameter_f(P_POINTPARAMS + pp, {"pointparam:unused", "PUnused", "Pxxx"}, 0.04, 0.04, 0.0, 1.0, DfxParam::Unit::Generic); setparameterattributes(P_POINTPARAMS + pp, DfxParam::kAttribute_Unused); /* don't display as an available parameter */ } @@ -73,7 +73,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) initparameter_f(P_INTERPARAMS + INTERP_SING, {"interp:sing", "IntSing", "ISing", "ISng"}, 0.8, 0.8, 0.0, 1.0, DfxParam::Unit::Custom, DfxParam::Curve::Linear, "mod"); initparameter_f(P_INTERPARAMS + INTERP_SHUFFLE, {"interp:shuffle", "IShuffl", "IShufl", "IShf"}, 0.3, 0.3, 0.0, 1.0, DfxParam::Unit::Generic); - for(int ip = NUM_INTERPSTYLES; ip < MAX_INTERPSTYLES; ip++) { + for(dfx::ParameterID ip = NUM_INTERPSTYLES; ip < MAX_INTERPSTYLES; ip++) { initparameter_f(P_INTERPARAMS + ip, {"inter:unused", "IUnused", "Ixxx"}, 0.0, 0.0, 0.0, 1.0, DfxParam::Unit::Generic); setparameterattributes(P_INTERPARAMS + ip, DfxParam::kAttribute_Unused); /* don't display as an available parameter */ } @@ -98,7 +98,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) allop(OP_FAST, "fast", "fast", 0.5, DfxParam::Unit::Scalar, {}); // "factor" allop(OP_NONE, "none", "none", 0.0, DfxParam::Unit::Generic, {}); - for(int op = NUM_OPS; op < MAX_OPS; op++) { + for(dfx::ParameterID op = NUM_OPS; op < MAX_OPS; op++) { allop(op, "unused", "xxx", 0.5, DfxParam::Unit::Generic, {}); setparameterattributes(P_OPPAR1S + op, DfxParam::kAttribute_Unused); /* don't display as an available parameter */ setparameterattributes(P_OPPAR2S + op, DfxParam::kAttribute_Unused); /* don't display as an available parameter */ @@ -121,7 +121,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) setparametervaluestring(P_SHAPE, WINDOW_ARROW, "arrow"); setparametervaluestring(P_SHAPE, WINDOW_WEDGE, "wedge"); setparametervaluestring(P_SHAPE, WINDOW_COS, "best"); - for (long i=NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) + for (int i=NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) setparametervaluestring(P_SHAPE, i, "???"); /* geometer */ setparametervaluestring(P_POINTSTYLE, POINT_EXTNCROSS, "ext 'n cross"); @@ -130,7 +130,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) setparametervaluestring(P_POINTSTYLE, POINT_RANDOM, "randomly"); setparametervaluestring(P_POINTSTYLE, POINT_SPAN, "span"); setparametervaluestring(P_POINTSTYLE, POINT_DYDX, "dy/dx"); - for (long i=NUM_POINTSTYLES; i < MAX_POINTSTYLES; i++) + for (int i=NUM_POINTSTYLES; i < MAX_POINTSTYLES; i++) setparametervaluestring(P_POINTSTYLE, i, "unsup"); setparametervaluestring(P_INTERPSTYLE, INTERP_POLYGON, "polygon"); setparametervaluestring(P_INTERPSTYLE, INTERP_WRONGYGON, "wrongygon"); @@ -140,7 +140,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) setparametervaluestring(P_INTERPSTYLE, INTERP_FRIENDS, "friends"); setparametervaluestring(P_INTERPSTYLE, INTERP_SING, "sing"); setparametervaluestring(P_INTERPSTYLE, INTERP_SHUFFLE, "shuffle"); - for (long i=NUM_INTERPSTYLES; i < MAX_INTERPSTYLES; i++) + for (int i=NUM_INTERPSTYLES; i < MAX_INTERPSTYLES; i++) setparametervaluestring(P_INTERPSTYLE, i, "unsup"); auto const allopstr = [this](auto n, auto str) { setparametervaluestring(P_POINTOP1, n, str); @@ -155,13 +155,13 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) allopstr(OP_SLOW, "slow"); allopstr(OP_FAST, "fast"); allopstr(OP_NONE, "none"); - for (long i=NUM_OPS; i < MAX_OPS; i++) + for (int i=NUM_OPS; i < MAX_OPS; i++) allopstr(i, "unsup"); addparametergroup("windowing", {P_BUFSIZE, P_SHAPE}); - auto const addparameterrangegroup = [this](auto name, long parameterIndexBegin, long parameterIndexEnd) { + auto const addparameterrangegroup = [this](auto name, dfx::ParameterID parameterIndexBegin, dfx::ParameterID parameterIndexEnd) { assert(parameterIndexBegin < parameterIndexEnd); - std::vector parameters(parameterIndexEnd - parameterIndexBegin, dfx::kParameterID_Invalid); + std::vector parameters(parameterIndexEnd - parameterIndexBegin, dfx::kParameterID_Invalid); std::iota(parameters.begin(), parameters.end(), parameterIndexBegin); addparametergroup(name, parameters); }; @@ -224,11 +224,11 @@ long PLUGIN::dfx_GetProperty(dfx::PropertyID inPropertyID, dfx::Scope inScope, u } } -void PLUGIN::randomizeparameter(long inParameterIndex) +void PLUGIN::randomizeparameter(dfx::ParameterID inParameterID) { // we need to constrain the range of values of the parameters that have extra (currently unused) room for future expansion int64_t maxValue = 0; - switch (inParameterIndex) + switch (inParameterID) { case P_SHAPE: maxValue = NUM_WINDOWSHAPES; @@ -245,14 +245,14 @@ void PLUGIN::randomizeparameter(long inParameterIndex) maxValue = NUM_OPS; break; default: - DfxPlugin::randomizeparameter(inParameterIndex); + DfxPlugin::randomizeparameter(inParameterID); return; } auto const newValue = generateParameterRandomValue(0, maxValue - 1); - setparameter_i(inParameterIndex, newValue); + setparameter_i(inParameterID, newValue); - postupdate_parameter(inParameterIndex); // inform any parameter listeners of the changes + postupdate_parameter(inParameterID); // inform any parameter listeners of the changes } void PLUGIN::clearwindowcache() @@ -312,10 +312,13 @@ void PLUGINCORE::updatewindowcache() } } -std::optional PLUGIN::settings_getLearningAssignData(long inParameterIndex) const +std::optional PLUGIN::settings_getLearningAssignData(dfx::ParameterID inParameterID) const { - auto const getConstrainedToggleAssignment = [](long inNumStates, long inNumUsableStates) + auto const getConstrainedToggleAssignment = [](int inNumStates, int inNumUsableStates) { + assert(inNumStates > 0); + assert(inNumUsableStates > 0); + assert(inNumUsableStates <= inNumStates); dfx::ParameterAssignment result; result.mEventBehaviorFlags = dfx::kMidiEventBehaviorFlag_Toggle; result.mDataInt1 = inNumStates; @@ -323,7 +326,7 @@ std::optional PLUGIN::settings_getLearningAssignData(l return result; }; - switch (inParameterIndex) + switch (inParameterID) { case P_SHAPE: return getConstrainedToggleAssignment(MAX_WINDOWSHAPES, NUM_WINDOWSHAPES); diff --git a/geometer/geometer.h b/geometer/geometer.h index b1790757..fbcf293c 100644 --- a/geometer/geometer.h +++ b/geometer/geometer.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Geometer. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org Geometer, starring the Super Destroy FX Windowing System! ------------------------------------------------------------------------*/ @@ -55,13 +55,13 @@ class PLUGIN final : public DfxPlugin { long dfx_GetProperty(dfx::PropertyID inPropertyID, dfx::Scope inScope, unsigned int inItemIndex, void* outData) override; - void randomizeparameter(long inParameterIndex) override; + void randomizeparameter(dfx::ParameterID inParameterID) override; void clearwindowcache(); void updatewindowcache(class PLUGINCORE * geometercore); protected: - std::optional settings_getLearningAssignData(long inParameterIndex) const override; + std::optional settings_getLearningAssignData(dfx::ParameterID inParameterID) const override; private: static constexpr size_t NUM_PRESETS = 16; diff --git a/geometer/gui/geometereditor.cpp b/geometer/gui/geometereditor.cpp index fbe7cbc5..4d6d0972 100644 --- a/geometer/gui/geometereditor.cpp +++ b/geometer/gui/geometereditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Geometer. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "geometereditor.h" @@ -226,9 +226,9 @@ long GeometerEditor::OpenEditor() { DGRect lpos(pos_sliderlabelX, pos_sliderlabelY, pos_sliderlabelwidth, pos_sliderlabelheight); for (size_t i=0; i < NUM_SLIDERS; i++) { auto const baseparam = get_base_param_for_slider(i); - assert(dfxgui_IsValidParamID(baseparam)); + assert(dfxgui_IsValidParameterID(baseparam)); auto labelstrings = &ops_labelstrings; - long xoff = 0, yoff = 0; + int xoff = 0, yoff = 0; // how to generate landmarks if (baseparam == P_POINTSTYLE) { labelstrings = &landmarks_labelstrings; @@ -253,7 +253,7 @@ long GeometerEditor::OpenEditor() { } auto const param = choose_multiparam(baseparam); - constexpr long sliderRangeMargin = 1; + constexpr int sliderRangeMargin = 1; sliders[i] = emplaceControl(this, param, pos, dfx::kAxis_Horizontal, g_sliderhandle, g_sliderbackground, sliderRangeMargin); sliders[i]->setAlternateHandle(g_sliderhandle_glowing); @@ -346,7 +346,7 @@ void GeometerEditor::CloseEditor() { //----------------------------------------------------------------------------- -void GeometerEditor::parameterChanged(long inParameterID) { +void GeometerEditor::parameterChanged(dfx::ParameterID inParameterID) { for (size_t i=0; i < NUM_SLIDERS; i++) { auto const baseparam = get_base_param_for_slider(i); @@ -466,7 +466,13 @@ std::string GeometerEditor::helptext(size_t inHelpCategory, int inItemNum) { } //----------------------------------------------------------------------------- -long GeometerEditor::get_base_param_for_slider(size_t sliderIndex) noexcept { +dfx::ParameterID GeometerEditor::choose_multiparam(dfx::ParameterID baseParamID) { + + return static_cast(getparameter_i(baseParamID)) + baseParamID + 1; +} + +//----------------------------------------------------------------------------- +dfx::ParameterID GeometerEditor::get_base_param_for_slider(size_t sliderIndex) noexcept { switch (sliderIndex) { case 0: diff --git a/geometer/gui/geometereditor.h b/geometer/gui/geometereditor.h index bd2e64cc..3a59338c 100644 --- a/geometer/gui/geometereditor.h +++ b/geometer/gui/geometereditor.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Geometer. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -33,16 +33,14 @@ class GeometerEditor final : public DfxGuiEditor { long OpenEditor() override; void CloseEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; void mouseovercontrolchanged(IDGControl * currentControlUnderMouse) override; private: std::string changehelp(IDGControl * currentControlUnderMouse); static std::string helptext(size_t inHelpCategory, int inItemNum); - long choose_multiparam(long baseParamID) { - return getparameter_i(baseParamID) + baseParamID + 1; - } - static long get_base_param_for_slider(size_t sliderIndex) noexcept; + dfx::ParameterID choose_multiparam(dfx::ParameterID baseParamID); + static dfx::ParameterID get_base_param_for_slider(size_t sliderIndex) noexcept; std::vector sliders; std::vector displays; diff --git a/midigater/midigater.h b/midigater/midigater.h index 33469ca6..d4bd049a 100644 --- a/midigater/midigater.h +++ b/midigater/midigater.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MIDI Gater. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -31,7 +31,7 @@ To contact the author, use the contact form at http://destroyfx.org/ //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kAttack, kRelease, diff --git a/monomaker/gui/monomakereditor.cpp b/monomaker/gui/monomakereditor.cpp index 09d88e09..048254dd 100644 --- a/monomaker/gui/monomakereditor.cpp +++ b/monomaker/gui/monomakereditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Monomaker. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "monomakereditor.h" @@ -108,7 +108,7 @@ long MonomakerEditor::OpenEditor() // --- sliders --- - constexpr long numAnimationFrames = 19; + constexpr size_t numAnimationFrames = 19; // monomerge slider pos.set(kSliderX, kSliderY, kSliderWidth, sliderHandleImage->getHeight()); diff --git a/monomaker/monomaker.h b/monomaker/monomaker.h index d815637d..0a29b22c 100644 --- a/monomaker/monomaker.h +++ b/monomaker/monomaker.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Monomaker. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -29,7 +29,7 @@ To contact the author, use the contact form at http://destroyfx.org/ //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kInputSelection, kMonomerge, diff --git a/polarizer/gui/polarizereditor.cpp b/polarizer/gui/polarizereditor.cpp index c7f35676..436212d8 100644 --- a/polarizer/gui/polarizereditor.cpp +++ b/polarizer/gui/polarizereditor.cpp @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------ -Copyright (C) 2001-2021 Sophia Poirier +Copyright (C) 2001-2022 Sophia Poirier This file is part of Polarizer. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Polarizer. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "polarizereditor.h" @@ -83,9 +83,9 @@ static float amountValueFromTextConvertProc(float inValue, DGTextDisplay*) class PolarizerSlider final : public DGSlider { public: - PolarizerSlider(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, + PolarizerSlider(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, DGImage* inHandleImage, DGImage* inBackgroundImage) - : DGSlider(inOwnerEditor, inParamID, inRegion, dfx::kAxis_Vertical, nullptr, inBackgroundImage), + : DGSlider(inOwnerEditor, inParameterID, inRegion, dfx::kAxis_Vertical, nullptr, inBackgroundImage), mHandleImage(inHandleImage) // store handle image independently so that CSlider does not base control range on it { setOffsetHandle(VSTGUI::CPoint(0, kSliderFrameThickness)); diff --git a/polarizer/polarizer.h b/polarizer/polarizer.h index ff39ca2c..c65a7e6e 100644 --- a/polarizer/polarizer.h +++ b/polarizer/polarizer.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Polarizer. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -26,7 +26,7 @@ To contact the author, use the contact form at http://destroyfx.org/ // these are Polarizer's parameters -enum +enum : dfx::ParameterID { kSkip, kAmount, diff --git a/rezsynth/gui/rezsyntheditor.cpp b/rezsynth/gui/rezsyntheditor.cpp index 21bb480c..4309ff07 100644 --- a/rezsynth/gui/rezsyntheditor.cpp +++ b/rezsynth/gui/rezsyntheditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Rez Synth. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "rezsyntheditor.h" @@ -112,7 +112,7 @@ constexpr float kUnusedControlAlpha = 0.39f; static bool bandwidthAmountDisplayProc(float inValue, char* outText, void* inEditor) { const auto success = snprintf(outText, DGTextDisplay::kTextMaxLength, "%.3f", inValue) > 0; - if (static_cast(inEditor)->getparameter_i(kBandwidthMode) == kBandwidthAmount_Hz) + if (static_cast(inEditor)->getparameter_i(kBandwidthMode) == kBandwidthMode_Hz) { dfx::StrlCat(outText, " Hz", DGTextDisplay::kTextMaxLength); } @@ -142,13 +142,13 @@ static bool sepAmountDisplayProc(float inValue, char* outText, void* inEditor) static bool attackDecayReleaseDisplayProc(float inValue, char* outText, void*) { - long const thousands = static_cast(inValue) / 1000; + int const thousands = static_cast(inValue) / 1000; float const remainder = std::fmod(inValue, 1000.0f); bool success = false; if (thousands > 0) { - success = snprintf(outText, DGTextDisplay::kTextMaxLength, "%ld,%05.1f", thousands, remainder) > 0; + success = snprintf(outText, DGTextDisplay::kTextMaxLength, "%d,%05.1f", thousands, remainder) > 0; } else { @@ -235,28 +235,28 @@ long RezSynthEditor::OpenEditor() pos.set(kHorizontalSliderX, kHorizontalSliderY, kHorizontalSliderWidth, kHorizontalSliderHeight); valueDisplayPos.set(kHorizontalDisplayX, kHorizontalDisplayY, kHorizontalDisplayWidth, kHorizontalDisplayHeight); - auto const addSliderComponents = [&](long const inParamID, auto const& inDisplayProc) + auto const addSliderComponents = [&](dfx::ParameterID const inParameterID, auto const& inDisplayProc) { auto const horizontalSliderHandleImage = std::map{ {Section::Bands, horizontalSliderHandleImage_bands}, {Section::Envelope, horizontalSliderHandleImage_envelope}, {Section::MidiNotes, horizontalSliderHandleImage_midiNotes}, {Section::MidiBends, horizontalSliderHandleImage_midiBends} - }.at(ParameterToSection(inParamID)); + }.at(ParameterToSection(inParameterID)); // slider control - auto const slider = emplaceControl(this, inParamID, pos, dfx::kAxis_Horizontal, horizontalSliderHandleImage); + auto const slider = emplaceControl(this, inParameterID, pos, dfx::kAxis_Horizontal, horizontalSliderHandleImage); slider->setAlternateHandle(horizontalSliderHandleImage_learning); // value display - auto const display = emplaceControl(this, inParamID, valueDisplayPos, inDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueTextFontSize, kValueTextFontColor, kValueTextFont); + auto const display = emplaceControl(this, inParameterID, valueDisplayPos, inDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueTextFontSize, kValueTextFontColor, kValueTextFont); - if ((inParamID == kBandwidthAmount_Hz) || (inParamID == kBandwidthAmount_Q)) + if ((inParameterID == kBandwidthAmount_Hz) || (inParameterID == kBandwidthAmount_Q)) { mBandwidthAmountSlider = slider; mBandwidthAmountDisplay = display; } - else if ((inParamID == kSepAmount_Octaval) || (inParamID == kSepAmount_Linear)) + else if ((inParameterID == kSepAmount_Octaval) || (inParameterID == kSepAmount_Linear)) { mSepAmountSlider = slider; mSepAmountDisplay = display; @@ -266,7 +266,7 @@ long RezSynthEditor::OpenEditor() auto parameterNamePos = valueDisplayPos; parameterNamePos.left = pos.left; parameterNamePos.right = valueDisplayPos.left; - emplaceControl(this, parameterNamePos)->setParameterID(inParamID); + emplaceControl(this, parameterNamePos)->setParameterID(inParameterID); pos.offset(0, kHorizontalSliderInc); valueDisplayPos.offset(0, kHorizontalSliderInc); @@ -286,17 +286,17 @@ long RezSynthEditor::OpenEditor() //--create the vertical gain sliders--------------------------------- pos.set(kVerticalSliderX, kVerticalSliderY, kVerticalSliderWidth, kVerticalSliderHeight); valueDisplayPos.set(kVerticalDisplayX, kVerticalDisplayY, kVerticalDisplayWidth, kVerticalDisplayHeight); - for (long paramID = kFilterOutputGain; paramID <= kDryWetMix; paramID++) + for (dfx::ParameterID parameterID = kFilterOutputGain; parameterID <= kDryWetMix; parameterID++) { - auto const displayProc = (paramID == kDryWetMix) ? percentDisplayProc : DGTextDisplay::valueToTextProc_LinearToDb; + auto const displayProc = (parameterID == kDryWetMix) ? percentDisplayProc : DGTextDisplay::valueToTextProc_LinearToDb; constexpr intptr_t decibelPrecisionOffset = -1; - auto const displayProcUserData = (paramID == kDryWetMix) ? nullptr : reinterpret_cast(decibelPrecisionOffset); - auto const textToValueProc = (paramID == kDryWetMix) ? nullptr : DGTextDisplay::textToValueProc_DbToLinear; + auto const displayProcUserData = (parameterID == kDryWetMix) ? nullptr : reinterpret_cast(decibelPrecisionOffset); + auto const textToValueProc = (parameterID == kDryWetMix) ? nullptr : DGTextDisplay::textToValueProc_DbToLinear; // slider control - emplaceControl(this, paramID, pos, dfx::kAxis_Vertical, verticalSliderHandleImage)->setAlternateHandle(verticalSliderHandleImage_learning); + emplaceControl(this, parameterID, pos, dfx::kAxis_Vertical, verticalSliderHandleImage)->setAlternateHandle(verticalSliderHandleImage_learning); // value display - auto const textDisplay = emplaceControl(this, paramID, valueDisplayPos, displayProc, displayProcUserData, nullptr, dfx::TextAlignment::Center, kValueTextFontSize, kValueTextFontColor, kValueTextFont); + auto const textDisplay = emplaceControl(this, parameterID, valueDisplayPos, displayProc, displayProcUserData, nullptr, dfx::TextAlignment::Center, kValueTextFontSize, kValueTextFontColor, kValueTextFont); if (textToValueProc) { textDisplay->setTextToValueProc(textToValueProc); @@ -306,7 +306,7 @@ long RezSynthEditor::OpenEditor() auto parameterNamePos = pos; parameterNamePos.left = pos.left - kVerticalSliderNameWidth; parameterNamePos.right = pos.left; - emplaceControl(this, parameterNamePos)->setParameterID(paramID); + emplaceControl(this, parameterNamePos)->setParameterID(parameterID); pos.offset(kVerticalSliderInc, 0); valueDisplayPos.offset(kVerticalSliderInc, 0); @@ -316,14 +316,14 @@ long RezSynthEditor::OpenEditor() //--create the buttons---------------------------------------------- - auto const addButtonWithNameRegion = [this](long paramID, DGRect const& pos, DGImage* image) + auto const addButtonWithNameRegion = [this](dfx::ParameterID const parameterID, DGRect const& pos, DGImage* const image) { auto parameterNamePos = pos; parameterNamePos.top = pos.top - kButtonNameHeight; parameterNamePos.bottom = pos.top; - emplaceControl(this, parameterNamePos)->setParameterID(paramID); + emplaceControl(this, parameterNamePos)->setParameterID(parameterID); - return emplaceControl(this, paramID, pos, image, DGButton::Mode::Radio); + return emplaceControl(this, parameterID, pos, image, DGButton::Mode::Radio); }; // filter response scaling @@ -402,22 +402,22 @@ void RezSynthEditor::CloseEditor() } //----------------------------------------------------------------------------- -void RezSynthEditor::parameterChanged(long inParameterID) +void RezSynthEditor::parameterChanged(dfx::ParameterID inParameterID) { auto const value_i = getparameter_i(inParameterID); - auto newParamID = dfx::kParameterID_Invalid; + auto newParameterID = dfx::kParameterID_Invalid; DGSlider* slider = nullptr; DGTextDisplay* display = nullptr; switch (inParameterID) { case kSepMode: - newParamID = (value_i == kSeparationMode_Octaval) ? kSepAmount_Octaval : kSepAmount_Linear; + newParameterID = (value_i == kSeparationMode_Octaval) ? kSepAmount_Octaval : kSepAmount_Linear; slider = mSepAmountSlider; display = mSepAmountDisplay; break; case kBandwidthMode: - newParamID = (value_i == kBandwidthMode_Hz) ? kBandwidthAmount_Hz : kBandwidthAmount_Q; + newParameterID = (value_i == kBandwidthMode_Hz) ? kBandwidthAmount_Hz : kBandwidthAmount_Q; slider = mBandwidthAmountSlider; display = mBandwidthAmountDisplay; break; @@ -428,15 +428,15 @@ void RezSynthEditor::parameterChanged(long inParameterID) return; } - if (newParamID != dfx::kParameterID_Invalid) + if (newParameterID != dfx::kParameterID_Invalid) { if (slider) { - slider->setParameterID(newParamID); + slider->setParameterID(newParameterID); } if (display) { - display->setParameterID(newParamID); + display->setParameterID(newParameterID); } } } @@ -633,7 +633,7 @@ dry and wet audio. You can choose linear mixing or equal power mixing.)DELIM"; } } -RezSynthEditor::Section RezSynthEditor::ParameterToSection(long inParameterID) +RezSynthEditor::Section RezSynthEditor::ParameterToSection(dfx::ParameterID inParameterID) noexcept { switch (inParameterID) { diff --git a/rezsynth/gui/rezsyntheditor.h b/rezsynth/gui/rezsyntheditor.h index da1472b0..73bd1a70 100644 --- a/rezsynth/gui/rezsyntheditor.h +++ b/rezsynth/gui/rezsyntheditor.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------ -Copyright (C) 2001-2021 Sophia Poirier +Copyright (C) 2001-2022 Sophia Poirier This file is part of Rez Synth. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Rez Synth. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -33,7 +33,7 @@ class RezSynthEditor final : public DfxGuiEditor long OpenEditor() override; void CloseEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; void mouseovercontrolchanged(IDGControl* currentControlUnderMouse) override; private: @@ -48,7 +48,7 @@ class RezSynthEditor final : public DfxGuiEditor void HandleLegatoChange(); std::string GetHelpForControl(IDGControl* inControl) const; - static Section ParameterToSection(long inParameterID); + static Section ParameterToSection(dfx::ParameterID inParameterID) noexcept; DGSlider* mSepAmountSlider = nullptr, * mBandwidthAmountSlider = nullptr; DGTextDisplay* mSepAmountDisplay = nullptr, * mBandwidthAmountDisplay = nullptr; diff --git a/rezsynth/rezsynth.h b/rezsynth/rezsynth.h index 9bd835a4..a1869fd2 100644 --- a/rezsynth/rezsynth.h +++ b/rezsynth/rezsynth.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Rez Synth. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -34,7 +34,7 @@ To contact the author, use the contact form at http://destroyfx.org/ // enums // these are the plugin parameters: -enum +enum : dfx::ParameterID { kBandwidthAmount_Hz, kBandwidthAmount_Q, diff --git a/scrubby/gui/scrubbyeditor.cpp b/scrubby/gui/scrubbyeditor.cpp index f39098ac..600d4387 100644 --- a/scrubby/gui/scrubbyeditor.cpp +++ b/scrubby/gui/scrubbyeditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Scrubby. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "scrubbyeditor.h" @@ -33,13 +33,14 @@ constexpr auto kValueDisplayFont = dfx::kFontName_Snooty10px; constexpr auto kValueDisplayFontSize = dfx::kFontSize_Snooty10px; constexpr DGColor kValueDisplayFontColor(187, 173, 131); constexpr float kUnusedControlAlpha = 0.234f; -constexpr long kRangeSliderOvershoot = 3; +constexpr int kRangeSliderOvershoot = 3; -constexpr long kOctavesSliderWidth = 118 - 2; -static long const kOctaveMaxSliderWidth = static_cast((static_cast(kOctave_MaxValue) / static_cast((std::abs(kOctave_MinValue) + kOctave_MaxValue))) * static_cast(kOctavesSliderWidth)); -static long const kOctaveMinSliderWidth = kOctavesSliderWidth - kOctaveMaxSliderWidth; -constexpr long kOctaveMinSliderX = 251 + 1; -static long const kOctaveMaxSliderX = kOctaveMinSliderX + kOctaveMinSliderWidth; +constexpr int kOctavesSliderWidth = 118 - 2; +// TODO C++23: constexpr +static int const kOctaveMaxSliderWidth = static_cast((static_cast(kOctave_MaxValue) / static_cast((std::abs(kOctave_MinValue) + kOctave_MaxValue))) * static_cast(kOctavesSliderWidth)); +static int const kOctaveMinSliderWidth = kOctavesSliderWidth - kOctaveMaxSliderWidth; +constexpr int kOctaveMinSliderX = 251 + 1; +static int const kOctaveMaxSliderX = kOctaveMinSliderX + kOctaveMinSliderWidth; //----------------------------------------------------------------------------- enum @@ -155,7 +156,7 @@ static bool seekRangeDisplayProc(float inValue, char* outText, void*) return snprintf(outText, DGTextDisplay::kTextMaxLength, "%.1f ms", inValue) > 0; } -static bool seekRateGenDisplayProc(float inValue, long inParameterID, char* outText, DfxGuiEditor* inEditor) +static bool seekRateGenDisplayProc(float inValue, dfx::ParameterID inParameterID, char* outText, DfxGuiEditor* inEditor) { if (inEditor->getparameter_b(kTempoSync)) { @@ -286,14 +287,14 @@ long ScrubbyEditor::OpenEditor() DGRect pos; - long const seekRateParamID = getparameter_b(kTempoSync) ? kSeekRate_Sync : kSeekRate_Hz; - long const seekRateRandMinParamID = getparameter_b(kTempoSync) ? kSeekRateRandMin_Sync : kSeekRateRandMin_Hz; + auto const seekRateParameterID = getparameter_b(kTempoSync) ? kSeekRate_Sync : kSeekRate_Hz; + auto const seekRateRandMinParameterID = getparameter_b(kTempoSync) ? kSeekRateRandMin_Sync : kSeekRateRandMin_Hz; //--create the sliders----------------------------------------------- // seek rate pos.set(kSeekRateSliderX, kSeekRateSliderY, kSeekRateSliderWidth, kSliderHeight); - mSeekRateSlider = emplaceControl(this, seekRateRandMinParamID, seekRateParamID, pos, + mSeekRateSlider = emplaceControl(this, seekRateRandMinParameterID, seekRateParameterID, pos, rangeSliderHandleLeftImage, rangeSliderHandleRightImage, nullptr, DGRangeSlider::PushStyle::Upper, kRangeSliderOvershoot); mSeekRateSlider->setAlternateHandles(rangeSliderHandleLeftImage_glowing, rangeSliderHandleRightImage_glowing); @@ -340,11 +341,11 @@ long ScrubbyEditor::OpenEditor() // seek rate random minimum pos.set(kSeekRateSliderX + kDisplayInsetX_leftAlign, kSeekRateSliderY - kDisplayHeight + kDisplayInsetY, kDisplayWidth_big, kDisplayHeight); - mSeekRateRandMinDisplay = emplaceControl(this, seekRateRandMinParamID, pos, seekRateRandMinDisplayProc, this, nullptr, dfx::TextAlignment::Left, kValueDisplayFontSize, kValueDisplayFontColor, kValueDisplayFont); + mSeekRateRandMinDisplay = emplaceControl(this, seekRateRandMinParameterID, pos, seekRateRandMinDisplayProc, this, nullptr, dfx::TextAlignment::Left, kValueDisplayFontSize, kValueDisplayFontColor, kValueDisplayFont); // seek rate pos.set(kSeekRateSliderX + kSeekRateSliderWidth - kDisplayWidth_big - kDisplayInsetX, kSeekRateSliderY - kDisplayHeight + kDisplayInsetY, kDisplayWidth_big, kDisplayHeight); - mSeekRateDisplay = emplaceControl(this, seekRateParamID, pos, seekRateDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kValueDisplayFontColor, kValueDisplayFont); + mSeekRateDisplay = emplaceControl(this, seekRateParameterID, pos, seekRateDisplayProc, this, nullptr, dfx::TextAlignment::Right, kValueDisplayFontSize, kValueDisplayFontColor, kValueDisplayFont); // seek range pos.set(kSeekRangeSliderX + kSeekRangeSliderWidth - kDisplayWidth - kDisplayInsetX, kSeekRangeSliderY - kDisplayHeight + kDisplayInsetY, kDisplayWidth, kDisplayHeight); @@ -393,7 +394,7 @@ long ScrubbyEditor::OpenEditor() DGRect keyboardBottomKeyPos(kKeyboardX, kKeyboardY + pos.getHeight(), keyboardBottomKeyImages[0]->getWidth(), keyboardBottomKeyImages[0]->getHeight() / 2); for (size_t i = 0; i < kNumPitchSteps; i++) { - long const paramID = kPitchStep0 + i; + dfx::ParameterID const parameterID = kPitchStep0 + i; // this visually syncs the top and bottom button images upon mouse clicks auto const keyboardButtonProc = [](DGButton* button, long value) @@ -401,9 +402,9 @@ long ScrubbyEditor::OpenEditor() auto const editor = button->getOwnerEditor(); editor->getFrame()->forEachChild([originalButton = button->asCControl()](VSTGUI::CView* child) { - auto const paramID = originalButton->getTag(); + auto const parameterIndex = originalButton->getTag(); auto const childControl = dynamic_cast(child); - if (childControl && (childControl->getTag() == paramID) && (childControl != originalButton)) + if (childControl && (childControl->getTag() == parameterIndex) && (childControl != originalButton)) { childControl->setValue(originalButton->getValue()); if (childControl->isDirty()) @@ -415,7 +416,7 @@ long ScrubbyEditor::OpenEditor() }; pos.setWidth(keyboardTopKeyImages[i]->getWidth()); - auto button = emplaceControl(this, paramID, pos, keyboardTopKeyImages[i], DGButton::Mode::Increment); + auto button = emplaceControl(this, parameterID, pos, keyboardTopKeyImages[i], DGButton::Mode::Increment); pos.offset(pos.getWidth(), 0); if (keyboardBottomKeyImages[i] != nullptr) @@ -423,7 +424,7 @@ long ScrubbyEditor::OpenEditor() button->setUserProcedure(std::bind_front(keyboardButtonProc, button)); keyboardBottomKeyPos.setWidth(keyboardBottomKeyImages[i]->getWidth()); - button = emplaceControl(this, paramID, keyboardBottomKeyPos, keyboardBottomKeyImages[i], DGButton::Mode::Increment); + button = emplaceControl(this, parameterID, keyboardBottomKeyPos, keyboardBottomKeyImages[i], DGButton::Mode::Increment); button->setUserProcedure(std::bind_front(keyboardButtonProc, button)); keyboardBottomKeyPos.offset(keyboardBottomKeyPos.getWidth(), 0); } @@ -447,13 +448,11 @@ long ScrubbyEditor::OpenEditor() // choose the seek rate type ("free" or synced) emplaceControl(this, kTempoSync, kTempoSyncButtonX, kTempoSyncButtonY, tempoSyncButtonImage, true); + emplaceControl(this, kTempoSync, kLittleTempoSyncButtonX, kLittleTempoSyncButtonY, tempoSyncButtonImage_little, false); // toggle pitch constraint emplaceControl(this, kPitchConstraint, kPitchConstraintButtonX, kPitchConstraintButtonY, pitchConstraintButtonImage, true); - // choose the seek rate type ("free" or synced) - emplaceControl(this, kTempoSync, kLittleTempoSyncButtonX, kLittleTempoSyncButtonY, tempoSyncButtonImage_little, false); - // enable sync to host tempo emplaceControl(this, kTempoAuto, kTempoAutoButtonX, kTempoAutoButtonY, hostTempoButtonImage, false); @@ -556,22 +555,22 @@ void ScrubbyEditor::HandleNotesButton(size_t inNotesButtonType) { case kNotes_Down: { - auto const tempValue = getparameter_b(kPitchStep0); - for (long i = kPitchStep0; i < kPitchStep11; i++) + auto const bottomValue = getparameter_b(kPitchStep0); + for (dfx::ParameterID i = kPitchStep0; i < kPitchStep11; i++) { setparameter_b(i, getparameter_b(i + 1)); } - setparameter_b(kPitchStep11, tempValue); + setparameter_b(kPitchStep11, bottomValue); break; } case kNotes_Up: { - auto const tempValue = getparameter_b(kPitchStep11); - for (long i = kPitchStep11; i > kPitchStep0; i--) + auto const topValue = getparameter_b(kPitchStep11); + for (dfx::ParameterID i = kPitchStep11; i > kPitchStep0; i--) { setparameter_b(i, getparameter_b(i - 1)); } - setparameter_b(kPitchStep0, tempValue); + setparameter_b(kPitchStep0, topValue); break; } case kNotes_Major: @@ -603,13 +602,13 @@ void ScrubbyEditor::HandleNotesButton(size_t inNotesButtonType) setparameter_b(kPitchStep11, false); break; case kNotes_All: - for (long i = kPitchStep0; i <= kPitchStep11; i++) + for (dfx::ParameterID i = kPitchStep0; i <= kPitchStep11; i++) { setparameter_b(i, true); } break; case kNotes_None: - for (long i = kPitchStep0; i <= kPitchStep11; i++) + for (dfx::ParameterID i = kPitchStep0; i <= kPitchStep11; i++) { setparameter_b(i, false); } @@ -630,12 +629,12 @@ void ScrubbyEditor::HandlePitchConstraintChange() for (auto& control : mControlsList) { - auto const paramID = control->getParameterID(); - if ((paramID >= kPitchStep0) && (paramID <= kPitchStep11)) + auto const parameterID = control->getParameterID(); + if ((parameterID >= kPitchStep0) && (parameterID <= kPitchStep11)) { control->setDrawAlpha(alpha); } - else if (paramID == kPitchConstraint) + else if (parameterID == kPitchConstraint) { control->setDrawAlpha(pitchConstraintAlpha); } @@ -666,7 +665,7 @@ void ScrubbyEditor::HandleTempoAutoChange() } //----------------------------------------------------------------------------- -void ScrubbyEditor::parameterChanged(long inParameterID) +void ScrubbyEditor::parameterChanged(dfx::ParameterID inParameterID) { switch (inParameterID) { diff --git a/scrubby/gui/scrubbyeditor.h b/scrubby/gui/scrubbyeditor.h index 60303d16..5e163101 100644 --- a/scrubby/gui/scrubbyeditor.h +++ b/scrubby/gui/scrubbyeditor.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Scrubby. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -35,7 +35,7 @@ class ScrubbyEditor final : public DfxGuiEditor long OpenEditor() override; void CloseEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; void mouseovercontrolchanged(IDGControl* currentControlUnderMouse) override; void outputChannelsChanged(size_t inChannelCount) override; diff --git a/scrubby/scrubby.h b/scrubby/scrubby.h index 3005aee7..b16ce019 100644 --- a/scrubby/scrubby.h +++ b/scrubby/scrubby.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Scrubby. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -34,7 +34,7 @@ To contact the author, use the contact form at http://destroyfx.org/ //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kSeekRange, kFreeze, @@ -163,5 +163,5 @@ class Scrubby final : public DfxPlugin std::array mActiveNotesTable {}; // how many voices of each note in the octave are being played bool mNotesWereAlreadyActive = false; // says whether any notes were active in the previous block -long mSineCount = 0; +size_t mSineCount = 0; }; diff --git a/scrubby/scrubbyformalities.cpp b/scrubby/scrubbyformalities.cpp index 28a95d42..bf54fb17 100644 --- a/scrubby/scrubbyformalities.cpp +++ b/scrubby/scrubbyformalities.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Scrubby. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "scrubby.h" @@ -80,7 +80,6 @@ Scrubby::Scrubby(TARGET_API_BASE_INSTANCE_TYPE inInstance) setparameterenforcevaluelimits(kPredelay, true); -//for (size_t i = 3; i < 12; i++) printf("%zu %s\n", i, getparametername(kSeekRange, i).c_str()); // set the value strings for the sync rate parameters for (long i = 0; i < numTempoRates; i++) { @@ -410,7 +409,7 @@ void Scrubby::processparameters() mUseHostTempo = getparameter_b(kTempoAuto); for (size_t i = 0; i < kNumPitchSteps; i++) { - auto const parameterID = i + kPitchStep0; + dfx::ParameterID const parameterID = i + kPitchStep0; // fetch latest value regardless of whether it "changed" since MIDI notes generate internal values "quietly" mPitchSteps[i] = getparameter_b(parameterID); // reset the associated note in the notes table; manual changes override MIDI diff --git a/scrubby/scrubbyprocess.cpp b/scrubby/scrubbyprocess.cpp index 12c8b970..cb298da2 100644 --- a/scrubby/scrubbyprocess.cpp +++ b/scrubby/scrubbyprocess.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Scrubby. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "scrubby.h" @@ -285,7 +285,7 @@ void Scrubby::generateNewTarget(size_t channel) double const targetReadStep = calculateTargetSpeed(oldReadStep, static_cast(mMoveCount[channel]), static_cast(targetDistance)); mPortamentoStep[channel] = std::pow(std::fabs(targetReadStep) / oldReadStep, 1.0 / static_cast(mMoveCount[channel])); mPortamentoStep[channel] = std::fabs(mPortamentoStep[channel]); -//auto const ktest = static_cast(std::fabs((targetReadStep * static_cast(mMoveCount)) / std::log(std::fabs(targetReadStep / oldReadStep)))); +//auto const ktest = static_cast(std::fabs((targetReadStep * static_cast(mMoveCount[channel])) / std::log(std::fabs(targetReadStep / oldReadStep)))); //printf("oldReadStep = %.6f\nreadStep = %.6f\ntargetReadStep = %.6f\nportamentoStep = %.6f\nmovecount = %ld\ntargetDistance = %ld\nktest = %ld\n\n", oldReadStep, newReadStep, targetReadStep, mPortamentoStep[channel], mMoveCount[channel], targetDistance, ktest); //printf("a = %.3f,\tb = %.3f,\tn = %ld,\tk = %ld\tportamentoStep = %.6f\n", oldReadStep, targetReadStep, mMoveCount[channel], targetDistance, mPortamentoStep[channel]); //printf("\noldReadStep = %.6f\treadStep = %.6f\ttargetReadStep = %.6f\tportamentoStep = %.6f\n", oldReadStep, newReadStep, targetReadStep, mPortamentoStep[channel]); @@ -540,7 +540,7 @@ void Scrubby::processMidiNotes() for (size_t i = 0; i < getmidistate().getBlockEventCount(); i++) { // wrap the note value around to our 1-octave range - int const currentNote = (getmidistate().getBlockEvent(i).mByte1) % kNumPitchSteps; + auto const currentNote = dfx::math::ToIndex(getmidistate().getBlockEvent(i).mByte1) % kNumPitchSteps; switch (getmidistate().getBlockEvent(i).mStatus) { @@ -571,14 +571,14 @@ void Scrubby::processMidiNotes() case DfxMidi::kStatus_CC: if (getmidistate().getBlockEvent(i).mByte1 == DfxMidi::kCC_AllNotesOff) { - for (size_t notecount = 0; notecount < mActiveNotesTable.size(); notecount++) + for (size_t noteIndex = 0; noteIndex < mActiveNotesTable.size(); noteIndex++) { // if this note is currently active, then turn its // associated pitch constraint parameter off // (and reset this note in the table) - if (std::exchange(mActiveNotesTable[notecount], 0) > 0) + if (std::exchange(mActiveNotesTable[noteIndex], 0) > 0) { - setparameterquietly_b(notecount + kPitchStep0, false); + setparameterquietly_b(noteIndex + kPitchStep0, false); } } } diff --git a/skidder/gui/skiddereditor.cpp b/skidder/gui/skiddereditor.cpp index bfff042e..56cea192 100644 --- a/skidder/gui/skiddereditor.cpp +++ b/skidder/gui/skiddereditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Skidder. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "skiddereditor.h" @@ -100,7 +100,7 @@ enum //----------------------------------------------------------------------------- // parameter value string display conversion functions -static bool rateGenDisplayProc(float inValue, long inSyncParameterID, char* outText, DfxGuiEditor* inEditor, bool inShowUnits) +static bool rateGenDisplayProc(float inValue, dfx::ParameterID inSyncParameterID, char* outText, DfxGuiEditor* inEditor, bool inShowUnits) { if (inEditor->getparameter_b(kTempoSync)) { @@ -379,7 +379,7 @@ void SkidderEditor::CloseEditor() } //----------------------------------------------------------------------------- -void SkidderEditor::parameterChanged(long inParameterID) +void SkidderEditor::parameterChanged(dfx::ParameterID inParameterID) { switch (inParameterID) { @@ -441,7 +441,7 @@ void SkidderEditor::mouseovercontrolchanged(IDGControl* currentControlUnderMouse } //----------------------------------------------------------------------------- -std::pair SkidderEditor::GetActiveRateParameterIDs() +std::pair SkidderEditor::GetActiveRateParameterIDs() { if (getparameter_b(kTempoSync)) { @@ -453,7 +453,7 @@ std::pair SkidderEditor::GetActiveRateParameterIDs() //----------------------------------------------------------------------------- void SkidderEditor::UpdateRandomMinimumDisplays() { - auto const updateRandomMinimumVisibility = [this](long mainParameterID, long randMinParameterID, VSTGUI::CControl* control) + auto const updateRandomMinimumVisibility = [this](dfx::ParameterID mainParameterID, dfx::ParameterID randMinParameterID, VSTGUI::CControl* control) { bool const visible = getparameter_f(mainParameterID) > getparameter_f(randMinParameterID); control->setVisible(visible); diff --git a/skidder/gui/skiddereditor.h b/skidder/gui/skiddereditor.h index d0b4c1f9..59f95308 100644 --- a/skidder/gui/skiddereditor.h +++ b/skidder/gui/skiddereditor.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Skidder. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -35,12 +35,12 @@ class SkidderEditor final : public DfxGuiEditor long OpenEditor() override; void CloseEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; void outputChannelsChanged(size_t inChannelCount) override; void mouseovercontrolchanged(IDGControl* currentControlUnderMouse) override; private: - std::pair GetActiveRateParameterIDs(); + std::pair GetActiveRateParameterIDs(); void UpdateRandomMinimumDisplays(); void HandleTempoSyncChange(); void HandleTempoAutoChange(); diff --git a/skidder/skidder.h b/skidder/skidder.h index dfac8a7c..e673c86b 100644 --- a/skidder/skidder.h +++ b/skidder/skidder.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Skidder. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -35,7 +35,7 @@ To contact the author, use the contact form at http://destroyfx.org/ //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kRate_Hz, kRate_Sync, @@ -96,7 +96,7 @@ class Skidder final : public DfxPlugin void processaudio(float const* const* inAudio, float* const* outAudio, size_t inNumFrames) override; // stuff for extending DfxSettings - void settings_doLearningAssignStuff(long tag, dfx::MidiEventType eventType, int eventChannel, + void settings_doLearningAssignStuff(dfx::ParameterID parameterID, dfx::MidiEventType eventType, int eventChannel, int eventNum, size_t offsetFrames, int eventNum2 = 0, dfx::MidiEventBehaviorFlags eventBehaviourFlags = dfx::kMidiEventBehaviorFlag_None, int data1 = 0, int data2 = 0, float fdata1 = 0.0f, float fdata2 = 0.0f) override; diff --git a/skidder/skiddermidi.cpp b/skidder/skiddermidi.cpp index 8945205b..96e60aba 100644 --- a/skidder/skiddermidi.cpp +++ b/skidder/skiddermidi.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Skidder. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "skidder.h" @@ -196,7 +196,8 @@ bool Skidder::isAnyNoteOn() const //----------------------------------------------------------------------------- // this gets called when Skidder automates a parameter from CC messages. // this is where we can link parameter automation for rangeslider points. -void Skidder::settings_doLearningAssignStuff(long tag, dfx::MidiEventType eventType, int eventChannel, int eventNum, +void Skidder::settings_doLearningAssignStuff(dfx::ParameterID parameterID, dfx::MidiEventType eventType, + int eventChannel, int eventNum, size_t /*offsetFrames*/, int eventNum2, dfx::MidiEventBehaviorFlags eventBehaviourFlags, int data1, int data2, float fdata1, float fdata2) { @@ -205,34 +206,34 @@ void Skidder::settings_doLearningAssignStuff(long tag, dfx::MidiEventType eventT return; } - switch (tag) + switch (parameterID) { case kPulsewidth: if (mPulsewidthDoubleAutomate) { - getsettings().assignParam(kPulsewidthRandMin, eventType, eventChannel, eventNum, eventNum2, - eventBehaviourFlags, data1, data2, fdata1, fdata2); + getsettings().assignParameter(kPulsewidthRandMin, eventType, eventChannel, eventNum, eventNum2, + eventBehaviourFlags, data1, data2, fdata1, fdata2); } break; case kPulsewidthRandMin: if (mPulsewidthDoubleAutomate) { - getsettings().assignParam(kPulsewidth, eventType, eventChannel, eventNum, eventNum2, - eventBehaviourFlags, data1, data2, fdata1, fdata2); + getsettings().assignParameter(kPulsewidth, eventType, eventChannel, eventNum, eventNum2, + eventBehaviourFlags, data1, data2, fdata1, fdata2); } break; case kFloor: if (mFloorDoubleAutomate) { - getsettings().assignParam(kFloorRandMin, eventType, eventChannel, eventNum, eventNum2, - eventBehaviourFlags, data1, data2, fdata1, fdata2); + getsettings().assignParameter(kFloorRandMin, eventType, eventChannel, eventNum, eventNum2, + eventBehaviourFlags, data1, data2, fdata1, fdata2); } break; case kFloorRandMin: if (mFloorDoubleAutomate) { - getsettings().assignParam(kFloor, eventType, eventChannel, eventNum, eventNum2, - eventBehaviourFlags, data1, data2, fdata1, fdata2); + getsettings().assignParameter(kFloor, eventType, eventChannel, eventNum, eventNum2, + eventBehaviourFlags, data1, data2, fdata1, fdata2); } break; default: diff --git a/slowft/slowft.cpp b/slowft/slowft.cpp index 1d7b40d7..4a65c8c5 100644 --- a/slowft/slowft.cpp +++ b/slowft/slowft.cpp @@ -24,14 +24,9 @@ Slowft, featuring the Super Destroy FX Windowing System! #include "slowft.h" #include +#include #include -#if defined(TARGET_API_VST) && TARGET_PLUGIN_HAS_GUI - #ifndef _DFX_SLOWFTEDITOR_H - #include "slowfteditor.hpp" - #endif -#endif - /* this macro does boring entry point stuff for us */ DFX_ENTRY(Slowft); DFX_CORE_ENTRY(SlowftDSP); @@ -44,20 +39,20 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) initparameter_indexed(P_SHAPE, {"wshape"}, WINDOW_TRIANGLE, WINDOW_TRIANGLE, MAX_WINDOWSHAPES); /* set up values for windowing */ - char bufstr[64]; + std::array bufstr {}; for (long i = 0; i < BUFFERSIZESSIZE; i++) { if (buffersizes[i] > 1000) - sprintf(bufstr, "%ld,%03ld", buffersizes[i]/1000, buffersizes[i]%1000); + snprintf(bufstr.data(), bufstr.size(), "%ld,%03ld", buffersizes[i]/1000, buffersizes[i]%1000); else - sprintf(bufstr, "%ld", buffersizes[i]); - setparametervaluestring(P_BUFSIZE, i, bufstr); + snprintf(bufstr.data(), bufstr.size(), "%ld", buffersizes[i]); + setparametervaluestring(P_BUFSIZE, i, bufstr.data()); } setparametervaluestring(P_SHAPE, WINDOW_TRIANGLE, "linear"); setparametervaluestring(P_SHAPE, WINDOW_ARROW, "arrow"); setparametervaluestring(P_SHAPE, WINDOW_WEDGE, "wedge"); setparametervaluestring(P_SHAPE, WINDOW_COS, "best"); - for (long i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) + for (int i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) setparametervaluestring(P_SHAPE, i, "???"); long delay_samples = buffersizes[getparameter_i(P_BUFSIZE)]; @@ -74,13 +69,6 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) #if !TARGET_PLUGIN_USES_DSPCORE addchannelconfig(1, 1); /* mono */ #endif - - #ifdef TARGET_API_VST - /* if you have a GUI, need an Editor class... */ - #if TARGET_PLUGIN_HAS_GUI - editor = new SlowftEditor(this); - #endif - #endif } PLUGINCORE::PLUGINCORE(DfxPlugin * inInstance) @@ -89,22 +77,14 @@ PLUGINCORE::PLUGINCORE(DfxPlugin * inInstance) constexpr auto maxframe = *std::max_element(std::cbegin(buffersizes), std::cend(buffersizes)); /* add some leeway? */ - in0 = (float*)malloc(maxframe * sizeof (float)); - out0 = (float*)malloc(maxframe * 2 * sizeof (float)); + in0.assign(maxframe, 0.f); + out0.assign(maxframe * 2, 0.f); /* prevmix is only a single third long */ - prevmix = (float*)malloc((maxframe / 2) * sizeof (float)); + prevmix.assign(maxframe / 2, 0.f); } -PLUGINCORE::~PLUGINCORE() { - /* windowing buffers */ - free (in0); - free (out0); - - free (prevmix); -} - void PLUGINCORE::reset() { framesize = buffersizes[getparameter_i(P_BUFSIZE)]; @@ -114,14 +94,9 @@ void PLUGINCORE::reset() { /* set up buffers. Prevmix and first frame of output are always filled with zeros. XXX memset */ - for (int i = 0; i < third; i ++) { - prevmix[i] = 0.0f; - } + std::fill_n(prevmix.begin(), third, 0.f); + std::fill_n(out0.begin(), framesize, 0.f); - for (int j = 0; j < framesize; j ++) { - out0[j] = 0.0f; - } - /* start input at beginning. Output has a frame of silence. */ insize = 0; outstart = 0; @@ -148,7 +123,7 @@ void PLUGINCORE::processparameters() { write your DSP, and it will be always called with the same sample size (as long as the block size parameter stays the same) and automatically overlapped. */ -void PLUGINCORE::processw(float * in, float * out, long samples) { +void PLUGINCORE::processw(float const * in, float * out, long samples) { /* compute the 'slow fourier transform' */ @@ -284,7 +259,7 @@ void PLUGINCORE::process(const float *tin, float *tout, size_t samples) { /* frame is full! */ /* in0 -> process -> out0(first free space) */ - processw(in0, out0+outstart+outsize, framesize); + processw(in0.data(), out0.data()+outstart+outsize, framesize); float oneDivThird = 1.0f / (float)third; /* apply envelope */ @@ -326,11 +301,11 @@ void PLUGINCORE::process(const float *tin, float *tout, size_t samples) { out0[u+outstart+outsize] += prevmix[u]; /* prevmix becomes out1 */ - memcpy(prevmix, out0 + outstart + outsize + third, third * sizeof (float)); + std::copy_n(std::next(out0.cbegin(), outstart + outsize + third), third, prevmix.begin()); /* copy 2nd third of input over in0 (need to re-use it for next frame), now insize = third */ - memcpy(in0, in0 + third, third * sizeof (float)); + std::copy_n(std::next(in0.cbegin(), third), third, in0.begin()); insize = third; @@ -345,7 +320,7 @@ void PLUGINCORE::process(const float *tin, float *tout, size_t samples) { /* make sure there is always enough room for a frame in out buffer */ if (outstart == third) { - memmove(out0, out0 + outstart, outsize * sizeof (float)); + memmove(out0.data(), out0.data() + outstart, outsize * sizeof (float)); outstart = 0; } } diff --git a/slowft/slowft.h b/slowft/slowft.h index b2a2f585..6609eb87 100644 --- a/slowft/slowft.h +++ b/slowft/slowft.h @@ -23,8 +23,8 @@ Slowft, starring the Super Destroy FX Windowing System! #pragma once -#include #include +#include #include "dfxplugin.h" @@ -51,8 +51,8 @@ enum { WINDOW_TRIANGLE, }; /* the names of the parameters */ -enum { P_BUFSIZE, P_SHAPE, - NUM_PARAMS, +enum : dfx::ParameterID { P_BUFSIZE, P_SHAPE, + NUM_PARAMS }; @@ -70,13 +70,12 @@ class PLUGIN : public DfxPlugin { class PLUGINCORE : public DfxPluginCore { public: PLUGINCORE(DfxPlugin * inInstance); - ~PLUGINCORE() override; void reset() override; void processparameters() override; void process(const float *in, float *out, size_t inNumFrames) override; - long getwindowsize() { return third; } + long getwindowsize() const noexcept { return third; } private: static constexpr float BASE_FREQ = 27.5f; @@ -87,32 +86,32 @@ class PLUGINCORE : public DfxPluginCore { /* input and output buffers. out is framesize*2 samples long, in is framesize samples long. (for maximum framesize) */ - float * in0, * out0; + std::vector in0, out0; /* bufsize is 3 * third, framesize is 2 * third bufsize is used for outbuf. */ - long bufsize, framesize, third; + long bufsize = 0, framesize = 0, third = 0; - void processw(float * in, float * out, long samples); + void processw(float const * in, float * out, long samples); - int shape; + int shape = 0; /* third-sized tail of previous processed frame. already has mixing envelope applied. */ - float * prevmix; + std::vector prevmix; /* number of samples in in0 */ - int insize; + int insize = 0; /* number of samples and starting position of valid samples in out0 */ - int outsize; - int outstart; + int outsize = 0; + int outstart = 0; /* the transformed data */ - float sines[NUM_KEYS]; - float cosines[NUM_KEYS]; + float sines[NUM_KEYS] {}; + float cosines[NUM_KEYS] {}; }; diff --git a/stub-dfxplugin/dfxplugin-stub.h b/stub-dfxplugin/dfxplugin-stub.h index 6a36a480..563084af 100644 --- a/stub-dfxplugin/dfxplugin-stub.h +++ b/stub-dfxplugin/dfxplugin-stub.h @@ -18,7 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Destroy FX Library. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org This is a template for making a DfxPlugin. ------------------------------------------------------------------------*/ @@ -33,7 +33,7 @@ This is a template for making a DfxPlugin. //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kFloatParam, kIntParam, diff --git a/thrush/thrush.cpp b/thrush/thrush.cpp index b02a9a70..a03adb4e 100644 --- a/thrush/thrush.cpp +++ b/thrush/thrush.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Thrush. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "thrush.h" @@ -43,26 +43,26 @@ Thrush::Thrush(TARGET_API_BASE_INSTANCE_TYPE inInstance) initparameter_b(kTempoAuto, dfx::MakeParameterNames(dfx::kParameterNames_TempoAuto), true); initparameter_f(kLFO1Rate_Hz, {"LFO1 rate (free)", "seven", "six", "four"}, 3., 3., kLFORateMin, kLFORateMax, DfxParam::Unit::Hz, DfxParam::Curve::Squared); initparameter_list(kLFO1Rate_Sync, {"LFO1 rate (sync)", "seven", "six", "four"}, unitTempoRateIndex, unitTempoRateIndex, numTempoRates, DfxParam::Unit::Beats); - initparameter_b(kLFO1tempoSync, {"LFO1 tempo sync", "seven", "six", "four"}, false); - initparameter_f(kLFO1depth, {"LFO1 depth", "seven", "six", "four"}, 81., 0., 0., 100., DfxParam::Unit::Percent); - initparameter_list(kLFO1shape, {"LFO1 shape", "seven", "six", "four"}, dfx::LFO::kShape_Thorn, dfx::LFO::kShape_Thorn, dfx::LFO::kNumShapes); + initparameter_b(kLFO1TempoSync, {"LFO1 tempo sync", "seven", "six", "four"}, false); + initparameter_f(kLFO1Depth, {"LFO1 depth", "seven", "six", "four"}, 81., 0., 0., 100., DfxParam::Unit::Percent); + initparameter_list(kLFO1Shape, {"LFO1 shape", "seven", "six", "four"}, dfx::LFO::kShape_Thorn, dfx::LFO::kShape_Thorn, dfx::LFO::kNumShapes); initparameter_f(kLFO2Rate_Hz, {"LFO2 rate (free)", "seven", "six", "four"}, 6., 6., kLFORateMin, kLFORateMax, DfxParam::Unit::Hz, DfxParam::Curve::Squared); initparameter_list(kLFO2Rate_Sync, {"LFO2 rate (sync)", "seven", "six", "four"}, unitTempoRateIndex, unitTempoRateIndex, numTempoRates, DfxParam::Unit::Beats); - initparameter_b(kLFO2tempoSync, {"LFO2 tempo sync", "seven", "six", "four"}, false); - initparameter_f(kLFO2depth, {"LFO2 depth", "seven", "six", "four"}, 0., 0., kLFO2DepthMin, kLFO2DepthMax, DfxParam::Unit::Scalar); - initparameter_list(kLFO2shape, {"LFO2 shape", "seven", "six", "four"}, dfx::LFO::kShape_Triangle, dfx::LFO::kShape_Triangle, dfx::LFO::kNumShapes); + initparameter_b(kLFO2TempoSync, {"LFO2 tempo sync", "seven", "six", "four"}, false); + initparameter_f(kLFO2Depth, {"LFO2 depth", "seven", "six", "four"}, 0., 0., kLFO2DepthMin, kLFO2DepthMax, DfxParam::Unit::Scalar); + initparameter_list(kLFO2Shape, {"LFO2 shape", "seven", "six", "four"}, dfx::LFO::kShape_Triangle, dfx::LFO::kShape_Triangle, dfx::LFO::kNumShapes); initparameter_b(kStereoLink, {"stereo link", "seven", "six", "four"}, true); initparameter_i(kDelay2, {"inverse delay R", "seven", "six", "four"}, 3, 3, kDelaySamplesMin, kDelaySamplesMax, DfxParam::Unit::Samples); initparameter_f(kLFO1Rate2_Hz, {"LFO1 rate R (free)", "seven", "six", "four"}, 9., 9., kLFORateMin, kLFORateMax, DfxParam::Unit::Hz, DfxParam::Curve::Squared); initparameter_list(kLFO1Rate2_Sync, {"LFO1 rate R (sync)", "seven", "six", "four"}, unitTempoRateIndex, unitTempoRateIndex, numTempoRates, DfxParam::Unit::Beats); - initparameter_b(kLFO1tempoSync2, {"LFO1 tempo sync R", "seven", "six", "four"}, false); - initparameter_f(kLFO1depth2, {"LFO1 depth R", "seven", "six", "four"}, 30., 0., 0., 100., DfxParam::Unit::Percent); - initparameter_list(kLFO1shape2, {"LFO1 shape R", "seven", "six", "four"}, dfx::LFO::kShape_Square, dfx::LFO::kShape_Square, dfx::LFO::kNumShapes); + initparameter_b(kLFO1TempoSync2, {"LFO1 tempo sync R", "seven", "six", "four"}, false); + initparameter_f(kLFO1Depth2, {"LFO1 depth R", "seven", "six", "four"}, 30., 0., 0., 100., DfxParam::Unit::Percent); + initparameter_list(kLFO1Shape2, {"LFO1 shape R", "seven", "six", "four"}, dfx::LFO::kShape_Square, dfx::LFO::kShape_Square, dfx::LFO::kNumShapes); initparameter_f(kLFO2Rate2_Hz, {"LFO2 rate R (free)", "seven", "six", "four"}, 12., 12., kLFORateMin, kLFORateMax, DfxParam::Unit::Hz, DfxParam::Curve::Squared); initparameter_list(kLFO2Rate2_Sync, {"LFO2 rate R (sync)", "seven", "six", "four"}, unitTempoRateIndex, unitTempoRateIndex, numTempoRates, DfxParam::Unit::Beats); - initparameter_b(kLFO2tempoSync2, {"LFO2 tempo sync R", "seven", "six", "four"}, false); - initparameter_f(kLFO2depth2, {"LFO2 depth R", "seven", "six", "four"}, 0., 0., kLFO2DepthMin, kLFO2DepthMax, DfxParam::Unit::Scalar); - initparameter_list(kLFO2shape2, {"LFO2 shape R", "seven", "six", "four"}, dfx::LFO::kShape_Saw, dfx::LFO::kShape_Saw, dfx::LFO::kNumShapes); + initparameter_b(kLFO2TempoSync2, {"LFO2 tempo sync R", "seven", "six", "four"}, false); + initparameter_f(kLFO2Depth2, {"LFO2 depth R", "seven", "six", "four"}, 0., 0., kLFO2DepthMin, kLFO2DepthMax, DfxParam::Unit::Scalar); + initparameter_list(kLFO2Shape2, {"LFO2 shape R", "seven", "six", "four"}, dfx::LFO::kShape_Saw, dfx::LFO::kShape_Saw, dfx::LFO::kNumShapes); initparameter_f(kDryWetMix, dfx::MakeParameterNames(dfx::kParameterNames_DryWetMix), 100., 50., 0.0, 100.0, DfxParam::Unit::DryWetMix); setparameterenforcevaluelimits(kDelay, true); @@ -72,10 +72,10 @@ Thrush::Thrush(TARGET_API_BASE_INSTANCE_TYPE inInstance) for (dfx::LFO::Shape i = 0; i < dfx::LFO::kNumShapes; i++) { auto const shapeName = dfx::LFO::getShapeName(i); - setparametervaluestring(kLFO1shape, i, shapeName); - setparametervaluestring(kLFO2shape, i, shapeName); - setparametervaluestring(kLFO1shape2, i, shapeName); - setparametervaluestring(kLFO2shape2, i, shapeName); + setparametervaluestring(kLFO1Shape, i, shapeName); + setparametervaluestring(kLFO2Shape, i, shapeName); + setparametervaluestring(kLFO1Shape2, i, shapeName); + setparametervaluestring(kLFO2Shape2, i, shapeName); } // set the value strings for the sync rate parameters for (long i = 0; i < mTempoRateTable.getNumRates(); i++) @@ -90,14 +90,14 @@ Thrush::Thrush(TARGET_API_BASE_INSTANCE_TYPE inInstance) addparametergroup("global/left", { kDelay, - kLFO1Rate_Hz, kLFO1Rate_Sync, kLFO1tempoSync, kLFO1depth, kLFO1shape, - kLFO2Rate_Hz, kLFO2Rate_Sync, kLFO2tempoSync, kLFO2depth, kLFO2shape + kLFO1Rate_Hz, kLFO1Rate_Sync, kLFO1TempoSync, kLFO1Depth, kLFO1Shape, + kLFO2Rate_Hz, kLFO2Rate_Sync, kLFO2TempoSync, kLFO2Depth, kLFO2Shape }); addparametergroup("right", { kStereoLink, kDelay2, - kLFO1Rate2_Hz, kLFO1Rate2_Sync, kLFO1tempoSync2, kLFO1depth2, kLFO1shape2, - kLFO2Rate2_Hz, kLFO2Rate2_Sync, kLFO2tempoSync2, kLFO2depth2, kLFO2shape2 + kLFO1Rate2_Hz, kLFO1Rate2_Sync, kLFO1TempoSync2, kLFO1Depth2, kLFO1Shape2, + kLFO2Rate2_Hz, kLFO2Rate2_Sync, kLFO2TempoSync2, kLFO2Depth2, kLFO2Shape2 }); addchannelconfig(2, 2); // stereo in / stereo out @@ -162,16 +162,16 @@ void Thrush::initPresets() setpresetname(i, "vibber"); // setpresetparameter_i(i, kDelay, ); - setpresetparameter_b(i, kLFO1tempoSync, false); + setpresetparameter_b(i, kLFO1TempoSync, false); // setpresetparameter_f(i, kLFO1Rate_Hz, ); -// setpresetparameter_f(i, kLFO1depth, ); - setpresetparameter_i(i, kLFO1shape, dfx::LFO::kShape_Saw); +// setpresetparameter_f(i, kLFO1Depth, ); + setpresetparameter_i(i, kLFO1Shape, dfx::LFO::kShape_Saw); setpresetparameter_b(i, kStereoLink, false); // setpresetparameter_i(i, kDelay2, ); - setpresetparameter_b(i, kLFO1tempoSync2, false); + setpresetparameter_b(i, kLFO1TempoSync2, false); // setpresetparameter_f(i, kLFO1Rate2_Hz, ); -// setpresetparameter_f(i, kLFO1depth2, ); - setpresetparameter_i(i, kLFO1shape2, dfx::LFO::kShape_Saw); +// setpresetparameter_f(i, kLFO1Depth2, ); + setpresetparameter_i(i, kLFO1Shape2, dfx::LFO::kShape_Saw); setpresetparameter_f(i, kDryWetMix, 100.); i++; }; @@ -254,15 +254,15 @@ void Thrush::processparameters() mNeedResync = true; } - if (auto const value = getparameterifchanged_b(kLFO1tempoSync)) + if (auto const value = getparameterifchanged_b(kLFO1TempoSync)) { mLFO1.mTempoSync = *value; // need to resync if tempo sync mode has just been switched on mNeedResync |= *value; } - mLFO1.setDepth(getparameter_scalar(kLFO1depth)); - mLFO1.setShape(getparameter_i(kLFO1shape)); + mLFO1.setDepth(getparameter_scalar(kLFO1Depth)); + mLFO1.setShape(getparameter_i(kLFO1Shape)); mLFO2.mRateHz = getparameter_f(kLFO2Rate_Hz); // make sure the cycles match up if the tempo rate has changed @@ -272,15 +272,15 @@ void Thrush::processparameters() mNeedResync = true; } - if (auto const value = getparameterifchanged_b(kLFO2tempoSync)) + if (auto const value = getparameterifchanged_b(kLFO2TempoSync)) { mLFO2.mTempoSync = *value; // need to resync if tempo sync mode has just been switched on mNeedResync |= *value; } - mLFO2.setDepth(getparameter_gen(kLFO2depth)); - mLFO2.setShape(getparameter_i(kLFO2shape)); + mLFO2.setDepth(getparameter_gen(kLFO2Depth)); + mLFO2.setShape(getparameter_i(kLFO2Shape)); mStereoLink = getparameter_b(kStereoLink); @@ -288,27 +288,27 @@ void Thrush::processparameters() mLFO1_2.mRateHz = getparameter_f(kLFO1Rate2_Hz); mLFO1_2.mTempoRateScalar = mTempoRateTable.getScalar(getparameter_i(kLFO1Rate2_Sync)); - if (auto const value = getparameterifchanged_b(kLFO1tempoSync2)) + if (auto const value = getparameterifchanged_b(kLFO1TempoSync2)) { mLFO1_2.mTempoSync = *value; // need to resync if tempo sync mode has just been switched on mNeedResync |= (!mStereoLink && *value); } - mLFO1_2.setDepth(getparameter_scalar(kLFO1depth2)); - mLFO1_2.setShape(getparameter_i(kLFO1shape2)); + mLFO1_2.setDepth(getparameter_scalar(kLFO1Depth2)); + mLFO1_2.setShape(getparameter_i(kLFO1Shape2)); mLFO2_2.mRateHz = getparameter_f(kLFO2Rate2_Hz); mLFO2_2.mTempoRateScalar = mTempoRateTable.getScalar(getparameter_i(kLFO2Rate2_Sync)); - if (auto const value = getparameterifchanged_b(kLFO2tempoSync2)) + if (auto const value = getparameterifchanged_b(kLFO2TempoSync2)) { mLFO2_2.mTempoSync = *value; // need to resync if tempo sync mode has just been switched on mNeedResync |= (!mStereoLink && *value); } - mLFO2_2.setDepth(getparameter_gen(kLFO2depth2)); - mLFO2_2.setShape(getparameter_i(kLFO2shape2)); + mLFO2_2.setDepth(getparameter_gen(kLFO2Depth2)); + mLFO2_2.setShape(getparameter_i(kLFO2Shape2)); if (auto const value = getparameterifchanged_scalar(kDryWetMix)) { @@ -331,7 +331,7 @@ void Thrush::processaudio(float const* const* inAudio, float* const* outAudio, s for (size_t sampleIndex = 0; sampleIndex < inNumFrames; sampleIndex++) { // evaluate the sample-by-sample output of the LFOs - auto const normalizedOffset = [this](long parameterID, double normalizedValue, ThrushLFO& lfoLayer1, ThrushLFO& lfoLayer2) + auto const normalizedOffset = [this](dfx::ParameterID parameterID, double normalizedValue, ThrushLFO& lfoLayer1, ThrushLFO& lfoLayer2) { auto const delayOffset = processLFOs(lfoLayer1, lfoLayer2); return expandparametervalue(parameterID, normalizedValue * delayOffset); diff --git a/thrush/thrush.h b/thrush/thrush.h index cce6b16a..57caf821 100644 --- a/thrush/thrush.h +++ b/thrush/thrush.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Thrush. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -34,38 +34,38 @@ To contact the author, use the contact form at http://destroyfx.org/ //------------------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kDelay, kTempo, kTempoAuto, - kLFO1tempoSync, + kLFO1TempoSync, kLFO1Rate_Hz, kLFO1Rate_Sync, - kLFO1depth, - kLFO1shape, + kLFO1Depth, + kLFO1Shape, - kLFO2tempoSync, + kLFO2TempoSync, kLFO2Rate_Hz, kLFO2Rate_Sync, - kLFO2depth, - kLFO2shape, + kLFO2Depth, + kLFO2Shape, kStereoLink, kDelay2, - kLFO1tempoSync2, + kLFO1TempoSync2, kLFO1Rate2_Hz, kLFO1Rate2_Sync, - kLFO1depth2, - kLFO1shape2, + kLFO1Depth2, + kLFO1Shape2, - kLFO2tempoSync2, + kLFO2TempoSync2, kLFO2Rate2_Hz, kLFO2Rate2_Sync, - kLFO2depth2, - kLFO2shape2, + kLFO2Depth2, + kLFO2Shape2, kDryWetMix, diff --git a/transverb/gui/transverbeditor.cpp b/transverb/gui/transverbeditor.cpp index c7d3fd29..69e44763 100644 --- a/transverb/gui/transverbeditor.cpp +++ b/transverb/gui/transverbeditor.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Transverb. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "transverbeditor.h" @@ -90,13 +90,13 @@ constexpr float kSemitonesPerOctave = 12.0f; static bool bsizeDisplayProcedure(float inValue, char* outText, void*) { - long const thousands = static_cast(inValue) / 1000; + int const thousands = static_cast(inValue) / 1000; auto const remainder = std::fmod(inValue, 1000.0f); bool success = false; if (thousands > 0) { - success = snprintf(outText, DGTextDisplay::kTextMaxLength, "%ld,%05.1f", thousands, remainder) > 0; + success = snprintf(outText, DGTextDisplay::kTextMaxLength, "%d,%05.1f", thousands, remainder) > 0; } else { @@ -188,19 +188,19 @@ static std::optional speedTextConvertProcedure(std::string const& inText, static bool feedbackDisplayProcedure(float inValue, char* outText, void*) { - return snprintf(outText, DGTextDisplay::kTextMaxLength, "%ld%%", static_cast(inValue)) > 0; + return snprintf(outText, DGTextDisplay::kTextMaxLength, "%d%%", static_cast(inValue)) > 0; } static bool distDisplayProcedure(float inValue, char* outText, void* inEditor) { float const distance = inValue * static_cast(inEditor)->getparameter_f(kBsize); - long const thousands = static_cast(distance) / 1000; + int const thousands = static_cast(distance) / 1000; auto const remainder = std::fmod(distance, 1000.0f); bool success = false; if (thousands > 0) { - success = snprintf(outText, DGTextDisplay::kTextMaxLength, "%ld,%06.2f", thousands, remainder) > 0; + success = snprintf(outText, DGTextDisplay::kTextMaxLength, "%d,%06.2f", thousands, remainder) > 0; } else { @@ -344,22 +344,22 @@ long TransverbEditor::OpenEditor() DGRect pos, textDisplayPos, tuneDownButtonPos, tuneUpButtonPos; - constexpr long sliderRangeMargin = 1; + constexpr int sliderRangeMargin = 1; // Make horizontal sliders and add them to the pane pos.set(kWideFaderX, kWideFaderY, horizontalSliderBackgroundImage->getWidth(), horizontalSliderBackgroundImage->getHeight()); textDisplayPos.set(kDisplayX, kDisplayY, kDisplayWidth, kDisplayHeight); tuneDownButtonPos.set(kFineDownButtonX, kFineButtonY, fineDownButtonImage->getWidth(), fineDownButtonImage->getHeight() / 2); tuneUpButtonPos.set(kFineUpButtonX, kFineButtonY, fineUpButtonImage->getWidth(), fineUpButtonImage->getHeight() / 2); - for (long tag = kSpeed1; tag <= kDist2; tag++) + for (dfx::ParameterID parameterID = kSpeed1; parameterID <= kDistParameters.back(); parameterID++) { VSTGUI::CParamDisplayValueToStringProc displayProc = nullptr; void* userData = nullptr; - if ((tag == kSpeed1) || (tag == kSpeed2)) + if (std::find(kSpeedParameters.cbegin(), kSpeedParameters.cend(), parameterID) != kSpeedParameters.cend()) { displayProc = speedDisplayProcedure; } - else if ((tag == kFeed1) || (tag == kFeed2)) + else if (std::find(kFeedParameters.cbegin(), kFeedParameters.cend(), parameterID) != kFeedParameters.cend()) { displayProc = feedbackDisplayProcedure; } @@ -369,28 +369,28 @@ long TransverbEditor::OpenEditor() userData = this; } assert(displayProc); - emplaceControl(this, tag, pos, dfx::kAxis_Horizontal, horizontalSliderHandleImage, horizontalSliderBackgroundImage, sliderRangeMargin)->setAlternateHandle(horizontalSliderHandleImage_glowing); + emplaceControl(this, parameterID, pos, dfx::kAxis_Horizontal, horizontalSliderHandleImage, horizontalSliderBackgroundImage, sliderRangeMargin)->setAlternateHandle(horizontalSliderHandleImage_glowing); - auto const textDisplay = emplaceControl(this, tag, textDisplayPos, displayProc, userData, nullptr, + auto const textDisplay = emplaceControl(this, parameterID, textDisplayPos, displayProc, userData, nullptr, dfx::TextAlignment::Right, kDisplayTextSize, kDisplayTextColor, kDisplayFont); - if (auto const speedTag = std::find(kSpeedParameters.cbegin(), kSpeedParameters.cend(), tag); speedTag != kSpeedParameters.cend()) + if (auto const speedParameterID = std::find(kSpeedParameters.cbegin(), kSpeedParameters.cend(), parameterID); speedParameterID != kSpeedParameters.cend()) { - auto const head = static_cast(std::distance(kSpeedParameters.cbegin(), speedTag)); - mSpeedDownButtons[head] = emplaceControl(this, tag, tuneDownButtonPos, fineDownButtonImage, -kFineTuneInc); - mSpeedUpButtons[head] = emplaceControl(this, tag, tuneUpButtonPos, fineUpButtonImage, kFineTuneInc); + auto const head = static_cast(std::distance(kSpeedParameters.cbegin(), speedParameterID)); + mSpeedDownButtons[head] = emplaceControl(this, parameterID, tuneDownButtonPos, fineDownButtonImage, -kFineTuneInc); + mSpeedUpButtons[head] = emplaceControl(this, parameterID, tuneUpButtonPos, fineUpButtonImage, kFineTuneInc); textDisplay->setTextToValueProc(speedTextConvertProcedure); } else { - emplaceControl(this, tag, tuneDownButtonPos, fineDownButtonImage, -kFineTuneInc); - emplaceControl(this, tag, tuneUpButtonPos, fineUpButtonImage, kFineTuneInc); + emplaceControl(this, parameterID, tuneDownButtonPos, fineDownButtonImage, -kFineTuneInc); + emplaceControl(this, parameterID, tuneUpButtonPos, fineUpButtonImage, kFineTuneInc); } - long yoff = kWideFaderInc; + auto yoff = kWideFaderInc; for (size_t head = 0; head < kNumDelays; head++) { - if (tag == kDistParameters[head]) + if (parameterID == kDistParameters[head]) { bool const lastHead = (kDistParameters[head] == kDistParameters.back()); yoff = lastHead ? kWideFaderEvenMoreInc : kWideFaderMoreInc; @@ -415,9 +415,9 @@ long TransverbEditor::OpenEditor() // make horizontal sliders and add them to the view pos.set(kTallFaderX, kTallFaderY, verticalSliderBackgroundImage->getWidth(), verticalSliderBackgroundImage->getHeight()); - for (long tag = kDrymix; tag <= kMix2; tag++) + for (dfx::ParameterID parameterID = kDrymix; parameterID <= kMixParameters.back(); parameterID++) { - emplaceControl(this, tag, pos, dfx::kAxis_Vertical, verticalSliderHandleImage, verticalSliderBackgroundImage, sliderRangeMargin)->setAlternateHandle(verticalSliderHandleImage_glowing); + emplaceControl(this, parameterID, pos, dfx::kAxis_Vertical, verticalSliderHandleImage, verticalSliderBackgroundImage, sliderRangeMargin)->setAlternateHandle(verticalSliderHandleImage_glowing); pos.offset(kTallFaderInc, 0); } @@ -463,18 +463,24 @@ long TransverbEditor::OpenEditor() SetParameterHelpText(kBsize, "the size of the buffer that both delays use"); constexpr char const* const speedHelpText = "how quickly or slowly the delay playback moves through the delay buffer"; - SetParameterHelpText(kSpeed1, speedHelpText); - SetParameterHelpText(kSpeed2, speedHelpText); + for (auto const parameterID : kSpeedParameters) + { + SetParameterHelpText(parameterID, speedHelpText); + } std::for_each(mSpeedModeButtons.begin(), mSpeedModeButtons.end(), [](auto* control){ control->setHelpText(speedHelpText); }); - constexpr char const* const feedbackHelpText = "how much of the delay sound gets mixed back into the delay buffer"; - SetParameterHelpText(kFeed1, feedbackHelpText); - SetParameterHelpText(kFeed2, feedbackHelpText); - constexpr char const* const distanceHelpText = "how far behind the delay is from the input signal (only really makes a difference when the speed is at zero)"; - SetParameterHelpText(kDist1, distanceHelpText); - SetParameterHelpText(kDist2, distanceHelpText); + for (auto const parameterID : kFeedParameters) + { + SetParameterHelpText(parameterID, "how much of the delay sound gets mixed back into the delay buffer"); + } + for (auto const parameterID : kDistParameters) + { + SetParameterHelpText(parameterID, "how far behind the delay is from the input signal (only really makes a difference when the speed is at zero)"); + } SetParameterHelpText(kDrymix, "input audio mix level"); - SetParameterHelpText(kMix1, "delay head #1 mix level"); - SetParameterHelpText(kMix2, "delay head #2 mix level"); + for (size_t i = 0; i < kMixParameters.size(); i++) + { + SetParameterHelpText(kMixParameters[i], ("delay head #" + std::to_string(i + 1) + " mix level").c_str()); + } SetParameterHelpText(kQuality, "level of transposition quality of the delays' speed"); SetParameterHelpText(kTomsound, "megaharsh sound"); SetParameterHelpText(kFreeze, "pause recording new audio into the delay buffer"); @@ -503,7 +509,7 @@ void TransverbEditor::CloseEditor() } //----------------------------------------------------------------------------- -void TransverbEditor::parameterChanged(long inParameterID) +void TransverbEditor::parameterChanged(dfx::ParameterID inParameterID) { switch (inParameterID) { diff --git a/transverb/gui/transverbeditor.h b/transverb/gui/transverbeditor.h index 5fe66d31..e6ee8f62 100644 --- a/transverb/gui/transverbeditor.h +++ b/transverb/gui/transverbeditor.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Transverb. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -33,14 +33,14 @@ To contact the author, use the contact form at http://destroyfx.org/ class TransverbSpeedTuneButton final : public DGFineTuneButton { public: - TransverbSpeedTuneButton(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, DGImage* inImage, - float inValueChangeAmount) - : DGFineTuneButton(inOwnerEditor, inParamID, inRegion, inImage, inValueChangeAmount) + TransverbSpeedTuneButton(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, + DGImage* inImage, float inValueChangeAmount) + : DGFineTuneButton(inOwnerEditor, inParameterID, inRegion, inImage, inValueChangeAmount) {} void onMouseDownEvent(VSTGUI::MouseDownEvent& ioEvent) override; - void setTuneMode(long inTuneMode) noexcept + void setTuneMode(unsigned int inTuneMode) noexcept { mTuneMode = inTuneMode; } @@ -48,7 +48,7 @@ class TransverbSpeedTuneButton final : public DGFineTuneButton CLASS_METHODS(TransverbSpeedTuneButton, DGFineTuneButton) private: - long mTuneMode {}; + unsigned int mTuneMode {}; }; @@ -62,7 +62,7 @@ class TransverbEditor final : public DfxGuiEditor long OpenEditor() override; void PostOpenEditor() override; void CloseEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; void HandlePropertyChange(dfx::PropertyID inPropertyID, dfx::Scope inScope, unsigned int inItemIndex) override; private: diff --git a/transverb/transverb-base.h b/transverb/transverb-base.h index 4a5a56a0..907cbbb8 100644 --- a/transverb/transverb-base.h +++ b/transverb/transverb-base.h @@ -16,13 +16,14 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Transverb. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once #include +#include "dfxdefines.h" #include "dfxpluginproperties.h" @@ -31,7 +32,7 @@ namespace dfx::TV //----------------------------------------------------------------------------- // these are the plugin parameters: -enum +enum : dfx::ParameterID { kBsize, kSpeed1, @@ -54,10 +55,10 @@ enum static constexpr size_t kNumDelays = 2; -static constexpr std::array kSpeedParameters { kSpeed1, kSpeed2 }; -static constexpr std::array kFeedParameters { kFeed1, kFeed2 }; -static constexpr std::array kDistParameters { kDist1, kDist2 }; -static constexpr std::array kMixParameters { kMix1, kMix2 }; +static constexpr std::array kSpeedParameters { kSpeed1, kSpeed2 }; +static constexpr std::array kFeedParameters { kFeed1, kFeed2 }; +static constexpr std::array kDistParameters { kDist1, kDist2 }; +static constexpr std::array kMixParameters { kMix1, kMix2 }; enum { kQualityMode_DirtFi, kQualityMode_HiFi, kQualityMode_UltraHiFi, kQualityMode_NumModes }; diff --git a/transverb/transverb.h b/transverb/transverb.h index d6fd3450..181392b6 100644 --- a/transverb/transverb.h +++ b/transverb/transverb.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Transverb. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #pragma once @@ -121,7 +121,7 @@ class Transverb final : public DfxPlugin { void settings_saveExtendedData(void* outData, bool isPreset) override; void settings_restoreExtendedData(void const* inData, size_t storedExtendedDataSize, unsigned int dataVersion, bool isPreset) override; - void settings_doChunkRestoreSetParameterStuff(long tag, float value, unsigned int dataVersion, std::optional presetIndex) override; + void settings_doChunkRestoreSetParameterStuff(dfx::ParameterID parameterID, float value, unsigned int dataVersion, std::optional presetIndex) override; private: static constexpr size_t kNumPresets = 16; diff --git a/transverb/transverbformalities.cpp b/transverb/transverbformalities.cpp index 49441748..d2ae1845 100644 --- a/transverb/transverbformalities.cpp +++ b/transverb/transverbformalities.cpp @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Transverb. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "transverb.h" @@ -59,8 +59,9 @@ Transverb::Transverb(TARGET_API_BASE_INSTANCE_TYPE inInstance) initparameter_b(kAttenuateFeedbackByMixLevel, {"attenuate feedback by mix level", "AtnFdbk", "AtnFdb", "-fdb"}, false); setparameterenforcevaluelimits(kBsize, true); - setparameterenforcevaluelimits(kDist1, true); - setparameterenforcevaluelimits(kDist2, true); + for (auto const parameterID : kDistParameters) { + setparameterenforcevaluelimits(parameterID, true); + } setparametervaluestring(kQuality, kQualityMode_DirtFi, "dirt-fi"); setparametervaluestring(kQuality, kQualityMode_HiFi, "hi-fi"); @@ -73,7 +74,7 @@ Transverb::Transverb(TARGET_API_BASE_INSTANCE_TYPE inInstance) addparameterattributes(kFreeze, DfxParam::kAttribute_OmitFromRandomizeAll); addparameterattributes(kAttenuateFeedbackByMixLevel, DfxParam::kAttribute_OmitFromRandomizeAll); - std::vector mixparameters(1, kDrymix); + std::vector mixparameters(1, kDrymix); for (size_t head = 0; head < kNumDelays; head++) { addparametergroup("head #" + std::to_string(head + 1), {kSpeedParameters[head], kFeedParameters[head], kDistParameters[head]}); @@ -422,7 +423,7 @@ void Transverb::randomizeparameters() { // randomize the non-mix-level parameters - for (long i = 0; i < kDrymix; i++) + for (dfx::ParameterID i = 0; i < kDrymix; i++) { if (hasparameterattribute(i, DfxParam::kAttribute_OmitFromRandomizeAll) || hasparameterattribute(i, DfxParam::kAttribute_Unused)) { @@ -499,7 +500,7 @@ void Transverb::randomizeparameters() } - for (long i = 0; i < kNumParameters; i++) + for (dfx::ParameterID i = 0; i < kNumParameters; i++) { if (hasparameterattribute(i, DfxParam::kAttribute_OmitFromRandomizeAll) || hasparameterattribute(i, DfxParam::kAttribute_Unused)) { @@ -575,40 +576,40 @@ void Transverb::settings_restoreExtendedData(void const* inData, size_t storedEx } } -void Transverb::settings_doChunkRestoreSetParameterStuff(long tag, float value, unsigned int dataVersion, std::optional presetIndex) +void Transverb::settings_doChunkRestoreSetParameterStuff(dfx::ParameterID parameterID, float value, unsigned int dataVersion, std::optional presetIndex) { // prevent old speed mode 1 settings from applying to freeze - if ((dataVersion < 0x00010501) && (tag == kFreeze)) + if ((dataVersion < 0x00010501) && (parameterID == kFreeze)) { - auto const defaultValue = getparameterdefault_b(tag); + auto const defaultValue = getparameterdefault_b(parameterID); if (presetIndex) { - setpresetparameter_b(*presetIndex, tag, defaultValue); + setpresetparameter_b(*presetIndex, parameterID, defaultValue); } else { - setparameter_b(tag, defaultValue); + setparameter_b(parameterID, defaultValue); } } if (dataVersion <= 0x00010502) { // invert old erroneously reversed dist parameter values - if ((tag == kDist1) || (tag == kDist2)) + if (std::find(kDistParameters.cbegin(), kDistParameters.cend(), parameterID) != kDistParameters.cend()) { - auto const valueNormalized = 1. - contractparametervalue(tag, value); + auto const valueNormalized = 1. - contractparametervalue(parameterID, value); if (presetIndex) { - setpresetparameter_gen(*presetIndex, tag, valueNormalized); + setpresetparameter_gen(*presetIndex, parameterID, valueNormalized); } else { - setparameter_gen(tag, valueNormalized); + setparameter_gen(parameterID, valueNormalized); } } // hi-fi mode used to behave the same as and ultra hi-fi mode in TOMSOUND - if (tag == kTomsound) // assumes that TOMSOUND parameter is restored after quality + if (parameterID == kTomsound) // assumes that TOMSOUND parameter is restored after quality { if (presetIndex) { diff --git a/turntablist/turntablist.cpp b/turntablist/turntablist.cpp index 3c6f7386..53ab1510 100644 --- a/turntablist/turntablist.cpp +++ b/turntablist/turntablist.cpp @@ -19,7 +19,7 @@ the Free Software Foundation, either version 2 of the License, or You should have received a copy of the GNU General Public License along with Turntablist. If not, see . -To contact the developer, use the contact form at http://destroyfx.org/ +To contact the developer, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #include "turntablist.h" @@ -788,25 +788,22 @@ OSStatus Turntablist::loadAudioFile(FSRef const& inFileRef) // libsndfile #else - UInt8 file[2048]; - memset(file, 0, sizeof(file)); - OSStatus status = FSRefMakePath(&inFileRef, file, sizeof(file)); + UInt8 file[2048] {}; + OSStatus status = FSRefMakePath(&inFileRef, file, std::size(file)); if (status != noErr) { return status; } //fprintf(stderr, PLUGIN_NAME_STRING " audio file: %s\n", file); - SF_INFO sfInfo; - memset(&sfInfo, 0, sizeof(SF_INFO)); - SNDFILE* const sndFile = sf_open((const char*)file, SFM_READ, &sfInfo); + SF_INFO sfInfo {}; + SNDFILE* const sndFile = sf_open(reinterpret_cast(file), SFM_READ, &sfInfo); if (!sndFile) { // print error - char buffer[256]; - memset(buffer, 0, sizeof(buffer)); - sf_error_str(sndFile, buffer, sizeof(buffer) - 1); + char buffer[256] {}; + sf_error_str(sndFile, buffer, std::size(buffer) - 1); fprintf(stderr, "\n" PLUGIN_NAME_STRING " could not open the audio file: %s\nlibsndfile error message: %s\n", file, buffer); return sf_error(sndFile); } @@ -908,7 +905,7 @@ void Turntablist::processaudio(float const* const* /*inAudio*/, float* const* ou size_t currEvent = 0; auto const numOutputs = getnumoutputs(); -// float (*interpolateHermiteFunctionPtr)(float *, double, long) = m_bLoop ? dfx::math::InterpolateHermite : dfx::math::InterpolateHermite_NoWrap; + //auto const interpolateHermiteFunctionPtr = m_bLoop ? dfx::math::InterpolateHermite : dfx::math::InterpolateHermite_NoWrap; if (numEvents == 0) @@ -1520,13 +1517,14 @@ void Turntablist::processMidiEvent(size_t inEventIndex) } #ifdef USE_MIDI_CC - if ((event.mByte1 >= 64) && (event.mByte1 <= (64 + kNumParameters - 1))) + constexpr int dataMidpoint = 64; + if ((event.mByte1 >= dataMidpoint) && (event.mByte1 <= (dataMidpoint + kNumParameters - 1))) { - long const param = event.mByte1 - 64; - long const new_data = fixMidiData(param, event.mByte2); - float const value = static_cast(new_data) * DfxMidi::kValueScalar; - setparameter_f(param, value); - postupdate_parameter(param); + dfx::ParameterID const parameterID = event.mByte1 - dataMidpoint; + auto const correctedData = fixMidiData(parameterID, event.mByte2); + float const value = static_cast(correctedData) * DfxMidi::kValueScalar; + setparameter_f(parameterID, value); + postupdate_parameter(parameterID); } #endif } @@ -1645,7 +1643,7 @@ void Turntablist::playNote(bool inValue) } //----------------------------------------------------------------------------------------- -long Turntablist::fixMidiData(long inParameterID, char inValue) +int Turntablist::fixMidiData(dfx::ParameterID inParameterID, int inValue) noexcept { switch (inParameterID) { diff --git a/turntablist/turntablist.h b/turntablist/turntablist.h index b7cddf28..b94761e3 100644 --- a/turntablist/turntablist.h +++ b/turntablist/turntablist.h @@ -19,7 +19,7 @@ the Free Software Foundation, either version 2 of the License, or You should have received a copy of the GNU General Public License along with Turntablist. If not, see . -To contact the developer, use the contact form at http://destroyfx.org/ +To contact the developer, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ @@ -75,7 +75,7 @@ enum //------------------------------------------------------------------------------------------ // parameters -enum +enum : dfx::ParameterID { // scratching kParam_ScratchAmount, @@ -174,7 +174,7 @@ class Turntablist final : public DfxPlugin void noteOn(int inNote, int inVelocity, size_t inOffsetFrames); void stopNote(bool inStopPlay = false); void playNote(bool inValue); - long fixMidiData(long inParameterID, char inValue); + static int fixMidiData(dfx::ParameterID inParameterID, int inValue) noexcept; OSStatus PostNotification_AudioFileNotFound(CFStringRef inFileName); diff --git a/turntablist/turntablisteditor.mm b/turntablist/turntablisteditor.mm index 38b4450a..7dde3e44 100644 --- a/turntablist/turntablisteditor.mm +++ b/turntablist/turntablisteditor.mm @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with Turntablist. If not, see . -To contact the author, use the contact form at http://destroyfx.org/ +To contact the author, use the contact form at http://destroyfx.org ------------------------------------------------------------------------*/ #import @@ -39,6 +39,7 @@ constexpr float kTurntablistFontSize = 10.0f; +constexpr size_t kKnobFrames = 61; //----------------------------------------------------------------------------- enum @@ -120,9 +121,7 @@ kAboutSplashX = 13, kAboutSplashY = 64, kAboutSplashWidth = 137, - kAboutSplashHeight = 28, - - kKnobFrames = 61 + kAboutSplashHeight = 28 }; @@ -141,7 +140,7 @@ void PostOpenEditor() override; void CloseEditor() override; - void parameterChanged(long inParameterID) override; + void parameterChanged(dfx::ParameterID inParameterID) override; void HandlePropertyChange(dfx::PropertyID inPropertyID, dfx::Scope inScope, unsigned int inItemIndex) override; void dfxgui_Idle() override; @@ -158,7 +157,7 @@ void HandlePlayChange(); void HandleMidiLearnButton(bool inLearn); void HandleMidiResetButton(); - void HandleParameterChange(long inParameterID, float inValue); + void HandleParameterChange(dfx::ParameterID inParameterID, float inValue); void SetFileNameDisplay(CFStringRef inText); OSStatus NotifyAudioFileLoadError(OSStatus inErrorCode, FSRef const& inAudioFileRef) const; @@ -180,9 +179,9 @@ class TurntablistScratchSlider final : public DGSlider { public: - TurntablistScratchSlider(DfxGuiEditor* inOwnerEditor, long inParamID, DGRect const& inRegion, + TurntablistScratchSlider(DfxGuiEditor* inOwnerEditor, dfx::ParameterID inParameterID, DGRect const& inRegion, dfx::Axis inOrientation, DGImage* inHandleImage) - : DGSlider(inOwnerEditor, inParamID, inRegion, inOrientation, inHandleImage) + : DGSlider(inOwnerEditor, inParameterID, inRegion, inOrientation, inHandleImage) { } @@ -473,6 +472,7 @@ bool onDrop(IDataPackage* inDrag, VSTGUI::CPoint const& inPos) override { return true; }*/ + CLASS_METHODS(TurntablistButton, DGButton) }; pos.set(kLoadButtonX, kLoadButtonY, onOffButtonImage->getWidth(), onOffButtonImage->getHeight() / 2); button = emplaceControl(this, pos, onOffButtonImage, 2, DGButton::Mode::Momentary); @@ -641,7 +641,7 @@ bool onDrop(IDataPackage* inDrag, VSTGUI::CPoint const& inPos) override } //----------------------------------------------------------------------------- -void TurntablistEditor::parameterChanged(long inParameterID) +void TurntablistEditor::parameterChanged(dfx::ParameterID inParameterID) { HandleParameterChange(inParameterID, getparameter_f(inParameterID)); } @@ -1284,14 +1284,13 @@ static auto DFX_CopyFileNameString(FSRef const& inFileRef) #pragma mark parameter -> string conversions //----------------------------------------------------------------------------- -static dfx::UniqueCFType DFX_CopyAUParameterName(AudioUnit inAUInstance, long inParameterID) +static dfx::UniqueCFType DFX_CopyAUParameterName(AudioUnit inAUInstance, dfx::ParameterID inParameterID) { assert(inAUInstance); - AudioUnitParameterInfo parameterInfo; - memset(¶meterInfo, 0, sizeof(parameterInfo)); + AudioUnitParameterInfo parameterInfo {}; UInt32 dataSize = sizeof(parameterInfo); - auto const status = AudioUnitGetProperty(inAUInstance, kAudioUnitProperty_ParameterInfo, kAudioUnitScope_Global, static_cast(inParameterID), ¶meterInfo, &dataSize); + auto const status = AudioUnitGetProperty(inAUInstance, kAudioUnitProperty_ParameterInfo, kAudioUnitScope_Global, inParameterID, ¶meterInfo, &dataSize); if (status == noErr) { auto const parameterName = parameterInfo.cfNameString; @@ -1311,24 +1310,24 @@ static auto DFX_CopyFileNameString(FSRef const& inFileRef) } //----------------------------------------------------------------------------- -static dfx::UniqueCFType DFX_CopyAUParameterValueStrings(AudioUnit inAUInstance, long inParameterID) +static dfx::UniqueCFType DFX_CopyAUParameterValueStrings(AudioUnit inAUInstance, dfx::ParameterID inParameterID) { assert(inAUInstance); CFArrayRef strings = nullptr; UInt32 dataSize = sizeof(strings); - auto const status = AudioUnitGetProperty(inAUInstance, kAudioUnitProperty_ParameterValueStrings, kAudioUnitScope_Global, static_cast(inParameterID), &strings, &dataSize); + auto const status = AudioUnitGetProperty(inAUInstance, kAudioUnitProperty_ParameterValueStrings, kAudioUnitScope_Global, inParameterID, &strings, &dataSize); return (status == noErr) ? dfx::MakeUniqueCFType(strings) : nullptr; } //----------------------------------------------------------------------------- -void TurntablistEditor::HandleParameterChange(long inParameterID, float inValue) +void TurntablistEditor::HandleParameterChange(dfx::ParameterID inParameterID, float inValue) { auto const value_i = (inValue >= 0.0f) ? static_cast(inValue + 0.001f) : static_cast(inValue - 0.001f); if ((inParameterID == kParam_ScratchMode) && mScratchSpeedKnob) { - auto const newParamID = (value_i == kScratchMode_Scrub) ? kParam_ScratchSpeed_scrub : kParam_ScratchSpeed_spin; - mScratchSpeedKnob->setParameterID(newParamID); + auto const newParameterID = (value_i == kScratchMode_Scrub) ? kParam_ScratchSpeed_scrub : kParam_ScratchSpeed_spin; + mScratchSpeedKnob->setParameterID(newParameterID); } if (!mAllParametersTextDisplay) diff --git a/windowingstub/windowingstub.cpp b/windowingstub/windowingstub.cpp index 504b80f0..61834f80 100644 --- a/windowingstub/windowingstub.cpp +++ b/windowingstub/windowingstub.cpp @@ -30,10 +30,6 @@ Windowingstub, featuring the Super Destroy FX Windowing System! #include #include -#if defined(TARGET_API_VST) && TARGET_PLUGIN_HAS_GUI - #include "windowingstubeditor.hpp" -#endif - /* this macro does boring entry point stuff for us */ DFX_ENTRY(Windowingstub); DFX_CORE_ENTRY(WindowingstubDSP); @@ -59,7 +55,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance) setparametervaluestring(P_SHAPE, WINDOW_ARROW, "arrow"); setparametervaluestring(P_SHAPE, WINDOW_WEDGE, "wedge"); setparametervaluestring(P_SHAPE, WINDOW_COS, "best"); - for (long i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) + for (int i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++) setparametervaluestring(P_SHAPE, i, "???"); long delay_samples = buffersizes[getparameter_i(P_BUFSIZE)]; diff --git a/windowingstub/windowingstub.h b/windowingstub/windowingstub.h index c1c949f7..f6278d99 100644 --- a/windowingstub/windowingstub.h +++ b/windowingstub/windowingstub.h @@ -48,8 +48,8 @@ enum { WINDOW_TRIANGLE, }; /* the names of the parameters */ -enum { P_BUFSIZE, P_SHAPE, - NUM_PARAMS, +enum : dfx::ParameterID { P_BUFSIZE, P_SHAPE, + NUM_PARAMS };