annotate Source/Mappings/KeyDivision/TouchkeyKeyDivisionMapping.h @ 16:61e3c9df4674

Fix bug where TouchKeys standalone mode turns off when mode is changed.
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Mon, 25 Nov 2013 21:36:02 +0000
parents 3580ffe87dc8
children 1526d2fbe01e
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 TouchkeyKeyDivisionMapping.h: per-note mapping for the split-key mapping
andrewm@0 21 which triggers different actions or pitches depending on where the key
andrewm@0 22 was struck.
andrewm@0 23 */
andrewm@0 24
andrewm@0 25
andrewm@0 26 #ifndef __TouchKeys__TouchkeyKeyDivisionMapping__
andrewm@0 27 #define __TouchKeys__TouchkeyKeyDivisionMapping__
andrewm@0 28
andrewm@0 29 #include "../TouchkeyBaseMapping.h"
andrewm@0 30
andrewm@0 31 // This class handles the division of a key into multiple
andrewm@0 32 // subsections, for example to handle microtonal divisions
andrewm@0 33
andrewm@0 34 class TouchkeyKeyDivisionMapping : public TouchkeyBaseMapping {
andrewm@0 35 friend class TouchkeyKeyDivisionMappingFactory;
andrewm@0 36 public:
andrewm@0 37 enum {
andrewm@0 38 kDetectionParameterYPosition,
andrewm@0 39 kDetectionParameterNumberOfTouches,
andrewm@0 40 kDetectionParameterYPositionAndNumberOfTouches
andrewm@0 41 };
andrewm@0 42
andrewm@0 43 private:
andrewm@0 44 // Default values
andrewm@0 45 static const int kDefaultNumberOfSegments;
andrewm@0 46 static const timestamp_diff_type kDefaultDetectionTimeout;
andrewm@0 47 static const int kDefaultDetectionParameter;
andrewm@0 48 static const int kDefaultRetriggerNumFrames;
andrewm@0 49
andrewm@0 50 public:
andrewm@0 51 // ***** Constructors *****
andrewm@0 52
andrewm@0 53 // Default constructor, passing the buffer on which to trigger
andrewm@0 54 TouchkeyKeyDivisionMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node<KeyTouchFrame>* touchBuffer,
andrewm@0 55 Node<key_position>* positionBuffer, KeyPositionTracker* positionTracker);
andrewm@0 56
andrewm@0 57 // ***** Modifiers *****
andrewm@0 58
andrewm@0 59 // Reset the state back initial values
andrewm@0 60 void reset();
andrewm@0 61
andrewm@0 62 // Resend the current state of all parameters
andrewm@0 63 void resend();
andrewm@0 64
andrewm@0 65 // ***** Evaluators *****
andrewm@0 66
andrewm@0 67 // This method receives triggers whenever events occur in the touch data or the
andrewm@0 68 // continuous key position (state changes only). It alters the behavior and scheduling
andrewm@0 69 // of the mapping but does not itself send OSC messages
andrewm@0 70 void triggerReceived(TriggerSource* who, timestamp_type timestamp);
andrewm@0 71
andrewm@0 72 // This method handles the OSC message transmission. It should be run in the Scheduler
andrewm@0 73 // thread provided by PianoKeyboard.
andrewm@0 74 timestamp_type performMapping();
andrewm@0 75
andrewm@0 76 // ***** Specific Methods *****
andrewm@0 77
andrewm@0 78 // Set the number of segments
andrewm@0 79 void setNumberOfSegments(int segments) {
andrewm@0 80 if(segments > 0)
andrewm@0 81 numberOfSegments_ = segments;
andrewm@0 82 }
andrewm@0 83
andrewm@0 84 // Set the default segment (upon timeout)
andrewm@0 85 void setDefaultSegment(int defaultSegment) {
andrewm@0 86 defaultSegment_ = defaultSegment;
andrewm@0 87 }
andrewm@0 88
andrewm@0 89 // Set the pitch bend values associated with each key segment
andrewm@0 90 void setSegmentPitchBends(const float *bendsInSemitones, int numBends);
andrewm@0 91
andrewm@0 92 // Set the detection timeout value (how long from MIDI note on to touch)
andrewm@0 93 void setTimeout(timestamp_diff_type timeout) {
andrewm@0 94 timeout_ = timeout;
andrewm@0 95 }
andrewm@0 96
andrewm@0 97 // Set which parameter is used to detect segment
andrewm@0 98 void setDetectionParameter(int parameter) {
andrewm@0 99 detectionParameter_ = parameter;
andrewm@0 100 }
andrewm@0 101
andrewm@0 102 // Set whether placing a second finger in the other segment triggers a
andrewm@0 103 // new note with that segment.
andrewm@0 104 void setRetriggerable(bool retrigger, int numFrames, bool keepOriginalVelocity) {
andrewm@0 105 retriggerable_ = retrigger;
andrewm@0 106 retriggerNumFrames_ = numFrames;
andrewm@0 107 retriggerKeepsVelocity_ = keepOriginalVelocity;
andrewm@0 108 }
andrewm@0 109
andrewm@0 110 private:
andrewm@0 111 // ***** Private Methods *****
andrewm@0 112
andrewm@0 113 void midiNoteOnReceived(int channel, int velocity);
andrewm@0 114 void midiNoteOffReceived(int channel);
andrewm@0 115
andrewm@0 116 void sendSegmentMessage(int segment, bool force = false);
andrewm@0 117 void sendPitchBendMessage(float pitchBendSemitones, bool force = false);
andrewm@0 118
andrewm@0 119 int segmentForLocation(float location);
andrewm@0 120 int segmentForNumTouches(int numTouches);
andrewm@0 121 float locationOfNewestTouch(KeyTouchFrame const& frame);
andrewm@0 122
andrewm@0 123 // ***** Member Variables *****
andrewm@0 124
andrewm@0 125 int numberOfSegments_; // How many segments to choose from total
andrewm@0 126 int candidateSegment_; // Which segment we would be in if the press were now
andrewm@0 127 int detectedSegment_; // Which segment of the key we detected
andrewm@0 128 int defaultSegment_; // Which segment to choose by default (on timeout)
andrewm@0 129 int detectionParameter_; // Which parameter is used to determine the segment
andrewm@0 130 bool retriggerable_; // Whether a second touch can retrigger this note
andrewm@0 131 int retriggerNumFrames_; // How many frames a new touch must be present to retrigger
andrewm@0 132 bool retriggerKeepsVelocity_; // Whether a retriggered note keeps the original velocity or a default
andrewm@0 133
andrewm@0 134 timestamp_type midiNoteOnTimestamp_; // When the MIDI note went on
andrewm@0 135 timestamp_diff_type timeout_; // How long to wait for a touch event
andrewm@0 136 int lastNumActiveTouches_; // How many touches were active before
andrewm@0 137
andrewm@0 138 std::vector<float> segmentBends_; // What the pitch bend values are for each segment
andrewm@0 139 };
andrewm@0 140
andrewm@0 141 #endif /* defined(__TouchKeys__TouchkeyKeyDivisionMapping__) */