--- linuxsampler/trunk/src/engines/gig/Engine.cpp 2004/10/25 15:14:27 293 +++ linuxsampler/trunk/src/engines/gig/Engine.cpp 2005/01/29 15:17:59 354 @@ -26,6 +26,7 @@ #include "EGADSR.h" #include "Engine.h" +#include namespace LinuxSampler { namespace gig { @@ -76,9 +77,14 @@ Engine::~Engine() { if (pDiskThread) { + dmsg(1,("Stopping disk thread...")); pDiskThread->StopThread(); delete pDiskThread; + dmsg(1,("OK\n")); } + + if (pInstrument) Instruments.HandBack(pInstrument, this); + if (pGig) delete pGig; if (pRIFF) delete pRIFF; for (uint i = 0; i < 128; i++) { @@ -88,18 +94,20 @@ for (uint i = 0; i < Event::destination_count; i++) { if (pSynthesisEvents[i]) delete pSynthesisEvents[i]; } - delete[] pSynthesisEvents; if (pEvents) delete pEvents; if (pCCEvents) delete pCCEvents; if (pEventQueue) delete pEventQueue; if (pEventPool) delete pEventPool; - if (pVoicePool) delete pVoicePool; + if (pVoicePool) { + pVoicePool->clear(); + delete pVoicePool; + } if (pActiveKeys) delete pActiveKeys; if (pSysexBuffer) delete pSysexBuffer; if (pEventGenerator) delete pEventGenerator; if (pMainFilterParameters) delete[] pMainFilterParameters; if (pBasicFilterParameters) delete[] pBasicFilterParameters; - if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0]; + if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); if (pVoiceStealingQueue) delete pVoiceStealingQueue; } @@ -158,6 +166,7 @@ ActiveVoiceCount = 0; ActiveVoiceCountMax = 0; GlobalVolume = 1.0; + CurrentKeyDimension = 0; // reset voice stealing parameters itLastStolenVoice = RTList::Iterator(); @@ -321,8 +330,10 @@ // (re)create disk thread if (this->pDiskThread) { + dmsg(1,("Stopping disk thread...")); this->pDiskThread->StopThread(); delete this->pDiskThread; + dmsg(1,("OK\n")); } this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo if (!pDiskThread) { @@ -341,8 +352,8 @@ pEventGenerator = new EventGenerator(pAudioOut->SampleRate()); // (re)allocate synthesis parameter matrix - if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0]; - pSynthesisParameters[0] = new float[Event::destination_count * pAudioOut->MaxSamplesPerCycle()]; + if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); + pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle())); for (int dst = 1; dst < Event::destination_count; dst++) pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle(); @@ -652,7 +663,15 @@ * @param itNoteOnEvent - key, velocity and time stamp of the event */ void Engine::ProcessNoteOn(Pool::Iterator& itNoteOnEvent) { - midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; + + const int key = itNoteOnEvent->Param.Note.Key; + + // Change key dimension value if key is in keyswitching area + if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high) + CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) / + (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); + + midi_key_info_t* pKey = &pMIDIKeyInfo[key]; pKey->KeyPressed = true; // the MIDI key was now pressed down @@ -726,7 +745,8 @@ * when there is no free voice * (optional, default = true) * @returns pointer to new voice or NULL if there was no free voice or - * if an error occured while trying to trigger the new voice + * if the voice wasn't triggered (for example when no region is + * defined for the given key). */ Pool::Iterator Engine::LaunchVoice(Pool::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) { midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key]; @@ -736,7 +756,7 @@ if (itNewVoice) { // launch the new voice if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) { - dmsg(1,("Triggering new voice failed!\n")); + dmsg(4,("Voice not triggered\n")); pKey->pActiveVoices->free(itNewVoice); } else { // on success @@ -1164,7 +1184,7 @@ } String Engine::Version() { - String s = "$Revision: 1.18 $"; + String s = "$Revision: 1.22 $"; return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword }