annotate Source/TouchKeys/KeyTouchFrame.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 3580ffe87dc8
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 KeyTouchFrame.h: class that represents the data of one frame from the TouchKeys.
andrewm@0 21 */
andrewm@0 22
andrewm@0 23 #ifndef KEY_TOUCH_FRAME_H
andrewm@0 24 #define KEY_TOUCH_FRAME_H
andrewm@0 25
andrewm@0 26 #define kWhiteFrontBackCutoff (6.5/19.0) // Border between 2- and 1-dimensional sensing regions
andrewm@0 27
andrewm@0 28 // This class holds one frame of key touch data, both raw values and unique ID numbers
andrewm@0 29 // that help connect one frame to the next
andrewm@0 30
andrewm@0 31 class KeyTouchFrame {
andrewm@0 32 public:
andrewm@0 33 KeyTouchFrame() : count(0), locH(-1.0), nextId(0), white(true) {
andrewm@0 34 for(int i = 0; i < 3; i++) {
andrewm@0 35 ids[i] = -1;
andrewm@0 36 locs[i] = -1.0;
andrewm@0 37 sizes[i] = 0.0;
andrewm@0 38 }
andrewm@0 39 }
andrewm@0 40
andrewm@0 41 KeyTouchFrame(int newCount, float* newLocs, float *newSizes, float newLocH, bool newWhite)
andrewm@0 42 : count(newCount), locH(newLocH), nextId(0), white(newWhite) {
andrewm@0 43 for(int i = 0; i < count; i++) {
andrewm@0 44 ids[i] = -1;
andrewm@0 45 locs[i] = newLocs[i];
andrewm@0 46 sizes[i] = newSizes[i];
andrewm@0 47 }
andrewm@0 48 for(int i = count; i < 3; i++) {
andrewm@0 49 ids[i] = -1;
andrewm@0 50 locs[i] = -1.0;
andrewm@0 51 sizes[i] = 0.0;
andrewm@0 52 }
andrewm@0 53 }
andrewm@0 54
andrewm@0 55 KeyTouchFrame(const KeyTouchFrame& copy) : count(copy.count), locH(copy.locH), nextId(copy.nextId), white(copy.white) {
andrewm@0 56 for(int i = 0; i < 3; i++) {
andrewm@0 57 ids[i] = copy.ids[i];
andrewm@0 58 locs[i] = copy.locs[i];
andrewm@0 59 sizes[i] = copy.sizes[i];
andrewm@0 60 }
andrewm@0 61 }
andrewm@0 62
andrewm@0 63 // Horizontal location only makes sense in the front part of the key. Return the
andrewm@0 64 // value if applicable, otherwise -1.
andrewm@0 65 float horizontal(int index) const {
andrewm@0 66 //if(!white)
andrewm@0 67 // return -1.0;
andrewm@0 68 if(index >= count || index > 2 || index < 0)
andrewm@0 69 return -1.0;
andrewm@0 70 //if(locs[index] < kWhiteFrontBackCutoff) // FIXME: need better hardware-dependent solution to this
andrewm@0 71 return locH;
andrewm@0 72 //return -1.0;
andrewm@0 73 }
andrewm@0 74
andrewm@0 75 int count; // Number of active touches (0-3)
andrewm@0 76 int ids[3]; // Unique ID numbers for current touches
andrewm@0 77 float locs[3]; // Vertical location of current touches
andrewm@0 78 float sizes[3]; // Contact area of current touches
andrewm@0 79 float locH; // Horizontal location (white keys only)
andrewm@0 80 int nextId; // ID number to be used for the next new touch added
andrewm@0 81 bool white; // Whether this is a white key
andrewm@0 82 };
andrewm@0 83
andrewm@0 84 #endif /* KEY_TOUCH_FRAME_H */