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-2010 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 * |
68 |
virtual void ClearRegionsInUse() { |
virtual void ClearRegionsInUse() { |
69 |
{ |
{ |
70 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
71 |
if(cmd.pRegionsInUse != NULL) cmd.pRegionsInUse->clear(); |
if (cmd.pRegionsInUse) cmd.pRegionsInUse->clear(); |
72 |
|
cmd.bChangeInstrument = false; |
73 |
} |
} |
74 |
{ |
{ |
75 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
76 |
if(cmd.pRegionsInUse != NULL) cmd.pRegionsInUse->clear(); |
if (cmd.pRegionsInUse) cmd.pRegionsInUse->clear(); |
77 |
|
cmd.bChangeInstrument = false; |
78 |
} |
} |
79 |
} |
} |
80 |
|
|
86 |
virtual void DeleteRegionsInUse() { |
virtual void DeleteRegionsInUse() { |
87 |
{ |
{ |
88 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
89 |
if(cmd.pRegionsInUse != NULL) { |
if (cmd.pRegionsInUse) { |
90 |
delete cmd.pRegionsInUse; |
delete cmd.pRegionsInUse; |
91 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
92 |
} |
} |
93 |
|
cmd.bChangeInstrument = false; |
94 |
} |
} |
95 |
{ |
{ |
96 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
97 |
if(cmd.pRegionsInUse != NULL) { |
if (cmd.pRegionsInUse) { |
98 |
delete cmd.pRegionsInUse; |
delete cmd.pRegionsInUse; |
99 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
100 |
} |
} |
101 |
|
cmd.bChangeInstrument = false; |
102 |
} |
} |
103 |
} |
} |
104 |
|
|
106 |
{ |
{ |
107 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
108 |
cmd.pRegionsInUse = new RTList<R*>(pRegionPool[0]); |
cmd.pRegionsInUse = new RTList<R*>(pRegionPool[0]); |
109 |
|
cmd.bChangeInstrument = false; |
110 |
} |
} |
111 |
{ |
{ |
112 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
113 |
cmd.pRegionsInUse = new RTList<R*>(pRegionPool[1]); |
cmd.pRegionsInUse = new RTList<R*>(pRegionPool[1]); |
114 |
|
cmd.bChangeInstrument = false; |
115 |
} |
} |
116 |
} |
} |
117 |
|
|
120 |
if (pEngine->pAudioOutputDevice == pAudioOut) return; |
if (pEngine->pAudioOutputDevice == pAudioOut) return; |
121 |
DisconnectAudioOutputDevice(); |
DisconnectAudioOutputDevice(); |
122 |
} |
} |
123 |
pEngine = AbstractEngine::AcquireEngine(this, pAudioOut); |
AbstractEngine* newEngine = AbstractEngine::AcquireEngine(this, pAudioOut); |
124 |
|
{ |
125 |
|
LockGuard lock(EngineMutex); |
126 |
|
pEngine = newEngine; |
127 |
|
} |
128 |
ResetInternal(); |
ResetInternal(); |
129 |
pEvents = new RTList<Event>(pEngine->pEventPool); |
pEvents = new RTList<Event>(pEngine->pEventPool); |
130 |
|
|
196 |
DeleteGroupEventLists(); |
DeleteGroupEventLists(); |
197 |
|
|
198 |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
199 |
pEngine = NULL; |
{ |
200 |
|
LockGuard lock(EngineMutex); |
201 |
|
pEngine = NULL; |
202 |
|
} |
203 |
AbstractEngine::FreeEngine(this, oldAudioDevice); |
AbstractEngine::FreeEngine(this, oldAudioDevice); |
204 |
AudioDeviceChannelLeft = -1; |
AudioDeviceChannelLeft = -1; |
205 |
AudioDeviceChannelRight = -1; |
AudioDeviceChannelRight = -1; |
221 |
pEvents->clear(); |
pEvents->clear(); |
222 |
// empty MIDI key specific event lists |
// empty MIDI key specific event lists |
223 |
ClearEventListsHandler handler; |
ClearEventListsHandler handler; |
224 |
ProcessActiveVoices(&handler); |
this->ProcessActiveVoices(&handler); |
225 |
|
|
226 |
// empty exclusive group specific event lists |
// empty exclusive group specific event lists |
227 |
ClearGroupEventLists(); |
// (pInstrument == 0 could mean that LoadInstrument is |
228 |
|
// building new group event lists, so we must check |
229 |
|
// for that) |
230 |
|
if (pInstrument) ClearGroupEventLists(); |
231 |
} |
} |
232 |
|
|
233 |
// implementation of abstract methods derived from interface class 'InstrumentConsumer' |
// implementation of abstract methods derived from interface class 'InstrumentConsumer' |
237 |
* we are currently using on this EngineChannel is going to be updated, |
* we are currently using on this EngineChannel is going to be updated, |
238 |
* so we can stop playback before that happens. |
* so we can stop playback before that happens. |
239 |
*/ |
*/ |
240 |
virtual void ResourceToBeUpdated(I* pResource, void*& pUpdateArg) { |
virtual void ResourceToBeUpdated(I* pResource, void*& pUpdateArg) OVERRIDE { |
241 |
dmsg(3,("EngineChannelBase: Received instrument update message.\n")); |
dmsg(3,("EngineChannelBase: Received instrument update message.\n")); |
242 |
if (pEngine) pEngine->DisableAndLock(); |
if (pEngine) pEngine->DisableAndLock(); |
243 |
ResetInternal(); |
ResetInternal(); |
248 |
* Will be called by the InstrumentResourceManager when the instrument |
* Will be called by the InstrumentResourceManager when the instrument |
249 |
* update process was completed, so we can continue with playback. |
* update process was completed, so we can continue with playback. |
250 |
*/ |
*/ |
251 |
virtual void ResourceUpdated(I* pOldResource, I* pNewResource, void* pUpdateArg) { |
virtual void ResourceUpdated(I* pOldResource, I* pNewResource, void* pUpdateArg) OVERRIDE { |
252 |
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()) |
253 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
254 |
bStatusChanged = true; // status of engine has changed, so set notify flag |
bStatusChanged = true; // status of engine has changed, so set notify flag |
260 |
* |
* |
261 |
* @param fProgress - current progress as value between 0.0 and 1.0 |
* @param fProgress - current progress as value between 0.0 and 1.0 |
262 |
*/ |
*/ |
263 |
virtual void OnResourceProgress(float fProgress) { |
virtual void OnResourceProgress(float fProgress) OVERRIDE { |
264 |
this->InstrumentStat = int(fProgress * 100.0f); |
this->InstrumentStat = int(fProgress * 100.0f); |
265 |
dmsg(7,("EngineChannelBase: progress %d%", InstrumentStat)); |
dmsg(7,("EngineChannelBase: progress %d%", InstrumentStat)); |
266 |
bStatusChanged = true; // status of engine has changed, so set notify flag |
bStatusChanged = true; // status of engine has changed, so set notify flag |
268 |
|
|
269 |
void RenderActiveVoices(uint Samples) { |
void RenderActiveVoices(uint Samples) { |
270 |
RenderVoicesHandler handler(this, Samples); |
RenderVoicesHandler handler(this, Samples); |
271 |
ProcessActiveVoices(&handler); |
this->ProcessActiveVoices(&handler); |
272 |
|
|
273 |
SetVoiceCount(handler.VoiceCount); |
SetVoiceCount(handler.VoiceCount); |
274 |
SetDiskStreamCount(handler.StreamCount); |
SetDiskStreamCount(handler.StreamCount); |
326 |
if ((itVoice->DiskStreamRef).State != Stream::state_unused) StreamCount++; |
if ((itVoice->DiskStreamRef).State != Stream::state_unused) StreamCount++; |
327 |
} |
} |
328 |
} else { // voice reached end, is now inactive |
} else { // voice reached end, is now inactive |
329 |
|
itVoice->VoiceFreed(); |
330 |
pChannel->FreeVoice(itVoice); // remove voice from the list of active voices |
pChannel->FreeVoice(itVoice); // remove voice from the list of active voices |
331 |
} |
} |
332 |
} |
} |