From 49ae303f35b885d4df5b25bd118f4f799dd10901 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Mon, 20 Feb 2012 13:00:29 -0500
Subject: [PATCH] Fixed bug in LfpDisplayCanvas

When an LfpDisplayCanvas was hidden for more than a few seconds, it would lose
track of the displayBufferIndex, causing it to pause for a few seconds when
it comes back into view. Now, the DataViewport sends a "refresh" reminder
to the canvas, to remind it to update its buffer indices in order to
display new data.
---
 .../Visualization/LfpDisplayCanvas.cpp        | 12 +++++++++++
 .../Visualization/LfpDisplayCanvas.h          |  2 ++
 .../Processors/Visualization/OpenGLCanvas.cpp |  2 +-
 .../Processors/Visualization/OpenGLCanvas.h   |  2 ++
 Source/UI/DataViewport.cpp                    | 20 +++++++------------
 Source/UI/DataViewport.h                      |  2 ++
 Source/UI/FilterList.cpp                      | 15 ++++++--------
 Source/UI/FilterList.h                        |  1 -
 8 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/Source/Processors/Visualization/LfpDisplayCanvas.cpp b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
index b5ba47979..3f9bc8cc7 100644
--- a/Source/Processors/Visualization/LfpDisplayCanvas.cpp
+++ b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
@@ -105,6 +105,14 @@ void LfpDisplayCanvas::setParameter(int param, float val)
 	
 }
 
+void LfpDisplayCanvas::refreshState()
+{
+	// called when the component's tab becomes visible again
+	displayBufferIndex = processor->getDisplayBufferIndex();
+	screenBufferIndex = 0;
+
+}
+
 void LfpDisplayCanvas::updateScreenBuffer()
 {
 	// copy new samples from the displayBuffer into the screenBuffer
@@ -112,6 +120,8 @@ void LfpDisplayCanvas::updateScreenBuffer()
 
 	int index = processor->getDisplayBufferIndex();
 
+	//std::cout << index << screenBufferIndex << std::endl;
+
 	int nSamples = index - displayBufferIndex;
 
 	if (nSamples < 0)
@@ -218,6 +228,8 @@ void LfpDisplayCanvas::renderOpenGL()
 		}	
 	}
 	drawScrollBars();
+
+	std::cout << "Render." << std::endl;
 }
 
 void LfpDisplayCanvas::drawWaveform(int chan, bool isSelected)
diff --git a/Source/Processors/Visualization/LfpDisplayCanvas.h b/Source/Processors/Visualization/LfpDisplayCanvas.h
index 8d5c1a639..7f577077e 100644
--- a/Source/Processors/Visualization/LfpDisplayCanvas.h
+++ b/Source/Processors/Visualization/LfpDisplayCanvas.h
@@ -43,6 +43,8 @@ public:
 	void beginAnimation();
 	void endAnimation();
 
+	void refreshState();
+
 	void updateNumInputs(int);
 	void updateSampleRate(float);
 
diff --git a/Source/Processors/Visualization/OpenGLCanvas.cpp b/Source/Processors/Visualization/OpenGLCanvas.cpp
index 3807f3b25..246cf6ccb 100644
--- a/Source/Processors/Visualization/OpenGLCanvas.cpp
+++ b/Source/Processors/Visualization/OpenGLCanvas.cpp
@@ -28,7 +28,7 @@
 OpenGLCanvas::OpenGLCanvas() : //OpenGLComponent(OpenGLComponent::OpenGLType::openGLDefault, true),
 	scrollPix(0), scrollTime(0), scrollDiff(0), originalScrollPix(0), 
 	scrollBarWidth(15), PI(3.1415926), showScrollTrack(true),
