From bd3a42179de66b99063739f32c110106be5e9aec Mon Sep 17 00:00:00 2001
From: aacuevas <aacuelo@teleco.upv.es>
Date: Thu, 25 Jul 2013 02:45:06 +0200
Subject: [PATCH] Fixed  TTL events causing Spike Viewer glitch SpikeDetector
 used the channel count as eventType on the event channel list, which was used
 by SpikeDisplayNode to draw the appropiate plot. However, eventType should be
 used to differentiate different event types, as TTL vs. SPIKE. As result,
 SpikeDisplayNode tried to plot TTL event channels as 3 electrode plots. Fixed
 by adding an offset (SPIKE_BASE_CODE=100) to the channel count at eventType
 to avoid said collision. However, we perhaps should try to find a more
 elegant solution.

---
 Source/Processors/SpikeDetector.cpp           | 2 +-
 Source/Processors/SpikeDisplayNode.cpp        | 8 ++++----
 Source/Processors/Visualization/SpikeObject.h | 2 ++
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/Source/Processors/SpikeDetector.cpp b/Source/Processors/SpikeDetector.cpp
index ea6b2b43d..3d9c9baac 100755
--- a/Source/Processors/SpikeDetector.cpp
+++ b/Source/Processors/SpikeDetector.cpp
@@ -90,7 +90,7 @@ void SpikeDetector::updateSettings()
 
         Channel* ch = new Channel(this, i);
         ch->isEventChannel = true;
-        ch->eventType = electrodes[i]->numChannels;
+        ch->eventType = SPIKE_BASE_CODE + electrodes[i]->numChannels;
         ch->name = electrodes[i]->name;
 
         eventChannels.add(ch);
diff --git a/Source/Processors/SpikeDisplayNode.cpp b/Source/Processors/SpikeDisplayNode.cpp
index 90d6b6552..3d87ec695 100755
--- a/Source/Processors/SpikeDisplayNode.cpp
+++ b/Source/Processors/SpikeDisplayNode.cpp
@@ -86,14 +86,14 @@ int SpikeDisplayNode::getNumberOfChannelsForElectrode(int elec)
 
     for (int i = 0; i < eventChannels.size(); i++)
     {
-        if (eventChannels[i]->eventType < 999)
+		if ((eventChannels[i]->eventType < 999) && (eventChannels[i]->eventType > SPIKE_BASE_CODE))
         {
             electrodeIndex++;
 
             if (electrodeIndex == elec)
             {
                 std::cout << "Electrode " << elec << " has " << eventChannels[i]->eventType << " channels" << std::endl;
-                return eventChannels[i]->eventType;
+                return (eventChannels[i]->eventType - SPIKE_BASE_CODE);
             }
         }
     }
@@ -108,7 +108,7 @@ String SpikeDisplayNode::getNameForElectrode(int elec)
 
     for (int i = 0; i < eventChannels.size(); i++)
     {
-        if (eventChannels[i]->eventType < 999)
+        if ((eventChannels[i]->eventType < 999) && (eventChannels[i]->eventType > SPIKE_BASE_CODE))
         {
             electrodeIndex++;
 
@@ -129,7 +129,7 @@ int SpikeDisplayNode::getNumElectrodes()
 
     for (int i = 0; i < eventChannels.size(); i++)
     {
-        if (eventChannels[i]->eventType < 999)
+        if ((eventChannels[i]->eventType < 999) && (eventChannels[i]->eventType > SPIKE_BASE_CODE))
         {
             nElectrodes++;
         }
diff --git a/Source/Processors/Visualization/SpikeObject.h b/Source/Processors/Visualization/SpikeObject.h
index 5a71b9e5b..a8bbad0ea 100755
--- a/Source/Processors/Visualization/SpikeObject.h
+++ b/Source/Processors/Visualization/SpikeObject.h
@@ -34,6 +34,8 @@
 #define SPIKE_EVENT_CODE 4;
 #define MAX_SPIKE_BUFFER_LEN 512 // the true max calculated from the spike values below is actually 507
 
+#define SPIKE_BASE_CODE 100
+
 /**
 
   Allows spikes to be transmitted between processors.
-- 
GitLab