3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
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 - 2007 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* 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 * |
27 |
|
|
28 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
29 |
|
|
30 |
EngineChannel::EngineChannel() { |
EngineChannel::EngineChannel() : |
31 |
|
InstrumentChangeCommandReader(InstrumentChangeCommand) { |
32 |
pMIDIKeyInfo = new midi_key_info_t[128]; |
pMIDIKeyInfo = new midi_key_info_t[128]; |
33 |
pEngine = NULL; |
pEngine = NULL; |
34 |
pInstrument = NULL; |
pInstrument = NULL; |
60 |
|
|
61 |
EngineChannel::~EngineChannel() { |
EngineChannel::~EngineChannel() { |
62 |
DisconnectAudioOutputDevice(); |
DisconnectAudioOutputDevice(); |
|
if (pInstrument) Engine::instruments.HandBack(pInstrument, this); |
|
63 |
if (pEventQueue) delete pEventQueue; |
if (pEventQueue) delete pEventQueue; |
64 |
if (pActiveKeys) delete pActiveKeys; |
if (pActiveKeys) delete pActiveKeys; |
65 |
if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; |
if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; |
164 |
* @see PrepareLoadInstrument() |
* @see PrepareLoadInstrument() |
165 |
*/ |
*/ |
166 |
void EngineChannel::LoadInstrument() { |
void EngineChannel::LoadInstrument() { |
167 |
::gig::Instrument* oldInstrument = pInstrument; |
// make sure we don't trigger any new notes with an old |
168 |
|
// instrument |
169 |
// free old instrument |
instrument_change_command_t& cmd = ChangeInstrument(0); |
170 |
if (oldInstrument) { |
if (cmd.pInstrument) { |
171 |
if (pEngine) { |
// give old instrument back to instrument manager, but |
172 |
// make sure we don't trigger any new notes with the |
// keep the dimension regions and samples that are in use |
173 |
// old instrument |
Engine::instruments.HandBackInstrument(cmd.pInstrument, this, cmd.pDimRegionsInUse); |
|
::gig::DimensionRegion** dimRegionsInUse = pEngine->ChangeInstrument(this, 0); |
|
|
|
|
|
// give old instrument back to instrument manager, but |
|
|
// keep the dimension regions and samples that are in |
|
|
// use |
|
|
Engine::instruments.HandBackInstrument(oldInstrument, this, dimRegionsInUse); |
|
|
} else { |
|
|
Engine::instruments.HandBack(oldInstrument, this); |
|
|
} |
|
174 |
} |
} |
175 |
|
cmd.pDimRegionsInUse->clear(); |
176 |
|
|
177 |
// delete all key groups |
// delete all key groups |
178 |
ActiveKeyGroups.clear(); |
ActiveKeyGroups.clear(); |
213 |
InstrumentIdxName = newInstrument->pInfo->Name; |
InstrumentIdxName = newInstrument->pInfo->Name; |
214 |
InstrumentStat = 100; |
InstrumentStat = 100; |
215 |
|
|
216 |
if (pEngine) pEngine->ChangeInstrument(this, newInstrument); |
ChangeInstrument(newInstrument); |
217 |
else pInstrument = newInstrument; |
|
|
|
|
218 |
StatusChanged(true); |
StatusChanged(true); |
219 |
} |
} |
220 |
|
|
221 |
|
|
222 |
|
/** |
223 |
|
* Changes the instrument for an engine channel. |
224 |
|
* |
225 |
|
* @param pInstrument - new instrument |
226 |
|
* @returns the resulting instrument change command after the |
227 |
|
* command switch, containing the old instrument and |
228 |
|
* the dimregions it is using |
229 |
|
*/ |
230 |
|
EngineChannel::instrument_change_command_t& EngineChannel::ChangeInstrument(::gig::Instrument* pInstrument) { |
231 |
|
instrument_change_command_t& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
232 |
|
cmd.pInstrument = pInstrument; |
233 |
|
cmd.bChangeInstrument = true; |
234 |
|
|
235 |
|
return InstrumentChangeCommand.SwitchConfig(); |
236 |
|
} |
237 |
|
|
238 |
/** |
/** |
239 |
* Will be called by the InstrumentResourceManager when the instrument |
* Will be called by the InstrumentResourceManager when the instrument |
240 |
* we are currently using on this EngineChannel is going to be updated, |
* we are currently using on this EngineChannel is going to be updated, |
277 |
pEngine = Engine::AcquireEngine(this, pAudioOut); |
pEngine = Engine::AcquireEngine(this, pAudioOut); |
278 |
ResetInternal(); |
ResetInternal(); |
279 |
pEvents = new RTList<Event>(pEngine->pEventPool); |
pEvents = new RTList<Event>(pEngine->pEventPool); |
280 |
|
|
281 |
|
// reset the instrument change command struct (need to be done |
282 |
|
// twice, as it is double buffered) |
283 |
|
{ |
284 |
|
instrument_change_command_t& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
285 |
|
cmd.pDimRegionsInUse = new RTList< ::gig::DimensionRegion*>(pEngine->pDimRegionPool[0]); |
286 |
|
cmd.pInstrument = 0; |
287 |
|
cmd.bChangeInstrument = false; |
288 |
|
} |
289 |
|
{ |
290 |
|
instrument_change_command_t& cmd = InstrumentChangeCommand.SwitchConfig(); |
291 |
|
cmd.pDimRegionsInUse = new RTList< ::gig::DimensionRegion*>(pEngine->pDimRegionPool[1]); |
292 |
|
cmd.pInstrument = 0; |
293 |
|
cmd.bChangeInstrument = false; |
294 |
|
} |
295 |
|
|
296 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
297 |
pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool); |
pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool); |
298 |
pMIDIKeyInfo[i].pEvents = new RTList<Event>(pEngine->pEventPool); |
pMIDIKeyInfo[i].pEvents = new RTList<Event>(pEngine->pEventPool); |
315 |
|
|
316 |
void EngineChannel::DisconnectAudioOutputDevice() { |
void EngineChannel::DisconnectAudioOutputDevice() { |
317 |
if (pEngine) { // if clause to prevent disconnect loops |
if (pEngine) { // if clause to prevent disconnect loops |
318 |
|
|
319 |
|
// delete the structures used for instrument change |
320 |
|
RTList< ::gig::DimensionRegion*>* d = InstrumentChangeCommand.GetConfigForUpdate().pDimRegionsInUse; |
321 |
|
if (d) delete d; |
322 |
|
EngineChannel::instrument_change_command_t& cmd = InstrumentChangeCommand.SwitchConfig(); |
323 |
|
d = cmd.pDimRegionsInUse; |
324 |
|
|
325 |
|
if (cmd.pInstrument) { |
326 |
|
// release the currently loaded instrument |
327 |
|
Engine::instruments.HandBackInstrument(cmd.pInstrument, this, d); |
328 |
|
} |
329 |
|
if (d) delete d; |
330 |
|
|
331 |
|
// release all active dimension regions to resource |
332 |
|
// manager |
333 |
|
RTList<uint>::Iterator iuiKey = pActiveKeys->first(); |
334 |
|
RTList<uint>::Iterator end = pActiveKeys->end(); |
335 |
|
while (iuiKey != end) { // iterate through all active keys |
336 |
|
midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey]; |
337 |
|
++iuiKey; |
338 |
|
|
339 |
|
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
340 |
|
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
341 |
|
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
342 |
|
Engine::instruments.HandBackDimReg(itVoice->pDimRgn); |
343 |
|
} |
344 |
|
} |
345 |
|
|
346 |
ResetInternal(); |
ResetInternal(); |
347 |
if (pEvents) { |
if (pEvents) { |
348 |
delete pEvents; |
delete pEvents; |
449 |
fxSends.push_back(pFxSend); |
fxSends.push_back(pFxSend); |
450 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
451 |
fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount()); |
fireFxSendCountChanged(iSamplerChannelIndex, GetFxSendCount()); |
452 |
|
|
453 |
return pFxSend; |
return pFxSend; |
454 |
} |
} |
455 |
|
|
757 |
if (pEngine && pEngine->pAudioOutputDevice) { |
if (pEngine && pEngine->pAudioOutputDevice) { |
758 |
// fallback to render directly to the AudioOutputDevice's buffer |
// fallback to render directly to the AudioOutputDevice's buffer |
759 |
pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight); |
pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight); |
760 |
} else pChannelRight = NULL; |
} else pChannelRight = NULL; |
761 |
} |
} |
762 |
} |
} |
763 |
for (int i = 0; i < fxSends.size(); i++) delete fxSends[i]; |
for (int i = 0; i < fxSends.size(); i++) delete fxSends[i]; |