comparison Source/Mappings/MappingFactory.h @ 0:3580ffe87dc8

First commit of TouchKeys public pre-release.
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Mon, 11 Nov 2013 18:19:35 +0000
parents
children e8965409903e
comparison
equal deleted inserted replaced
-1:000000000000 0:3580ffe87dc8
1 /*
2 TouchKeys: multi-touch musical keyboard control software
3 Copyright (c) 2013 Andrew McPherson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 =====================================================================
19
20 MappingFactory.h: base class for creating mappings. A factory is a singular
21 object, attached to a particular keyboard segment, which in turn allocates
22 and destroys individual Mapping objects for each active note. The factory
23 also is the usual point at which parameter changes are made.
24 */
25
26 #ifndef __touchkeys__MappingFactory__
27 #define __touchkeys__MappingFactory__
28
29 #include <map>
30 #include <boost/bind.hpp>
31 #include "Mapping.h"
32 #include "../GUI/MappingEditorComponent.h"
33
34 // This virtual base class defines a singular factory object from which individual
35 // instances of mapping objects can be created and destroyed. How the mappings are
36 // allocated and when is up to the factory, which also keeps track of which ones
37 // are active. The PianoKey class will call into any active factories when certain
38 // events occur: touch on/off, MIDI on/off, key idle/active.
39
40 class MappingFactory {
41 public:
42 // States for bypass status
43 enum {
44 kBypassOff = 0,
45 kBypassOn,
46 kBypassMixed
47 };
48
49 // ***** Constructor *****
50
51 // Default constructor, containing a reference to the PianoKeyboard class.
52 MappingFactory(PianoKeyboard &keyboard) : keyboard_(keyboard) {}
53
54 // ***** Destructor *****
55
56 virtual ~MappingFactory() {}
57
58 // ***** Accessors / Modifiers *****
59
60 // Generic name for this type of factory
61 virtual const std::string factoryTypeName() { return "Unknown\nMapping"; }
62
63 // Specific name for this particular factory
64 virtual string const getName() { return ""; }
65 virtual void setName(const string& name) {}
66
67 virtual Mapping* mapping(int noteNumber) = 0; // Look up a mapping with the given note number
68 virtual std::vector<int> activeMappings() = 0; // Return a list of all active notes
69
70 virtual void removeAllMappings() = 0; // Remove all active mappings
71 virtual void mappingFinished(int noteNumber) = 0; // Callback from mapping to say it's done
72
73 // Suspending mappings is a state managed internally by the TouchKeys
74 // controllers, for example to turn off a mapping of an older note in monophonic
75 // mode. By contrast, bypassing a mapping is intended to be manipulated from
76 // an external UI.
77
78 virtual void suspendMapping(int noteNumber) = 0; // Suspend messages from a particular note
79 virtual void suspendAllMappings() = 0; // ... or all notes
80 virtual void resumeMapping(int noteNumber, bool resend) = 0; // Resume messages from a particular note
81 virtual void resumeAllMappings(bool resend) = 0; // ... or all notes
82
83 virtual int bypassed() = 0; // Whether this mapping is bypassed
84 virtual void setBypassed(bool bypass) = 0; // Set whether the mapping is bypassed or not
85
86 // ***** State Updaters *****
87
88 // These are called by PianoKey whenever certain events occur that might
89 // merit the start and stop of a mapping. What is done with them depends on
90 // the particular factory subclass. The relevant buffers are passed in each
91 // time so the factory or the mapping can make use of them
92
93 // Touch becomes active on a key where it wasn't previously
94 virtual void touchBegan(int noteNumber, bool midiNoteIsOn, bool keyMotionActive,
95 Node<KeyTouchFrame>* touchBuffer,
96 Node<key_position>* positionBuffer,
97 KeyPositionTracker* positionTracker) = 0;
98 // Touch ends on a key where it wasn't previously
99 virtual void touchEnded(int noteNumber, bool midiNoteIsOn, bool keyMotionActive,
100 Node<KeyTouchFrame>* touchBuffer,
101 Node<key_position>* positionBuffer,
102 KeyPositionTracker* positionTracker) = 0;
103 // MIDI note on for a key
104 virtual void midiNoteOn(int noteNumber, bool touchIsOn, bool keyMotionActive,
105 Node<KeyTouchFrame>* touchBuffer,
106 Node<key_position>* positionBuffer,
107 KeyPositionTracker* positionTracker) = 0;
108 // MIDI note off for a key
109 virtual void midiNoteOff(int noteNumber, bool touchIsOn, bool keyMotionActive,
110 Node<KeyTouchFrame>* touchBuffer,
111 Node<key_position>* positionBuffer,
112 KeyPositionTracker* positionTracker) = 0;
113 // Key goes active from continuous key position
114 virtual void keyMotionActive(int noteNumber, bool midiNoteIsOn, bool touchIsOn,
115 Node<KeyTouchFrame>* touchBuffer,
116 Node<key_position>* positionBuffer,
117 KeyPositionTracker* positionTracker) = 0;
118 // Key goes idle from continuous key position
119 virtual void keyMotionIdle(int noteNumber, bool midiNoteIsOn, bool touchIsOn,
120 Node<KeyTouchFrame>* touchBuffer,
121 Node<key_position>* positionBuffer,
122 KeyPositionTracker* positionTracker) = 0;
123
124 // Notification from key that a note is about to be sent out
125 virtual void noteWillBegin(int noteNumber, int midiChannel, int midiVelocity) = 0;
126
127 // ***** GUI Support *****
128 // There are two types of editors for a mapping: one is a small editor that fits in the
129 // list view for adjusting the most important parameters, the other goes in a window of
130 // its own to adjust every parameter.
131
132 virtual bool hasBasicEditor() { return false; }
133 virtual MappingEditorComponent* createBasicEditor() { return nullptr; }
134 virtual bool hasExtendedEditor() { return false; }
135 virtual MappingEditorComponent* createExtendedEditor() { return nullptr; }
136
137 protected:
138 // ***** Member Variables *****
139
140 PianoKeyboard& keyboard_; // Reference to the main keyboard controller
141
142 private:
143 //JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MappingFactory)
144 };
145
146 #endif /* defined(__touchkeys__MappingFactory__) */