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 KeyPositionGraphDisplay.h: implements a graph of key position over time
|
andrewm@0
|
21 for a specific key press, which is useful for analysis of continuous key
|
andrewm@0
|
22 position.
|
andrewm@0
|
23 */
|
andrewm@0
|
24
|
andrewm@0
|
25 #ifndef __touchkeys__KeyPositionGraphDisplay__
|
andrewm@0
|
26 #define __touchkeys__KeyPositionGraphDisplay__
|
andrewm@0
|
27
|
andrewm@0
|
28 #include <iostream>
|
andrewm@0
|
29 #include <vector>
|
andrewm@0
|
30 #include "../JuceLibraryCode/JuceHeader.h"
|
andrewm@0
|
31 #include "../TouchKeys/PianoTypes.h"
|
andrewm@0
|
32 #include "../Utility/Node.h"
|
andrewm@0
|
33 #include "OpenGLDisplayBase.h"
|
andrewm@0
|
34
|
andrewm@0
|
35
|
andrewm@0
|
36
|
andrewm@0
|
37 // This class uses OpenGL to handle drawing of a graph showing key position
|
andrewm@0
|
38 // over time, for debugging or analysis purposes.
|
andrewm@0
|
39
|
andrewm@0
|
40 class KeyPositionGraphDisplay : public OpenGLDisplayBase {
|
andrewm@0
|
41 // Internal data structures and constants
|
andrewm@0
|
42 private:
|
andrewm@0
|
43 // Display margins
|
andrewm@0
|
44 static const float kDisplaySideMargin;
|
andrewm@0
|
45 static const float kDisplayBottomMargin;
|
andrewm@0
|
46 static const float kDisplayTopMargin;
|
andrewm@0
|
47
|
andrewm@0
|
48 // Size of the graph area
|
andrewm@0
|
49 static const float kDisplayGraphWidth;
|
andrewm@0
|
50 static const float kDisplayGraphHeight;
|
andrewm@0
|
51
|
andrewm@0
|
52 typedef struct {
|
andrewm@0
|
53 float x;
|
andrewm@0
|
54 float y;
|
andrewm@0
|
55 } Point;
|
andrewm@0
|
56
|
andrewm@0
|
57 public:
|
andrewm@0
|
58 KeyPositionGraphDisplay();
|
andrewm@0
|
59
|
andrewm@0
|
60 // Setup methods for display size and keyboard range
|
andrewm@0
|
61 void setDisplaySize(float width, float height);
|
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 copyKeyDataFromBuffer(Node<key_position>& keyBuffer, const Node<key_position>::size_type startIndex,
|
andrewm@0
|
77 const Node<key_position>::size_type endIndex);
|
andrewm@0
|
78 void setKeyPressStart(key_position position, timestamp_type timestamp) {
|
andrewm@0
|
79 pressStartTimestamp_ = timestamp;
|
andrewm@0
|
80 pressStartPosition_ = position;
|
andrewm@0
|
81 needsUpdate_ = true;
|
andrewm@0
|
82 }
|
andrewm@0
|
83 void setKeyPressFinish(key_position position, timestamp_type timestamp) {
|
andrewm@0
|
84 pressFinishTimestamp_ = timestamp;
|
andrewm@0
|
85 pressFinishPosition_ = position;
|
andrewm@0
|
86 needsUpdate_ = true;
|
andrewm@0
|
87 }
|
andrewm@0
|
88 void setKeyReleaseStart(key_position position, timestamp_type timestamp) {
|
andrewm@0
|
89 releaseStartTimestamp_ = timestamp;
|
andrewm@0
|
90 releaseStartPosition_ = position;
|
andrewm@0
|
91 needsUpdate_ = true;
|
andrewm@0
|
92 }
|
andrewm@0
|
93 void setKeyReleaseFinish(key_position position, timestamp_type timestamp) {
|
andrewm@0
|
94 releaseFinishTimestamp_ = timestamp;
|
andrewm@0
|
95 releaseFinishPosition_ = position;
|
andrewm@0
|
96 needsUpdate_ = true;
|
andrewm@0
|
97 }
|
andrewm@0
|
98
|
andrewm@0
|
99 private:
|
andrewm@0
|
100 // Convert mathematical XY coordinate space to drawing positions
|
andrewm@0
|
101 float graphToDisplayX(float x);
|
andrewm@0
|
102 float graphToDisplayY(float y);
|
andrewm@0
|
103
|
andrewm@0
|
104 void refreshViewport();
|
andrewm@0
|
105
|
andrewm@0
|
106 // Conversion from internal coordinate space to external pixel values and back
|
andrewm@0
|
107 Point screenToInternal(Point& inPoint);
|
andrewm@0
|
108 Point internalToScreen(Point& inPoint);
|
andrewm@0
|
109
|
andrewm@0
|
110
|
andrewm@0
|
111 private:
|
andrewm@0
|
112 float displayPixelWidth_, displayPixelHeight_; // Pixel resolution of the surrounding window
|
andrewm@0
|
113 float totalDisplayWidth_, totalDisplayHeight_; // Size of the internal view (centered around origin)
|
andrewm@0
|
114 float xMin_, xMax_, yMin_, yMax_; // Coordinates for the graph axes
|
andrewm@0
|
115
|
andrewm@0
|
116 bool needsUpdate_; // Whether the keyboard should be redrawn
|
andrewm@0
|
117 CriticalSection displayMutex_; // Synchronize access between data and display threads
|
andrewm@0
|
118
|
andrewm@0
|
119 std::vector<key_position> keyPositions_; // Positions (0-1 normalized) of the key
|
andrewm@0
|
120 std::vector<timestamp_type> keyTimestamps_; // Timestamps corresponding to the above positions
|
andrewm@0
|
121
|
andrewm@0
|
122 // Details on features of key motion: start, end, release, etc.
|
andrewm@0
|
123 key_position pressStartPosition_, pressFinishPosition_;
|
andrewm@0
|
124 timestamp_type pressStartTimestamp_, pressFinishTimestamp_;
|
andrewm@0
|
125 key_position releaseStartPosition_, releaseFinishPosition_;
|
andrewm@0
|
126 timestamp_type releaseStartTimestamp_, releaseFinishTimestamp_;
|
andrewm@0
|
127 };
|
andrewm@0
|
128
|
andrewm@0
|
129
|
andrewm@0
|
130 #endif /* defined(__touchkeys__KeyPositionGraphDisplay__) */
|