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 Mapping.h: base class for a single-note mapping. The mapping will take in
|
andrewm@0
|
21 MIDI, touch and (optionally) continuous key position data, and generate
|
andrewm@0
|
22 specific OSC or MIDI messages. TouchKeys-specific mappings generally
|
andrewm@0
|
23 inherit from the TouchkeyBaseMapping subclass, which provides other
|
andrewm@0
|
24 useful generic methods.
|
andrewm@0
|
25 */
|
andrewm@0
|
26
|
andrewm@0
|
27 #ifndef touchkeys_Mapping_h
|
andrewm@0
|
28 #define touchkeys_Mapping_h
|
andrewm@0
|
29
|
andrewm@0
|
30
|
andrewm@0
|
31 #include <map>
|
andrewm@0
|
32 #include <boost/bind.hpp>
|
andrewm@0
|
33 #include "../TouchKeys/KeyTouchFrame.h"
|
andrewm@0
|
34 #include "../TouchKeys/KeyPositionTracker.h"
|
andrewm@0
|
35 #include "../TouchKeys/PianoKeyboard.h"
|
andrewm@0
|
36
|
andrewm@0
|
37 #define NEW_MAPPING_SCHEDULER
|
andrewm@0
|
38
|
andrewm@0
|
39 class MappingFactory;
|
andrewm@0
|
40
|
andrewm@0
|
41 // This virtual base class defines a mapping from keyboard data to OSC or
|
andrewm@0
|
42 // other output information. Specific behavior is implemented by subclasses.
|
andrewm@0
|
43
|
andrewm@0
|
44 class Mapping : public TriggerDestination {
|
andrewm@0
|
45 protected:
|
andrewm@0
|
46 // Default frequency of mapping data, in the absence of other triggers
|
andrewm@0
|
47 //const timestamp_diff_type kDefaultUpdateInterval = microseconds_to_timestamp(5500);
|
andrewm@0
|
48 static const timestamp_diff_type kDefaultUpdateInterval;
|
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 Mapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
55 Node<key_position>* positionBuffer, KeyPositionTracker* positionTracker);
|
andrewm@0
|
56
|
andrewm@0
|
57 // Copy constructor
|
andrewm@0
|
58 Mapping(Mapping const& obj);
|
andrewm@0
|
59
|
andrewm@0
|
60 // ***** Destructor *****
|
andrewm@0
|
61
|
andrewm@0
|
62 virtual ~Mapping();
|
andrewm@0
|
63
|
andrewm@0
|
64 // ***** Modifiers *****
|
andrewm@0
|
65
|
andrewm@0
|
66 // Enable mappings to be sent
|
andrewm@0
|
67 virtual void engage();
|
andrewm@0
|
68
|
andrewm@0
|
69 // Disable mappings from being sent
|
andrewm@0
|
70 virtual void disengage(bool shouldDelete = false);
|
andrewm@0
|
71
|
andrewm@0
|
72 // Reset the state back initial values
|
andrewm@0
|
73 virtual void reset();
|
andrewm@0
|
74
|
andrewm@0
|
75 // Set the interval between mapping actions
|
andrewm@0
|
76 virtual void setUpdateInterval(timestamp_diff_type interval) {
|
andrewm@0
|
77 if(interval <= 0)
|
andrewm@0
|
78 return;
|
andrewm@0
|
79 updateInterval_ = interval;
|
andrewm@0
|
80 }
|
andrewm@0
|
81
|
andrewm@0
|
82 // Suspend any further messages from this mapping
|
andrewm@0
|
83 virtual void suspend() { suspended_ = true; }
|
andrewm@0
|
84
|
andrewm@0
|
85 // Resume sending messages, optionally re-sending the current state
|
andrewm@0
|
86 virtual void resume(bool resendCurrentState) {
|
andrewm@0
|
87 if(resendCurrentState)
|
andrewm@0
|
88 resend();
|
andrewm@0
|
89 suspended_ = false;
|
andrewm@0
|
90 }
|
andrewm@0
|
91
|
andrewm@0
|
92 // Resend the current state of all the managed parameters
|
andrewm@0
|
93 virtual void resend() {}
|
andrewm@0
|
94
|
andrewm@0
|
95 // ***** Evaluators *****
|
andrewm@0
|
96 // These are the main mapping functions, and they need to be implemented
|
andrewm@0
|
97 // specifically in any subclass.
|
andrewm@0
|
98
|
andrewm@0
|
99 // This method receives triggers whenever events occur in the touch data or the
|
andrewm@0
|
100 // continuous key position (state changes only).
|
andrewm@0
|
101 virtual void triggerReceived(TriggerSource* who, timestamp_type timestamp) = 0;
|
andrewm@0
|
102
|
andrewm@0
|
103 // This method is run periodically the Scheduler provided by PianoKeyboard and
|
andrewm@0
|
104 // handles the actual work of performing the mapping.
|
andrewm@0
|
105 virtual timestamp_type performMapping() = 0;
|
andrewm@0
|
106
|
andrewm@0
|
107 // Indicate whether the mapping has finished all of its processing and can be deleted.
|
andrewm@0
|
108 // By default a mapping can be deleted whenever the factory wants to, but some
|
andrewm@0
|
109 // may persist beyond note release for a limited period of time.
|
andrewm@0
|
110 virtual bool requestFinish() { return true; }
|
andrewm@0
|
111
|
andrewm@0
|
112 protected:
|
andrewm@0
|
113
|
andrewm@0
|
114 // ***** Member Variables *****
|
andrewm@0
|
115
|
andrewm@0
|
116 PianoKeyboard& keyboard_; // Reference to the main keyboard controller
|
andrewm@0
|
117 MappingFactory *factory_; // Factory that created this mapping
|
andrewm@0
|
118 int noteNumber_; // MIDI note number for this key
|
andrewm@0
|
119 Node<KeyTouchFrame>* touchBuffer_; // Key touch location history
|
andrewm@0
|
120 Node<key_position>* positionBuffer_; // Raw key position data
|
andrewm@0
|
121 KeyPositionTracker* positionTracker_; // Object which manages states of key
|
andrewm@0
|
122
|
andrewm@0
|
123 bool engaged_; // Whether we're actively mapping
|
andrewm@0
|
124 bool suspended_; // Whether we're suppressing messages
|
andrewm@0
|
125 timestamp_diff_type updateInterval_; // How long between mapping calls
|
andrewm@0
|
126 timestamp_type nextScheduledTimestamp_; // When we've asked for the next callback
|
andrewm@0
|
127 Scheduler::action mappingAction_; // Action function which calls performMapping()
|
andrewm@0
|
128 };
|
andrewm@0
|
129
|
andrewm@0
|
130
|
andrewm@0
|
131 #endif
|