1 |
schoenebeck |
201 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
1695 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
schoenebeck |
201 |
* * |
8 |
|
|
* This program is free software; you can redistribute it and/or modify * |
9 |
|
|
* it under the terms of the GNU General Public License as published by * |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
11 |
|
|
* (at your option) any later version. * |
12 |
|
|
* * |
13 |
|
|
* This program is distributed in the hope that it will be useful, * |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
|
|
* GNU General Public License for more details. * |
17 |
|
|
* * |
18 |
|
|
* You should have received a copy of the GNU General Public License * |
19 |
|
|
* along with this program; if not, write to the Free Software * |
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
|
|
* MA 02111-1307 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
#ifndef __LS_MIDIINPUTDEVICE_H__ |
25 |
|
|
#define __LS_MIDIINPUTDEVICE_H__ |
26 |
|
|
|
27 |
|
|
#include <stdexcept> |
28 |
|
|
#include <set> |
29 |
|
|
#include <map> |
30 |
|
|
#include <vector> |
31 |
|
|
|
32 |
|
|
#include "../../common/global.h" |
33 |
schoenebeck |
880 |
#include "../../common/Exception.h" |
34 |
schoenebeck |
201 |
#include "../DeviceParameter.h" |
35 |
schoenebeck |
221 |
#include "MidiInputPort.h" |
36 |
schoenebeck |
890 |
#include "../../engines/Engine.h" |
37 |
schoenebeck |
1695 |
#include "../../EventListeners.h" |
38 |
schoenebeck |
201 |
|
39 |
|
|
namespace LinuxSampler { |
40 |
|
|
|
41 |
|
|
// just symbol prototyping |
42 |
schoenebeck |
221 |
class MidiInputPort; |
43 |
schoenebeck |
201 |
class Engine; |
44 |
|
|
|
45 |
schoenebeck |
221 |
/** |
46 |
|
|
* Midi input exception that should be thrown by the MidiInputDevice |
47 |
|
|
* descendants in case initialization of the MIDI input system failed |
48 |
|
|
* (which should be done in the constructor of the MidiInputDevice |
49 |
|
|
* descendant). |
50 |
|
|
*/ |
51 |
schoenebeck |
880 |
class MidiInputException : public Exception { |
52 |
schoenebeck |
221 |
public: |
53 |
schoenebeck |
880 |
MidiInputException(const std::string& msg) : Exception(msg) {} |
54 |
schoenebeck |
221 |
}; |
55 |
|
|
|
56 |
schoenebeck |
201 |
/** Abstract base class for MIDI input drivers in LinuxSampler |
57 |
|
|
* |
58 |
|
|
* This class will be derived by specialized classes which implement the |
59 |
|
|
* connection to a specific MIDI input system (e.g. Alsa Sequencer, |
60 |
|
|
* CoreMIDI). The MidiInputDevice desendant should just call the |
61 |
|
|
* appropriate (protected) Dispatch* method here when an MIDI event |
62 |
|
|
* occured. The dispatch* methods here will automatically forward the |
63 |
|
|
* MIDI event to the appropriate, connected sampler engines. |
64 |
|
|
*/ |
65 |
schoenebeck |
207 |
class MidiInputDevice : public Device { |
66 |
schoenebeck |
201 |
public: |
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////// |
69 |
|
|
// type definitions |
70 |
|
|
|
71 |
schoenebeck |
221 |
/** Device Parameter 'ACTIVE' |
72 |
|
|
* |
73 |
|
|
* Used to activate / deactivate the MIDI input device. |
74 |
|
|
*/ |
75 |
schoenebeck |
201 |
class ParameterActive : public DeviceCreationParameterBool { |
76 |
schoenebeck |
221 |
public: |
77 |
|
|
ParameterActive(); |
78 |
|
|
ParameterActive(String active); |
79 |
|
|
virtual String Description(); |
80 |
|
|
virtual bool Fix(); |
81 |
|
|
virtual bool Mandatory(); |
82 |
|
|
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
83 |
|
|
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters); |
84 |
schoenebeck |
880 |
virtual void OnSetValue(bool b) throw (Exception); |
85 |
schoenebeck |
221 |
static String Name(); |
86 |
|
|
}; |
87 |
schoenebeck |
201 |
|
88 |
schoenebeck |
221 |
/** Device Parameter 'PORTS' |
89 |
|
|
* |
90 |
|
|
* Used to increase / decrease the number of MIDI ports of the |
91 |
|
|
* MIDI input device. |
92 |
|
|
*/ |
93 |
|
|
class ParameterPorts : public DeviceCreationParameterInt { |
94 |
|
|
public: |
95 |
|
|
ParameterPorts(); |
96 |
|
|
ParameterPorts(String val); |
97 |
|
|
virtual String Description(); |
98 |
|
|
virtual bool Fix(); |
99 |
|
|
virtual bool Mandatory(); |
100 |
|
|
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
101 |
|
|
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); |
102 |
|
|
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); |
103 |
|
|
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); |
104 |
|
|
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); |
105 |
schoenebeck |
880 |
virtual void OnSetValue(int i) throw (Exception); |
106 |
schoenebeck |
221 |
static String Name(); |
107 |
|
|
}; |
108 |
schoenebeck |
201 |
|
109 |
|
|
|
110 |
|
|
|
111 |
schoenebeck |
221 |
///////////////////////////////////////////////////////////////// |
112 |
|
|
// abstract methods |
113 |
|
|
// (these have to be implemented by the descendant) |
114 |
schoenebeck |
201 |
|
115 |
schoenebeck |
221 |
/** |
116 |
|
|
* Start listen to MIDI input events on the MIDI input port. |
117 |
|
|
* The MIDIInputPort descendant should forward all MIDI input |
118 |
|
|
* events by calling the appropriate (protected) Dispatch* |
119 |
|
|
* method of class MidiInputPort. |
120 |
|
|
*/ |
121 |
|
|
virtual void Listen() = 0; |
122 |
schoenebeck |
201 |
|
123 |
schoenebeck |
221 |
/** |
124 |
|
|
* Stop to listen to MIDI input events on the MIDI input port. |
125 |
|
|
* After this method was called, the MidiInputPort descendant |
126 |
|
|
* should ignore all MIDI input events. |
127 |
|
|
*/ |
128 |
|
|
virtual void StopListen() = 0; |
129 |
schoenebeck |
201 |
|
130 |
schoenebeck |
221 |
/** |
131 |
|
|
* Return device driver name |
132 |
|
|
*/ |
133 |
|
|
virtual String Driver() = 0; |
134 |
schoenebeck |
201 |
|
135 |
schoenebeck |
221 |
/** |
136 |
|
|
* Create new Midi port |
137 |
|
|
* This will be called by AcquirePorts |
138 |
|
|
* Each individual device must implement this. |
139 |
|
|
*/ |
140 |
|
|
virtual MidiInputPort* CreateMidiPort() = 0; |
141 |
schoenebeck |
201 |
|
142 |
|
|
|
143 |
|
|
|
144 |
schoenebeck |
221 |
///////////////////////////////////////////////////////////////// |
145 |
|
|
// normal methods |
146 |
|
|
// (usually not to be overriden by descendant) |
147 |
schoenebeck |
201 |
|
148 |
schoenebeck |
221 |
/** |
149 |
|
|
* Return midi port \a iPort. |
150 |
|
|
* |
151 |
|
|
* @throws MidiInputException if index out of bounds |
152 |
|
|
*/ |
153 |
|
|
MidiInputPort* GetPort(uint iPort) throw (MidiInputException); |
154 |
schoenebeck |
201 |
|
155 |
schoenebeck |
221 |
/** |
156 |
schoenebeck |
1695 |
* Returns amount of MIDI ports this MIDI input device currently |
157 |
|
|
* provides. |
158 |
|
|
*/ |
159 |
|
|
uint PortCount(); |
160 |
|
|
|
161 |
|
|
/** |
162 |
schoenebeck |
221 |
* Return all device parameter settings. |
163 |
|
|
*/ |
164 |
|
|
std::map<String,DeviceCreationParameter*> DeviceParameters(); |
165 |
schoenebeck |
201 |
|
166 |
schoenebeck |
1695 |
/** |
167 |
|
|
* Registers the specified listener to be notified |
168 |
|
|
* when the number of MIDI input ports is changed. |
169 |
|
|
*/ |
170 |
|
|
void AddMidiPortCountListener(MidiPortCountListener* l); |
171 |
|
|
|
172 |
|
|
/** |
173 |
|
|
* Removes the specified listener, to stop being notified of |
174 |
|
|
* further MIDI input port count chances. |
175 |
|
|
*/ |
176 |
|
|
void RemoveMidiPortCountListener(MidiPortCountListener* l); |
177 |
|
|
|
178 |
schoenebeck |
201 |
protected: |
179 |
schoenebeck |
221 |
std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters. |
180 |
schoenebeck |
551 |
std::map<int,MidiInputPort*> Ports; ///< All MIDI ports. |
181 |
|
|
void* pSampler; ///< Sampler instance. FIXME: should actually be of type Sampler* |
182 |
schoenebeck |
1695 |
ListenerList<MidiPortCountListener*> portCountListeners; |
183 |
schoenebeck |
201 |
|
184 |
schoenebeck |
221 |
/** |
185 |
|
|
* Constructor |
186 |
schoenebeck |
551 |
* |
187 |
|
|
* FIXME: the pointer argument \a pSapmler should actually be of type Sampler*. |
188 |
|
|
* Unfortunately the bidirectional relationship between this |
189 |
|
|
* header and Sampler.h would clash on header file inclusion, |
190 |
|
|
* so that's why I had to make it of type void* here. This is |
191 |
|
|
* an annoying constraint of C++. |
192 |
schoenebeck |
221 |
*/ |
193 |
schoenebeck |
551 |
MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler); |
194 |
schoenebeck |
201 |
|
195 |
schoenebeck |
221 |
/** |
196 |
|
|
* Destructor |
197 |
|
|
*/ |
198 |
|
|
virtual ~MidiInputDevice(); |
199 |
schoenebeck |
201 |
|
200 |
|
|
/** |
201 |
schoenebeck |
1695 |
* Notifies listeners that the amount of MIDI inpurt ports have |
202 |
|
|
* been changed. |
203 |
|
|
* @param NewCount The new number of MIDI input ports. |
204 |
|
|
*/ |
205 |
|
|
void fireMidiPortCountChanged(int NewCount); |
206 |
|
|
|
207 |
|
|
/** |
208 |
|
|
* Notifies listeners that the supplied MIDI input port is |
209 |
|
|
* going to be removed soon. |
210 |
|
|
* @param pPort The MIDI input port that is going to be removed. |
211 |
|
|
*/ |
212 |
|
|
void fireMidiPortToBeRemoved(MidiInputPort* pPort); |
213 |
|
|
|
214 |
|
|
/** |
215 |
|
|
* Notifies listeners that the supplied MIDI input port has |
216 |
|
|
* just been added. |
217 |
|
|
* @param pPort The MIDI input port that has been added. |
218 |
|
|
*/ |
219 |
|
|
void fireMidiPortAdded(MidiInputPort* pPort); |
220 |
|
|
|
221 |
|
|
/** |
222 |
schoenebeck |
201 |
* Set number of MIDI ports required by the engine |
223 |
schoenebeck |
221 |
* This can either do nothing, create more ports |
224 |
|
|
* or destroy ports depenging on the parameter |
225 |
|
|
* and how many ports already exist on this driver. |
226 |
schoenebeck |
201 |
* |
227 |
|
|
* @param Ports - number of ports to be left on this driver after this call. |
228 |
|
|
*/ |
229 |
schoenebeck |
221 |
void AcquirePorts(uint Ports); |
230 |
schoenebeck |
201 |
|
231 |
schoenebeck |
277 |
friend class ParameterActive; |
232 |
|
|
friend class ParameterPorts; |
233 |
schoenebeck |
221 |
friend class Sampler; // allow Sampler class to destroy midi devices |
234 |
schoenebeck |
551 |
friend class MidiInputPort; // allow MidiInputPort to access pSampler |
235 |
schoenebeck |
201 |
}; |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
#endif // __LS_MIDIINPUTDEVICE_H__ |