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 TouchkeyOnsetAngleMapping.h: per-note mapping for the onset angle mapping,
|
andrewm@0
|
21 which measures the speed of finger motion along the key surface at the
|
andrewm@0
|
22 time of MIDI note onset.
|
andrewm@0
|
23 */
|
andrewm@0
|
24
|
andrewm@0
|
25
|
andrewm@0
|
26 #ifndef __TouchKeys__TouchkeyOnsetAngleMapping__
|
andrewm@0
|
27 #define __TouchKeys__TouchkeyOnsetAngleMapping__
|
andrewm@0
|
28
|
andrewm@0
|
29 #include "../TouchkeyBaseMapping.h"
|
andrewm@0
|
30
|
andrewm@0
|
31 // This class handles the detection of finger motion specifically at
|
andrewm@0
|
32 // note release, which can be used to trigger specific release effects.
|
andrewm@0
|
33
|
andrewm@0
|
34 class TouchkeyOnsetAngleMapping : public TouchkeyBaseMapping {
|
andrewm@0
|
35 private:
|
andrewm@0
|
36 // Default values
|
andrewm@0
|
37 /*constexpr static const int kDefaultFilterBufferLength = 30;
|
andrewm@0
|
38 constexpr static const timestamp_diff_type kDefaultMaxLookbackTime = milliseconds_to_timestamp(100);*/
|
andrewm@0
|
39
|
andrewm@0
|
40 static const int kDefaultFilterBufferLength;
|
andrewm@0
|
41 static const timestamp_diff_type kDefaultMaxLookbackTime;
|
andrewm@0
|
42 static const int kDefaultMaxLookbackSamples;
|
andrewm@0
|
43
|
andrewm@0
|
44 public:
|
andrewm@0
|
45 // ***** Constructors *****
|
andrewm@0
|
46
|
andrewm@0
|
47 // Default constructor, passing the buffer on which to trigger
|
andrewm@0
|
48 TouchkeyOnsetAngleMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
49 Node<key_position>* positionBuffer, KeyPositionTracker* positionTracker);
|
andrewm@0
|
50
|
andrewm@0
|
51 // ***** Modifiers *****
|
andrewm@0
|
52
|
andrewm@0
|
53 // Reset the state back initial values
|
andrewm@0
|
54 void reset();
|
andrewm@0
|
55
|
andrewm@0
|
56 // Resend the current state of all parameters
|
andrewm@0
|
57 void resend();
|
andrewm@0
|
58
|
andrewm@0
|
59 // ***** Evaluators *****
|
andrewm@0
|
60
|
andrewm@0
|
61 // This method receives triggers whenever events occur in the touch data or the
|
andrewm@0
|
62 // continuous key position (state changes only). It alters the behavior and scheduling
|
andrewm@0
|
63 // of the mapping but does not itself send OSC messages
|
andrewm@0
|
64 void triggerReceived(TriggerSource* who, timestamp_type timestamp);
|
andrewm@0
|
65
|
andrewm@0
|
66 // This method handles the OSC message transmission. It should be run in the Scheduler
|
andrewm@0
|
67 // thread provided by PianoKeyboard.
|
andrewm@0
|
68 timestamp_type performMapping();
|
andrewm@0
|
69
|
andrewm@0
|
70 // ***** Specific Methods *****
|
andrewm@0
|
71 // Process the release by calculating the angle
|
andrewm@0
|
72 void processOnset(timestamp_type timestamp);
|
andrewm@0
|
73
|
andrewm@0
|
74 private:
|
andrewm@0
|
75 // ***** Private Methods *****
|
andrewm@0
|
76
|
andrewm@0
|
77 void sendOnsetAngleMessage(float onsetAngle, bool force = false);
|
andrewm@0
|
78 void sendPitchBendMessage(float pitchBendSemitones, bool force = false);
|
andrewm@0
|
79
|
andrewm@0
|
80 // ***** Member Variables *****
|
andrewm@0
|
81
|
andrewm@0
|
82 Node<KeyTouchFrame> pastSamples_; // Locations of touch
|
andrewm@0
|
83 timestamp_diff_type maxLookbackTime_; // How long to look backwards to find release velocity
|
andrewm@0
|
84 CriticalSection sampleBufferMutex_; // Mutex to protect threaded access to sample buffer
|
andrewm@0
|
85
|
andrewm@0
|
86 float startingPitchBendSemitones_; // The value of pitch bend to start with
|
andrewm@0
|
87 float lastPitchBendSemitones_; // The last pitch value we sent out
|
andrewm@0
|
88 timestamp_type rampBeginTime_; // When did the pitch bend ramp begin?
|
andrewm@0
|
89 timestamp_diff_type rampLength_; // How long should the ramp be?
|
andrewm@0
|
90 };
|
andrewm@0
|
91
|
andrewm@0
|
92 #endif /* defined(__TouchKeys__TouchkeyOnsetAngleMapping__) */
|