Skip to content

Commit cb90564

Browse files
committed
More nice stuff
1 parent 2a0a45e commit cb90564

11 files changed

Lines changed: 348 additions & 80 deletions

modules/yup_audio_plugin_client/au/yup_audio_plugin_client_AU.mm

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ void Cleanup() override
187187

188188
//==============================================================================
189189

190+
OSStatus GetParameterList(AudioUnitScope inScope,
191+
AudioUnitParameterID* outParameterList,
192+
UInt32& outNumParameters) override
193+
{
194+
if (inScope != kAudioUnitScope_Global || processor == nullptr)
195+
{
196+
outNumParameters = 0;
197+
return kAudioUnitErr_InvalidParameter;
198+
}
199+
200+
const auto parameters = processor->getParameters();
201+
202+
if (outParameterList != nullptr)
203+
{
204+
for (size_t i = 0; i < parameters.size(); ++i)
205+
outParameterList[i] = static_cast<AudioUnitParameterID>(parameters[i]->getHostParameterID());
206+
}
207+
208+
outNumParameters = static_cast<UInt32>(parameters.size());
209+
return noErr;
210+
}
211+
190212
OSStatus GetParameterInfo(AudioUnitScope inScope,
191213
AudioUnitParameterID inParameterID,
192214
AudioUnitParameterInfo& outParameterInfo) override
@@ -195,10 +217,11 @@ OSStatus GetParameterInfo(AudioUnitScope inScope,
195217
return kAudioUnitErr_InvalidParameter;
196218

197219
const auto parameters = processor->getParameters();
198-
if (inParameterID >= static_cast<AudioUnitParameterID>(parameters.size()))
220+
const auto parameterIndex = processor->getParameterIndexByHostID(static_cast<uint32>(inParameterID));
221+
if (! isPositiveAndBelow(parameterIndex, static_cast<int>(parameters.size())))
199222
return kAudioUnitErr_InvalidParameter;
200223

201-
const auto& param = parameters[static_cast<int>(inParameterID)];
224+
const auto& param = parameters[parameterIndex];
202225

203226
outParameterInfo.flags = kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritable | kAudioUnitParameterFlag_HasCFNameString;
204227

@@ -223,10 +246,11 @@ OSStatus GetParameter(AudioUnitParameterID inID,
223246
return kAudioUnitErr_InvalidParameter;
224247

225248
const auto parameters = processor->getParameters();
226-
if (inID >= static_cast<AudioUnitParameterID>(parameters.size()))
249+
const auto parameterIndex = processor->getParameterIndexByHostID(static_cast<uint32>(inID));
250+
if (! isPositiveAndBelow(parameterIndex, static_cast<int>(parameters.size())))
227251
return kAudioUnitErr_InvalidParameter;
228252

229-
outValue = static_cast<AudioUnitParameterValue>(parameters[static_cast<int>(inID)]->getValue());
253+
outValue = static_cast<AudioUnitParameterValue>(parameters[parameterIndex]->getValue());
230254
return noErr;
231255
}
232256

@@ -240,10 +264,11 @@ OSStatus SetParameter(AudioUnitParameterID inID,
240264
return kAudioUnitErr_InvalidParameter;
241265

242266
const auto parameters = processor->getParameters();
243-
if (inID >= static_cast<AudioUnitParameterID>(parameters.size()))
267+
const auto parameterIndex = processor->getParameterIndexByHostID(static_cast<uint32>(inID));
268+
if (! isPositiveAndBelow(parameterIndex, static_cast<int>(parameters.size())))
244269
return kAudioUnitErr_InvalidParameter;
245270

246-
parameters[static_cast<int>(inID)]->setValue(static_cast<float>(inValue));
271+
parameters[parameterIndex]->setValue(static_cast<float>(inValue));
247272
return noErr;
248273
}
249274

modules/yup_audio_plugin_client/clap/yup_audio_plugin_client_CLAP.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ void clapEventToParameterChange (const clap_event_header_t* event, AudioProcesso
110110

111111
const clap_event_param_value_t* paramEvent = reinterpret_cast<const clap_event_param_value_t*> (event);
112112

113+
auto parameterIndex = audioProcessor.getParameterIndexByHostID (paramEvent->param_id);
113114
auto parameters = audioProcessor.getParameters();
114-
115-
auto parameterIndex = static_cast<int> (paramEvent->param_id);
116115
if (! isPositiveAndBelow (parameterIndex, static_cast<int> (parameters.size())))
117116
return;
118117

@@ -498,7 +497,7 @@ AudioPluginProcessorCLAP::AudioPluginProcessorCLAP (const clap_host_t* host)
498497
if (event->type == CLAP_EVENT_PARAM_VALUE)
499498
{
500499
const auto* paramEvent = reinterpret_cast<const clap_event_param_value_t*> (event);
501-
const auto paramIndex = static_cast<int> (paramEvent->param_id);
500+
const auto paramIndex = audioProcessor.getParameterIndexByHostID (paramEvent->param_id);
502501

503502
if (isPositiveAndBelow (paramIndex, static_cast<int> (audioProcessor.getParameters().size())))
504503
{
@@ -635,7 +634,7 @@ bool AudioPluginProcessorCLAP::initialise()
635634

636635
auto& parameter = parameters[index];
637636

638-
information->id = index;
637+
information->id = parameter->getHostParameterID();
639638
information->cookie = parameter.get();
640639
information->flags = CLAP_PARAM_IS_AUTOMATABLE | CLAP_PARAM_IS_MODULATABLE | CLAP_PARAM_IS_MODULATABLE_PER_NOTE_ID;
641640
information->min_value = parameter->getMinimumValue();
@@ -651,10 +650,11 @@ bool AudioPluginProcessorCLAP::initialise()
651650
auto wrapper = getWrapper (plugin);
652651
auto parameters = wrapper->audioProcessor->getParameters();
653652

654-
if (parameterId >= static_cast<uint32_t> (parameters.size()))
653+
const auto parameterIndex = wrapper->audioProcessor->getParameterIndexByHostID (parameterId);
654+
if (! isPositiveAndBelow (parameterIndex, static_cast<int> (parameters.size())))
655655
return false;
656656

657-
*value = parameters[parameterId]->getValue();
657+
*value = parameters[parameterIndex]->getValue();
658658

659659
return true;
660660
};
@@ -664,10 +664,11 @@ bool AudioPluginProcessorCLAP::initialise()
664664
auto wrapper = getWrapper (plugin);
665665
auto parameters = wrapper->audioProcessor->getParameters();
666666

667-
if (parameterId >= static_cast<uint32_t> (parameters.size()))
667+
const auto parameterIndex = wrapper->audioProcessor->getParameterIndexByHostID (parameterId);
668+
if (! isPositiveAndBelow (parameterIndex, static_cast<int> (parameters.size())))
668669
return false;
669670

670-
const auto text = parameters[parameterId]->convertToString (static_cast<float> (value));
671+
const auto text = parameters[parameterIndex]->convertToString (static_cast<float> (value));
671672
text.copyToUTF8 (display, size);
672673

673674
return true;
@@ -678,10 +679,11 @@ bool AudioPluginProcessorCLAP::initialise()
678679
auto wrapper = getWrapper (plugin);
679680
auto parameters = wrapper->audioProcessor->getParameters();
680681

681-
if (parameterId >= static_cast<uint32_t> (parameters.size()))
682+
const auto parameterIndex = wrapper->audioProcessor->getParameterIndexByHostID (parameterId);
683+
if (! isPositiveAndBelow (parameterIndex, static_cast<int> (parameters.size())))
682684
return false;
683685

684-
*value = static_cast<double> (parameters[parameterId]->convertFromString (display));
686+
*value = static_cast<double> (parameters[parameterIndex]->convertFromString (display));
685687

686688
return true;
687689
};

modules/yup_audio_plugin_client/vst3/yup_audio_plugin_client_VST3.cpp

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

100120
static 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

Comments
 (0)