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@0
|
59 // Setup methods for display size and keyboard range
|
andrewm@0
|
60 void setDisplaySize(float width, float height);
|
andrewm@0
|
61 float aspectRatio() { return totalDisplayWidth_ / totalDisplayHeight_; }
|
andrewm@0
|
62
|
andrewm@0
|
63 // Drawing methods
|
andrewm@0
|
64 bool needsRender() { return needsUpdate_; }
|
andrewm@0
|
65 void render();
|
andrewm@0
|
66
|
andrewm@0
|
67 // Interaction methods
|
andrewm@0
|
68 void mouseDown(float x, float y);
|
andrewm@0
|
69 void mouseDragged(float x, float y);
|
andrewm@0
|
70 void mouseUp(float x, float y);
|
andrewm@0
|
71 void rightMouseDown(float x, float y);
|
andrewm@0
|
72 void rightMouseDragged(float x, float y);
|
andrewm@0
|
73 void rightMouseUp(float x, float y);
|
andrewm@0
|
74
|
andrewm@0
|
75 // Data update methods
|
andrewm@0
|
76 void setDisplayData(std::vector<int> const& values);
|
andrewm@0
|
77
|
andrewm@0
|
78 private:
|
andrewm@0
|
79 // Convert mathematical XY coordinate space to drawing positions
|
andrewm@0
|
80 float graphToDisplayX(float x);
|
andrewm@0
|
81 float graphToDisplayY(float y);
|
andrewm@0
|
82
|
andrewm@0
|
83 void refreshViewport();
|
andrewm@0
|
84
|
andrewm@0
|
85 // Conversion from internal coordinate space to external pixel values and back
|
andrewm@0
|
86 Point screenToInternal(Point& inPoint);
|
andrewm@0
|
87 Point internalToScreen(Point& inPoint);
|
andrewm@0
|
88
|
andrewm@0
|
89
|
andrewm@0
|
90 private:
|
andrewm@0
|
91 float displayPixelWidth_, displayPixelHeight_; // Pixel resolution of the surrounding window
|
andrewm@0
|
92 float totalDisplayWidth_, totalDisplayHeight_; // Size of the internal view (centered around origin)
|
andrewm@0
|
93 float yMin_, yMax_; // Range of the graph axes
|
andrewm@0
|
94
|
andrewm@0
|
95 bool needsUpdate_; // Whether the keyboard should be redrawn
|
andrewm@0
|
96 CriticalSection displayMutex_; // Synchronize access between data and display threads
|
andrewm@0
|
97 std::vector<int> displayValues_; // Values to display as a bar graph
|
andrewm@0
|
98 };
|
andrewm@0
|
99
|
andrewm@0
|
100 #endif /* defined(__touchkeys__RawSensorDisplay__) */
|