annotate Source/Display/RawSensorDisplay.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents eef567a60146
children
rev   line source
andrewm@0 1 /*
andrewm@0 2 TouchKeys: multi-touch musical keyboard control software
andrewm@0 3 Copyright (c) 2013 Andrew McPherson
andrewm@0 4
andrewm@0 5 This program is free software: you can redistribute it and/or modify
andrewm@0 6 it under the terms of the GNU General Public License as published by
andrewm@0 7 the Free Software Foundation, either version 3 of the License, or
andrewm@0 8 (at your option) any later version.
andrewm@0 9
andrewm@0 10 This program is distributed in the hope that it will be useful,
andrewm@0 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0 13 GNU General Public License for more details.
andrewm@0 14
andrewm@0 15 You should have received a copy of the GNU General Public License
andrewm@0 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
andrewm@0 17
andrewm@0 18 =====================================================================
andrewm@0 19
andrewm@0 20 RawSensorDisplay.h: simple graph for showing raw TouchKeys sensor values
andrewm@0 21 */
andrewm@0 22
andrewm@0 23 #ifndef __touchkeys__RawSensorDisplay__
andrewm@0 24 #define __touchkeys__RawSensorDisplay__
andrewm@0 25
andrewm@0 26 #include <iostream>
andrewm@0 27 #include <vector>
andrewm@0 28 //#include <OpenGL/gl.h>
andrewm@0 29 #include "../JuceLibraryCode/JuceHeader.h"
andrewm@0 30 #include "../TouchKeys/PianoTypes.h"
andrewm@0 31 #include "../Utility/Node.h"
andrewm@0 32 #include "OpenGLDisplayBase.h"
andrewm@0 33
andrewm@0 34
andrewm@0 35 // This class uses OpenGL to draw a bar graph of key sensor data,
andrewm@0 36 // for the purpose of debugging and validating individual keys
andrewm@0 37
andrewm@0 38 class RawSensorDisplay : public OpenGLDisplayBase {
andrewm@0 39 // Internal data structures and constants
andrewm@0 40 private:
andrewm@0 41 // Display margins
andrewm@0 42 static const float kDisplaySideMargin;
andrewm@0 43 static const float kDisplayBottomMargin;
andrewm@0 44 static const float kDisplayTopMargin;
andrewm@0 45
andrewm@0 46 // Size of bar graphs and spacing
andrewm@0 47 static const float kDisplayBarWidth;
andrewm@0 48 static const float kDisplayBarSpacing;
andrewm@0 49 static const float kDisplayBarHeight;
andrewm@0 50
andrewm@0 51 typedef struct {
andrewm@0 52 float x;
andrewm@0 53 float y;
andrewm@0 54 } Point;
andrewm@0 55
andrewm@0 56 public:
andrewm@0 57 RawSensorDisplay();
andrewm@0 58
andrewm@27 59 // Set canvas for triggering rendering;
andrewm@27 60 void setCanvas(OpenGLJuceCanvas *canvas) { canvas_ = canvas; }
andrewm@27 61 void tellCanvasToRepaint();
andrewm@27 62
andrewm@0 63 // Setup methods for display size and keyboard range
andrewm@0 64 void setDisplaySize(float width, float height);
andrewm@0 65 float aspectRatio() { return totalDisplayWidth_ / totalDisplayHeight_; }
andrewm@0 66
andrewm@0 67 // Drawing methods
andrewm@0 68 void render();
andrewm@0 69
andrewm@0 70 // Interaction methods
andrewm@0 71 void mouseDown(float x, float y);
andrewm@0 72 void mouseDragged(float x, float y);
andrewm@0 73 void mouseUp(float x, float y);
andrewm@0 74 void rightMouseDown(float x, float y);
andrewm@0 75 void rightMouseDragged(float x, float y);
andrewm@0 76 void rightMouseUp(float x, float y);
andrewm@0 77
andrewm@0 78 // Data update methods
andrewm@0 79 void setDisplayData(std::vector<int> const& values);
andrewm@0 80
andrewm@0 81 private:
andrewm@0 82 // Convert mathematical XY coordinate space to drawing positions
andrewm@0 83 float graphToDisplayX(float x);
andrewm@0 84 float graphToDisplayY(float y);
andrewm@0 85
andrewm@0 86 void refreshViewport();
andrewm@0 87
andrewm@0 88 // Conversion from internal coordinate space to external pixel values and back
andrewm@0 89 Point screenToInternal(Point& inPoint);
andrewm@0 90 Point internalToScreen(Point& inPoint);
andrewm@0 91
andrewm@0 92
andrewm@0 93 private:
andrewm@27 94 OpenGLJuceCanvas *canvas_; // Reference to object which handles rendering
andrewm@27 95
andrewm@0 96 float displayPixelWidth_, displayPixelHeight_; // Pixel resolution of the surrounding window
andrewm@0 97 float totalDisplayWidth_, totalDisplayHeight_; // Size of the internal view (centered around origin)
andrewm@0 98 float yMin_, yMax_; // Range of the graph axes
andrewm@0 99
andrewm@0 100 CriticalSection displayMutex_; // Synchronize access between data and display threads
andrewm@0 101 std::vector<int> displayValues_; // Values to display as a bar graph
andrewm@0 102 };
andrewm@0 103
andrewm@0 104 #endif /* defined(__touchkeys__RawSensorDisplay__) */