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 MappingFactory.h: base class for creating mappings. A factory is a singular
|
andrewm@0
|
21 object, attached to a particular keyboard segment, which in turn allocates
|
andrewm@0
|
22 and destroys individual Mapping objects for each active note. The factory
|
andrewm@0
|
23 also is the usual point at which parameter changes are made.
|
andrewm@0
|
24 */
|
andrewm@0
|
25
|
andrewm@0
|
26 #ifndef __touchkeys__MappingFactory__
|
andrewm@0
|
27 #define __touchkeys__MappingFactory__
|
andrewm@0
|
28
|
andrewm@0
|
29 #include <map>
|
andrewm@0
|
30 #include <boost/bind.hpp>
|
andrewm@0
|
31 #include "Mapping.h"
|
andrewm@0
|
32 #include "../GUI/MappingEditorComponent.h"
|
andrewm@0
|
33
|
andrewm@0
|
34 // This virtual base class defines a singular factory object from which individual
|
andrewm@0
|
35 // instances of mapping objects can be created and destroyed. How the mappings are
|
andrewm@0
|
36 // allocated and when is up to the factory, which also keeps track of which ones
|
andrewm@0
|
37 // are active. The PianoKey class will call into any active factories when certain
|
andrewm@0
|
38 // events occur: touch on/off, MIDI on/off, key idle/active.
|
andrewm@0
|
39
|
andrewm@0
|
40 class MappingFactory {
|
andrewm@0
|
41 public:
|
andrewm@0
|
42 // States for bypass status
|
andrewm@0
|
43 enum {
|
andrewm@0
|
44 kBypassOff = 0,
|
andrewm@0
|
45 kBypassOn,
|
andrewm@0
|
46 kBypassMixed
|
andrewm@0
|
47 };
|
andrewm@0
|
48
|
andrewm@0
|
49 // ***** Constructor *****
|
andrewm@0
|
50
|
andrewm@0
|
51 // Default constructor, containing a reference to the PianoKeyboard class.
|
andrewm@0
|
52 MappingFactory(PianoKeyboard &keyboard) : keyboard_(keyboard) {}
|
andrewm@0
|
53
|
andrewm@0
|
54 // ***** Destructor *****
|
andrewm@0
|
55
|
andrewm@0
|
56 virtual ~MappingFactory() {}
|
andrewm@0
|
57
|
andrewm@0
|
58 // ***** Accessors / Modifiers *****
|
andrewm@0
|
59
|
andrewm@0
|
60 // Generic name for this type of factory
|
andrewm@0
|
61 virtual const std::string factoryTypeName() { return "Unknown\nMapping"; }
|
andrewm@0
|
62
|
andrewm@0
|
63 // Specific name for this particular factory
|
andrewm@0
|
64 virtual string const getName() { return ""; }
|
andrewm@0
|
65 virtual void setName(const string& name) {}
|
andrewm@0
|
66
|
andrewm@0
|
67 virtual Mapping* mapping(int noteNumber) = 0; // Look up a mapping with the given note number
|
andrewm@0
|
68 virtual std::vector<int> activeMappings() = 0; // Return a list of all active notes
|
andrewm@0
|
69
|
andrewm@0
|
70 virtual void removeAllMappings() = 0; // Remove all active mappings
|
andrewm@0
|
71 virtual void mappingFinished(int noteNumber) = 0; // Callback from mapping to say it's done
|
andrewm@0
|
72
|
andrewm@0
|
73 // Suspending mappings is a state managed internally by the TouchKeys
|
andrewm@0
|
74 // controllers, for example to turn off a mapping of an older note in monophonic
|
andrewm@0
|
75 // mode. By contrast, bypassing a mapping is intended to be manipulated from
|
andrewm@0
|
76 // an external UI.
|
andrewm@0
|
77
|
andrewm@0
|
78 virtual void suspendMapping(int noteNumber) = 0; // Suspend messages from a particular note
|
andrewm@0
|
79 virtual void suspendAllMappings() = 0; // ... or all notes
|
andrewm@0
|
80 virtual void resumeMapping(int noteNumber, bool resend) = 0; // Resume messages from a particular note
|
andrewm@0
|
81 virtual void resumeAllMappings(bool resend) = 0; // ... or all notes
|
andrewm@0
|
82
|
andrewm@0
|
83 virtual int bypassed() = 0; // Whether this mapping is bypassed
|
andrewm@0
|
84 virtual void setBypassed(bool bypass) = 0; // Set whether the mapping is bypassed or not
|
andrewm@0
|
85
|
andrewm@0
|
86 // ***** State Updaters *****
|
andrewm@0
|
87
|
andrewm@0
|
88 // These are called by PianoKey whenever certain events occur that might
|
andrewm@0
|
89 // merit the start and stop of a mapping. What is done with them depends on
|
andrewm@0
|
90 // the particular factory subclass. The relevant buffers are passed in each
|
andrewm@0
|
91 // time so the factory or the mapping can make use of them
|
andrewm@0
|
92
|
andrewm@0
|
93 // Touch becomes active on a key where it wasn't previously
|
andrewm@0
|
94 virtual void touchBegan(int noteNumber, bool midiNoteIsOn, bool keyMotionActive,
|
andrewm@0
|
95 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
96 Node<key_position>* positionBuffer,
|
andrewm@0
|
97 KeyPositionTracker* positionTracker) = 0;
|
andrewm@0
|
98 // Touch ends on a key where it wasn't previously
|
andrewm@0
|
99 virtual void touchEnded(int noteNumber, bool midiNoteIsOn, bool keyMotionActive,
|
andrewm@0
|
100 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
101 Node<key_position>* positionBuffer,
|
andrewm@0
|
102 KeyPositionTracker* positionTracker) = 0;
|
andrewm@0
|
103 // MIDI note on for a key
|
andrewm@0
|
104 virtual void midiNoteOn(int noteNumber, bool touchIsOn, bool keyMotionActive,
|
andrewm@0
|
105 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
106 Node<key_position>* positionBuffer,
|
andrewm@0
|
107 KeyPositionTracker* positionTracker) = 0;
|
andrewm@0
|
108 // MIDI note off for a key
|
andrewm@0
|
109 virtual void midiNoteOff(int noteNumber, bool touchIsOn, bool keyMotionActive,
|
andrewm@0
|
110 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
111 Node<key_position>* positionBuffer,
|
andrewm@0
|
112 KeyPositionTracker* positionTracker) = 0;
|
andrewm@0
|
113 // Key goes active from continuous key position
|
andrewm@0
|
114 virtual void keyMotionActive(int noteNumber, bool midiNoteIsOn, bool touchIsOn,
|
andrewm@0
|
115 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
116 Node<key_position>* positionBuffer,
|
andrewm@0
|
117 KeyPositionTracker* positionTracker) = 0;
|
andrewm@0
|
118 // Key goes idle from continuous key position
|
andrewm@0
|
119 virtual void keyMotionIdle(int noteNumber, bool midiNoteIsOn, bool touchIsOn,
|
andrewm@0
|
120 Node<KeyTouchFrame>* touchBuffer,
|
andrewm@0
|
121 Node<key_position>* positionBuffer,
|
andrewm@0
|
122 KeyPositionTracker* positionTracker) = 0;
|
andrewm@0
|
123
|
andrewm@0
|
124 // Notification from key that a note is about to be sent out
|
andrewm@0
|
125 virtual void noteWillBegin(int noteNumber, int midiChannel, int midiVelocity) = 0;
|
andrewm@0
|
126
|
andrewm@0
|
127 // ***** GUI Support *****
|
andrewm@0
|
128 // There are two types of editors for a mapping: one is a small editor that fits in the
|
andrewm@0
|
129 // list view for adjusting the most important parameters, the other goes in a window of
|
andrewm@0
|
130 // its own to adjust every parameter.
|
andrewm@0
|
131
|
andrewm@0
|
132 virtual bool hasBasicEditor() { return false; }
|
andrewm@0
|
133 virtual MappingEditorComponent* createBasicEditor() { return nullptr; }
|
andrewm@0
|
134 virtual bool hasExtendedEditor() { return false; }
|
andrewm@0
|
135 virtual MappingEditorComponent* createExtendedEditor() { return nullptr; }
|
andrewm@0
|
136
|
andrewm@33
|
137 // ****** Preset Save/Load ******
|
andrewm@33
|
138 // These methods generate XML settings files and reload values from them
|
andrewm@33
|
139 // The specific implementation is up to the subclass
|
andrewm@33
|
140
|
andrewm@33
|
141 virtual XmlElement* getPreset() = 0;
|
andrewm@33
|
142 virtual bool loadPreset(XmlElement const* preset) = 0;
|
andrewm@33
|
143
|
andrewm@0
|
144 protected:
|
andrewm@0
|
145 // ***** Member Variables *****
|
andrewm@0
|
146
|
andrewm@0
|
147 PianoKeyboard& keyboard_; // Reference to the main keyboard controller
|
andrewm@0
|
148
|
andrewm@0
|
149 private:
|
andrewm@0
|
150 //JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MappingFactory)
|
andrewm@0
|
151 };
|
andrewm@0
|
152
|
andrewm@0
|
153 #endif /* defined(__touchkeys__MappingFactory__) */
|