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 MappingFactorySplitter.h: MappingFactory subclass which in turn contains
|
andrewm@0
|
21 several factories, routing all incoming method calls to each of them.
|
andrewm@0
|
22 */
|
andrewm@0
|
23
|
andrewm@0
|
24 #ifndef __touchkeys__TouchkeyMappingFactorySplitter__
|
andrewm@0
|
25 #define __touchkeys__TouchkeyMappingFactorySplitter__
|
andrewm@0
|
26
|
andrewm@0
|
27 #include <iostream>
|
andrewm@0
|
28 #include <list>
|
andrewm@0
|
29 #include "MappingFactory.h"
|
andrewm@0
|
30
|
andrewm@0
|
31 // Factory class to produce Touchkey vibrato (pitch-bend) mappings
|
andrewm@0
|
32 // This class keeps track of all the active mappings and responds
|
andrewm@0
|
33 // whenever touches or notes begin or end
|
andrewm@0
|
34
|
andrewm@0
|
35 class MappingFactorySplitter : public MappingFactory {
|
andrewm@0
|
36 public:
|
andrewm@0
|
37 // ***** Constructor *****
|
andrewm@0
|
38
|
andrewm@0
|
39 // Default constructor, containing a reference to the PianoKeyboard class.
|
andrewm@0
|
40 MappingFactorySplitter(PianoKeyboard &keyboard) : MappingFactory(keyboard), bypassNewMappings_(false) {}
|
andrewm@0
|
41
|
andrewm@0
|
42 // ***** Destructor *****
|
andrewm@0
|
43
|
andrewm@0
|
44 ~MappingFactorySplitter() {
|
andrewm@0
|
45 removeAllFactories();
|
andrewm@0
|
46 }
|
andrewm@0
|
47
|
andrewm@0
|
48 // ***** Accessors / Modifiers *****
|
andrewm@0
|
49
|
andrewm@0
|
50 Mapping* mapping(int noteNumber); // Look up a mapping with the given note number
|
andrewm@0
|
51 std::vector<int> activeMappings(); // Return a list of all active notes
|
andrewm@0
|
52
|
andrewm@0
|
53 void removeAllMappings(); // Remove all active mappings
|
andrewm@0
|
54 void mappingFinished(int noteNumber) {} // Callback from a mapping to say it's finished.
|
andrewm@0
|
55 // Nobody should ever call this since we don't have our own mappings
|
andrewm@0
|
56
|
andrewm@0
|
57 void suspendMapping(int noteNumber); // Suspend messages from a particular note
|
andrewm@0
|
58 void suspendAllMappings(); // ... or all notes
|
andrewm@0
|
59 void resumeMapping(int noteNumber, bool resend); // Resume messages from a particular note
|
andrewm@0
|
60 void resumeAllMappings(bool resend); // ... or all notes
|
andrewm@0
|
61
|
andrewm@0
|
62 int bypassed(); // Whether this mapping is bypassed
|
andrewm@0
|
63 void setBypassed(bool bypass); // Set whether the mapping is bypassed or not
|
andrewm@0
|
64
|
andrewm@0
|
65 // ***** Specific Methods *****
|
andrewm@0
|
66
|
andrewm@0
|
67 void addFactory(MappingFactory* factory);
|
andrewm@0
|
68 void removeFactory(MappingFactory* factory);
|
andrewm@0
|
69 void removeAllFactories();
|
andrewm@33
|
70
|
andrewm@33
|
71 // ****** Preset Save/Load ******
|
andrewm@33
|
72 // These methods generate XML settings files and reload values from them
|
andrewm@33
|
73 // The specific implementation is up to the subclass
|
andrewm@33
|
74
|
andrewm@33
|
75 XmlElement* getPreset();
|
andrewm@33
|
76 bool loadPreset(XmlElement const* preset);
|
andrewm@0
|
77
|
andrewm@0
|
78 // ***** State Updaters *****
|
andrewm@0
|
79
|
andrewm@0
|
80 // These are called by PianoKey whenever certain events occur that might
|
andrewm@0
|
81 // merit the start and stop of a mapping. What is done with them depends on
|
andrewm@0
|
82 // the particular factory subclass.
|
andrewm@0
|
83
|
andrewm@0
|
84 // Touch becomes active on a key where it wasn't previously
|
andrewm@0
|
85 void touchBegan(int noteNumber, bool midiNoteIsOn, bool keyMotionActive,
|
andrewm@0
|
86 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
87 Node<key_position>* positionBuffer,
|
andrewm@0
|
88 KeyPositionTracker* positionTracker);
|
andrewm@0
|
89 // Touch ends on a key where it wasn't previously
|
andrewm@0
|
90 void touchEnded(int noteNumber, bool midiNoteIsOn, bool keyMotionActive,
|
andrewm@0
|
91 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
92 Node<key_position>* positionBuffer,
|
andrewm@0
|
93 KeyPositionTracker* positionTracker);
|
andrewm@0
|
94 // MIDI note on for a key
|
andrewm@0
|
95 void midiNoteOn(int noteNumber, bool touchIsOn, bool keyMotionActive,
|
andrewm@0
|
96 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
97 Node<key_position>* positionBuffer,
|
andrewm@0
|
98 KeyPositionTracker* positionTracker);
|
andrewm@0
|
99 // MIDI note off for a key
|
andrewm@0
|
100 void midiNoteOff(int noteNumber, bool touchIsOn, bool keyMotionActive,
|
andrewm@0
|
101 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
102 Node<key_position>* positionBuffer,
|
andrewm@0
|
103 KeyPositionTracker* positionTracker);
|
andrewm@0
|
104 // Key goes active from continuous key position
|
andrewm@0
|
105 void keyMotionActive(int noteNumber, bool midiNoteIsOn, bool touchIsOn,
|
andrewm@0
|
106 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
107 Node<key_position>* positionBuffer,
|
andrewm@0
|
108 KeyPositionTracker* positionTracker);
|
andrewm@0
|
109 // Key goes idle from continuous key position
|
andrewm@0
|
110 void keyMotionIdle(int noteNumber, bool midiNoteIsOn, bool touchIsOn,
|
andrewm@0
|
111 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
112 Node<key_position>* positionBuffer,
|
andrewm@0
|
113 KeyPositionTracker* positionTracker);
|
andrewm@0
|
114 // MIDI note about to begin
|
andrewm@0
|
115 void noteWillBegin(int noteNumber, int midiChannel, int midiVelocity);
|
andrewm@0
|
116
|
andrewm@0
|
117 private:
|
andrewm@0
|
118
|
andrewm@0
|
119 // State variables
|
andrewm@0
|
120 std::list<MappingFactory*> factories_; // List of child factories
|
andrewm@0
|
121 bool bypassNewMappings_; // Whether to bypass mappings that are added
|
andrewm@0
|
122 };
|
andrewm@0
|
123
|
andrewm@0
|
124 #endif /* defined(__touchkeys__TouchkeyMappingFactorySplitter__) */
|