annotate Source/Mappings/ReleaseAngle/TouchkeyReleaseAngleMapping.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 78b9808a2c65
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 TouchkeyReleaseAngleMapping.h: per-note mapping for the release angle
andrewm@0 21 mapping, which measures the speed of finger motion along the key at
andrewm@0 22 the time of MIDI note off.
andrewm@0 23 */
andrewm@0 24
andrewm@0 25 #ifndef __TouchKeys__TouchkeyReleaseAngleMapping__
andrewm@0 26 #define __TouchKeys__TouchkeyReleaseAngleMapping__
andrewm@0 27
andrewm@0 28 #include "../TouchkeyBaseMapping.h"
andrewm@0 29
andrewm@46 30 #define RELEASE_ANGLE_MAX_SEQUENCE_LENGTH 16
andrewm@46 31
andrewm@0 32 // This class handles the detection of finger motion specifically at
andrewm@0 33 // note release, which can be used to trigger specific release effects.
andrewm@0 34
andrewm@0 35 class TouchkeyReleaseAngleMapping : public TouchkeyBaseMapping {
andrewm@46 36 friend class TouchkeyReleaseAngleMappingFactory;
andrewm@46 37
andrewm@0 38 private:
andrewm@0 39 // Default values
andrewm@0 40 /*constexpr static const int kDefaultFilterBufferLength = 30;
andrewm@0 41 constexpr static const timestamp_diff_type kDefaultMaxLookbackTime = milliseconds_to_timestamp(100);*/
andrewm@0 42
andrewm@0 43 static const int kDefaultFilterBufferLength;
andrewm@0 44 static const timestamp_diff_type kDefaultMaxLookbackTime;
andrewm@0 45
andrewm@46 46 static const float kDefaultUpMinimumAngle;
andrewm@46 47 static const float kDefaultDownMinimumAngle;
andrewm@46 48
andrewm@0 49 public:
andrewm@0 50 // ***** Constructors *****
andrewm@0 51
andrewm@0 52 // Default constructor, passing the buffer on which to trigger
andrewm@0 53 TouchkeyReleaseAngleMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node<KeyTouchFrame>* touchBuffer,
andrewm@0 54 Node<key_position>* positionBuffer, KeyPositionTracker* positionTracker);
andrewm@0 55
andrewm@0 56 // Copy constructor
andrewm@0 57 //TouchkeyReleaseAngleMapping(TouchkeyReleaseAngleMapping const& obj);
andrewm@0 58
andrewm@0 59 // ***** Modifiers *****
andrewm@0 60
andrewm@0 61 // Reset the state back initial values
andrewm@0 62 void reset();
andrewm@0 63
andrewm@0 64 // Resend the current state of all parameters
andrewm@0 65 void resend();
andrewm@0 66
andrewm@46 67 // Parameters for release angle algorithm
andrewm@46 68 void setWindowSize(float windowSize);
andrewm@46 69 void setUpMessagesEnabled(bool enable);
andrewm@46 70 void setDownMessagesEnabled(bool enable);
andrewm@46 71 void setUpMinimumAngle(float minAngle);
andrewm@46 72 void setUpNote(int sequence, int note);
andrewm@46 73 void setUpVelocity(int sequence, int velocity);
andrewm@46 74 void setDownMinimumAngle(float minAngle);
andrewm@46 75 void setDownNote(int sequence, int note);
andrewm@46 76 void setDownVelocity(int sequence, int velocity);
andrewm@46 77
andrewm@0 78 // ***** Evaluators *****
andrewm@0 79
andrewm@0 80 // This method receives triggers whenever events occur in the touch data or the
andrewm@0 81 // continuous key position (state changes only). It alters the behavior and scheduling
andrewm@0 82 // of the mapping but does not itself send OSC messages
andrewm@0 83 void triggerReceived(TriggerSource* who, timestamp_type timestamp);
andrewm@0 84
andrewm@0 85 // This method handles the OSC message transmission. It should be run in the Scheduler
andrewm@0 86 // thread provided by PianoKeyboard.
andrewm@0 87 timestamp_type performMapping();
andrewm@46 88
andrewm@46 89 // Called when MIDI note release happens
andrewm@46 90 void midiNoteOffReceived(int channel);
andrewm@0 91
andrewm@0 92 // ***** Specific Methods *****
andrewm@0 93 // Process the release by calculating the angle
andrewm@46 94 void processRelease(/*timestamp_type timestamp*/);
andrewm@0 95
andrewm@0 96 timestamp_type releaseKeySwitch();
andrewm@0 97
andrewm@0 98 private:
andrewm@0 99 // ***** Private Methods *****
andrewm@0 100
andrewm@0 101 void sendReleaseAngleMessage(float releaseAngle, bool force = false);
andrewm@0 102
andrewm@0 103 // ***** Member Variables *****
andrewm@0 104
andrewm@46 105 bool upEnabled_, downEnabled_; // Whether messages are enabled for upward and downward releases
andrewm@46 106 float upMinimumAngle_; // Minimum release angle for trigger for up...
andrewm@46 107 float downMinimumAngle_; // ...and down cases
andrewm@46 108 int upNotes_[RELEASE_ANGLE_MAX_SEQUENCE_LENGTH]; // Notes and velocities to send on upward
andrewm@46 109 int upVelocities_[RELEASE_ANGLE_MAX_SEQUENCE_LENGTH]; // and downward release
andrewm@46 110 int downNotes_[RELEASE_ANGLE_MAX_SEQUENCE_LENGTH];
andrewm@46 111 int downVelocities_[RELEASE_ANGLE_MAX_SEQUENCE_LENGTH];
andrewm@46 112
andrewm@0 113 Node<KeyTouchFrame> pastSamples_; // Locations of touch
andrewm@0 114 timestamp_diff_type maxLookbackTime_; // How long to look backwards to find release velocity
andrewm@0 115 CriticalSection sampleBufferMutex_; // Mutex to protect threaded access to sample buffer
andrewm@0 116 };
andrewm@0 117
andrewm@0 118 #endif /* defined(__TouchKeys__TouchkeyReleaseAngleMapping__) */