@@ -95,6 +95,26 @@ void toString128 (const String& source, Vst::String128 destination)
9595 destination[length] = 0 ;
9696}
9797
98+ Vst::ParamID getVST3ParameterID (const AudioParameter::Ptr& parameter)
99+ {
100+ return static_cast <Vst::ParamID> (parameter->getHostParameterID ());
101+ }
102+
103+ Vst::ParamID getVST3BypassParameterID (const AudioProcessor& processor)
104+ {
105+ auto parameterID = static_cast <uint32> (processor.getParameters ().size ());
106+
107+ while (processor.getParameterByHostID (parameterID) != nullptr
108+ && parameterID < AudioParameter::maximumHostParameterID)
109+ {
110+ ++parameterID;
111+ }
112+
113+ jassert (parameterID <= AudioParameter::maximumHostParameterID);
114+ jassert (processor.getParameterByHostID (parameterID) == nullptr );
115+ return static_cast <Vst::ParamID> (parameterID);
116+ }
117+
98118// ==============================================================================
99119
100120static std::atomic_int numScopedInitInstancesGui = 0 ;
@@ -503,16 +523,16 @@ class AudioPluginControllerVST3
503523 if (processor == nullptr )
504524 return kInternalError ;
505525
506- const auto processorParamCount = static_cast <Vst::ParamID> ( processor-> getParameters (). size () );
526+ const auto bypassParameterID = getVST3BypassParameterID (* processor);
507527
508- if (tag >= processorParamCount )
528+ if (tag == bypassParameterID )
509529 {
510530 // Bypass parameter
511531 toString128 (valueNormalized >= 0.5 ? " On" : " Off" , string);
512532 return kResultOk ;
513533 }
514534
515- if (auto parameter = processor->getParameters ()[ static_cast <int > (tag)] )
535+ if (auto parameter = processor->getParameterByHostID ( static_cast <uint32 > (tag)) )
516536 {
517537 toString128 (parameter->convertToString (parameter->convertToDenormalizedValue (valueNormalized)), string);
518538 return kResultOk ;
@@ -526,17 +546,17 @@ class AudioPluginControllerVST3
526546 if (processor == nullptr )
527547 return kInternalError ;
528548
529- const auto processorParamCount = static_cast <Vst::ParamID> ( processor-> getParameters (). size () );
549+ const auto bypassParameterID = getVST3BypassParameterID (* processor);
530550
531- if (tag >= processorParamCount )
551+ if (tag == bypassParameterID )
532552 {
533553 // Bypass parameter
534554 const auto str = toString (string);
535555 valueNormalized = (str == " On" || str == " 1" ) ? 1.0 : 0.0 ;
536556 return kResultOk ;
537557 }
538558
539- if (auto parameter = processor->getParameters ()[ static_cast <int > (tag)] )
559+ if (auto parameter = processor->getParameterByHostID ( static_cast <uint32 > (tag)) )
540560 {
541561 valueNormalized = parameter->convertToNormalizedValue (parameter->convertFromString (toString (string)));
542562 return kResultOk ;
@@ -550,11 +570,10 @@ class AudioPluginControllerVST3
550570 if (processor == nullptr )
551571 return valueNormalized;
552572
553- const auto processorParamCount = static_cast <Vst::ParamID> (processor->getParameters ().size ());
554- if (tag >= processorParamCount)
573+ if (tag == getVST3BypassParameterID (*processor))
555574 return valueNormalized;
556575
557- if (auto parameter = processor->getParameters ()[ static_cast <int > (tag)] )
576+ if (auto parameter = processor->getParameterByHostID ( static_cast <uint32 > (tag)) )
558577 return parameter->convertToDenormalizedValue (valueNormalized);
559578
560579 return valueNormalized;
@@ -565,11 +584,10 @@ class AudioPluginControllerVST3
565584 if (processor == nullptr )
566585 return plainValue;
567586
568- const auto processorParamCount = static_cast <Vst::ParamID> (processor->getParameters ().size ());
569- if (tag >= processorParamCount)
587+ if (tag == getVST3BypassParameterID (*processor))
570588 return plainValue;
571589
572- if (auto parameter = processor->getParameters ()[ static_cast <int > (tag)] )
590+ if (auto parameter = processor->getParameterByHostID ( static_cast <uint32 > (tag)) )
573591 return parameter->convertToNormalizedValue (plainValue);
574592
575593 return plainValue;
@@ -580,11 +598,10 @@ class AudioPluginControllerVST3
580598 if (processor == nullptr )
581599 return 0.0 ;
582600
583- const auto processorParamCount = static_cast <Vst::ParamID> (processor->getParameters ().size ());
584- if (tag >= processorParamCount)
601+ if (tag == getVST3BypassParameterID (*processor))
585602 return Vst::EditController::getParamNormalized (tag);
586603
587- if (auto parameter = processor->getParameters ()[ static_cast <int > (tag)] )
604+ if (auto parameter = processor->getParameterByHostID ( static_cast <uint32 > (tag)) )
588605 return parameter->getNormalizedValue ();
589606
590607 return 0.0 ;
@@ -595,11 +612,10 @@ class AudioPluginControllerVST3
595612 if (processor == nullptr )
596613 return kInternalError ;
597614
598- const auto processorParamCount = static_cast <Vst::ParamID> (processor->getParameters ().size ());
599- if (tag >= processorParamCount)
615+ if (tag == getVST3BypassParameterID (*processor))
600616 return Vst::EditController::setParamNormalized (tag, value);
601617
602- if (auto parameter = processor->getParameters ()[ static_cast <int > (tag)] )
618+ if (auto parameter = processor->getParameterByHostID ( static_cast <uint32 > (tag)) )
603619 {
604620 parameter->setNormalizedValue (static_cast <float > (value));
605621 Vst::EditController::setParamNormalized (tag, value);
@@ -616,7 +632,8 @@ class AudioPluginControllerVST3
616632 if (processor == nullptr )
617633 return kInternalError ;
618634
619- if (oldParamID < static_cast <Vst::ParamID> (parameters.getParameterCount ()))
635+ if (processor->getParameterByHostID (static_cast <uint32> (oldParamID)) != nullptr
636+ || oldParamID == getVST3BypassParameterID (*processor))
620637 {
621638 newParamID = oldParamID;
622639 return kResultOk ;
@@ -635,10 +652,10 @@ class AudioPluginControllerVST3
635652 if (processor == nullptr )
636653 return kResultFalse ;
637654
638- const auto numParams = static_cast <int32> ( processor->getParameters (). size () );
639- if (midiControllerNumber < numParams )
655+ const auto parameters = processor->getParameters ();
656+ if (midiControllerNumber < static_cast <int32> (parameters. size ()) )
640657 {
641- id = static_cast <Vst::ParamID > (midiControllerNumber);
658+ id = getVST3ParameterID (parameters[ static_cast <int > (midiControllerNumber)] );
642659 return kResultOk ;
643660 }
644661
@@ -815,13 +832,13 @@ class AudioPluginControllerVST3
815832
816833 parameters.addParameter (
817834 reinterpret_cast <const Vst::TChar*> (parameter->getName ().toUTF16 ().getAddress ()),
818- nullptr , // units
819- 0 , // step count
820- parameter->getNormalizedValue (), // normalized value
821- Vst::ParameterInfo::kCanAutomate , // flags
822- static_cast < int > (parameterIndex), // tag
823- Vst::kRootUnitId , // unit
824- nullptr ); // short title
835+ nullptr , // units
836+ 0 , // step count
837+ parameter->getNormalizedValue (), // normalized value
838+ Vst::ParameterInfo::kCanAutomate , // flags
839+ getVST3ParameterID (parameter), // tag
840+ Vst::kRootUnitId , // unit
841+ nullptr ); // short title
825842
826843 parameter->addListener (this );
827844 listenedParameters.push_back (parameter);
@@ -834,7 +851,7 @@ class AudioPluginControllerVST3
834851 1 , // step count 1 = toggle
835852 0 , // default: not bypassed
836853 Vst::ParameterInfo::kCanAutomate | Vst::ParameterInfo::kIsBypass ,
837- static_cast <Vst::ParamID> ( processor-> getParameters (). size () ),
854+ getVST3BypassParameterID (* processor),
838855 Vst::kRootUnitId ,
839856 nullptr );
840857 }
@@ -852,7 +869,7 @@ class AudioPluginControllerVST3
852869 if (! isValidProcessorParameterIndex (indexInContainer))
853870 return ;
854871
855- const auto tag = static_cast <Vst::ParamID> (indexInContainer );
872+ const auto tag = getVST3ParameterID (parameter );
856873 const auto normalizedValue = static_cast <Vst::ParamValue> (parameter->getNormalizedValue ());
857874
858875 Vst::EditController::setParamNormalized (tag, normalizedValue);
@@ -862,13 +879,13 @@ class AudioPluginControllerVST3
862879 void parameterGestureBegin (const AudioParameter::Ptr&, int indexInContainer) override
863880 {
864881 if (isValidProcessorParameterIndex (indexInContainer))
865- Vst::EditController::beginEdit (static_cast <Vst::ParamID> ( indexInContainer));
882+ Vst::EditController::beginEdit (getVST3ParameterID (processor-> getParameters ()[ indexInContainer] ));
866883 }
867884
868885 void parameterGestureEnd (const AudioParameter::Ptr&, int indexInContainer) override
869886 {
870887 if (isValidProcessorParameterIndex (indexInContainer))
871- Vst::EditController::endEdit (static_cast <Vst::ParamID> ( indexInContainer));
888+ Vst::EditController::endEdit (getVST3ParameterID (processor-> getParameters ()[ indexInContainer] ));
872889 }
873890
874891 bool isValidProcessorParameterIndex (int indexInContainer) const
@@ -1119,7 +1136,7 @@ class AudioPluginProcessorVST3 : public Vst::AudioEffect
11191136 if (data.inputParameterChanges )
11201137 {
11211138 const auto parameters = processor->getParameters ();
1122- const auto bypassTag = static_cast <Vst::ParamID> (parameters. size () );
1139+ const auto bypassTag = getVST3BypassParameterID (*processor );
11231140
11241141 const int32 numParams = data.inputParameterChanges ->getParameterCount ();
11251142 for (int32 i = 0 ; i < numParams; ++i)
@@ -1144,17 +1161,21 @@ class AudioPluginProcessorVST3 : public Vst::AudioEffect
11441161 isBypassed = bypassed;
11451162 }
11461163 }
1147- else if (tag < static_cast <Vst::ParamID> (parameters. size ()))
1164+ else
11481165 {
1149- if (parameters[static_cast <int > (tag)]->isPerformingChangeGesture ())
1166+ const auto parameterIndex = processor->getParameterIndexByHostID (static_cast <uint32> (tag));
1167+ if (! isPositiveAndBelow (parameterIndex, static_cast <int > (parameters.size ())))
1168+ continue ;
1169+
1170+ if (parameters[parameterIndex]->isPerformingChangeGesture ())
11501171 continue ;
11511172
11521173 for (int32 p = 0 ; p < numPoints; ++p)
11531174 {
11541175 int32 sampleOffset;
11551176 Vst::ParamValue value;
11561177 if (queue->getPoint (p, sampleOffset, value) == kResultOk )
1157- paramChangeBuffer.addChange (static_cast < int > (tag) , static_cast <float > (value), sampleOffset);
1178+ paramChangeBuffer.addChange (parameterIndex , static_cast <float > (value), sampleOffset);
11581179 }
11591180 }
11601181 }
0 commit comments