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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3054 - (show annotations) (download) (as text)
Thu Dec 15 12:47:45 2016 UTC (7 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 13298 byte(s)
* Fixed numerous compiler warnings.
* Bumped version (2.0.0.svn32).

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

  ViewVC Help
Powered by ViewVC