From 10a567fc4a08a9500d34436f331a6cd0a7572630 Mon Sep 17 00:00:00 2001
From: Septen <gammerxpower@gmail.com>
Date: Tue, 22 Mar 2016 20:46:36 +0300
Subject: [PATCH] ChannelSelector:removed listener. Changed channelChanged()
 signature.

---
 .../SpikeDetector/SpikeDetectorEditor.cpp     |  6 ++---
 .../SpikeDetector/SpikeDetectorEditor.h       |  2 +-
 Source/Plugins/CAR/CAREditor.cpp              |  3 +--
 Source/Plugins/CAR/CAREditor.h                |  6 +----
 .../ChannelMappingEditor.cpp                  | 12 ++++-----
 .../ChannelMappingNode/ChannelMappingEditor.h |  2 +-
 Source/Plugins/FilterNode/FilterEditor.cpp    |  8 +++---
 Source/Plugins/FilterNode/FilterEditor.h      |  2 +-
 .../Plugins/SpikeSorter/SpikeSorterEditor.cpp | 27 ++++++++++---------
 .../Plugins/SpikeSorter/SpikeSorterEditor.h   |  2 +-
 .../DataThreads/RhythmNode/RHD2000Editor.cpp  |  7 +++--
 .../DataThreads/RhythmNode/RHD2000Editor.h    |  2 +-
 Source/Processors/Editors/ChannelSelector.cpp |  9 +++----
 Source/Processors/Editors/ChannelSelector.h   | 12 ---------
 Source/Processors/Editors/GenericEditor.cpp   |  2 +-
 Source/Processors/Editors/GenericEditor.h     |  2 +-
 16 files changed, 42 insertions(+), 62 deletions(-)

diff --git a/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp b/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp
index 34723c468..50100748a 100644
--- a/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp
+++ b/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp
@@ -383,7 +383,7 @@ void SpikeDetectorEditor::buttonEvent(Button* button)
 
 }
 
-void SpikeDetectorEditor::channelChanged(int chan)
+void SpikeDetectorEditor::channelChanged (int channel, bool /*newState*/)
 {
 
     if (electrodeEditorButtons[0]->getToggleState()) // editing is active
@@ -394,13 +394,13 @@ void SpikeDetectorEditor::channelChanged(int chan)
         {
             if (electrodeButtons[i]->getToggleState())
             {
-                electrodeButtons[i]->setChannelNum(chan);
+                electrodeButtons[i]->setChannelNum (channel);
                 electrodeButtons[i]->repaint();
 
                 SpikeDetector* processor = (SpikeDetector*) getProcessor();
                 processor->setChannel(electrodeList->getSelectedItemIndex(),
                                       i,
-                                      chan-1);
+                                      channel - 1);
             }
         }
     }
diff --git a/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h b/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h
index 086129d38..07162cd77 100644
--- a/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h
+++ b/Source/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h
@@ -58,7 +58,7 @@ public:
     void comboBoxChanged(ComboBox* comboBox);
     void sliderEvent(Slider* slider);
 
-    void channelChanged(int chan);
+    void channelChanged (int channel, bool newState) override;
 
     bool addElectrode(int nChans, int electrodeID = 0);
     void removeElectrode(int index);
diff --git a/Source/Plugins/CAR/CAREditor.cpp b/Source/Plugins/CAR/CAREditor.cpp
index 59c240254..8de479043 100644
--- a/Source/Plugins/CAR/CAREditor.cpp
+++ b/Source/Plugins/CAR/CAREditor.cpp
@@ -68,7 +68,6 @@ CAREditor::CAREditor (GenericProcessor* parentProcessor, bool useDefaultParamete
     addAndMakeVisible (m_gainSlider);
 
     channelSelector->paramButtonsToggledByDefault (false);
-    channelSelector->addListener (this);
 
     setDesiredWidth (280);
 }
@@ -126,7 +125,7 @@ void CAREditor::buttonClicked (Button* buttonThatWasClicked)
 }
 
 
