From 7047bf8ef295074427acfa3c50905755532a4ef3 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Sat, 10 Mar 2012 15:18:26 -0500
Subject: [PATCH] Cleaned up OpenGLCanvas code

---
 Source/Main.cpp                               |  6 +-
 Source/MainWindow.cpp                         |  6 +-
 Source/Processors/AudioNode.h                 |  2 +
 Source/Processors/Editors/EventNodeEditor.cpp | 14 ++--
 Source/Processors/GenericProcessor.h          | 11 +--
 .../Visualization/LfpDisplayCanvas.cpp        |  3 +-
 .../Visualization/LfpDisplayCanvas.h          |  2 +-
 .../Processors/Visualization/OpenGLCanvas.cpp | 81 +++++++++----------
 .../Processors/Visualization/OpenGLCanvas.h   | 32 ++++----
 Source/UI/EditorViewport.cpp                  |  2 +-
 Source/UI/EditorViewport.h                    |  8 +-
 Source/UI/InfoLabel.cpp                       |  4 +-
 Source/UI/InfoLabel.h                         |  2 +-
 Source/UI/ProcessorList.cpp                   | 14 +---
 Source/UI/ProcessorList.h                     | 10 +--
 15 files changed, 80 insertions(+), 117 deletions(-)

diff --git a/Source/Main.cpp b/Source/Main.cpp
index f70d622a9..68b8d21ee 100644
--- a/Source/Main.cpp
+++ b/Source/Main.cpp
@@ -57,11 +57,7 @@ public:
         LookAndFeel::setDefaultLookAndFeel(customLookAndFeel);
     }
 
-    void shutdown()
-    {
-        mainWindow = 0;
-        customLookAndFeel = 0;
-    }
+    void shutdown() { }
 
     //==============================================================================
     void systemRequestedQuit()
diff --git a/Source/MainWindow.cpp b/Source/MainWindow.cpp
index d234bf003..31ed94a0a 100644
--- a/Source/MainWindow.cpp
+++ b/Source/MainWindow.cpp
@@ -31,7 +31,7 @@ MainWindow::MainWindow()
                       Colour(Colours::black),
                       DocumentWindow::allButtons)
 {
-    //centreWithSize (500, 400);
+
     setResizable (true,     // isResizable
                   false);   // useBottomCornerRisizer -- doesn't work very well
     
@@ -66,8 +66,8 @@ MainWindow::~MainWindow()
 
   audioComponent->disconnectProcessorGraph();
 
-   deleteAndZero(processorGraph);
-   deleteAndZero(audioComponent);
+  deleteAndZero(processorGraph);
+  deleteAndZero(audioComponent);
 
   setContentComponent (0);
   setMenuBar(0);
diff --git a/Source/Processors/AudioNode.h b/Source/Processors/AudioNode.h
index 6040c43d0..9e19c2eb9 100644
--- a/Source/Processors/AudioNode.h
+++ b/Source/Processors/AudioNode.h
@@ -56,6 +56,8 @@ public:
 
 	AudioProcessorEditor* createEditor();
 
+   // AudioEditor* getEditor() {return audioEditor;}
+
     ScopedPointer<AudioEditor> audioEditor;
 	
 private:
diff --git a/Source/Processors/Editors/EventNodeEditor.cpp b/Source/Processors/Editors/EventNodeEditor.cpp
index 11d68a5b5..103d56d9e 100644
--- a/Source/Processors/Editors/EventNodeEditor.cpp
+++ b/Source/Processors/Editors/EventNodeEditor.cpp
@@ -39,15 +39,15 @@ EventNodeEditor::EventNodeEditor (GenericProcessor* parentNode)
 
 	createRadioButtons(35, 65, 160, hzValues, "Event frequency");
 
-	for (int n = 0; n < getNumChildComponents(); n++)
-	{
-		Button* c = (Button*) getChildComponent(n);
+	// for (int n = 0; n < getNumChildComponents(); n++)
+	// {
+	// 	Button* c = (Button*) getChildComponent(n);
 
-		if (c->isVisible())
-			c->addListener(this);
+	// 	if (c->isVisible())
+	// 		c->addListener(this);
 
-		c->setVisible(true);
-	}
+	// 	c->setVisible(true);
+	// }
 
 }
 
diff --git a/Source/Processors/GenericProcessor.h b/Source/Processors/GenericProcessor.h
index 3889ee507..e59e3ca0f 100644
--- a/Source/Processors/GenericProcessor.h
+++ b/Source/Processors/GenericProcessor.h
@@ -109,8 +109,6 @@ public:
 						 MidiBuffer& /*buffer*/,
 						 int& /*nSamples*/) = 0;
 
-	
-
 	GenericProcessor* sourceNode;
 	GenericProcessor* destNode;
 
@@ -119,8 +117,6 @@ public:
 
 	float sampleRate;
 
-	//void sendMessage(const String& msg);
-
 	virtual float getSampleRate();
 	virtual void setSampleRate(float sr);
 	virtual float getDefaultSampleRate() {return 44100.0;}
@@ -193,12 +189,7 @@ public:
 
 	int currentChannel;
 
-
-	// Getting and setting:
-
-	GenericEditor* getEditor() {return editor;}
-	//void setEditor(GenericEditor* e) {editor = e;}
-
+	virtual GenericEditor* getEditor() {return editor;}
 	ScopedPointer<GenericEditor> editor;
 
 private:
diff --git a/Source/Processors/Visualization/LfpDisplayCanvas.cpp b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
index 809dbcc15..868371bfe 100644
--- a/Source/Processors/Visualization/LfpDisplayCanvas.cpp
+++ b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
@@ -343,7 +343,7 @@ int LfpDisplayCanvas::getTotalHeight()
 }
 
 
-void LfpDisplayCanvas::mouseDown(const MouseEvent& e) 
+void LfpDisplayCanvas::mouseDownInCanvas(const MouseEvent& e) 
 {
 
 	Point<int> pos = e.getPosition();
@@ -358,7 +358,6 @@ void LfpDisplayCanvas::mouseDown(const MouseEvent& e)
 		repaint();
 	}
 
-	mouseDownInCanvas(e);
 }
 
 // void LfpDisplayCanvas::mouseDrag(const MouseEvent& e) {mouseDragInCanvas(e);}
diff --git a/Source/Processors/Visualization/LfpDisplayCanvas.h b/Source/Processors/Visualization/LfpDisplayCanvas.h
index e12491196..f9350ee35 100644
--- a/Source/Processors/Visualization/LfpDisplayCanvas.h
+++ b/Source/Processors/Visualization/LfpDisplayCanvas.h
@@ -86,7 +86,7 @@ private:
 	int getTotalHeight();
 
 	// void resized();
-	 void mouseDown(const MouseEvent& e);
+	 void mouseDownInCanvas(const MouseEvent& e);
 	// void mouseDrag(const MouseEvent& e);
 	// void mouseMove(const MouseEvent& e);
 	// void mouseUp(const MouseEvent& e);
diff --git a/Source/Processors/Visualization/OpenGLCanvas.cpp b/Source/Processors/Visualization/OpenGLCanvas.cpp
index 4353220dc..17357d382 100644
--- a/Source/Processors/Visualization/OpenGLCanvas.cpp
+++ b/Source/Processors/Visualization/OpenGLCanvas.cpp
@@ -334,7 +334,7 @@ void OpenGLCanvas::drawRoundedRect(float x,
 
 }
 
-void OpenGLCanvas::mouseMoveInCanvas(const MouseEvent& e)
+void OpenGLCanvas::mouseMove(const MouseEvent& e)
 {
 	if (getTotalHeight() > getHeight()) {
 	Point<int> pos = e.getPosition();
@@ -344,9 +344,11 @@ void OpenGLCanvas::mouseMoveInCanvas(const MouseEvent& e)
 		showScrollTrack = true; showScrollBars();
 	}
 	}
+
+	mouseMoveInCanvas(e);
 }
 
-void OpenGLCanvas::mouseDownInCanvas(const MouseEvent& e)
+void OpenGLCanvas::mouseDown(const MouseEvent& e)
 {
 
 	if (getTotalHeight() > getHeight()) {
@@ -376,9 +378,11 @@ void OpenGLCanvas::mouseDownInCanvas(const MouseEvent& e)
 		showScrollBars();
 	}
 	}
+
+	mouseDownInCanvas(e);
 }
 
-void OpenGLCanvas::mouseDragInCanvas(const MouseEvent& e)
+void OpenGLCanvas::mouseDrag(const MouseEvent& e)
 {
 
 	if (getTotalHeight() > getHeight()) {
@@ -415,54 +419,48 @@ void OpenGLCanvas::mouseDragInCanvas(const MouseEvent& e)
 		} 
 	}
 	}
+
+	mouseDragInCanvas(e);
 }
 
-void OpenGLCanvas::mouseUpInCanvas(const MouseEvent& e)
+void OpenGLCanvas::mouseUp(const MouseEvent& e)
 {
 	scrollDiff = 0;
+
+	mouseUpInCanvas(e);
 }
 
-void OpenGLCanvas::mouseWheelMoveInCanvas(const MouseEvent&e,
+void OpenGLCanvas::mouseWheelMove(const MouseEvent&e,
                                       float wheelIncrementX, float wheelIncrementY)
 
 {
 	if (getTotalHeight() > getHeight()) {
-	if (wheelIncrementY > 0)
-	{
-		if (scrollPix + getHeight() < getTotalHeight())
+
+		if (wheelIncrementY > 0)
 		{
-			scrollPix += int(100.0f*wheelIncrementY);
-			if (scrollPix + getHeight() > getTotalHeight())
-				scrollPix = getTotalHeight() - getHeight();
-		}
-	} else if (wheelIncrementY < 0)
-	{
-		if (scrollPix > 0)
+			if (scrollPix + getHeight() < getTotalHeight())
+			{
+				scrollPix += int(100.0f*wheelIncrementY);
+				if (scrollPix + getHeight() > getTotalHeight())
+					scrollPix = getTotalHeight() - getHeight();
+			}
+		} else if (wheelIncrementY < 0)
 		{
-			scrollPix += int(100.0f*wheelIncrementY);
-			if (scrollPix < 0)
-				scrollPix = 0;
+			if (scrollPix > 0)
+			{
+				scrollPix += int(100.0f*wheelIncrementY);
+				if (scrollPix < 0)
+					scrollPix = 0;
+			}
 		}
-	}
 
-	repaint();
+		repaint();
 
-	showScrollBars();
+		showScrollBars();
 
 	}
 
-}
-
-void OpenGLCanvas::canvasWasResized()
-{
-	//glClear(GL_COLOR_BUFFER_BIT);
-
-	if (scrollPix + getHeight() > getTotalHeight() && getTotalHeight() > getHeight())
-		scrollPix = getTotalHeight() - getHeight();
-	else
-		scrollPix = 0;
-
-	showScrollBars();
+	mouseWheelMoveInCanvas(e, wheelIncrementX, wheelIncrementY);
 
 }
 
@@ -472,18 +470,15 @@ void OpenGLCanvas::timerCallback()
 }
 
 
-
-void OpenGLCanvas::mouseDown(const MouseEvent& e) 
+void OpenGLCanvas::resized()
 {
-	mouseDownInCanvas(e);
-}
 
-void OpenGLCanvas::mouseDrag(const MouseEvent& e) {mouseDragInCanvas(e);}
-void OpenGLCanvas::mouseMove(const MouseEvent& e) {mouseMoveInCanvas(e);}
-void OpenGLCanvas::mouseUp(const MouseEvent& e) 	{mouseUpInCanvas(e);}
-void OpenGLCanvas::mouseWheelMove(const MouseEvent& e, float a, float b) {mouseWheelMoveInCanvas(e,a,b);}
+	if (scrollPix + getHeight() > getTotalHeight() && getTotalHeight() > getHeight())
+		scrollPix = getTotalHeight() - getHeight();
+	else
+		scrollPix = 0;
+
+	showScrollBars();
 
-void OpenGLCanvas::resized()
-{
 	canvasWasResized();
 }
\ No newline at end of file
diff --git a/Source/Processors/Visualization/OpenGLCanvas.h b/Source/Processors/Visualization/OpenGLCanvas.h
index 3712b51d8..595e2dee1 100644
--- a/Source/Processors/Visualization/OpenGLCanvas.h
+++ b/Source/Processors/Visualization/OpenGLCanvas.h
@@ -40,24 +40,28 @@ public:
 
 	virtual void refreshState() {};
 
-	void mouseDownInCanvas(const MouseEvent& e);
-	void mouseDragInCanvas(const MouseEvent& e);
-	void mouseMoveInCanvas(const MouseEvent& e);
-	void mouseUpInCanvas(const MouseEvent& e);
-	void mouseWheelMoveInCanvas(const MouseEvent&, float, float);
-
-	virtual void resized();
-	virtual void mouseDown(const MouseEvent& e);
-	virtual void mouseDrag(const MouseEvent& e);
-	virtual void mouseMove(const MouseEvent& e);
-	virtual void mouseUp(const MouseEvent& e);
-	virtual void mouseWheelMove(const MouseEvent&, float, float);
+
+
+	void resized();
+	virtual void canvasWasResized() { }
+
+	void mouseDown(const MouseEvent& e);
+	void mouseDrag(const MouseEvent& e);
+	void mouseMove(const MouseEvent& e);
+	void mouseUp(const MouseEvent& e);
+	void mouseWheelMove(const MouseEvent&, float, float);
+
+	virtual void mouseDownInCanvas(const MouseEvent& e) {}
+	virtual void mouseDragInCanvas(const MouseEvent& e) {}
+	virtual void mouseMoveInCanvas(const MouseEvent& e) {}
+	virtual void mouseUpInCanvas(const MouseEvent& e) {}
+	virtual void mouseWheelMoveInCanvas(const MouseEvent&,
+									    float,
+									    float) {}
 
 	void startCallbacks();
 	void stopCallbacks();
 
-	void canvasWasResized();
-
 	int getScrollAmount() {return scrollPix;};
 	int getScrollBarWidth() {return scrollBarWidth;}
 	void drawScrollBars();
diff --git a/Source/UI/EditorViewport.cpp b/Source/UI/EditorViewport.cpp
index 8bdb0b2d3..2d89b1332 100644
--- a/Source/UI/EditorViewport.cpp
+++ b/Source/UI/EditorViewport.cpp
@@ -70,7 +70,7 @@ EditorViewport::EditorViewport()
 
 EditorViewport::~EditorViewport()
 {
-    deleteAndZero(signalChainManager);
+   // deleteAndZero(signalChainManager);
     deleteAllChildren();
 }
 
diff --git a/Source/UI/EditorViewport.h b/Source/UI/EditorViewport.h
index 0d547454a..669eee4a4 100644
--- a/Source/UI/EditorViewport.h
+++ b/Source/UI/EditorViewport.h
@@ -121,7 +121,7 @@ private:
     Array<GenericEditor*, CriticalSection> editorArray;
     Array<SignalChainTabButton*, CriticalSection> signalChainArray;
 
-    SignalChainManager* signalChainManager;
+    ScopedPointer<SignalChainManager> signalChainManager;
 
     Font font;
     Image sourceDropImage;
@@ -152,8 +152,6 @@ private:
 
     void resized();
 
-    //bool signalChainNeedsSource;
-
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EditorViewport);  
 
 };
@@ -175,8 +173,6 @@ public:
 
     int offset;
 
-
-
 private:
 
     GenericEditor* firstEditor;
@@ -187,7 +183,6 @@ private:
 
     void clicked();
     
