andrewm@0: /* andrewm@0: TouchKeys: multi-touch musical keyboard control software andrewm@0: Copyright (c) 2013 Andrew McPherson andrewm@0: andrewm@0: This program is free software: you can redistribute it and/or modify andrewm@0: it under the terms of the GNU General Public License as published by andrewm@0: the Free Software Foundation, either version 3 of the License, or andrewm@0: (at your option) any later version. andrewm@0: andrewm@0: This program is distributed in the hope that it will be useful, andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@0: GNU General Public License for more details. andrewm@0: andrewm@0: You should have received a copy of the GNU General Public License andrewm@0: along with this program. If not, see . andrewm@0: andrewm@0: ===================================================================== andrewm@0: andrewm@0: KeyTouchFrame.h: class that represents the data of one frame from the TouchKeys. andrewm@0: */ andrewm@0: andrewm@0: #ifndef KEY_TOUCH_FRAME_H andrewm@0: #define KEY_TOUCH_FRAME_H andrewm@0: andrewm@0: #define kWhiteFrontBackCutoff (6.5/19.0) // Border between 2- and 1-dimensional sensing regions andrewm@0: andrewm@0: // This class holds one frame of key touch data, both raw values and unique ID numbers andrewm@0: // that help connect one frame to the next andrewm@0: andrewm@0: class KeyTouchFrame { andrewm@0: public: andrewm@0: KeyTouchFrame() : count(0), locH(-1.0), nextId(0), white(true) { andrewm@0: for(int i = 0; i < 3; i++) { andrewm@0: ids[i] = -1; andrewm@0: locs[i] = -1.0; andrewm@0: sizes[i] = 0.0; andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: KeyTouchFrame(int newCount, float* newLocs, float *newSizes, float newLocH, bool newWhite) andrewm@0: : count(newCount), locH(newLocH), nextId(0), white(newWhite) { andrewm@0: for(int i = 0; i < count; i++) { andrewm@0: ids[i] = -1; andrewm@0: locs[i] = newLocs[i]; andrewm@0: sizes[i] = newSizes[i]; andrewm@0: } andrewm@0: for(int i = count; i < 3; i++) { andrewm@0: ids[i] = -1; andrewm@0: locs[i] = -1.0; andrewm@0: sizes[i] = 0.0; andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: KeyTouchFrame(const KeyTouchFrame& copy) : count(copy.count), locH(copy.locH), nextId(copy.nextId), white(copy.white) { andrewm@0: for(int i = 0; i < 3; i++) { andrewm@0: ids[i] = copy.ids[i]; andrewm@0: locs[i] = copy.locs[i]; andrewm@0: sizes[i] = copy.sizes[i]; andrewm@0: } andrewm@0: } andrewm@0: andrewm@0: // Horizontal location only makes sense in the front part of the key. Return the andrewm@0: // value if applicable, otherwise -1. andrewm@0: float horizontal(int index) const { andrewm@0: //if(!white) andrewm@0: // return -1.0; andrewm@0: if(index >= count || index > 2 || index < 0) andrewm@0: return -1.0; andrewm@0: //if(locs[index] < kWhiteFrontBackCutoff) // FIXME: need better hardware-dependent solution to this andrewm@0: return locH; andrewm@0: //return -1.0; andrewm@0: } andrewm@0: andrewm@0: int count; // Number of active touches (0-3) andrewm@0: int ids[3]; // Unique ID numbers for current touches andrewm@0: float locs[3]; // Vertical location of current touches andrewm@0: float sizes[3]; // Contact area of current touches andrewm@0: float locH; // Horizontal location (white keys only) andrewm@0: int nextId; // ID number to be used for the next new touch added andrewm@0: bool white; // Whether this is a white key andrewm@0: }; andrewm@0: andrewm@0: #endif /* KEY_TOUCH_FRAME_H */