-	animationIsActive(false), refreshMs(60)
+	animationIsActive(false), refreshMs(200)
 {
 
 	loadFonts();
diff --git a/Source/Processors/Visualization/OpenGLCanvas.h b/Source/Processors/Visualization/OpenGLCanvas.h
index 7500a79b2..3712b51d8 100644
--- a/Source/Processors/Visualization/OpenGLCanvas.h
+++ b/Source/Processors/Visualization/OpenGLCanvas.h
@@ -38,6 +38,8 @@ public:
 	void setUp2DCanvas();
 	void activateAntiAliasing();
 
+	virtual void refreshState() {};
+
 	void mouseDownInCanvas(const MouseEvent& e);
 	void mouseDragInCanvas(const MouseEvent& e);
 	void mouseMoveInCanvas(const MouseEvent& e);
diff --git a/Source/UI/DataViewport.cpp b/Source/UI/DataViewport.cpp
index 608669a04..565b74dd4 100644
--- a/Source/UI/DataViewport.cpp
+++ b/Source/UI/DataViewport.cpp
@@ -22,6 +22,7 @@
 */
 
 #include "DataViewport.h"
+#include "../Processors/Visualization/OpenGLCanvas.h"
 
 DataViewport::DataViewport() :
 	TabbedComponent(TabbedButtonBar::TabsAtRight),
@@ -67,9 +68,6 @@ DataViewport::~DataViewport()
      int newIndex = tabArray->indexOf(index);
      tabArray->remove(newIndex);
 
-     //Component* p = getTabContentComponent(newIndex);
-     //removeChildComponent(p);
-
      getTabbedButtonBar().removeTab(newIndex);
 
      if (tabArray->size() == 0)
@@ -77,6 +75,12 @@ DataViewport::~DataViewport()
 
  }
 
+ void DataViewport::currentTabChanged(int newIndex, const String& newTabName)
+ {
+     OpenGLCanvas* canvas = (OpenGLCanvas*) getTabContentComponent(newIndex);
+     canvas->refreshState();
+ }
+
 void DataViewport::paint(Graphics& g)
 {
 
@@ -97,16 +101,6 @@ void DataViewport::paint(Graphics& g)
         r -= tabDepth;
 
 	g.setColour(Colour(58,58,58));
-
-  //   Colour c1 (103, 116, 140);
-  ///  Colour c2 (120, 130, 155);
-
-    // g.setGradientFill (ColourGradient (c1,
-    //                                  0.0f, 0.0f,
-    //                                  c2,
-    //                                  0.0f, (float) getHeight(),
-    //                                  false));
-
     g.fillRoundedRectangle(x,y,r-x,b-y,5.0f);
 	g.fillRect(x,y,r-20,b-y);
     g.fillRect(x,20,r-x,b-20);
diff --git a/Source/UI/DataViewport.h b/Source/UI/DataViewport.h
index f56a6934d..21ac3ba9c 100644
--- a/Source/UI/DataViewport.h
+++ b/Source/UI/DataViewport.h
@@ -48,6 +48,8 @@ public:
     int addTabToDataViewport(String tabName, Component* componentToAdd);
     void removeTab(int);
 
+    void currentTabChanged(int newIndex, const String& newTabName);
+
 private:
 
 	Array<int>* tabArray;
diff --git a/Source/UI/FilterList.cpp b/Source/UI/FilterList.cpp
index 8ab4415e4..c5a27adc1 100644
--- a/Source/UI/FilterList.cpp
+++ b/Source/UI/FilterList.cpp
@@ -28,17 +28,14 @@
 #include "UIComponent.h"
 
 
-FilterList::FilterList() : isDragging(false)
+FilterList::FilterList() : isDragging(false),
+                           itemHeight(32),
+                           subItemHeight(22),
+                           totalHeight(800),
+                           xBuffer(1),
+                           yBuffer(1)
 {
 
-	//setBounds(0,0,225,500);
-
-	itemHeight = 32;
-	subItemHeight = 22;
-	totalHeight = 800;
-	xBuffer = 1;
-	yBuffer = 1;
-
 	FilterListItem* sources = new FilterListItem("Sources");
 	sources->addSubItem(new FilterListItem("Intan Demo Board"));
 	sources->addSubItem(new FilterListItem("Signal Generator"));
diff --git a/Source/UI/FilterList.h b/Source/UI/FilterList.h
index ed0b642fd..bed15e48b 100644
--- a/Source/UI/FilterList.h
+++ b/Source/UI/FilterList.h
@@ -77,7 +77,6 @@ private:
 	int totalHeight, itemHeight, subItemHeight;
 	int xBuffer, yBuffer;
 
-
 	UIComponent* UI;
 
 	String category;
-- 
GitLab