Skip to content

Commit 7f586b3

Browse files
committed
Update change message and editor for SelectedChannelsParameter
1 parent 05f58df commit 7f586b3

2 files changed

Lines changed: 44 additions & 36 deletions

File tree

Source/Processors/Parameter/Parameter.cpp

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -773,40 +773,27 @@ String SelectedChannelsParameter::getValueAsString()
773773

774774
String SelectedChannelsParameter::getChangeDescription()
775775
{
776-
//compare previousValue to currentValue and return a string describing the change
777-
Array<int> prev;
778-
for (int i = 0; i < previousValue.getArray()->size(); i++)
779-
{
780-
prev.add (previousValue[i]);
781-
}
782-
783-
Array<int> curr;
784-
for (int i = 0; i < currentValue.getArray()->size(); i++)
785-
{
786-
curr.add (currentValue[i]);
787-
}
788-
789-
//find how many values different from prev to curr
790-
int diff = 0;
791-
792-
for (int i = 0; i < curr.size(); i++)
793-
{
794-
if (! prev.contains (curr[i]))
795-
diff++;
796-
}
797-
798-
for (int i = 0; i < prev.size(); i++)
799-
{
800-
if (! curr.contains (prev[i]))
801-
diff++;
776+
// Check number of selected channels:
777+
int selectedChannelCount = currentValue.getArray()->size();
778+
779+
// If more than four channels, state the number selected
780+
if (selectedChannelCount > 4)
781+
return "selected " + String(selectedChannelCount) + " channels";
782+
else // Get string describing selected channels
783+
{
784+
String selectedChannelsString;
785+
786+
for (int i = 0; i < selectedChannelCount; i++)
787+
{
788+
selectedChannelsString += String(int(currentValue[i]) + 1);
789+
790+
if (i < selectedChannelCount - 1)
791+
selectedChannelsString += ", ";
792+
}
793+
794+
return selectedChannelsString;
802795
}
803-
804-
if (diff == 0) //should never get here
805-
return "No change";
806-
else if (diff == 1)
807-
return "changed 1";
808-
else
809-
return "changed selection";
796+
810797
}
811798

812799
void SelectedChannelsParameter::toXml (XmlElement* xml)

Source/Processors/Parameter/ParameterEditor.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ SelectedChannelsParameterEditor::SelectedChannelsParameterEditor (Parameter* par
582582
button->setBounds (0, 0, rowWidthPixels / 2, rowHeightPixels);
583583

584584
editor = (Component*) button.get();
585+
586+
updateView();
585587
}
586588

587589
Array<int> SelectedChannelsParameterEditor::getSelectedChannels()
@@ -648,12 +650,31 @@ void SelectedChannelsParameterEditor::updateView()
648650
else
649651
{
650652
button->setEnabled (true);
653+
651654
int numChannels = int (((SelectedChannelsParameter*) param)->getChannelStates().size());
652-
int selected = 0;
655+
656+
int numSelected = 0;
653657
for (auto chan : ((SelectedChannelsParameter*) param)->getChannelStates())
654658
if (chan)
655-
selected++;
656-
button->setButtonText (String (selected) + "/" + String (numChannels));
659+
numSelected++;
660+
661+
if (numSelected > 4)
662+
{
663+
button->setButtonText (String (numSelected) + "/" + String (numChannels));
664+
} else {
665+
String selectedChannelsString;
666+
667+
for (int i = 0; i < numSelected; i++)
668+
{
669+
selectedChannelsString += String(int(param->currentValue[i]) + 1);
670+
671+
if (i < numSelected - 1)
672+
selectedChannelsString += ", ";
673+
}
674+
button->setButtonText (selectedChannelsString);
675+
}
676+
677+
657678
}
658679
}
659680

0 commit comments

Comments
 (0)