annotate Source/Display/KeyPositionGraphDisplay.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 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@27 60 // Set canvas for triggering rendering;
andrewm@27 61 void setCanvas(OpenGLJuceCanvas *canvas) { canvas_ = canvas; }
andrewm@27 62 void tellCanvasToRepaint();
andrewm@27 63
andrewm@0 64 // Setup methods for display size and keyboard range
andrewm@0 65 void setDisplaySize(float width, float height);
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 copyKeyDataFromBuffer(Node<key_position>& keyBuffer, const Node<key_position>::size_type startIndex,
andrewm@0 80 const Node<key_position>::size_type endIndex);
andrewm@0 81 void setKeyPressStart(key_position position, timestamp_type timestamp) {
andrewm@0 82 pressStartTimestamp_ = timestamp;
andrewm@0 83 pressStartPosition_ = position;
andrewm@27 84 tellCanvasToRepaint();
andrewm@0 85 }
andrewm@0 86 void setKeyPressFinish(key_position position, timestamp_type timestamp) {
andrewm@0 87 pressFinishTimestamp_ = timestamp;
andrewm@0 88 pressFinishPosition_ = position;
andrewm@27 89 tellCanvasToRepaint();
andrewm@0 90 }
andrewm@0 91 void setKeyReleaseStart(key_position position, timestamp_type timestamp) {
andrewm@0 92 releaseStartTimestamp_ = timestamp;
andrewm@0 93 releaseStartPosition_ = position;
andrewm@27 94 tellCanvasToRepaint();
andrewm@0 95 }
andrewm@0 96 void setKeyReleaseFinish(key_position position, timestamp_type timestamp) {
andrewm@0 97 releaseFinishTimestamp_ = timestamp;
andrewm@0 98 releaseFinishPosition_ = position;
andrewm@27 99 tellCanvasToRepaint();
andrewm@0 100 }
andrewm@0 101
andrewm@0 102 private:
andrewm@0 103 // Convert mathematical XY coordinate space to drawing positions
andrewm@0 104 float graphToDisplayX(float x);
andrewm@0 105 float graphToDisplayY(float y);
andrewm@0 106
andrewm@0 107 void refreshViewport();
andrewm@0 108
andrewm@0 109 // Conversion from internal coordinate space to external pixel values and back
andrewm@0 110 Point screenToInternal(Point& inPoint);
andrewm@0 111 Point internalToScreen(Point& inPoint);
andrewm@0 112
andrewm@27 113 private:
andrewm@27 114 OpenGLJuceCanvas *canvas_; // Reference to canvas that renders OpenGL
andrewm@0 115
andrewm@0 116 float displayPixelWidth_, displayPixelHeight_; // Pixel resolution of the surrounding window
andrewm@0 117 float totalDisplayWidth_, totalDisplayHeight_; // Size of the internal view (centered around origin)
andrewm@0 118 float xMin_, xMax_, yMin_, yMax_; // Coordinates for the graph axes
andrewm@0 119
andrewm@0 120 CriticalSection displayMutex_; // Synchronize access between data and display threads
andrewm@0 121
andrewm@0 122 std::vector<key_position> keyPositions_; // Positions (0-1 normalized) of the key
andrewm@0 123 std::vector<timestamp_type> keyTimestamps_; // Timestamps corresponding to the above positions
andrewm@0 124
andrewm@0 125 // Details on features of key motion: start, end, release, etc.
andrewm@0 126 key_position pressStartPosition_, pressFinishPosition_;
andrewm@0 127 timestamp_type pressStartTimestamp_, pressFinishTimestamp_;
andrewm@0 128 key_position releaseStartPosition_, releaseFinishPosition_;
andrewm@0 129 timestamp_type releaseStartTimestamp_, releaseFinishTimestamp_;
andrewm@0 130 };
andrewm@0 131
andrewm@0 132
andrewm@0 133 #endif /* defined(__touchkeys__KeyPositionGraphDisplay__) */