/[svn]/linuxsampler/trunk/src/plugins/InstrumentEditor.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/plugins/InstrumentEditor.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1659 - (show annotations) (download) (as text)
Sun Feb 3 00:13:27 2008 UTC (16 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 13883 byte(s)
* added support for triggering notes by instrument editors
  (still some cleanup / refactoring ahead, but it should work)
* bumped version to 0.5.1.1cvs

1 /***************************************************************************
2 * *
3 * Copyright (C) 2007, 2008 Christian Schoenebeck *
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., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #ifndef LS_INSTRUMENT_EDITOR_H
22 #define LS_INSTRUMENT_EDITOR_H
23
24 #include "../common/global.h"
25 #include "../common/Thread.h"
26 #include "../drivers/midi/VirtualMidiDevice.h"
27
28 #include <set>
29
30 namespace LinuxSampler {
31
32 // just symbol prototyping
33 class InstrumentEditorListener;
34
35 /** @brief Instrument Editor Interface (external plugin)
36 *
37 * LinuxSampler allows to spawn arbitrary instrument editor applications
38 * within the sampler's own process. That way instrument editors are
39 * able to modify already loaded instruments live or on-the-fly, that is
40 * without having to load it again neither on sampler nor on editor side,
41 * which is essential for editing large instruments.
42 *
43 * Instrument editors have to implement this abstract base class, embedded
44 * into a DLL and placed into the respective sampler's library path. The
45 * sampler will load these external DLLs as plugins on startup. Whenever
46 * there's a request for editing an instrument, the sampler will try to
47 * launch a matching registered editor, by calling the respective
48 * plugin's @c Main() method.
49 */
50 class InstrumentEditor : public VirtualMidiDevice, protected Thread {
51 public:
52
53 /////////////////////////////////////////////////////////////////
54 // abstract methods
55 // (these have to be implemented by the descendant)
56
57 /**
58 * Entry point for the instrument editor's thread. As the
59 * instrument data structure is passed as typeless (void*)
60 * pointer, this is not type safe! The implementing instrument
61 * editor has to interpret the @a sTypeName and @a sTypeVersion
62 * arguments to determine if it's able to cast the instrument
63 * pointer to a known type and actually be able to work with it.
64 *
65 * @param pInstrument - pointer to the respective instrument object
66 * @param sTypeName - format of the instrument data structure
67 * (i.e. @c "libgig" )
68 * @param sTypeVersion - version of the instrument data structure
69 * (i.e. @c "3.0.1" ).
70 */
71 virtual int Main(void* pInstrument, String sTypeName, String sTypeVersion) = 0;
72
73 /**
74 * The instrument editor has to return @c true in case it supports
75 * the given instrument data structure type and version, it has to
76 * return @c false otherwise. This method will be called by the
77 * sampler to determine which editor is capable to work with a
78 * certain instrument.
79 *
80 * @param sTypeName - i.e. @c "libgig"
81 * @param sTypeVersion - i.e. @c "3.0.1"
82 */
83 virtual bool IsTypeSupported(String sTypeName, String sTypeVersion) = 0;
84
85 /**
86 * The instrument editor's name (i.e. @c "gigedit" ).
87 */
88 virtual String Name() = 0;
89
90 /**
91 * The instrument editor's version (i.e. @c "0.0.1" ).
92 */
93 virtual String Version() = 0;
94
95 /**
96 * Arbitrary textual description of the instrument editor
97 * (i.e. "Gigasampler and DLS format editor, GTK based").
98 */
99 virtual String Description() = 0;
100
101
102
103 /////////////////////////////////////////////////////////////////
104 // normal methods
105 // (usually not to be overriden by descendant)
106
107 /** @brief Dispatch pending sample removal event.
108 *
109 * @e SHOULD be called by the instrument editor @e before deleting
110 * samples, so the sampler can react by stopping usage of these
111 * samples to avoid a crash.
112 *
113 * After calling this method, the instrument editor @e MUST call
114 * @c NotifySamplesRemoved() after it actually deleted the samples, so
115 * the sampler can react by i.e. resuming playback of sampler engines.
116 *
117 * @param Samples - list of samples that will be deleted by the
118 * instrument editor
119 */
120 void NotifySamplesToBeRemoved(std::set<void*> Samples);
121
122 /** @brief Dispatch completed sample removal event.
123 *
124 * Inform the sampler that the by @c NotifySamplesToBeRemoved()
125 * previously announced samples have been deleted.
126 */
127 void NotifySamplesRemoved();
128
129 /** @brief Dispatch pending data structure modification event.
130 *
131 * @e SHOULD be called by the instrument editor @e before modifying
132 * data structures (except samples, which have their own dispatch
133 * methods) which could otherwise lead to undesired synchronisation
134 * issues and a crash. The respective data structure is passed as a
135 * typeless pointer @a pStruct , so the instrument editor additionally
136 * has to pass the name of the data structure (i.e. @c "gig::Region" ),
137 * so the sampler can cast the pointer to an appropriate type. The
138 * sampler will react by stopping usage of the respective data
139 * structure.
140 *
141 * After calling this method, the instrument editor @e MUST call
142 * @c NotifyDataStructureChanged() , so the sampler can react by
143 * resuming usage of the respective data structure for playback.
144 *
145 * @param pStruct - data structure going to be modified
146 * @param sStructType - name of the data structure (i.e. its C++
147 * struct or class name)
148 */
149 void NotifyDataStructureToBeChanged(void* pStruct, String sStructType);
150
151 /** @brief Dispatch completed data structure modification event.
152 *
153 * Inform the sampler that the by @c NotifyDataStructureToBeChanged()
154 * previously announced data structure has been completely modified.
155 *
156 * @param pStruct - data structure that has been modified
157 * @param sStructType - name of the data structure (i.e. its C++
158 * struct or class name)
159 */
160 void NotifyDataStructureChanged(void* pStruct, String sStructType);
161
162 /** @brief Dispatch sample reference changed event.
163 *
164 * @e SHOULD be called by the instrument editor @e after a certain data
165 * structure changed its reference / pointer to a sample, so the
166 * sampler can react by:
167 *
168 * - Caching the newly referenced sample if necessary.
169 * - Un-caching the old referenced sample if necessary.
170 *
171 * @e Note: the instrument editor additionally @e MUST embed this call
172 * into the respective @c NotifyDataStructureToBeChanged() and
173 * @c NotifyDataStructureChanged() calls for announcing the data
174 * structure whose sample reference is actually to be changed, so the
175 * sampler can react by suspending usage. For example:
176 * @code
177 * NotifyDataStructureToBeChanged(pDimReg, "gig::DimensionRegion");
178 * gig::Sample* pOldSample = pDimReg->pSample;
179 * pDimReg->pSample = pNewSample;
180 * NotifySampleReferenceChanged(pOldSample, pNewSample);
181 * NotifyDataStructureChanged(pDimReg, "gig::DimensionRegion");
182 * @endcode
183 * So calling this method alone is not safe!
184 *
185 * @param pOldSample - previous sample reference
186 * @param pNewSample - current sample reference
187 */
188 void NotifySampleReferenceChanged(void* pOldSample, void* pNewSample);
189
190 /**
191 * Launch the instrument editor for the given instrument. The
192 * editor will be spawned in its own thread and this method will
193 * return as soon as the editor's thread actually started.
194 */
195 void Launch(void* pInstrument, String sTypeName, String sTypeVersion);
196
197 /**
198 * Registers object that wants to be notified on events.
199 */
200 void AddListener(InstrumentEditorListener* pListener);
201
202 /**
203 * Unregisters object that doesn't want to be notified anymore.
204 */
205 void RemoveListener(InstrumentEditorListener* pListener);
206
207 /**
208 * Constructor
209 */
210 InstrumentEditor();
211
212 /**
213 * Destructor
214 */
215 virtual ~InstrumentEditor();
216
217 protected:
218 std::set<InstrumentEditorListener*> listeners;
219
220 // derived abstract method from base class 'Thread'
221 virtual int Main();
222 private:
223 void* pInstrument;
224 String sTypeName;
225 String sTypeVersion;
226 };
227
228 /** @brief Instrument Editor Notifications
229 *
230 * This abstract interface class has to be implemented by classes that
231 * want to be notified on certain events of an instrument editor. This is
232 * typically used on sampler side, but might also be used by an instrument
233 * editor to get informed about modifications another instrument editor
234 * makes.
235 */
236 class InstrumentEditorListener {
237 public:
238 /** @brief Called after the instrument editor stopped running.
239 *
240 * Automatically called after the instrument editor application stopped
241 * running. This method has to be implemented by the descendant.
242 *
243 * @param pSender - instrument editor that died
244 */
245 virtual void OnInstrumentEditorQuit(InstrumentEditor* pSender) = 0;
246
247 /** @brief Called before samples are to be deleted.
248 *
249 * See the dispatcher method
250 * @c InstrumentEditor::NotifySamplesToBeRemoved() for details.
251 * This method has to be implemented by the descendant.
252 *
253 * @param Samples - list of samples that will be deleted by the
254 * instrument editor
255 * @param pSender - instrument editor that is going to do this
256 * modification
257 */
258 virtual void OnSamplesToBeRemoved(std::set<void*> Samples, InstrumentEditor* pSender) = 0;
259
260 /** @brief Called after samples have been deleted.
261 *
262 * See the dispatcher method
263 * @c InstrumentEditor::NotifySamplesRemoved() for details.
264 * This method has to be implemented by the descendant.
265 *
266 * @param pSender - instrument editor that did this modification
267 */
268 virtual void OnSamplesRemoved(InstrumentEditor* pSender) = 0;
269
270 /** @brief Called before data structure is to be modified.
271 *
272 * See the dispatcher method
273 * @c InstrumentEditor::NotifyDataStructureToBeChanged() for details.
274 * This method has to be implemented by the descendant.
275 *
276 * @param pStruct - data structure going to be modified
277 * @param sStructType - name of the data structure (i.e. its C++
278 * struct or class name)
279 * @param pSender - instrument editor that is going to do this
280 * modification
281 */
282 virtual void OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) = 0;
283
284 /** @brief Called after data structure has been modified.
285 *
286 * See the dispatcher method
287 * @c InstrumentEditor::NotifyDataStructureChanged() for details.
288 * This method has to be implemented by the descendant.
289 *
290 * @param pStruct - data structure that has been modified
291 * @param sStructType - name of the data structure (i.e. its C++
292 * struct or class name)
293 * @param pSender - instrument editor that did this modification
294 */
295 virtual void OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) = 0;
296
297 /** @brief Called after some data structure changed its reference to a sample.
298 *
299 * @c InstrumentEditor::NotifySampleReferenceChanged() for details.
300 * This method has to be implemented by the descendant.
301 *
302 * @param pOldSample - previous sample reference
303 * @param pNewSample - current sample reference
304 * @param pSender - instrument editor that did this modification
305 */
306 virtual void OnSampleReferenceChanged(void* pOldSample, void* pNewSample, InstrumentEditor* pSender) = 0;
307 };
308
309 } // namespace LinuxSampler
310
311 #endif // LS_INSTRUMENT_EDITOR_H

  ViewVC Help
Powered by ViewVC