/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInstrumentMapper.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/midi/MidiInstrumentMapper.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1695 - (show annotations) (download) (as text)
Sat Feb 16 01:09:33 2008 UTC (16 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 12692 byte(s)
* added new LSCP event "DEVICE_MIDI" which can be used by frontends to
  react on MIDI data arriving on certain MIDI input devices (so far only
  Note-On and Note-Off events are sent via this LSCP event)
* bumped version to 0.5.1.4cvs

1 /***************************************************************************
2 * *
3 * Copyright (C) 2006 - 2008 Christian Schoenebeck *
4 * *
5 * This library 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 library 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 library; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #ifndef __LS_MIDIINSTRUMENTMAPPER_H__
22 #define __LS_MIDIINSTRUMENTMAPPER_H__
23
24 #include <map>
25
26 #include "midi.h"
27 #include "../../EventListeners.h"
28 #include "../../common/global.h"
29 #include "../../common/optional.h"
30 #include "../../engines/InstrumentManager.h"
31
32 namespace LinuxSampler {
33
34 // just symbol prototyping
35 class MidiInputPort;
36
37 /** @brief Mapping MIDI bank/program numbers with real instruments.
38 *
39 * By default (that is on startup) the sampler will simply ignore all
40 * MIDI program change messages. The MidiInstrumentMapper allows to map
41 * arbitrary (MIDI bank MSB, MIDI bank LSB, MIDI program) triples with
42 * an actual (Sampler Engine, Instrument File, Index) triple, so the
43 * sampler knows which instrument to load on the respective MIDI program
44 * change messages.
45 *
46 * The sampler allows to manage arbitrary amount of MIDI instrument
47 * maps. For example you might create (at least) two MIDI instrument
48 * maps: one for "normal" instruments and one for drumkits.
49 */
50 class MidiInstrumentMapper {
51 public:
52 /**
53 * Defines the life-time strategy for an instrument.
54 */
55 enum mode_t {
56 ON_DEMAND = 0, ///< Instrument will be loaded when needed, freed once not needed anymore.
57 ON_DEMAND_HOLD = 1, ///< Instrument will be loaded when needed and kept even if not needed anymore.
58 PERSISTENT = 2, ///< Instrument will immediately be loaded and kept all the time.
59 #if !defined(WIN32)
60 VOID = 127, ///< @deprecated use DONTCARE instead!
61 #endif
62 DONTCARE = 127 ///< Don't care, let it up to the InstrumentManager to decide for an appropriate LoadMode.
63 };
64
65 /**
66 * Defines the instrument and settings a MIDI bank MSB, LSB,
67 * program triple ought to be mapped to.
68 */
69 struct entry_t {
70 String EngineName; ///< The sampler engine to be used.
71 String InstrumentFile; ///< File name of the instrument to be loaded.
72 uint InstrumentIndex; ///< Index of the instrument within its file.
73 mode_t LoadMode; ///< Life-time strategy of instrument.
74 float Volume; ///< Global volume factor for this instrument.
75 String Name; ///< Display name that should be associated with this mapping entry.
76 };
77
78 /**
79 * Registers the specified listener to be notified when the number
80 * of MIDI instruments on a particular MIDI instrument map is changed.
81 */
82 static void AddMidiInstrumentCountListener(MidiInstrumentCountListener* l);
83
84 /**
85 * Removes the specified listener.
86 */
87 static void RemoveMidiInstrumentCountListener(MidiInstrumentCountListener* l);
88
89 /**
90 * Registers the specified listener to be notified when
91 * a MIDI instrument in a MIDI instrument map is changed.
92 */
93 static void AddMidiInstrumentInfoListener(MidiInstrumentInfoListener* l);
94
95 /**
96 * Removes the specified listener.
97 */
98 static void RemoveMidiInstrumentInfoListener(MidiInstrumentInfoListener* l);
99
100 /**
101 * Registers the specified listener to be notified
102 * when the number of MIDI instrument maps is changed.
103 */
104 static void AddMidiInstrumentMapCountListener(MidiInstrumentMapCountListener* l);
105
106 /**
107 * Removes the specified listener.
108 */
109 static void RemoveMidiInstrumentMapCountListener(MidiInstrumentMapCountListener* l);
110
111 /**
112 * Registers the specified listener to be notified when
113 * the settings of a MIDI instrument map are changed.
114 */
115 static void AddMidiInstrumentMapInfoListener(MidiInstrumentMapInfoListener* l);
116
117 /**
118 * Removes the specified listener.
119 */
120 static void RemoveMidiInstrumentMapInfoListener(MidiInstrumentMapInfoListener* l);
121
122 /**
123 * Adds a new entry to the given MIDI instrument map in case
124 * an entry with \a Index does not exist yet, otherwise it will
125 * replace the existing entry. Note that some given settings
126 * might simply be ignored or might change the settings of other
127 * entries in the map (i.e. because another instrument in the
128 * map is part of the same file and the respective sampler
129 * engine does not allow to use different LoadModes for
130 * instruments of the same file). Note that in case of a
131 * PERSISTENT LoadMode argument the given instrument will
132 * immediately be loaded, that means by default this method will
133 * block until the whole instrument was loaded completely. You
134 * can override this behavior by setting \a bInBackground to
135 * true, so the instrument will be loaded in a separate thread
136 * (in that case you won't catch loading errors though, i.e. if
137 * the file does not exist or might be corrupt for example).
138 *
139 * @param Map - map index
140 * @param Index - unique index of the new entry to add
141 * @param Entry - the actual instrument and settings
142 * @param bInBackground - avoid this method to block for long time
143 * @throws Exception - if the given map or engine type does not
144 * exist or instrument loading failed
145 */
146 static void AddOrReplaceEntry(int Map, midi_prog_index_t Index, entry_t Entry, bool bInBackground = false) throw (Exception);
147
148 /**
149 * Remove an existing entry from the MIDI instrument map.
150 *
151 * @param Map - map index
152 * @param Index - index of entry to delete
153 */
154 static void RemoveEntry(int Map, midi_prog_index_t Index);
155
156 /**
157 * Clear the whole given MIDI instrument map, that is delete all
158 * its entries.
159 *
160 * @param Map - map index
161 */
162 static void RemoveAllEntries(int Map);
163
164 /**
165 * Returns the currently existing MIDI instrument map entries
166 * of the given map with their current settings.
167 *
168 * @param Map - map index
169 * @throws Exception - in case \a Map does not exist
170 */
171 static std::map<midi_prog_index_t,entry_t> Entries(int Map) throw (Exception);
172
173 /**
174 * Returns the IDs of all currently existing MIDI instrument
175 * maps.
176 */
177 static std::vector<int> Maps();
178
179 /**
180 * Create a new MIDI instrument map. Optionally you can assign
181 * a custom name for the map. Map names don't have to be unique.
182 *
183 * @param MapName - (optional) name for the map
184 * @returns ID of the new map
185 * @throws Exception - if there's no free map ID left
186 */
187 static int AddMap(String MapName = "") throw (Exception) ;
188
189 /**
190 * Returns the custom name of the given map.
191 *
192 * @param Map - map index
193 * @throws Exception - if given map does not exist
194 */
195 static String MapName(int Map) throw (Exception);
196
197 /**
198 * Rename the given, already existing map. Map names don't have
199 * to be unique.
200 *
201 * @param Map - map index
202 * @param NewName - the map's new name to be assigned
203 * @throws Exception - if the given map does not exist
204 */
205 static void RenameMap(int Map, String NewName) throw (Exception);
206
207 /**
208 * Delete the given map.
209 *
210 * @param Map - ID of the map to delete
211 */
212 static void RemoveMap(int Map);
213
214 /**
215 * Completely delete all existing maps.
216 */
217 static void RemoveAllMaps();
218
219 /**
220 * Returns amount of currently available MIDI instrument maps.
221 */
222 static int GetMapCount();
223
224 /**
225 * Gets the ID of the default map.
226 * For now, the default map is the first available map. When
227 * the default map is removed, the default map becomes the next available map.
228 * @return The ID of the default map or -1 if the there are no maps added.
229 */
230 static int GetDefaultMap();
231
232 /**
233 * Sets the default map.
234 * @param MapId The ID of the new default map.
235 */
236 static void SetDefaultMap(int MapId);
237
238 protected:
239 /**
240 * Notifies listeners that the number of MIDI instruments
241 * on the specified MIDI instrument map has been changed.
242 * @param MapId The numerical ID of the MIDI instrument map.
243 * @param NewCount The new number of MIDI instruments.
244 */
245 static void fireMidiInstrumentCountChanged(int MapId, int NewCount);
246
247 /**
248 * Notifies listeners that a MIDI instrument
249 * in a MIDI instrument map is changed.
250 * @param MapId The numerical ID of the MIDI instrument map.
251 * @param Bank The index of the MIDI bank, containing the instrument.
252 * @param Program The MIDI program number of the instrument.
253 */
254 static void fireMidiInstrumentInfoChanged(int MapId, int Bank, int Program);
255
256 /**
257 * Notifies listeners that the number of MIDI instrument maps has been changed.
258 * @param NewCount The new number of MIDI instrument maps.
259 */
260 static void fireMidiInstrumentMapCountChanged(int NewCount);
261
262 /**
263 * Notifies listeners that the settings of a MIDI instrument map are changed.
264 */
265 static void fireMidiInstrumentMapInfoChanged(int MapId);
266
267 static optional<entry_t> GetEntry(int Map, midi_prog_index_t Index); // shall only be used by MidiInputPort ATM (see source comment)
268 friend class MidiInputPort; // allow MidiInputPort to access GetEntry()
269
270 private:
271 static ListenerList<MidiInstrumentCountListener*> llMidiInstrumentCountListeners;
272 static ListenerList<MidiInstrumentInfoListener*> llMidiInstrumentInfoListeners;
273 static ListenerList<MidiInstrumentMapCountListener*> llMidiInstrumentMapCountListeners;
274 static ListenerList<MidiInstrumentMapInfoListener*> llMidiInstrumentMapInfoListeners;
275
276 static int DefaultMap;
277 };
278
279 } // namespace LinuxSampler
280
281 #endif // __LS_MIDIINSTRUMENTMAPPER_H__

  ViewVC Help
Powered by ViewVC