-void CAREditor::channelSelectionChanged (int channel, bool newState)
+void CAREditor::channelChanged (int channel, bool newState)
 {
     auto processor = static_cast<CAR*> (getProcessor());
     if (m_currentChannelsView == REFERENCE_CHANNELS)
diff --git a/Source/Plugins/CAR/CAREditor.h b/Source/Plugins/CAR/CAREditor.h
index 5b66ff135..f17ca1c0a 100644
--- a/Source/Plugins/CAR/CAREditor.h
+++ b/Source/Plugins/CAR/CAREditor.h
@@ -35,7 +35,6 @@ class ParameterSlider;
    @see CAR
 */
 class CAREditor : public GenericEditor
-                , private ChannelSelector::Listener
 {
 public:
     CAREditor (GenericProcessor* parentProcessor, bool useDefaultParameterEditors);
@@ -49,14 +48,11 @@ public:
     // ==========================================================
     void buttonClicked (Button* buttonThatWasClicked) override;
 
-    // ChannelSelector::Listener methods
-    // =========================================================
-    void channelSelectionChanged (int channel, bool newState) override;
-
     // GenericEditor methods
     // =========================================================
     /** This methods is called when any sliders that we are listen for change their values */
     void sliderEvent (Slider* sliderWhichValueHasChanged) override;
+    void channelChanged (int channel, bool newState) override;
 
 
 private:
diff --git a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp
index ac4fcbc04..9835bb378 100644
--- a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp
+++ b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp
@@ -612,14 +612,14 @@ void ChannelMappingEditor::setChannelReference(ElectrodeButton* button)
 
 }
 
-void ChannelMappingEditor::channelChanged(int chan)
+void ChannelMappingEditor::channelChanged (int channel, bool /*newState*/)
 {
-    if (!reorderActive)
+    if (! reorderActive)
     {
-        setConfigured(true);
-        getProcessor()->setCurrentChannel(chan-1);
-        getProcessor()->setParameter(2,selectedReference);
-        referenceChannels.set(selectedReference,chan-1);
+        setConfigured (true);
+        getProcessor()->setCurrentChannel (channel - 1);
+        getProcessor()->setParameter (2, selectedReference);
+        referenceChannels.set (selectedReference, channel - 1);
     }
 }
 
diff --git a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h
index be25bf7c6..e2b2408b4 100644
--- a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h
+++ b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h
@@ -55,7 +55,7 @@ public:
     void saveCustomParameters(XmlElement* xml);
     void loadCustomParameters(XmlElement* xml);
 
-    void channelChanged(int chan);
+    void channelChanged (int channel, bool newState) override;
 
     void mouseDrag(const MouseEvent& e);
 
diff --git a/Source/Plugins/FilterNode/FilterEditor.cpp b/Source/Plugins/FilterNode/FilterEditor.cpp
index 29a777f86..4983f530c 100644
--- a/Source/Plugins/FilterNode/FilterEditor.cpp
+++ b/Source/Plugins/FilterNode/FilterEditor.cpp
@@ -162,13 +162,13 @@ void FilterEditor::labelTextChanged(Label* label)
 
 }
 
-void FilterEditor::channelChanged(int chan)
+void FilterEditor::channelChanged (int channel, bool /*newState*/)
 {
     FilterNode* fn = (FilterNode*) getProcessor();
 
-    highCutValue->setText(String(fn->getHighCutValueForChannel(chan)), dontSendNotification);
-    lowCutValue->setText(String(fn->getLowCutValueForChannel(chan)), dontSendNotification);
-    applyFilterOnChan->setToggleState(fn->getBypassStatusForChannel(chan), dontSendNotification);
+    highCutValue->setText (String (fn->getHighCutValueForChannel (channel)), dontSendNotification);
+    lowCutValue->setText  (String (fn->getLowCutValueForChannel  (channel)), dontSendNotification);
+    applyFilterOnChan->setToggleState (fn->getBypassStatusForChannel (channel), dontSendNotification);
 
 }
 
diff --git a/Source/Plugins/FilterNode/FilterEditor.h b/Source/Plugins/FilterNode/FilterEditor.h
index 2ab56711c..79f5df095 100644
--- a/Source/Plugins/FilterNode/FilterEditor.h
+++ b/Source/Plugins/FilterNode/FilterEditor.h
@@ -52,7 +52,7 @@ public:
 
     void setDefaults(double lowCut, double highCut);
 
