From 38c80ac01ce41954a4f9ca644fe6be4a4d5f20bf Mon Sep 17 00:00:00 2001 From: anjaldoshi Date: Thu, 16 Jan 2025 17:07:12 -0800 Subject: [PATCH] Fix SelectedChannelsParameter initialization and channel count handling --- Source/Processors/Parameter/Parameter.cpp | 44 ++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/Source/Processors/Parameter/Parameter.cpp b/Source/Processors/Parameter/Parameter.cpp index 3ba73ed16..850b427a4 100755 --- a/Source/Processors/Parameter/Parameter.cpp +++ b/Source/Processors/Parameter/Parameter.cpp @@ -698,19 +698,6 @@ SelectedChannelsParameter::SelectedChannelsParameter (ParameterOwner* owner, maxSelectableChannels (maxSelectableChannels_), channelCount (0) { - if (defaultValue_.size() == 0 && maxSelectableChannels != std::numeric_limits::max()) - { - //Set default selected to the first maxSelectableChannels channels - Array values; - for (int i = 0; i < maxSelectableChannels; i++) - values.add (i); - - currentValue = values; - } - else - { - currentValue = defaultValue_; - } } void SelectedChannelsParameter::setNextValue (var newValue_, bool undoable) @@ -865,18 +852,35 @@ Array SelectedChannelsParameter::parseSelectedString (const String& input) void SelectedChannelsParameter::setChannelCount (int newCount) { - if (newCount > 0 && channelCount > newCount) + if (newCount > 0) { Array values; - for (int i = 0; i < currentValue.getArray()->size(); i++) + + // If the new count is less than the current count, remove any channels that are out of bounds + if (channelCount > newCount) { - if ((int) currentValue[i] < newCount) + for (int i = 0; i < currentValue.getArray()->size(); i++) { - values.add (currentValue[i]); + if ((int) currentValue[i] < newCount) + { + values.add (currentValue[i]); + } } + + currentValue = values; } + else if (channelCount == 0) // If the current count is 0, set the selected channels to the first maxSelectableChannels channels + { + for (int i = 0; i < maxSelectableChannels; i++) + { + if (i < newCount) + { + values.add (i); + } + } - currentValue = values; + currentValue = values; + } } channelCount = newCount; @@ -1218,7 +1222,7 @@ void PathParameter::setNextValue (var newValue_, bool undoable) { newValue = newValue_; } - + if (! undoable) { getOwner()->parameterChangeRequest (this); @@ -1228,7 +1232,7 @@ void PathParameter::setNextValue (var newValue_, bool undoable) { getOwner()->handleLinkedParameterChange (this, newValue); } - else + else { ChangeValue* action = new Parameter::ChangeValue (getKey(), newValue);