/[svn]/linuxsampler/trunk/src/EventListeners.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/EventListeners.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2012 - (show annotations) (download) (as text)
Fri Oct 23 17:53:17 2009 UTC (14 years, 5 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 13215 byte(s)
* Refactoring: moved the independent code from
  the Gigasampler format engine to base classes
* SFZ format engine: experimental code (not usable yet)
* SoundFont format engine: experimental code (not usable yet)
* Fixed crash which may occur when MIDI key + transpose is out of range

1 /***************************************************************************
2 * *
3 * Copyright (C) 2007, 2008 Grigor Iliev *
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 2 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, write to the Free Software *
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
18 * MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #ifndef __LS_EVENTLISTENERS_H__
22 #define __LS_EVENTLISTENERS_H__
23
24 #include <vector>
25 #include "common/global.h"
26
27 namespace LinuxSampler {
28
29 // just symbol prototyping
30 class SamplerChannel;
31 class MidiInputDevice;
32 class MidiInputPort;
33
34 template<class L>
35 class ListenerList {
36 public:
37 /**
38 * Registers the specified listener for receiving event messages.
39 */
40 void AddListener(L l) {
41 vListenerList.push_back(l);
42 }
43
44 /**
45 * Removes the specified listener.
46 */
47 void RemoveListener(L l) {
48 typename std::vector<L>::iterator it;
49 it = vListenerList.begin();
50 for (; it != vListenerList.end(); it++) {
51 if (*it == l) {
52 vListenerList.erase(it);
53 return;
54 }
55 }
56 }
57
58 /**
59 * Removes all listeners.
60 */
61 void RemoveAllListeners() {
62 vListenerList.clear();
63 }
64
65 /**
66 * Gets the number of the registered listeners.
67 */
68 int GetListenerCount() {
69 return vListenerList.size();
70 }
71
72 /**
73 * Gets the listener at the specified position.
74 * @param index The position of the listener to return.
75 */
76 L GetListener(int index) {
77 return vListenerList.at(index);
78 }
79
80 private:
81 std::vector<L> vListenerList;
82 };
83
84 #define REGISTER_FIRE_EVENT_METHOD(method) virtual void method() \
85 { for(int i = 0; i < GetListenerCount(); i++) GetListener(i)->method(); }
86
87 #define REGISTER_FIRE_EVENT_METHOD_ARG1(method, T1) virtual void method(T1 _evt_arg1_) \
88 { for(int i = 0; i < GetListenerCount(); i++) GetListener(i)->method(_evt_arg1_); }
89
90 #define REGISTER_FIRE_EVENT_METHOD_ARG2(method, T1, T2) virtual void method(T1 _evt_arg1_, T2 _evt_arg2_) \
91 { for(int i = 0; i < GetListenerCount(); i++) GetListener(i)->method(_evt_arg1_, _evt_arg2_); }
92
93 /**
94 * This class is used as a listener, which is notified
95 * when the number of sampler channels is changed.
96 */
97 class ChannelCountListener {
98 public:
99 /**
100 * Invoked when the number of sampler channels has changed.
101 * @param NewCount The new number of sampler channels.
102 */
103 virtual void ChannelCountChanged(int NewCount) = 0;
104 virtual void ChannelAdded(SamplerChannel* pChannel) = 0;
105 virtual void ChannelToBeRemoved(SamplerChannel* pChannel) = 0;
106 };
107
108 /**
109 * This class exists as convenience for creating listener objects.
110 * The methods in this class are empty.
111 */
112 class ChannelCountAdapter : public ChannelCountListener {
113 public:
114 virtual void ChannelCountChanged(int NewCount) { };
115 virtual void ChannelAdded(SamplerChannel* pChannel) { };
116 virtual void ChannelToBeRemoved(SamplerChannel* pChannel) { };
117 };
118
119 /**
120 * This class is used as a listener, which is notified
121 * when the number of audio output devices is changed.
122 */
123 class AudioDeviceCountListener {
124 public:
125 /**
126 * Invoked when the number of audio output devices has changed.
127 * @param NewCount The new number of audio output devices.
128 */
129 virtual void AudioDeviceCountChanged(int NewCount) = 0;
130 };
131
132 /**
133 * This class is used as a listener, which is notified
134 * when the number of MIDI input devices is changed.
135 */
136 class MidiDeviceCountListener {
137 public:
138 /**
139 * Invoked when the number of MIDI input devices has changed.
140 * @param NewCount The new number of MIDI input devices.
141 */
142 virtual void MidiDeviceCountChanged(int NewCount) = 0;
143
144 /**
145 * Invoked right before the supplied MIDI input device is going
146 * to be destroyed.
147 * @param pDevice MidiInputDevice to be deleted
148 */
149 virtual void MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) = 0;
150
151 /**
152 * Invoked to inform that a new MidiInputDevice has just been
153 * created.
154 * @param pDevice newly created MidiInputDevice
155 */
156 virtual void MidiDeviceCreated(MidiInputDevice* pDevice) = 0;
157 };
158
159 /**
160 * This class is used as a listener, which is notified
161 * when the number of MIDI input ports is changed.
162 */
163 class MidiPortCountListener {
164 public:
165 /**
166 * Invoked when the number of MIDI input ports has changed.
167 * @param NewCount The new number of MIDI input ports.
168 */
169 virtual void MidiPortCountChanged(int NewCount) = 0;
170
171 /**
172 * Invoked right before the supplied MIDI input port is going
173 * to be destroyed.
174 * @param pPort MidiInputPort to be deleted
175 */
176 virtual void MidiPortToBeRemoved(MidiInputPort* pPort) = 0;
177
178 /**
179 * Invoked to inform that a new MidiInputPort has just been
180 * added.
181 * @param pPort newly created MidiInputPort
182 */
183 virtual void MidiPortAdded(MidiInputPort* pPort) = 0;
184 };
185
186 /**
187 * This class is used as a listener, which is notified when the number
188 * of MIDI instruments on a particular MIDI instrument map is changed.
189 */
190 class MidiInstrumentCountListener {
191 public:
192 /**
193 * Invoked when the number of MIDI instruments has changed.
194 * @param MapId The numerical ID of the MIDI instrument map.
195 * @param NewCount The new number of MIDI instruments.
196 */
197 virtual void MidiInstrumentCountChanged(int MapId, int NewCount) = 0;
198 };
199
200 /**
201 * This class is used as a listener, which is notified
202 * when a MIDI instrument in a MIDI instrument map is changed.
203 */
204 class MidiInstrumentInfoListener {
205 public:
206 /**
207 * Invoked when a MIDI instrument in a MIDI instrument map is changed.
208 * @param MapId The numerical ID of the MIDI instrument map.
209 * @param Bank The index of the MIDI bank, containing the instrument.
210 * @param Program The MIDI program number of the instrument.
211 */
212 virtual void MidiInstrumentInfoChanged(int MapId, int Bank, int Program) = 0;
213 };
214
215 /**
216 * This class is used as a listener, which is notified
217 * when the number of MIDI instrument maps is changed.
218 */
219 class MidiInstrumentMapCountListener {
220 public:
221 /**
222 * Invoked when the number of MIDI instrument maps has changed.
223 * @param NewCount The new number of MIDI instruments.
224 */
225 virtual void MidiInstrumentMapCountChanged(int NewCount) = 0;
226 };
227
228 /**
229 * This class is used as a listener, which is notified
230 * when the settings of a MIDI instrument map are changed.
231 */
232 class MidiInstrumentMapInfoListener {
233 public:
234 /**
235 * Invoked when the settings of a MIDI instrument map are changed.
236 * @param MapId The numerical ID of the MIDI instrument map.
237 */
238 virtual void MidiInstrumentMapInfoChanged(int MapId) = 0;
239 };
240
241 /**
242 * This class is used as a listener, which is notified when the number
243 * of effect sends on a particular sampler channel is changed.
244 */
245 class FxSendCountListener {
246 public:
247 /**
248 * Invoked when the number of effect sends
249 * on the specified sampler channel has changed.
250 * @param ChannelId The numerical ID of the sampler channel.
251 * @param NewCount The new number of effect sends.
252 */
253 virtual void FxSendCountChanged(int ChannelId, int NewCount) = 0;
254 };
255
256 /**
257 * This class is used as a listener, which is notified when the number
258 * of active voices in a particular sampler channel is changed.
259 */
260 class VoiceCountListener {
261 public:
262 /**
263 * Invoked when the number of active voices
264 * on the specified sampler channel has changed.
265 * @param ChannelId The numerical ID of the sampler channel.
266 * @param NewCount The new number of active voices.
267 */
268 virtual void VoiceCountChanged(int ChannelId, int NewCount) = 0;
269 };
270
271 /**
272 * This class is used as a listener, which is notified when the number
273 * of active disk streams in a particular sampler channel is changed.
274 */
275 class StreamCountListener {
276 public:
277 /**
278 * Invoked when the number of active disk streams
279 * on the specified sampler channel has changed.
280 * @param ChannelId The numerical ID of the sampler channel.
281 * @param NewCount The new number of active disk streams.
282 */
283 virtual void StreamCountChanged(int ChannelId, int NewCount) = 0;
284 };
285
286 /**
287 * This class is used as a listener, which is notified when the fill state
288 * of the disk stream buffers on a particular sampler channel is changed.
289 */
290 class BufferFillListener {
291 public:
292 /**
293 * Invoked when the fill state of the disk stream
294 * buffers on the specified sampler channel is changed.
295 * @param ChannelId The numerical ID of the sampler channel.
296 * @param FillData The buffer fill data for the specified sampler channel.
297 */
298 virtual void BufferFillChanged(int ChannelId, String FillData) = 0;
299 };
300
301 /**
302 * This class is used as a listener, which is notified
303 * when the total number of active streams is changed.
304 */
305 class TotalStreamCountListener {
306 public:
307 /**
308 * Invoked when the total number of active streams is changed.
309 * @param NewCount The new number of active streams.
310 */
311 virtual void TotalStreamCountChanged(int NewCount) = 0;
312 };
313
314 /**
315 * This class is used as a listener, which is notified
316 * when the total number of active voices is changed.
317 */
318 class TotalVoiceCountListener {
319 public:
320 /**
321 * Invoked when the total number of active voices is changed.
322 * @param NewCount The new number of active voices.
323 */
324 virtual void TotalVoiceCountChanged(int NewCount) = 0;
325 };
326
327 /**
328 * This class is used as a listener, which is notified
329 * when the engine type of a particular sampler channel is changed.
330 */
331 class EngineChangeListener {
332 public:
333 /**
334 * Invoked when the engine type of the specified sampler channel
335 * is going to be changed soon.
336 * @param ChannelId The numerical ID of the sampler channel
337 */
338 virtual void EngineToBeChanged(int ChannelId) = 0;
339
340 /**
341 * Invoked when the engine type of the
342 * specified sampler channel was changed.
343 * @param ChannelId The numerical ID of the sampler
344 * channel, which engine type has been changed.
345 */
346 virtual void EngineChanged(int ChannelId) = 0;
347 };
348 }
349 #endif

  ViewVC Help
Powered by ViewVC