-    void channelChanged(int chan);
+    void channelChanged (int chan, bool newState);
 
 private:
 
diff --git a/Source/Plugins/SpikeSorter/SpikeSorterEditor.cpp b/Source/Plugins/SpikeSorter/SpikeSorterEditor.cpp
index 9bd835626..bf4bff7e8 100644
--- a/Source/Plugins/SpikeSorter/SpikeSorterEditor.cpp
+++ b/Source/Plugins/SpikeSorter/SpikeSorterEditor.cpp
@@ -494,42 +494,43 @@ void SpikeSorterEditor::setThresholdValue(int channel, double threshold)
     repaint();
 }
 
-void SpikeSorterEditor::channelChanged(int chan)
+void SpikeSorterEditor::channelChanged (int channel, bool newState)
 {
     //std::cout << "New channel: " << chan << std::endl;
-    if (chan <=0)
+    if (channel <= 0)
         return;
 
-    for (int i = 0; i < electrodeButtons.size(); i++)
+    const int numElectrodeButtons = electrodeButtons.size();
+    for (int i = 0; i < numElectrodeButtons; ++i)
     {
         if (electrodeButtons[i]->getToggleState())
         {
-            electrodeButtons[i]->setChannelNum(chan);
+            electrodeButtons[i]->setChannelNum (channel);
             electrodeButtons[i]->repaint();
+
             Array<int> a;
-            a.add(chan-1);
-            channelSelector->setActiveChannels(a);
+            a.add (channel - 1);
+            channelSelector->setActiveChannels (a);
+
             SpikeSorter* processor = (SpikeSorter*) getProcessor();
             processor->setChannel(electrodeList->getSelectedItemIndex(),
                                   i,
-                                  chan-1);
+                                  channel - 1);
 
             // if DAC is selected, update the mapping.
-            int dacchannel = dacCombo->getSelectedId()-2;
+            int dacchannel = dacCombo->getSelectedId() - 2;
             if (dacchannel >=0)
             {
-                processor->assignDACtoChannel(dacchannel, chan-1);
+                processor->assignDACtoChannel (dacchannel, channel - 1);
             }
             if (processor->getAutoDacAssignmentStatus())
             {
-                processor->assignDACtoChannel(0,chan-1);
-                processor->assignDACtoChannel(1,chan-1);
+                processor->assignDACtoChannel (0, channel - 1);
+                processor->assignDACtoChannel (1, channel - 1);
                 break;
             }
-
         }
     }
-
 }
 
 int SpikeSorterEditor::getSelectedElectrode()
diff --git a/Source/Plugins/SpikeSorter/SpikeSorterEditor.h b/Source/Plugins/SpikeSorter/SpikeSorterEditor.h
index 08c51458a..b0213feb0 100644
--- a/Source/Plugins/SpikeSorter/SpikeSorterEditor.h
+++ b/Source/Plugins/SpikeSorter/SpikeSorterEditor.h
@@ -54,7 +54,7 @@ public:
     void comboBoxChanged(ComboBox* comboBox);
     void sliderEvent(Slider* slider);
 
-    void channelChanged(int chan);
+    void channelChanged (int chan, bool newState) override;
 
     Visualizer* createNewCanvas();
     void checkSettings();
diff --git a/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp b/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp
index 5de38bd7a..ccf6b80ac 100644
--- a/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp
+++ b/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.cpp
@@ -867,16 +867,15 @@ void RHD2000Editor::buttonEvent(Button* button)
 
 }
 
-void RHD2000Editor::channelChanged(int chan)
+void RHD2000Editor::channelChanged (int channel, bool /*newState*/)
 {
     for (int i = 0; i < 2; i++)
     {
         if (electrodeButtons[i]->getToggleState())
         {
-            electrodeButtons[i]->setChannelNum(chan);
+            electrodeButtons[i]->setChannelNum (channel);
             electrodeButtons[i]->repaint();
-            board->setDACchannel(i, chan);
-
+            board->setDACchannel (i, channel);
         }
     }
 }
diff --git a/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.h b/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.h
index ab18fab07..2d784906d 100644
--- a/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.h
+++ b/Source/Processors/DataThreads/RhythmNode/RHD2000Editor.h
@@ -176,7 +176,7 @@ public:
     void startAcquisition();
     void stopAcquisition();
 
