4 |
* * |
* * |
5 |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2013 Christian Schoenebeck and Grigor Iliev * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
39 |
bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. |
bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. |
40 |
I* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. |
I* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. |
41 |
RTList<R*>* pRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. |
RTList<R*>* pRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. |
42 |
|
InstrumentScript* pScript; ///< Instrument script to be executed for this instrument, or NULL if instrument does not have a script. |
43 |
}; |
}; |
44 |
|
|
45 |
template<class R> |
template<class R> |
122 |
DisconnectAudioOutputDevice(); |
DisconnectAudioOutputDevice(); |
123 |
} |
} |
124 |
AbstractEngine* newEngine = AbstractEngine::AcquireEngine(this, pAudioOut); |
AbstractEngine* newEngine = AbstractEngine::AcquireEngine(this, pAudioOut); |
125 |
EngineMutex.Lock(); |
{ |
126 |
pEngine = newEngine; |
LockGuard lock(EngineMutex); |
127 |
EngineMutex.Unlock(); |
pEngine = newEngine; |
128 |
|
} |
129 |
ResetInternal(); |
ResetInternal(); |
130 |
pEvents = new RTList<Event>(pEngine->pEventPool); |
pEvents = new RTList<Event>(pEngine->pEventPool); |
131 |
|
|
197 |
DeleteGroupEventLists(); |
DeleteGroupEventLists(); |
198 |
|
|
199 |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
200 |
EngineMutex.Lock(); |
{ |
201 |
pEngine = NULL; |
LockGuard lock(EngineMutex); |
202 |
EngineMutex.Unlock(); |
pEngine = NULL; |
203 |
|
} |
204 |
AbstractEngine::FreeEngine(this, oldAudioDevice); |
AbstractEngine::FreeEngine(this, oldAudioDevice); |
205 |
AudioDeviceChannelLeft = -1; |
AudioDeviceChannelLeft = -1; |
206 |
AudioDeviceChannelRight = -1; |
AudioDeviceChannelRight = -1; |
225 |
this->ProcessActiveVoices(&handler); |
this->ProcessActiveVoices(&handler); |
226 |
|
|
227 |
// empty exclusive group specific event lists |
// empty exclusive group specific event lists |
228 |
ClearGroupEventLists(); |
// (pInstrument == 0 could mean that LoadInstrument is |
229 |
|
// building new group event lists, so we must check |
230 |
|
// for that) |
231 |
|
if (pInstrument) ClearGroupEventLists(); |
232 |
} |
} |
233 |
|
|
234 |
// implementation of abstract methods derived from interface class 'InstrumentConsumer' |
// implementation of abstract methods derived from interface class 'InstrumentConsumer' |
238 |
* we are currently using on this EngineChannel is going to be updated, |
* we are currently using on this EngineChannel is going to be updated, |
239 |
* so we can stop playback before that happens. |
* so we can stop playback before that happens. |
240 |
*/ |
*/ |
241 |
virtual void ResourceToBeUpdated(I* pResource, void*& pUpdateArg) { |
virtual void ResourceToBeUpdated(I* pResource, void*& pUpdateArg) OVERRIDE { |
242 |
dmsg(3,("EngineChannelBase: Received instrument update message.\n")); |
dmsg(3,("EngineChannelBase: Received instrument update message.\n")); |
243 |
if (pEngine) pEngine->DisableAndLock(); |
if (pEngine) pEngine->DisableAndLock(); |
244 |
ResetInternal(); |
ResetInternal(); |
249 |
* Will be called by the InstrumentResourceManager when the instrument |
* Will be called by the InstrumentResourceManager when the instrument |
250 |
* update process was completed, so we can continue with playback. |
* update process was completed, so we can continue with playback. |
251 |
*/ |
*/ |
252 |
virtual void ResourceUpdated(I* pOldResource, I* pNewResource, void* pUpdateArg) { |
virtual void ResourceUpdated(I* pOldResource, I* pNewResource, void* pUpdateArg) OVERRIDE { |
253 |
this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument()) |
this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument()) |
254 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
255 |
bStatusChanged = true; // status of engine has changed, so set notify flag |
bStatusChanged = true; // status of engine has changed, so set notify flag |
261 |
* |
* |
262 |
* @param fProgress - current progress as value between 0.0 and 1.0 |
* @param fProgress - current progress as value between 0.0 and 1.0 |
263 |
*/ |
*/ |
264 |
virtual void OnResourceProgress(float fProgress) { |
virtual void OnResourceProgress(float fProgress) OVERRIDE { |
265 |
this->InstrumentStat = int(fProgress * 100.0f); |
this->InstrumentStat = int(fProgress * 100.0f); |
266 |
dmsg(7,("EngineChannelBase: progress %d%", InstrumentStat)); |
dmsg(7,("EngineChannelBase: progress %d%", InstrumentStat)); |
267 |
bStatusChanged = true; // status of engine has changed, so set notify flag |
bStatusChanged = true; // status of engine has changed, so set notify flag |
290 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
291 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
292 |
cmd.pInstrument = NULL; |
cmd.pInstrument = NULL; |
293 |
|
cmd.pScript = new InstrumentScript(this); |
294 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
295 |
} |
} |
296 |
{ |
{ |
297 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
298 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
299 |
cmd.pInstrument = NULL; |
cmd.pInstrument = NULL; |
300 |
|
cmd.pScript = new InstrumentScript(this); |
301 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
302 |
} |
} |
303 |
} |
} |
304 |
|
|
305 |
virtual ~EngineChannelBase() { } |
virtual ~EngineChannelBase() { |
306 |
|
{ |
307 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
308 |
|
if (cmd.pScript) delete cmd.pScript; |
309 |
|
} |
310 |
|
{ |
311 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
312 |
|
if (cmd.pScript) delete cmd.pScript; |
313 |
|
} |
314 |
|
} |
315 |
|
|
316 |
typedef typename RTList<V>::Iterator RTListVoiceIterator; |
typedef typename RTList<V>::Iterator RTListVoiceIterator; |
317 |
|
|
364 |
} |
} |
365 |
|
|
366 |
/** |
/** |
367 |
|
* Load real-time instrument script and all its resources required |
368 |
|
* for the upcoming instrument change. |
369 |
|
* |
370 |
|
* @param text - source code of script |
371 |
|
*/ |
372 |
|
void LoadInstrumentScript(const String& text) { |
373 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
374 |
|
// unload *PRE*-previous script |
375 |
|
cmd.pScript->reset(); //TODO: previous script should be freed as soon as the EngineBase switched the instrument, right now 2 scripts are kept in memory all the time, even though the old one is not used anymore |
376 |
|
// load the new script |
377 |
|
cmd.pScript->load(text); |
378 |
|
} |
379 |
|
|
380 |
|
/** |
381 |
* Changes the instrument for an engine channel. |
* Changes the instrument for an engine channel. |
382 |
* |
* |
383 |
* @param pInstrument - new instrument |
* @param pInstrument - new instrument |