From 10e5a30fabc641182c5271d3205d49b1e592f37b Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Sat, 15 Jun 2013 13:18:05 -0400
Subject: [PATCH] Names of SpikePlots now reflect actual electrode names

---
 .../Editors/SpikeDetectorEditor.cpp           |  2 ++
 Source/Processors/SpikeDetector.cpp           |  2 +-
 Source/Processors/SpikeDisplayNode.cpp        | 22 +++++++++++++++++++
 Source/Processors/SpikeDisplayNode.h          |  2 +-
 .../Visualization/SpikeDisplayCanvas.cpp      | 18 ++++++++-------
 .../Visualization/SpikeDisplayCanvas.h        |  7 ++++--
 6 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/Source/Processors/Editors/SpikeDetectorEditor.cpp b/Source/Processors/Editors/SpikeDetectorEditor.cpp
index 20bfdee9d..92ba61003 100755
--- a/Source/Processors/Editors/SpikeDetectorEditor.cpp
+++ b/Source/Processors/Editors/SpikeDetectorEditor.cpp
@@ -443,6 +443,8 @@ void SpikeDetectorEditor::labelTextChanged(Label* label)
         electrodeTypes->setText(currentText += "s");
     }
 
+    getEditorViewport()->makeEditorVisible(this, false, true);
+
 }
 
 void SpikeDetectorEditor::comboBoxChanged(ComboBox* comboBox)
diff --git a/Source/Processors/SpikeDetector.cpp b/Source/Processors/SpikeDetector.cpp
index 1a5025421..48d8c18b0 100755
--- a/Source/Processors/SpikeDetector.cpp
+++ b/Source/Processors/SpikeDetector.cpp
@@ -165,7 +165,7 @@ bool SpikeDetector::addElectrode(int nChans)
 
 float SpikeDetector::getDefaultThreshold()
 {
-    return 75.0f;
+    return 50.0f;
 }
 
 StringArray SpikeDetector::getElectrodeNames()
diff --git a/Source/Processors/SpikeDisplayNode.cpp b/Source/Processors/SpikeDisplayNode.cpp
index 161aed18f..ce983edeb 100755
--- a/Source/Processors/SpikeDisplayNode.cpp
+++ b/Source/Processors/SpikeDisplayNode.cpp
@@ -101,6 +101,28 @@ int SpikeDisplayNode::getNumberOfChannelsForElectrode(int elec)
     return 0;
 }
 
+String SpikeDisplayNode::getNameForElectrode(int elec)
+{
+
+    int electrodeIndex = -1;
+
+    for (int i = 0; i < eventChannels.size(); i++)
+    {
+        if (eventChannels[i]->eventType < 999)
+        {
+            electrodeIndex++;
+
+            if (electrodeIndex == elec)
+            {
+                std::cout << "Electrode " << elec << " has " << eventChannels[i]->eventType << " channels" << std::endl;
+                return eventChannels[i]->name;
+            }
+        }
+    }
+
+    return " ";
+}
+
 int SpikeDisplayNode::getNumElectrodes()
 {
     int nElectrodes = 0;
diff --git a/Source/Processors/SpikeDisplayNode.h b/Source/Processors/SpikeDisplayNode.h
index 66dcb85b4..9de5055d3 100755
--- a/Source/Processors/SpikeDisplayNode.h
+++ b/Source/Processors/SpikeDisplayNode.h
@@ -71,7 +71,7 @@ public:
         return eventBuffer;
     }
 
-
+    String getNameForElectrode(int i);
     int getNumberOfChannelsForElectrode(int i);
     int getNumElectrodes();
 
diff --git a/Source/Processors/Visualization/SpikeDisplayCanvas.cpp b/Source/Processors/Visualization/SpikeDisplayCanvas.cpp
index 6bc549931..022d0805c 100755
--- a/Source/Processors/Visualization/SpikeDisplayCanvas.cpp
+++ b/Source/Processors/Visualization/SpikeDisplayCanvas.cpp
@@ -79,7 +79,8 @@ void SpikeDisplayCanvas::update()
 
     for (int i = 0; i < nPlots; i++)
     {
-        spikeDisplay->addSpikePlot(processor->getNumberOfChannelsForElectrode(i), i);
+        spikeDisplay->addSpikePlot(processor->getNumberOfChannelsForElectrode(i), i,
+                                   processor->getNameForElectrode(i));
     }
 
     spikeDisplay->resized();
