annotate Source/Mappings/MultiFingerTrigger/TouchkeyMultiFingerTriggerMapping.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 1526d2fbe01e
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 TouchkeyMultiFingerTriggerMapping.h: per-note mapping for the multiple-
andrewm@0 21 finger trigger mapping, which performs actions when two or more fingers
andrewm@0 22 are added or removed from the key.
andrewm@0 23 */
andrewm@0 24
andrewm@0 25 #ifndef __TouchKeys__TouchkeyMultiFingerTriggerMapping__
andrewm@0 26 #define __TouchKeys__TouchkeyMultiFingerTriggerMapping__
andrewm@0 27
andrewm@0 28 #include "../TouchkeyBaseMapping.h"
andrewm@42 29 #include <set>
andrewm@42 30
andrewm@42 31 class TouchkeyMultiFingerTriggerMappingFactory;
andrewm@0 32
andrewm@0 33 // This class handles the detection of finger motion specifically at
andrewm@0 34 // note release, which can be used to trigger specific release effects.
andrewm@0 35
andrewm@0 36 class TouchkeyMultiFingerTriggerMapping : public TouchkeyBaseMapping {
andrewm@42 37 friend class TouchkeyMultiFingerTriggerMappingFactory;
andrewm@42 38 public:
andrewm@42 39 enum {
andrewm@42 40 kActionNone = 1,
andrewm@42 41 kActionNoteOn,
andrewm@42 42 kActionNoteOff,
andrewm@42 43 kActionMax
andrewm@42 44 };
andrewm@42 45
andrewm@0 46 private:
andrewm@0 47 // Default values
andrewm@0 48 /*constexpr static const int kDefaultFilterBufferLength = 30;
andrewm@0 49 constexpr static const int kDefaultNumTouchesForTrigger = 2;
andrewm@0 50 constexpr static const int kDefaultNumFramesForTrigger = 2;
andrewm@0 51 constexpr static const int kDefaultNumConsecutiveTapsForTrigger = 1;
andrewm@0 52 constexpr static const timestamp_diff_type kDefaultMaxTapSpacing = milliseconds_to_timestamp(500.0);*/
andrewm@0 53 static const int kDefaultFilterBufferLength;
andrewm@0 54 static const int kDefaultNumTouchesForTrigger;
andrewm@0 55 static const int kDefaultNumFramesForTrigger;
andrewm@0 56 static const int kDefaultNumConsecutiveTapsForTrigger;
andrewm@0 57 static const timestamp_diff_type kDefaultMaxTapSpacing;
andrewm@42 58 static const int kDefaultTriggerOnAction;
andrewm@42 59 static const int kDefaultTriggerOffAction;
andrewm@42 60 static const int kDefaultTriggerOnNoteNum;
andrewm@42 61 static const int kDefaultTriggerOffNoteNum;
andrewm@42 62 static const int kDefaultTriggerOnNoteVel;
andrewm@42 63 static const int kDefaultTriggerOffNoteVel;
andrewm@42 64
andrewm@0 65 public:
andrewm@0 66 // ***** Constructors *****
andrewm@0 67
andrewm@0 68 // Default constructor, passing the buffer on which to trigger
andrewm@0 69 TouchkeyMultiFingerTriggerMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node<KeyTouchFrame>* touchBuffer,
andrewm@0 70 Node<key_position>* positionBuffer, KeyPositionTracker* positionTracker);
andrewm@0 71
andrewm@0 72 // ***** Modifiers *****
andrewm@0 73
andrewm@42 74 // Disable mappings from being sent
andrewm@42 75 void disengage(bool shouldDelete = false);
andrewm@42 76
andrewm@0 77 // Reset the state back initial values
andrewm@0 78 void reset();
andrewm@0 79
andrewm@0 80 // Resend the current state of all parameters
andrewm@0 81 void resend();
andrewm@0 82
andrewm@42 83 // Parameters for multi-finger trigger
andrewm@42 84 void setTouchesForTrigger(int touches);
andrewm@42 85 void setFramesForTrigger(int frames);
andrewm@42 86 void setConsecutiveTapsForTrigger(int taps);
andrewm@42 87 void setMaxTimeBetweenTapsForTrigger(timestamp_diff_type timeDiff);
andrewm@42 88 void setNeedsMidiNoteOn(bool needsMidi);
andrewm@42 89 void setTriggerOnAction(int action);
andrewm@42 90 void setTriggerOffAction(int action);
andrewm@42 91 void setTriggerOnNoteNumber(int note);
andrewm@42 92 void setTriggerOffNoteNumber(int note);
andrewm@42 93 void setTriggerOnNoteVelocity(int velocity);
andrewm@42 94 void setTriggerOffNoteVelocity(int velocity);
andrewm@42 95
andrewm@0 96 // ***** Evaluators *****
andrewm@0 97
andrewm@0 98 // This method receives triggers whenever events occur in the touch data or the
andrewm@0 99 // continuous key position (state changes only). It alters the behavior and scheduling
andrewm@0 100 // of the mapping but does not itself send OSC messages
andrewm@0 101 void triggerReceived(TriggerSource* who, timestamp_type timestamp);
andrewm@0 102
andrewm@0 103 // This method handles the OSC message transmission. It should be run in the Scheduler
andrewm@0 104 // thread provided by PianoKeyboard.
andrewm@0 105 timestamp_type performMapping();
andrewm@0 106
andrewm@0 107 // ***** Specific Methods *****
andrewm@0 108
andrewm@0 109
andrewm@0 110 private:
andrewm@0 111 // ***** Private Methods *****
andrewm@0 112 // Generate the multi-finger trigger
andrewm@0 113 void generateTriggerOn(timestamp_type timestamp, timestamp_diff_type timeBetweenTaps, float distanceBetweenPoints);
andrewm@0 114 void generateTriggerOff(timestamp_type timestamp);
andrewm@0 115
andrewm@0 116 void midiNoteOffReceived(int channel);
andrewm@0 117
andrewm@0 118 // ***** Member Variables *****
andrewm@0 119
andrewm@0 120 // Parameters
andrewm@0 121 int numTouchesForTrigger_; // How many touches are needed for a trigger
andrewm@0 122 int numFramesForTrigger_; // How many consecutive frames with these touches are needed to trigger
andrewm@0 123 int numConsecutiveTapsForTrigger_; // How many taps with this number of touches are needed to trigger
andrewm@0 124 timestamp_diff_type maxTapSpacing_; // How far apart the taps can come and be considered a multi-tap gesture
andrewm@0 125 bool needsMidiNoteOn_; // Whether the MIDI note has to be on for this gesture to trigger
andrewm@42 126 int triggerOnAction_, triggerOffAction_; // Actions to take on trigger on/off
andrewm@42 127 int triggerOnNoteNum_, triggerOffNoteNum_; // Which notes to send if a note is being sent
andrewm@42 128 int triggerOnNoteVel_, triggerOffNoteVel_; // Velocity to send if a note is being sent
andrewm@0 129
andrewm@0 130 int lastNumActiveTouches_; // How many touches were active before
andrewm@0 131 float lastActiveTouchLocations_[3]; // Where (Y coord.) the active touches were last frame
andrewm@0 132 int framesCount_; // How many frames have met the current number of active touches
andrewm@0 133 int tapsCount_; // How many taps we've registered so far
andrewm@0 134 bool hasGeneratedTap_; // Whether we've generated a tap with this number of touches yet
andrewm@0 135 timestamp_type lastTapStartTimestamp_; // When the last tap ended
andrewm@0 136 bool hasTriggered_; // Whether we've generated a trigger
andrewm@0 137
andrewm@42 138 std::set<std::pair<int, int> > otherNotesOn_; // Which other notes are on as a result of triggers?
andrewm@42 139
andrewm@0 140 Node<KeyTouchFrame> pastSamples_; // Locations of touch
andrewm@0 141 CriticalSection sampleBufferMutex_; // Mutex to protect threaded access to sample buffer
andrewm@0 142 };
andrewm@0 143
andrewm@0 144
andrewm@0 145 #endif /* defined(__TouchKeys__TouchkeyMultiFingerTriggerMapping__) */