2 |
* * |
* * |
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, 2006 Christian Schoenebeck * |
* Copyright (C) 2005-2007 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 * |
51 |
if (engines.count(pDevice)) { |
if (engines.count(pDevice)) { |
52 |
dmsg(4,("Using existing gig::Engine.\n")); |
dmsg(4,("Using existing gig::Engine.\n")); |
53 |
pEngine = engines[pDevice]; |
pEngine = engines[pDevice]; |
54 |
|
|
55 |
|
// Disable the engine while the new engine channel is |
56 |
|
// added and initialized. The engine will be enabled again |
57 |
|
// in EngineChannel::Connect. |
58 |
|
pEngine->DisableAndLock(); |
59 |
} else { // create a new engine (and disk thread) instance for the given audio output device |
} else { // create a new engine (and disk thread) instance for the given audio output device |
60 |
dmsg(4,("Creating new gig::Engine.\n")); |
dmsg(4,("Creating new gig::Engine.\n")); |
61 |
pEngine = (Engine*) EngineFactory::Create("gig"); |
pEngine = (Engine*) EngineFactory::Create("gig"); |
102 |
pAudioOutputDevice = NULL; |
pAudioOutputDevice = NULL; |
103 |
pDiskThread = NULL; |
pDiskThread = NULL; |
104 |
pEventGenerator = NULL; |
pEventGenerator = NULL; |
105 |
pSysexBuffer = new RingBuffer<uint8_t>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
pSysexBuffer = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
106 |
pEventQueue = new RingBuffer<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
pEventQueue = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
107 |
pEventPool = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT); |
pEventPool = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT); |
108 |
pVoicePool = new Pool<Voice>(CONFIG_MAX_VOICES); |
pVoicePool = new Pool<Voice>(CONFIG_MAX_VOICES); |
109 |
|
pDimRegionsInUse = new ::gig::DimensionRegion*[CONFIG_MAX_VOICES + 1]; |
110 |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
111 |
pGlobalEvents = new RTList<Event>(pEventPool); |
pGlobalEvents = new RTList<Event>(pEventPool); |
112 |
|
InstrumentChangeQueue = new RingBuffer<instrument_change_command_t,false>(1, 0); |
113 |
|
InstrumentChangeReplyQueue = new RingBuffer<instrument_change_reply_t,false>(1, 0); |
114 |
|
|
115 |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
116 |
iterVoice->SetEngine(this); |
iterVoice->SetEngine(this); |
117 |
} |
} |
125 |
* Destructor |
* Destructor |
126 |
*/ |
*/ |
127 |
Engine::~Engine() { |
Engine::~Engine() { |
128 |
|
MidiInputPort::RemoveSysexListener(this); |
129 |
if (pDiskThread) { |
if (pDiskThread) { |
130 |
dmsg(1,("Stopping disk thread...")); |
dmsg(1,("Stopping disk thread...")); |
131 |
pDiskThread->StopThread(); |
pDiskThread->StopThread(); |
141 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
142 |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
143 |
if (pSysexBuffer) delete pSysexBuffer; |
if (pSysexBuffer) delete pSysexBuffer; |
144 |
EngineFactory::Destroy(this); |
Unregister(); |
145 |
} |
} |
146 |
|
|
147 |
void Engine::Enable() { |
void Engine::Enable() { |
175 |
|
|
176 |
/** |
/** |
177 |
* Reset all voices and disk thread and clear input event queue and all |
* Reset all voices and disk thread and clear input event queue and all |
178 |
* control and status variables. This method is not thread safe! |
* control and status variables. This method is protected by a mutex. |
179 |
*/ |
*/ |
180 |
void Engine::ResetInternal() { |
void Engine::ResetInternal() { |
181 |
|
ResetInternalMutex.Lock(); |
182 |
|
|
183 |
|
// make sure that the engine does not get any sysex messages |
184 |
|
// while it's reseting |
185 |
|
bool sysexDisabled = MidiInputPort::RemoveSysexListener(this); |
186 |
ActiveVoiceCount = 0; |
ActiveVoiceCount = 0; |
187 |
ActiveVoiceCountMax = 0; |
ActiveVoiceCountMax = 0; |
188 |
|
|
206 |
// delete all input events |
// delete all input events |
207 |
pEventQueue->init(); |
pEventQueue->init(); |
208 |
pSysexBuffer->init(); |
pSysexBuffer->init(); |
209 |
|
if (sysexDisabled) MidiInputPort::AddSysexListener(this); |
210 |
|
ResetInternalMutex.Unlock(); |
211 |
} |
} |
212 |
|
|
213 |
/** |
/** |
237 |
} |
} |
238 |
catch (AudioOutputException e) { |
catch (AudioOutputException e) { |
239 |
String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message(); |
String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message(); |
240 |
throw LinuxSamplerException(msg); |
throw Exception(msg); |
241 |
} |
} |
242 |
|
|
243 |
this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle(); |
this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle(); |
266 |
delete this->pDiskThread; |
delete this->pDiskThread; |
267 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
268 |
} |
} |
269 |
this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6); //FIXME: assuming stereo |
this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6, //FIXME: assuming stereo |
270 |
|
&instruments); |
271 |
if (!pDiskThread) { |
if (!pDiskThread) { |
272 |
dmsg(0,("gig::Engine new diskthread = NULL\n")); |
dmsg(0,("gig::Engine new diskthread = NULL\n")); |
273 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
316 |
* current audio cycle |
* current audio cycle |
317 |
*/ |
*/ |
318 |
void Engine::ImportEvents(uint Samples) { |
void Engine::ImportEvents(uint Samples) { |
319 |
RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
320 |
Event* pEvent; |
Event* pEvent; |
321 |
while (true) { |
while (true) { |
322 |
// get next event from input event queue |
// get next event from input event queue |
339 |
} |
} |
340 |
|
|
341 |
/** |
/** |
342 |
* Let this engine proceed to render the given amount of sample points. The |
* Let this engine proceed to render the given amount of sample points. |
343 |
* calculated audio data of all voices of this engine will be placed into |
* The engine will iterate through all engine channels and render audio |
344 |
* the engine's audio sum buffer which has to be copied and eventually be |
* for each engine channel independently. The calculated audio data of |
345 |
* converted to the appropriate value range by the audio output class (e.g. |
* all voices of each engine channel will be placed into the audio sum |
346 |
* AlsaIO or JackIO) right after. |
* buffers of the respective audio output device, connected to the |
347 |
|
* respective engine channel. |
348 |
* |
* |
349 |
* @param Samples - number of sample points to be rendered |
* @param Samples - number of sample points to be rendered |
350 |
* @returns 0 on success |
* @returns 0 on success |
351 |
*/ |
*/ |
352 |
int Engine::RenderAudio(uint Samples) { |
int Engine::RenderAudio(uint Samples) { |
353 |
dmsg(5,("RenderAudio(Samples=%d)\n", Samples)); |
dmsg(7,("RenderAudio(Samples=%d)\n", Samples)); |
354 |
|
|
355 |
// return if engine disabled |
// return if engine disabled |
356 |
if (EngineDisabled.Pop()) { |
if (EngineDisabled.Pop()) { |
387 |
// reset internal voice counter (just for statistic of active voices) |
// reset internal voice counter (just for statistic of active voices) |
388 |
ActiveVoiceCountTemp = 0; |
ActiveVoiceCountTemp = 0; |
389 |
|
|
390 |
|
// handle instrument change commands |
391 |
|
instrument_change_command_t command; |
392 |
|
if (InstrumentChangeQueue->pop(&command) > 0) { |
393 |
|
EngineChannel* pEngineChannel = command.pEngineChannel; |
394 |
|
pEngineChannel->pInstrument = command.pInstrument; |
395 |
|
|
396 |
|
// iterate through all active voices and mark their |
397 |
|
// dimension regions as "in use". The instrument resource |
398 |
|
// manager may delete all of the instrument except the |
399 |
|
// dimension regions and samples that are in use. |
400 |
|
int i = 0; |
401 |
|
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
402 |
|
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
403 |
|
while (iuiKey != end) { // iterate through all active keys |
404 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
405 |
|
++iuiKey; |
406 |
|
|
407 |
|
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
408 |
|
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
409 |
|
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
410 |
|
if (!itVoice->Orphan) { |
411 |
|
itVoice->Orphan = true; |
412 |
|
pDimRegionsInUse[i++] = itVoice->pDimRgn; |
413 |
|
} |
414 |
|
} |
415 |
|
} |
416 |
|
pDimRegionsInUse[i] = 0; // end of list |
417 |
|
|
418 |
|
// send a reply to the calling thread, which is waiting |
419 |
|
instrument_change_reply_t reply; |
420 |
|
InstrumentChangeReplyQueue->push(&reply); |
421 |
|
} |
422 |
|
|
423 |
// handle events on all engine channels |
// handle events on all engine channels |
424 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
|
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
|
425 |
ProcessEvents(engineChannels[i], Samples); |
ProcessEvents(engineChannels[i], Samples); |
426 |
} |
} |
427 |
|
|
428 |
// render all 'normal', active voices on all engine channels |
// render all 'normal', active voices on all engine channels |
429 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
|
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
|
430 |
RenderActiveVoices(engineChannels[i], Samples); |
RenderActiveVoices(engineChannels[i], Samples); |
431 |
} |
} |
432 |
|
|
433 |
// now that all ordinary voices on ALL engine channels are rendered, render new stolen voices |
// now that all ordinary voices on ALL engine channels are rendered, render new stolen voices |
434 |
RenderStolenVoices(Samples); |
RenderStolenVoices(Samples); |
435 |
|
|
436 |
|
// handle audio routing for engine channels with FX sends |
437 |
|
for (int i = 0; i < engineChannels.size(); i++) { |
438 |
|
if (engineChannels[i]->fxSends.empty()) continue; // ignore if no FX sends |
439 |
|
RouteAudio(engineChannels[i], Samples); |
440 |
|
} |
441 |
|
|
442 |
// handle cleanup on all engine channels for the next audio fragment |
// handle cleanup on all engine channels for the next audio fragment |
443 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
|
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
|
444 |
PostProcess(engineChannels[i]); |
PostProcess(engineChannels[i]); |
445 |
} |
} |
446 |
|
|
559 |
RTList<Event>::Iterator end = pVoiceStealingQueue->end(); |
RTList<Event>::Iterator end = pVoiceStealingQueue->end(); |
560 |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
561 |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
562 |
|
if (!pEngineChannel->pInstrument) continue; // ignore if no instrument loaded |
563 |
Pool<Voice>::Iterator itNewVoice = |
Pool<Voice>::Iterator itNewVoice = |
564 |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false, false); |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false, false); |
565 |
if (itNewVoice) { |
if (itNewVoice) { |
579 |
} |
} |
580 |
|
|
581 |
/** |
/** |
582 |
|
* Will be called in case the respective engine channel sports FX send |
583 |
|
* channels. In this particular case, engine channel local buffers are |
584 |
|
* used to render and mix all voices to. This method is responsible for |
585 |
|
* copying the audio data from those local buffers to the master audio |
586 |
|
* output channels as well as to the FX send audio output channels with |
587 |
|
* their respective FX send levels. |
588 |
|
* |
589 |
|
* @param pEngineChannel - engine channel from which audio should be |
590 |
|
* routed |
591 |
|
* @param Samples - amount of sample points to be routed in |
592 |
|
* this audio fragment cycle |
593 |
|
*/ |
594 |
|
void Engine::RouteAudio(EngineChannel* pEngineChannel, uint Samples) { |
595 |
|
// route master signal |
596 |
|
{ |
597 |
|
AudioChannel* pDstL = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelLeft); |
598 |
|
AudioChannel* pDstR = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelRight); |
599 |
|
pEngineChannel->pChannelLeft->MixTo(pDstL, Samples); |
600 |
|
pEngineChannel->pChannelRight->MixTo(pDstR, Samples); |
601 |
|
} |
602 |
|
// route FX send signal |
603 |
|
{ |
604 |
|
for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) { |
605 |
|
FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend); |
606 |
|
// left channel |
607 |
|
const int iDstL = pFxSend->DestinationChannel(0); |
608 |
|
if (iDstL < 0) { |
609 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (L) destination channel")); |
610 |
|
} else { |
611 |
|
AudioChannel* pDstL = pAudioOutputDevice->Channel(iDstL); |
612 |
|
if (!pDstL) { |
613 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (L) destination channel")); |
614 |
|
} else pEngineChannel->pChannelLeft->MixTo(pDstL, Samples, pFxSend->Level()); |
615 |
|
} |
616 |
|
// right channel |
617 |
|
const int iDstR = pFxSend->DestinationChannel(1); |
618 |
|
if (iDstR < 0) { |
619 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (R) destination channel")); |
620 |
|
} else { |
621 |
|
AudioChannel* pDstR = pAudioOutputDevice->Channel(iDstR); |
622 |
|
if (!pDstR) { |
623 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (R) destination channel")); |
624 |
|
} else pEngineChannel->pChannelRight->MixTo(pDstR, Samples, pFxSend->Level()); |
625 |
|
} |
626 |
|
} |
627 |
|
} |
628 |
|
// reset buffers with silence (zero out) for the next audio cycle |
629 |
|
pEngineChannel->pChannelLeft->Clear(); |
630 |
|
pEngineChannel->pChannelRight->Clear(); |
631 |
|
} |
632 |
|
|
633 |
|
/** |
634 |
* Free all keys which have turned inactive in this audio fragment, from |
* Free all keys which have turned inactive in this audio fragment, from |
635 |
* the list of active keys and clear all event lists on that engine |
* the list of active keys and clear all event lists on that engine |
636 |
* channel. |
* channel. |
707 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
708 |
#endif |
#endif |
709 |
|
|
710 |
|
if (!pEngineChannel->pInstrument) return; // ignore if no instrument loaded |
711 |
|
|
712 |
const int key = itNoteOnEvent->Param.Note.Key; |
const int key = itNoteOnEvent->Param.Note.Key; |
713 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
714 |
|
|
744 |
{ |
{ |
745 |
const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument; |
const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument; |
746 |
if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high) |
if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high) |
747 |
pEngineChannel->CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) / |
pEngineChannel->CurrentKeyDimension = float(key - pInstrument->DimensionKeyRange.low) / |
748 |
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
749 |
} |
} |
750 |
|
|
806 |
bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key); |
bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key); |
807 |
|
|
808 |
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
809 |
if (pEngineChannel->SoloMode) { //TODO: this feels like too much code just for handling solo mode :P |
if (pEngineChannel->SoloMode && pEngineChannel->pInstrument) { //TODO: this feels like too much code just for handling solo mode :P |
810 |
bool bOtherKeysPressed = false; |
bool bOtherKeysPressed = false; |
811 |
if (iKey == pEngineChannel->SoloKey) { |
if (iKey == pEngineChannel->SoloKey) { |
812 |
pEngineChannel->SoloKey = -1; |
pEngineChannel->SoloKey = -1; |
869 |
itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type |
itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type |
870 |
|
|
871 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
872 |
if (pKey->ReleaseTrigger) { |
if (pKey->ReleaseTrigger && pEngineChannel->pInstrument) { |
873 |
// first, get total amount of required voices (dependant on amount of layers) |
// first, get total amount of required voices (dependant on amount of layers) |
874 |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); |
875 |
if (pRegion) { |
if (pRegion) { |
972 |
DimValues[i] = itNoteOnEvent->Param.Note.Velocity; |
DimValues[i] = itNoteOnEvent->Param.Note.Velocity; |
973 |
break; |
break; |
974 |
case ::gig::dimension_channelaftertouch: |
case ::gig::dimension_channelaftertouch: |
975 |
DimValues[i] = 0; //TODO: we currently ignore this dimension |
DimValues[i] = pEngineChannel->ControllerTable[128]; |
976 |
break; |
break; |
977 |
case ::gig::dimension_releasetrigger: |
case ::gig::dimension_releasetrigger: |
978 |
VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal; |
VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal; |
979 |
DimValues[i] = (uint) ReleaseTriggerVoice; |
DimValues[i] = (uint) ReleaseTriggerVoice; |
980 |
break; |
break; |
981 |
case ::gig::dimension_keyboard: |
case ::gig::dimension_keyboard: |
982 |
DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension; |
DimValues[i] = (uint) (pEngineChannel->CurrentKeyDimension * pRegion->pDimensionDefinitions[i].zones); |
983 |
break; |
break; |
984 |
case ::gig::dimension_roundrobin: |
case ::gig::dimension_roundrobin: |
985 |
DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on |
DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on |
1064 |
std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush; |
std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush; |
1065 |
} |
} |
1066 |
} |
} |
1067 |
|
|
1068 |
|
// return if this is a release triggered voice and there is no |
1069 |
|
// releasetrigger dimension (could happen if an instrument |
1070 |
|
// change has occured between note on and off) |
1071 |
|
if (ReleaseTriggerVoice && VoiceType != Voice::type_release_trigger) return Pool<Voice>::Iterator(); |
1072 |
|
|
1073 |
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues); |
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues); |
1074 |
|
|
1075 |
// no need to continue if sample is silent |
// no need to continue if sample is silent |
1299 |
|
|
1300 |
uint keygroup = itVoice->KeyGroup; |
uint keygroup = itVoice->KeyGroup; |
1301 |
|
|
1302 |
|
// if the sample and dimension region belong to an |
1303 |
|
// instrument that is unloaded, tell the disk thread to |
1304 |
|
// release them |
1305 |
|
if (itVoice->Orphan) { |
1306 |
|
pDiskThread->OrderDeletionOfDimreg(itVoice->pDimRgn); |
1307 |
|
} |
1308 |
|
|
1309 |
// free the voice object |
// free the voice object |
1310 |
pVoicePool->free(itVoice); |
pVoicePool->free(itVoice); |
1311 |
|
|
1350 |
// update controller value in the engine channel's controller table |
// update controller value in the engine channel's controller table |
1351 |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
1352 |
|
|
1353 |
|
// handle hard coded MIDI controllers |
1354 |
switch (itControlChangeEvent->Param.CC.Controller) { |
switch (itControlChangeEvent->Param.CC.Controller) { |
1355 |
case 5: { // portamento time |
case 5: { // portamento time |
1356 |
pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
1358 |
} |
} |
1359 |
case 7: { // volume |
case 7: { // volume |
1360 |
//TODO: not sample accurate yet |
//TODO: not sample accurate yet |
1361 |
pEngineChannel->GlobalVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value] * CONFIG_GLOBAL_ATTENUATION; |
pEngineChannel->MidiVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value]; |
1362 |
pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag |
pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag |
1363 |
break; |
break; |
1364 |
} |
} |
1473 |
break; |
break; |
1474 |
} |
} |
1475 |
case 123: { // all notes off |
case 123: { // all notes off |
1476 |
|
#if CONFIG_PROCESS_ALL_NOTES_OFF |
1477 |
ReleaseAllVoices(pEngineChannel, itControlChangeEvent); |
ReleaseAllVoices(pEngineChannel, itControlChangeEvent); |
1478 |
|
#endif // CONFIG_PROCESS_ALL_NOTES_OFF |
1479 |
break; |
break; |
1480 |
} |
} |
1481 |
case 126: { // mono mode on |
case 126: { // mono mode on |
1489 |
break; |
break; |
1490 |
} |
} |
1491 |
} |
} |
1492 |
|
|
1493 |
|
// handle FX send controllers |
1494 |
|
if (!pEngineChannel->fxSends.empty()) { |
1495 |
|
for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) { |
1496 |
|
FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend); |
1497 |
|
if (pFxSend->MidiController() == itControlChangeEvent->Param.CC.Controller) |
1498 |
|
pFxSend->SetLevel(itControlChangeEvent->Param.CC.Value); |
1499 |
|
} |
1500 |
|
} |
1501 |
} |
} |
1502 |
|
|
1503 |
/** |
/** |
1506 |
* @param itSysexEvent - sysex data size and time stamp of the sysex event |
* @param itSysexEvent - sysex data size and time stamp of the sysex event |
1507 |
*/ |
*/ |
1508 |
void Engine::ProcessSysex(Pool<Event>::Iterator& itSysexEvent) { |
void Engine::ProcessSysex(Pool<Event>::Iterator& itSysexEvent) { |
1509 |
RingBuffer<uint8_t>::NonVolatileReader reader = pSysexBuffer->get_non_volatile_reader(); |
RingBuffer<uint8_t,false>::NonVolatileReader reader = pSysexBuffer->get_non_volatile_reader(); |
1510 |
|
|
1511 |
uint8_t exclusive_status, id; |
uint8_t exclusive_status, id; |
1512 |
if (!reader.pop(&exclusive_status)) goto free_sysex_data; |
if (!reader.pop(&exclusive_status)) goto free_sysex_data; |
1525 |
|
|
1526 |
// command address |
// command address |
1527 |
uint8_t addr[3]; // 2 byte addr MSB, followed by 1 byte addr LSB) |
uint8_t addr[3]; // 2 byte addr MSB, followed by 1 byte addr LSB) |
1528 |
const RingBuffer<uint8_t>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later |
const RingBuffer<uint8_t,false>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later |
1529 |
if (reader.read(&addr[0], 3) != 3) goto free_sysex_data; |
if (reader.read(&addr[0], 3) != 3) goto free_sysex_data; |
1530 |
if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters |
if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters |
1531 |
dmsg(3,("\tSystem Parameter\n")); |
dmsg(3,("\tSystem Parameter\n")); |
1572 |
* question |
* question |
1573 |
* @param DataSize - size of the GS message data (in bytes) |
* @param DataSize - size of the GS message data (in bytes) |
1574 |
*/ |
*/ |
1575 |
uint8_t Engine::GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize) { |
uint8_t Engine::GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize) { |
1576 |
RingBuffer<uint8_t>::NonVolatileReader reader = AddrReader; |
RingBuffer<uint8_t,false>::NonVolatileReader reader = AddrReader; |
1577 |
uint bytes = 3 /*addr*/ + DataSize; |
uint bytes = 3 /*addr*/ + DataSize; |
1578 |
uint8_t addr_and_data[bytes]; |
uint8_t addr_and_data[bytes]; |
1579 |
reader.read(&addr_and_data[0], bytes); |
reader.read(&addr_and_data[0], bytes); |
1692 |
} |
} |
1693 |
|
|
1694 |
String Engine::Version() { |
String Engine::Version() { |
1695 |
String s = "$Revision: 1.58 $"; |
String s = "$Revision: 1.72 $"; |
1696 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
1697 |
} |
} |
1698 |
|
|
1699 |
|
InstrumentManager* Engine::GetInstrumentManager() { |
1700 |
|
return &instruments; |
1701 |
|
} |
1702 |
|
|
1703 |
// static constant initializers |
// static constant initializers |
1704 |
const float* Engine::VolumeCurve(InitVolumeCurve()); |
const float* Engine::VolumeCurve(InitVolumeCurve()); |
1705 |
const float* Engine::PanCurve(InitPanCurve()); |
const float* Engine::PanCurve(InitPanCurve()); |
1706 |
|
const float* Engine::CrossfadeCurve(InitCrossfadeCurve()); |
1707 |
|
|
1708 |
float* Engine::InitVolumeCurve() { |
float* Engine::InitVolumeCurve() { |
1709 |
// line-segment approximation |
// line-segment approximation |
1724 |
return InitCurve(segments, 129); |
return InitCurve(segments, 129); |
1725 |
} |
} |
1726 |
|
|
1727 |
|
float* Engine::InitCrossfadeCurve() { |
1728 |
|
// line-segment approximation |
1729 |
|
const float segments[] = { |
1730 |
|
0, 0, 1, 0.03, 10, 0.1, 51, 0.58, 127, 1 |
1731 |
|
}; |
1732 |
|
return InitCurve(segments); |
1733 |
|
} |
1734 |
|
|
1735 |
float* Engine::InitCurve(const float* segments, int size) { |
float* Engine::InitCurve(const float* segments, int size) { |
1736 |
float* y = new float[size]; |
float* y = new float[size]; |
1737 |
for (int x = 0 ; x < size ; x++) { |
for (int x = 0 ; x < size ; x++) { |
1742 |
return y; |
return y; |
1743 |
} |
} |
1744 |
|
|
1745 |
|
/** |
1746 |
|
* Changes the instrument for an engine channel. |
1747 |
|
* |
1748 |
|
* @param pEngineChannel - engine channel on which the instrument |
1749 |
|
* should be changed |
1750 |
|
* @param pInstrument - new instrument |
1751 |
|
* @returns a list of dimension regions from the old instrument |
1752 |
|
* that are still in use |
1753 |
|
*/ |
1754 |
|
::gig::DimensionRegion** Engine::ChangeInstrument(EngineChannel* pEngineChannel, ::gig::Instrument* pInstrument) { |
1755 |
|
instrument_change_command_t command; |
1756 |
|
command.pEngineChannel = pEngineChannel; |
1757 |
|
command.pInstrument = pInstrument; |
1758 |
|
InstrumentChangeQueue->push(&command); |
1759 |
|
|
1760 |
|
// wait for the audio thread to confirm that the instrument |
1761 |
|
// change has been done |
1762 |
|
instrument_change_reply_t reply; |
1763 |
|
while (InstrumentChangeReplyQueue->pop(&reply) == 0) { |
1764 |
|
usleep(10000); |
1765 |
|
} |
1766 |
|
return pDimRegionsInUse; |
1767 |
|
} |
1768 |
|
|
1769 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |