andrewm@0: /* andrewm@0: TouchKeys: multi-touch musical keyboard control software andrewm@0: Copyright (c) 2013 Andrew McPherson andrewm@0: andrewm@0: This program is free software: you can redistribute it and/or modify andrewm@0: it under the terms of the GNU General Public License as published by andrewm@0: the Free Software Foundation, either version 3 of the License, or andrewm@0: (at your option) any later version. andrewm@0: andrewm@0: This program is distributed in the hope that it will be useful, andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@0: GNU General Public License for more details. andrewm@0: andrewm@0: You should have received a copy of the GNU General Public License andrewm@0: along with this program. If not, see . andrewm@0: andrewm@0: ===================================================================== andrewm@0: andrewm@0: RawSensorDisplay.h: simple graph for showing raw TouchKeys sensor values andrewm@0: */ andrewm@0: andrewm@0: #ifndef __touchkeys__RawSensorDisplay__ andrewm@0: #define __touchkeys__RawSensorDisplay__ andrewm@0: andrewm@0: #include andrewm@0: #include andrewm@0: //#include andrewm@0: #include "../JuceLibraryCode/JuceHeader.h" andrewm@0: #include "../TouchKeys/PianoTypes.h" andrewm@0: #include "../Utility/Node.h" andrewm@0: #include "OpenGLDisplayBase.h" andrewm@0: andrewm@0: andrewm@0: // This class uses OpenGL to draw a bar graph of key sensor data, andrewm@0: // for the purpose of debugging and validating individual keys andrewm@0: andrewm@0: class RawSensorDisplay : public OpenGLDisplayBase { andrewm@0: // Internal data structures and constants andrewm@0: private: andrewm@0: // Display margins andrewm@0: static const float kDisplaySideMargin; andrewm@0: static const float kDisplayBottomMargin; andrewm@0: static const float kDisplayTopMargin; andrewm@0: andrewm@0: // Size of bar graphs and spacing andrewm@0: static const float kDisplayBarWidth; andrewm@0: static const float kDisplayBarSpacing; andrewm@0: static const float kDisplayBarHeight; andrewm@0: andrewm@0: typedef struct { andrewm@0: float x; andrewm@0: float y; andrewm@0: } Point; andrewm@0: andrewm@0: public: andrewm@0: RawSensorDisplay(); andrewm@0: andrewm@27: // Set canvas for triggering rendering; andrewm@27: void setCanvas(OpenGLJuceCanvas *canvas) { canvas_ = canvas; } andrewm@27: void tellCanvasToRepaint(); andrewm@27: andrewm@0: // Setup methods for display size and keyboard range andrewm@0: void setDisplaySize(float width, float height); andrewm@0: float aspectRatio() { return totalDisplayWidth_ / totalDisplayHeight_; } andrewm@0: andrewm@0: // Drawing methods andrewm@0: void render(); andrewm@0: andrewm@0: // Interaction methods andrewm@0: void mouseDown(float x, float y); andrewm@0: void mouseDragged(float x, float y); andrewm@0: void mouseUp(float x, float y); andrewm@0: void rightMouseDown(float x, float y); andrewm@0: void rightMouseDragged(float x, float y); andrewm@0: void rightMouseUp(float x, float y); andrewm@0: andrewm@0: // Data update methods andrewm@0: void setDisplayData(std::vector const& values); andrewm@0: andrewm@0: private: andrewm@0: // Convert mathematical XY coordinate space to drawing positions andrewm@0: float graphToDisplayX(float x); andrewm@0: float graphToDisplayY(float y); andrewm@0: andrewm@0: void refreshViewport(); andrewm@0: andrewm@0: // Conversion from internal coordinate space to external pixel values and back andrewm@0: Point screenToInternal(Point& inPoint); andrewm@0: Point internalToScreen(Point& inPoint); andrewm@0: andrewm@0: andrewm@0: private: andrewm@27: OpenGLJuceCanvas *canvas_; // Reference to object which handles rendering andrewm@27: andrewm@0: float displayPixelWidth_, displayPixelHeight_; // Pixel resolution of the surrounding window andrewm@0: float totalDisplayWidth_, totalDisplayHeight_; // Size of the internal view (centered around origin) andrewm@0: float yMin_, yMax_; // Range of the graph axes andrewm@0: andrewm@0: CriticalSection displayMutex_; // Synchronize access between data and display threads andrewm@0: std::vector displayValues_; // Values to display as a bar graph andrewm@0: }; andrewm@0: andrewm@0: #endif /* defined(__touchkeys__RawSensorDisplay__) */