-    void channelChanged(int chan);
+    void channelChanged (int channel, bool newState) override;
 
     void saveCustomParameters(XmlElement* xml);
     void loadCustomParameters(XmlElement* xml);
diff --git a/Source/Processors/Editors/ChannelSelector.cpp b/Source/Processors/Editors/ChannelSelector.cpp
index 53c02c8fb..f9fca0de3 100755
--- a/Source/Processors/Editors/ChannelSelector.cpp
+++ b/Source/Processors/Editors/ChannelSelector.cpp
@@ -610,7 +610,7 @@ void ChannelSelector::buttonClicked(Button* button)
         {
             // send a message to parent
             GenericEditor* editor = (GenericEditor*) getParentComponent();
-            editor->channelChanged(-1);
+            editor->channelChanged (-1, false);
         }
     }
     else
@@ -668,18 +668,15 @@ void ChannelSelector::buttonClicked(Button* button)
         else // parameter type
         {
             GenericEditor* editor = (GenericEditor*) getParentComponent();
-            editor->channelChanged(b->getChannel()-1);
+            editor->channelChanged (b->getChannel() - 1, b->getToggleState());
 
             // do nothing
             if (radioStatus) // if radio buttons are active
             {
                 // send a message to parent
                 GenericEditor* editor = (GenericEditor*) getParentComponent();
-                editor->channelChanged(b->getChannel());
+                editor->channelChanged (b->getChannel(), b->getToggleState());
             }
-
-            m_listeners.call (&ChannelSelector::Listener::channelSelectionChanged,
-                              b->getChannel() - 1, b->getToggleState());
         }
     }
     refreshParameterColors();
diff --git a/Source/Processors/Editors/ChannelSelector.h b/Source/Processors/Editors/ChannelSelector.h
index 77b8af339..ad7bd3992 100644
--- a/Source/Processors/Editors/ChannelSelector.h
+++ b/Source/Processors/Editors/ChannelSelector.h
@@ -52,19 +52,9 @@ class PLUGIN_API ChannelSelector : public Component
                                  , public Timer
 {
 public:
-    class PLUGIN_API Listener
-    {
-    public:
-        virtual ~Listener() { }
-        virtual void channelSelectionChanged (int channel, bool newState) = 0;
-    };
-
     ChannelSelector(bool createButtons, Font& titleFont);
     ~ChannelSelector();
 
-    void addListener    (Listener* listener) { m_listeners.add (listener); }
-    void removeListener (Listener* listener) { m_listeners.remove (listener); }
-
     /** button callback */
     void buttonClicked(Button* button);
     
@@ -158,8 +148,6 @@ private:
      will be written to disk when the record button is pressed. */
     Array<ChannelSelectorButton*> recordButtons;
 
-    ListenerList<Listener> m_listeners;
-
     bool paramsToggled;
     bool paramsActive;
     bool recActive;
diff --git a/Source/Processors/Editors/GenericEditor.cpp b/Source/Processors/Editors/GenericEditor.cpp
index 96543c97a..c41d7caf4 100755
--- a/Source/Processors/Editors/GenericEditor.cpp
+++ b/Source/Processors/Editors/GenericEditor.cpp
@@ -1158,7 +1158,7 @@ void GenericEditor::updateSettings() {}
 
 void GenericEditor::updateVisualizer() {}
 
-void GenericEditor::channelChanged(int chan) {}
+void GenericEditor::channelChanged (int channel, bool newState) {}
 
 void GenericEditor::saveCustomParameters(XmlElement* xml) { }
 
diff --git a/Source/Processors/Editors/GenericEditor.h b/Source/Processors/Editors/GenericEditor.h
index b98f7103e..d6481971a 100755
--- a/Source/Processors/Editors/GenericEditor.h
+++ b/Source/Processors/Editors/GenericEditor.h
@@ -234,7 +234,7 @@ public:
     virtual void updateVisualizer();
 
     /** Used by SpikeDetectorEditor. */
-    virtual void channelChanged(int chan);
+    virtual void channelChanged (int channel, bool newState);
 
     /** Returns all selected channels from the ChannelSelector. */
     Array<int> getActiveChannels();
-- 
GitLab