Skip to content

Commit

Permalink
Update PopupChannelSelector to include channel names and title
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Oct 18, 2024
1 parent 0ee18c9 commit 17f102f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 8 deletions.
36 changes: 33 additions & 3 deletions Source/Processors/Editors/PopupChannelSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ RangeEditor::RangeEditor (const String& name, const Font& font) : TextEditor (na
setFont (font);
}

PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelector::Listener* listener_, std::vector<bool> channelStates)
PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelector::Listener* listener_, std::vector<bool> channelStates, Array<String> channelNames, const String& title)
: PopupComponent (parent), listener (listener_), nChannels (int (channelStates.size())), mouseDragged (false), startDragCoords (0, 0), shiftKeyDown (false), firstButtonSelectedState (false), isDragging (false), editable (true), maxSelectable (-1)
{
int nColumns;
Expand Down Expand Up @@ -153,6 +153,15 @@ PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelec
buttonColour = Colours::azure;

auto contentComponent = std::make_unique<Component>();

if (channelNames.isEmpty())
{
for (int i = 0; i < nChannels; i++)
{
channelNames.add ("CH" + String (i + 1));
}
}

for (int i = 0; i < nRows; i++)
{
for (int j = 0; j < nColumns; j++)
Expand All @@ -162,6 +171,7 @@ PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelec
auto* button = new ChannelButton (nColumns * i + j, this);
button->setBounds (width / nColumns * j, height / nRows * i, buttonSize, buttonSize);
button->setToggleState (channelStates[nColumns * i + j], NotificationType::dontSendNotification);
button->setTooltip (channelNames[nColumns * i + j]);
button->addListener (this);
contentComponent->addAndMakeVisible (button);

Expand Down Expand Up @@ -228,13 +238,33 @@ PopupChannelSelector::PopupChannelSelector (Component* parent, PopupChannelSelec
viewport->setSize (width, height + (editable ? buttonSize : 0));
}

setSize (viewport->getWidth(), viewport->getHeight());
if (title.isNotEmpty())
{
titleLabel = std::make_unique<Label> ("Title", title);
titleLabel->setBounds (0, 0, viewport->getWidth(), 20);
titleLabel->setJustificationType (Justification::centredLeft);
titleLabel->setFont (FontOptions ("Inter", "Regular", 16.0f));
addAndMakeVisible (titleLabel.get());

setSize (viewport->getWidth(), viewport->getHeight() + 20);
}
else
{
setSize (viewport->getWidth(), viewport->getHeight());
}

setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
}

void PopupChannelSelector::resized()
{
viewport->setBounds (getLocalBounds());
viewport->setBounds (0, getHeight() - viewport->getHeight(), getWidth(), viewport->getHeight());
}

void PopupChannelSelector::paint (Graphics& g)
{
g.setColour (findColour (ThemeColours::widgetBackground));
g.fillRoundedRectangle (getLocalBounds().toFloat().reduced (1.0f), 5.0f);
}

void PopupChannelSelector::updatePopup()
Expand Down
6 changes: 5 additions & 1 deletion Source/Processors/Editors/PopupChannelSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class PLUGIN_API PopupChannelSelector : public PopupComponent,
};

/** Constructor */
PopupChannelSelector (Component* parent, Listener* listener, std::vector<bool> channelStates);
PopupChannelSelector (Component* parent, Listener* listener, std::vector<bool> channelStates, Array<String> channelNames = Array<String>(), const String& title = String());

/** Destructor */
~PopupChannelSelector() {}
Expand Down Expand Up @@ -168,6 +168,8 @@ class PLUGIN_API PopupChannelSelector : public PopupComponent,

void resized() override;

void paint (Graphics& g) override;

private:
std::unique_ptr<Viewport> viewport;
Listener* listener;
Expand All @@ -180,6 +182,8 @@ class PLUGIN_API PopupChannelSelector : public PopupComponent,
void updateRangeString();
void parseRangeString();

std::unique_ptr<Label> titleLabel;

OwnedArray<SelectButton> selectButtons;
std::unique_ptr<RangeEditor> rangeEditor;

Expand Down
28 changes: 26 additions & 2 deletions Source/Processors/Parameter/ParameterEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,19 @@ void SelectedChannelsParameterEditor::buttonClicked (Button* button_)

SelectedChannelsParameter* p = (SelectedChannelsParameter*) param;

auto* channelSelector = new PopupChannelSelector (button.get(), this, p->getChannelStates());
Array<String> channelNames;
String popupTitle;

if (p->getOwner()->getType() == ParameterOwner::DATASTREAM)
{
DataStream* stream = (DataStream*) p->getOwner();
popupTitle = String (stream->getSourceNodeId()) + " - " + stream->getName();

for (auto channel : stream->getContinuousChannels())
channelNames.add (channel->getName());
}

auto* channelSelector = new PopupChannelSelector (button.get(), this, p->getChannelStates(), channelNames, popupTitle);

channelSelector->setChannelButtonColour (param->getColour());

Expand Down Expand Up @@ -700,7 +712,19 @@ void MaskChannelsParameterEditor::buttonClicked (Button* button_)

std::vector<bool> channelStates = p->getChannelStates();

auto* channelSelector = new PopupChannelSelector (button.get(), this, channelStates);
Array<String> channelNames;
String popupTitle;

if (p->getOwner()->getType() == ParameterOwner::DATASTREAM)
{
DataStream* stream = (DataStream*) p->getOwner();
popupTitle = String (stream->getSourceNodeId()) + " - " + stream->getName();

for (auto channel : stream->getContinuousChannels())
channelNames.add (channel->getName());
}

auto* channelSelector = new PopupChannelSelector (button.get(), this, channelStates, channelNames, popupTitle);

channelSelector->setChannelButtonColour (param->getColour());

Expand Down
16 changes: 14 additions & 2 deletions Source/Processors/RecordNode/RecordNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void SyncAccuracyMonitor::paint (Graphics& g)
if (isSynchronized)
{
g.setColour (findColour (ThemeColours::defaultText));
g.drawText (String (std::abs(metric), 3) + " ms", 0, 0, 55, 20, Justification::centred);
g.drawText (String (std::abs (metric), 3) + " ms", 0, 0, 55, 20, Justification::centred);
}

else
Expand Down Expand Up @@ -278,9 +278,21 @@ void RecordChannelsParameterEditor::buttonClicked (Button* label)

MaskChannelsParameter* p = (MaskChannelsParameter*) param;

Array<String> channelNames;
String popupTitle;

if (p->getOwner()->getType() == ParameterOwner::DATASTREAM)
{
DataStream* stream = (DataStream*) p->getOwner();
popupTitle = String (stream->getSourceNodeId()) + " - " + stream->getName();

for (auto channel : stream->getContinuousChannels())
channelNames.add (channel->getName());
}

std::vector<bool> channelStates = p->getChannelStates();

auto* channelSelector = new PopupChannelSelector (label, this, channelStates);
auto* channelSelector = new PopupChannelSelector (label, this, channelStates, channelNames, popupTitle);

channelSelector->setChannelButtonColour (param->getColour());

Expand Down

0 comments on commit 17f102f

Please sign in to comment.