@@ -214,12 +215,12 @@ void SpikeDisplay::removePlots()
         
 }
 
-void SpikeDisplay::addSpikePlot(int numChannels, int electrodeNum)
+void SpikeDisplay::addSpikePlot(int numChannels, int electrodeNum, String name_)
 {
 
     std::cout << "Adding new spike plot." << std::endl;
 
-    SpikePlot* spikePlot = new SpikePlot(canvas, electrodeNum, 1000 + numChannels);
+    SpikePlot* spikePlot = new SpikePlot(canvas, electrodeNum, 1000 + numChannels, name_);
     spikePlots.add(spikePlot);
     addAndMakeVisible(spikePlot);
 }
@@ -348,9 +349,9 @@ void SpikeDisplay::plotSpike(const SpikeObject& spike, int electrodeNum)
 
 // ----------------------------------------------------------------
 
-SpikePlot::SpikePlot(SpikeDisplayCanvas* sdc, int elecNum, int p) :
+SpikePlot::SpikePlot(SpikeDisplayCanvas* sdc, int elecNum, int p, String name_) :
      canvas(sdc), isSelected(false), electrodeNumber(elecNum),  plotType(p),
-    limitsChanged(true)
+    limitsChanged(true), name(name_)
 
 {
 
@@ -422,7 +423,7 @@ void SpikePlot::paint(Graphics& g)
 
     g.setFont(font);
 
-    g.drawText(String(electrodeNumber+1),10,0,50,20,Justification::left,false);
+    g.drawText(name,10,0,200,20,Justification::left,false);
 
 }
 
@@ -430,6 +431,8 @@ void SpikePlot::processSpikeObject(const SpikeObject& s)
 {
     //std::cout<<"ElectrodePlot::processSpikeObject()"<<std::endl;
 
+    // first, check if it's above threshold
+
     for (int i = 0; i < nWaveAx; i++)
         wAxes[i]->updateSpikeData(s);
 
@@ -764,7 +767,6 @@ void WaveAxes::updateSpikeData(const SpikeObject& s)
     spikeBuffer.set(spikeIndex, newSpike);
 
     
-
 }
 
 void WaveAxes::clear()
@@ -844,7 +846,7 @@ void WaveAxes::mouseDrag(const MouseEvent& event)
 
         thresholdLevel = (0.5f - thresholdSliderPosition) * range;
 
-        std::cout << "Threshold = " << thresholdLevel << std::endl;
+        //std::cout << "Threshold = " << thresholdLevel << std::endl;
 
         repaint();
     }
diff --git a/Source/Processors/Visualization/SpikeDisplayCanvas.h b/Source/Processors/Visualization/SpikeDisplayCanvas.h
index 02ba77143..4facac441 100755
--- a/Source/Processors/Visualization/SpikeDisplayCanvas.h
+++ b/Source/Processors/Visualization/SpikeDisplayCanvas.h
@@ -122,7 +122,7 @@ public:
 
     void removePlots();
     void clear();
-    void addSpikePlot(int numChannels, int electrodeNum);
+    void addSpikePlot(int numChannels, int electrodeNum, String name);
 
     void paint(Graphics& g);
 
@@ -161,12 +161,14 @@ private:
 
   Class for drawing the waveforms and projections of incoming spikes.
 
+  Also responsible for saving spikes.
+
 */
 
 class SpikePlot : public Component, Button::Listener
 {
 public:
-    SpikePlot(SpikeDisplayCanvas*, int elecNum, int plotType);
+    SpikePlot(SpikeDisplayCanvas*, int elecNum, int plotType, String name_);
     virtual ~SpikePlot();
 
     void paint(Graphics& g);
@@ -215,6 +217,7 @@ private:
     void setLimitsOnAxes();
     void updateAxesPositions();
 
+    String name;
 
     Font font;
 
-- 
GitLab