-
     enum actions {ADD, MOVE, REMOVE, ACTIVATE};
     
     int num;
@@ -195,7 +190,6 @@ private:
 
     Font buttonFont;
 
-
 };
 
 #endif  // __EDITORVIEWPORT_H_80260F3F__
diff --git a/Source/UI/InfoLabel.cpp b/Source/UI/InfoLabel.cpp
index 9aa437b50..2da53f277 100644
--- a/Source/UI/InfoLabel.cpp
+++ b/Source/UI/InfoLabel.cpp
@@ -105,13 +105,11 @@ void InfoLabel::drawLabel()
 
 }
 
-void InfoLabel::resized() 
+void InfoLabel::canvasWasResized() 
 {
 
 	layout.SetLineLength(getWidth()-45);
 
-	canvasWasResized();
-
 }
 
 int InfoLabel::getTotalHeight() 
diff --git a/Source/UI/InfoLabel.h b/Source/UI/InfoLabel.h
index f3fd77740..4967de8fc 100644
--- a/Source/UI/InfoLabel.h
+++ b/Source/UI/InfoLabel.h
@@ -54,7 +54,7 @@ private:
 
 	int getTotalHeight();
 
-	void resized();
+	void canvasWasResized();
 
 	FTSimpleLayout layout;	
 	String infoString;
diff --git a/Source/UI/ProcessorList.cpp b/Source/UI/ProcessorList.cpp
index 6c2af6c89..a7d3a5dd1 100644
--- a/Source/UI/ProcessorList.cpp
+++ b/Source/UI/ProcessorList.cpp
@@ -322,9 +322,7 @@ int ProcessorList::getTotalHeight()
  	return totalHeight;
 }
 
-void ProcessorList::resized() {canvasWasResized();}
-
-void ProcessorList::mouseDown(const MouseEvent& e) 
+void ProcessorList::mouseDownInCanvas(const MouseEvent& e) 
 {
 
 	isDragging = false;
@@ -370,12 +368,10 @@ void ProcessorList::mouseDown(const MouseEvent& e)
 		}
 	}
 
-	mouseDownInCanvas(e);
-
 	repaint();
 }
 
-void ProcessorList::mouseDrag(const MouseEvent& e) 
+void ProcessorList::mouseDragInCanvas(const MouseEvent& e) 
 {
 
 	if (e.getMouseDownX() < getWidth()-getScrollBarWidth() && !(isDragging))
@@ -427,14 +423,8 @@ void ProcessorList::mouseDrag(const MouseEvent& e)
 		}
 	}
 
-	mouseDragInCanvas(e);
 }
 
-void ProcessorList::mouseMove(const MouseEvent& e) {mouseMoveInCanvas(e);}
-void ProcessorList::mouseUp(const MouseEvent& e) 	{mouseUpInCanvas(e);}
-void ProcessorList::mouseWheelMove(const MouseEvent& e, float a, float b) {mouseWheelMoveInCanvas(e,a,b);}
-
-
 ProcessorListItem::ProcessorListItem(const String& name_) : name(name_), open(true), selected(false)
 {
 }
diff --git a/Source/UI/ProcessorList.h b/Source/UI/ProcessorList.h
index 57150369a..88ca2f6b2 100644
--- a/Source/UI/ProcessorList.h
+++ b/Source/UI/ProcessorList.h
@@ -78,16 +78,10 @@ private:
 	int totalHeight, itemHeight, subItemHeight;
 	int xBuffer, yBuffer;
 
-	//UIComponent* UI;
-
 	String category;
 	
-	void resized();
-	void mouseDown(const MouseEvent& e);
-	void mouseDrag(const MouseEvent& e);
-	void mouseMove(const MouseEvent& e);
-	void mouseUp(const MouseEvent& e);
-	void mouseWheelMove(const MouseEvent&, float, float);
+	void mouseDownInCanvas(const MouseEvent& e);
+	void mouseDragInCanvas(const MouseEvent& e);
 
 	ProcessorListItem* baseItem;
 
-- 
GitLab