/[svn]/linuxsampler/trunk/src/engines/gig/Engine.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/Engine.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 271 by schoenebeck, Fri Oct 8 20:51:39 2004 UTC revision 376 by senkov, Sat Feb 12 23:48:50 2005 UTC
# Line 23  Line 23 
23  #include <sstream>  #include <sstream>
24  #include "DiskThread.h"  #include "DiskThread.h"
25  #include "Voice.h"  #include "Voice.h"
26    #include "EGADSR.h"
27    
28  #include "Engine.h"  #include "Engine.h"
29    
30    #if defined(__APPLE__)
31    # include <stdlib.h>
32    #else
33    # include <malloc.h>
34    #endif
35    
36  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
37    
38      InstrumentResourceManager Engine::Instruments;      InstrumentResourceManager Engine::Instruments;
# Line 75  namespace LinuxSampler { namespace gig { Line 82  namespace LinuxSampler { namespace gig {
82    
83      Engine::~Engine() {      Engine::~Engine() {
84          if (pDiskThread) {          if (pDiskThread) {
85                dmsg(1,("Stopping disk thread..."));
86              pDiskThread->StopThread();              pDiskThread->StopThread();
87              delete pDiskThread;              delete pDiskThread;
88                dmsg(1,("OK\n"));
89          }          }
90    
91            if (pInstrument) Instruments.HandBack(pInstrument, this);
92    
93          if (pGig)  delete pGig;          if (pGig)  delete pGig;
94          if (pRIFF) delete pRIFF;          if (pRIFF) delete pRIFF;
95          for (uint i = 0; i < 128; i++) {          for (uint i = 0; i < 128; i++) {
# Line 87  namespace LinuxSampler { namespace gig { Line 99  namespace LinuxSampler { namespace gig {
99          for (uint i = 0; i < Event::destination_count; i++) {          for (uint i = 0; i < Event::destination_count; i++) {
100              if (pSynthesisEvents[i]) delete pSynthesisEvents[i];              if (pSynthesisEvents[i]) delete pSynthesisEvents[i];
101          }          }
         delete[] pSynthesisEvents;  
102          if (pEvents)     delete pEvents;          if (pEvents)     delete pEvents;
103          if (pCCEvents)   delete pCCEvents;          if (pCCEvents)   delete pCCEvents;
104          if (pEventQueue) delete pEventQueue;          if (pEventQueue) delete pEventQueue;
105          if (pEventPool)  delete pEventPool;          if (pEventPool)  delete pEventPool;
106          if (pVoicePool)  delete pVoicePool;          if (pVoicePool) {
107                    pVoicePool->clear();
108                    delete pVoicePool;
109            }
110          if (pActiveKeys) delete pActiveKeys;          if (pActiveKeys) delete pActiveKeys;
111          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
112          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
113          if (pMainFilterParameters) delete[] pMainFilterParameters;          if (pMainFilterParameters) delete[] pMainFilterParameters;
114          if (pBasicFilterParameters) delete[] pBasicFilterParameters;          if (pBasicFilterParameters) delete[] pBasicFilterParameters;
115          if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0];          if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);
116          if (pVoiceStealingQueue) delete pVoiceStealingQueue;          if (pVoiceStealingQueue) delete pVoiceStealingQueue;
117      }      }
118    
# Line 157  namespace LinuxSampler { namespace gig { Line 171  namespace LinuxSampler { namespace gig {
171          ActiveVoiceCount    = 0;          ActiveVoiceCount    = 0;
172          ActiveVoiceCountMax = 0;          ActiveVoiceCountMax = 0;
173          GlobalVolume        = 1.0;          GlobalVolume        = 1.0;
174            CurrentKeyDimension = 0;
175    
176          // reset voice stealing parameters          // reset voice stealing parameters
177          itLastStolenVoice = RTList<Voice>::Iterator();          itLastStolenVoice = RTList<Voice>::Iterator();
# Line 257  namespace LinuxSampler { namespace gig { Line 272  namespace LinuxSampler { namespace gig {
272          for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion())          for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion())
273              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;
274    
275            InstrumentIdxName = pInstrument->pInfo->Name;
276          InstrumentStat = 100;          InstrumentStat = 100;
277    
278          // inform audio driver for the need of two channels          // inform audio driver for the need of two channels
# Line 313  namespace LinuxSampler { namespace gig { Line 329  namespace LinuxSampler { namespace gig {
329          this->MaxSamplesPerCycle      = pAudioOutputDevice->MaxSamplesPerCycle();          this->MaxSamplesPerCycle      = pAudioOutputDevice->MaxSamplesPerCycle();
330          this->SampleRate              = pAudioOutputDevice->SampleRate();          this->SampleRate              = pAudioOutputDevice->SampleRate();
331    
332            // FIXME: audio drivers with varying fragment sizes might be a problem here
333            MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * EG_MIN_RELEASE_TIME) - 1;
334            if (MaxFadeOutPos < 0)
335                throw LinuxSamplerException("EG_MIN_RELEASE_TIME in EGADSR.h to big for current audio fragment size / sampling rate!");
336    
337          // (re)create disk thread          // (re)create disk thread
338          if (this->pDiskThread) {          if (this->pDiskThread) {
339                dmsg(1,("Stopping disk thread..."));
340              this->pDiskThread->StopThread();              this->pDiskThread->StopThread();
341              delete this->pDiskThread;              delete this->pDiskThread;
342                dmsg(1,("OK\n"));
343          }          }
344          this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo          this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo
345          if (!pDiskThread) {          if (!pDiskThread) {
# Line 335  namespace LinuxSampler { namespace gig { Line 358  namespace LinuxSampler { namespace gig {
358          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());
359    
360          // (re)allocate synthesis parameter matrix          // (re)allocate synthesis parameter matrix
361          if (pSynthesisParameters[0]) delete[] pSynthesisParameters[0];          if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);
362          pSynthesisParameters[0] = new float[Event::destination_count * pAudioOut->MaxSamplesPerCycle()];  
363            #if defined(__APPLE__)
364            pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle());
365            #else
366            pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()));
367            #endif
368          for (int dst = 1; dst < Event::destination_count; dst++)          for (int dst = 1; dst < Event::destination_count; dst++)
369              pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();              pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();
370    
# Line 392  namespace LinuxSampler { namespace gig { Line 420  namespace LinuxSampler { namespace gig {
420          }          }
421    
422    
423            // update time of start and end of this audio fragment (as events' time stamps relate to this)
424            pEventGenerator->UpdateFragmentTime(Samples);
425    
426    
427          // empty the event lists for the new fragment          // empty the event lists for the new fragment
428          pEvents->clear();          pEvents->clear();
429          pCCEvents->clear();          pCCEvents->clear();
# Line 406  namespace LinuxSampler { namespace gig { Line 438  namespace LinuxSampler { namespace gig {
438              }              }
439          }          }
440    
         // read and copy events from input queue  
         Event event = pEventGenerator->CreateEvent();  
         while (true) {  
             if (!pEventQueue->pop(&event) || pEvents->poolIsEmpty()) break;  
             *pEvents->allocAppend() = event;  
         }  
   
441    
442          // update time of start and end of this audio fragment (as events' time stamps relate to this)          // get all events from the input event queue which belong to the current fragment
443          pEventGenerator->UpdateFragmentTime(Samples);          {
444                RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();
445                Event* pEvent;
446                while (true) {
447                    // get next event from input event queue
448                    if (!(pEvent = eventQueueReader.pop())) break;
449                    // if younger event reached, ignore that and all subsequent ones for now
450                    if (pEvent->FragmentPos() >= Samples) {
451                        eventQueueReader--;
452                        dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples));
453                        pEvent->ResetFragmentPos();
454                        break;
455                    }
456                    // copy event to internal event list
457                    if (pEvents->poolIsEmpty()) {
458                        dmsg(1,("Event pool emtpy!\n"));
459                        break;
460                    }
461                    *pEvents->allocAppend() = *pEvent;
462                }
463                eventQueueReader.free(); // free all copied events from input queue
464            }
465    
466    
467          // process events          // process events
# Line 466  namespace LinuxSampler { namespace gig { Line 512  namespace LinuxSampler { namespace gig {
512                      itVoice->Render(Samples);                      itVoice->Render(Samples);
513                      if (itVoice->IsActive()) active_voices++; // still active                      if (itVoice->IsActive()) active_voices++; // still active
514                      else { // voice reached end, is now inactive                      else { // voice reached end, is now inactive
515                          KillVoiceImmediately(itVoice); // remove voice from the list of active voices                          FreeVoice(itVoice); // remove voice from the list of active voices
516                      }                      }
517                  }                  }
518              }              }
# Line 480  namespace LinuxSampler { namespace gig { Line 526  namespace LinuxSampler { namespace gig {
526              for (; itVoiceStealEvent != end; ++itVoiceStealEvent) {              for (; itVoiceStealEvent != end; ++itVoiceStealEvent) {
527                  Pool<Voice>::Iterator itNewVoice = LaunchVoice(itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false);                  Pool<Voice>::Iterator itNewVoice = LaunchVoice(itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false);
528                  if (itNewVoice) {                  if (itNewVoice) {
529                      itNewVoice->Render(Samples);                      for (; itNewVoice; itNewVoice = itNewVoice->itChildVoice) {
530                      if (itNewVoice->IsActive()) active_voices++; // still active                          itNewVoice->Render(Samples);
531                      else { // voice reached end, is now inactive                          if (itNewVoice->IsActive()) active_voices++; // still active
532                          KillVoiceImmediately(itNewVoice); // remove voice from the list of active voices                          else { // voice reached end, is now inactive
533                                FreeVoice(itNewVoice); // remove voice from the list of active voices
534                            }
535                      }                      }
536                  }                  }
537                  else dmsg(1,("Ouch, voice stealing didn't work out!\n"));                  else dmsg(1,("gig::Engine: ERROR, voice stealing didn't work out!\n"));
538              }              }
539          }          }
540          // reset voice stealing for the new fragment          // reset voice stealing for the new fragment
# Line 495  namespace LinuxSampler { namespace gig { Line 543  namespace LinuxSampler { namespace gig {
543          iuiLastStolenKey  = RTList<uint>::Iterator();          iuiLastStolenKey  = RTList<uint>::Iterator();
544    
545    
546            // free all keys which have no active voices left
547            {
548                RTList<uint>::Iterator iuiKey = pActiveKeys->first();
549                RTList<uint>::Iterator end    = pActiveKeys->end();
550                while (iuiKey != end) { // iterate through all active keys
551                    midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey];
552                    ++iuiKey;
553                    if (pKey->pActiveVoices->isEmpty()) FreeKey(pKey);
554                    #if DEVMODE
555                    else { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)
556                        RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();
557                        RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();
558                        for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
559                            if (itVoice->itKillEvent) {
560                                dmsg(1,("gig::Engine: ERROR, killed voice survived !!!\n"));
561                            }
562                        }
563                    }
564                    #endif // DEVMODE
565                }
566            }
567    
568    
569          // write that to the disk thread class so that it can print it          // write that to the disk thread class so that it can print it
570          // on the console for debugging purposes          // on the console for debugging purposes
571          ActiveVoiceCount = active_voices;          ActiveVoiceCount = active_voices;
# Line 603  namespace LinuxSampler { namespace gig { Line 674  namespace LinuxSampler { namespace gig {
674       *  @param itNoteOnEvent - key, velocity and time stamp of the event       *  @param itNoteOnEvent - key, velocity and time stamp of the event
675       */       */
676      void Engine::ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent) {      void Engine::ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent) {
677          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];  
678            const int key = itNoteOnEvent->Param.Note.Key;
679    
680            // Change key dimension value if key is in keyswitching area
681            if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)
682                CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) /
683                    (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);
684    
685            midi_key_info_t* pKey = &pMIDIKeyInfo[key];
686    
687          pKey->KeyPressed = true; // the MIDI key was now pressed down          pKey->KeyPressed = true; // the MIDI key was now pressed down
688    
# Line 621  namespace LinuxSampler { namespace gig { Line 700  namespace LinuxSampler { namespace gig {
700          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
701    
702          // allocate and trigger a new voice for the key          // allocate and trigger a new voice for the key
703          LaunchVoice(itNoteOnEventOnKeyList);          LaunchVoice(itNoteOnEventOnKeyList, 0, false, true);
704      }      }
705    
706      /**      /**
# Line 647  namespace LinuxSampler { namespace gig { Line 726  namespace LinuxSampler { namespace gig {
726    
727          // spawn release triggered voice(s) if needed          // spawn release triggered voice(s) if needed
728          if (pKey->ReleaseTrigger) {          if (pKey->ReleaseTrigger) {
729              LaunchVoice(itNoteOffEventOnKeyList, 0, true);              LaunchVoice(itNoteOffEventOnKeyList, 0, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples
730              pKey->ReleaseTrigger = false;              pKey->ReleaseTrigger = false;
731          }          }
732      }      }
# Line 677  namespace LinuxSampler { namespace gig { Line 756  namespace LinuxSampler { namespace gig {
756       *                               when there is no free voice       *                               when there is no free voice
757       *                               (optional, default = true)       *                               (optional, default = true)
758       *  @returns pointer to new voice or NULL if there was no free voice or       *  @returns pointer to new voice or NULL if there was no free voice or
759       *           if an error occured while trying to trigger the new voice       *           if the voice wasn't triggered (for example when no region is
760         *           defined for the given key).
761       */       */
762      Pool<Voice>::Iterator Engine::LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) {      Pool<Voice>::Iterator Engine::LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing) {
763          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];          midi_key_info_t* pKey = &pMIDIKeyInfo[itNoteOnEvent->Param.Note.Key];
# Line 686  namespace LinuxSampler { namespace gig { Line 766  namespace LinuxSampler { namespace gig {
766          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();
767          if (itNewVoice) {          if (itNewVoice) {
768              // launch the new voice              // launch the new voice
769              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice) < 0) {              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) {
770                  dmsg(1,("Triggering new voice failed!\n"));                  dmsg(4,("Voice not triggered\n"));
771                  pKey->pActiveVoices->free(itNewVoice);                  pKey->pActiveVoices->free(itNewVoice);
772              }              }
773              else { // on success              else { // on success
# Line 716  namespace LinuxSampler { namespace gig { Line 796  namespace LinuxSampler { namespace gig {
796                  return itNewVoice; // success                  return itNewVoice; // success
797              }              }
798          }          }
799          else if (VoiceStealing) StealVoice(itNoteOnEvent, iLayer, ReleaseTriggerVoice); // no free voice left, so steal one          else if (VoiceStealing) {
800                // first, get total amount of required voices (dependant on amount of layers)
801                ::gig::Region* pRegion = pInstrument->GetRegion(itNoteOnEvent->Param.Note.Key);
802                if (!pRegion) return Pool<Voice>::Iterator(); // nothing defined for this MIDI key, so no voice needed
803                int voicesRequired = pRegion->Layers;
804    
805                // now steal the (remaining) amount of voices
806                for (int i = iLayer; i < voicesRequired; i++)
807                    StealVoice(itNoteOnEvent);
808    
809                // put note-on event into voice-stealing queue, so it will be reprocessed after killed voice died
810                RTList<Event>::Iterator itStealEvent = pVoiceStealingQueue->allocAppend();
811                if (itStealEvent) {
812                    *itStealEvent = *itNoteOnEvent; // copy event
813                    itStealEvent->Param.Note.Layer = iLayer;
814                    itStealEvent->Param.Note.ReleaseTrigger = ReleaseTriggerVoice;
815                }
816                else dmsg(1,("Voice stealing queue full!\n"));
817            }
818    
819          return Pool<Voice>::Iterator(); // no free voice or error          return Pool<Voice>::Iterator(); // no free voice or error
820      }      }
# Line 727  namespace LinuxSampler { namespace gig { Line 825  namespace LinuxSampler { namespace gig {
825       *  voice stealing and postpone the note-on event until the selected       *  voice stealing and postpone the note-on event until the selected
826       *  voice actually died.       *  voice actually died.
827       *       *
828       *  @param itNoteOnEvent       - key, velocity and time stamp of the event       *  @param itNoteOnEvent - key, velocity and time stamp of the event
      *  @param iLayer              - layer index for the new voice  
      *  @param ReleaseTriggerVoice - if new voice is a release triggered voice  
829       */       */
830      void Engine::StealVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice) {      void Engine::StealVoice(Pool<Event>::Iterator& itNoteOnEvent) {
831          if (!pEventPool->poolIsEmpty()) {          if (!pEventPool->poolIsEmpty()) {
832    
833              RTList<uint>::Iterator  iuiOldestKey;              RTList<uint>::Iterator  iuiOldestKey;
# Line 773  namespace LinuxSampler { namespace gig { Line 869  namespace LinuxSampler { namespace gig {
869                                  midi_key_info_t* pOldestKey = &pMIDIKeyInfo[*iuiOldestKey];                                  midi_key_info_t* pOldestKey = &pMIDIKeyInfo[*iuiOldestKey];
870                                  itOldestVoice = pOldestKey->pActiveVoices->first();                                  itOldestVoice = pOldestKey->pActiveVoices->first();
871                              }                              }
872                              else { // too less voices, even for voice stealing                              else {
873                                  dmsg(1,("Voice overflow! - You might recompile with higher MAX_AUDIO_VOICES!\n"));                                  dmsg(1,("gig::Engine: Warning, too less voices, even for voice stealing! - Better recompile with higher MAX_AUDIO_VOICES.\n"));
874                                  return;                                  return;
875                              }                              }
876                          }                          }
# Line 796  namespace LinuxSampler { namespace gig { Line 892  namespace LinuxSampler { namespace gig {
892                  }                  }
893              }              }
894    
895                //FIXME: can be removed, just a sanity check for debugging
896                if (!itOldestVoice->IsActive()) dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n"));
897    
898              // now kill the selected voice              // now kill the selected voice
899              itOldestVoice->Kill(itNoteOnEvent);              itOldestVoice->Kill(itNoteOnEvent);
900              // remember which voice on which key we stole, so we can simply proceed for the next voice stealing              // remember which voice on which key we stole, so we can simply proceed for the next voice stealing
901              this->itLastStolenVoice = itOldestVoice;              this->itLastStolenVoice = itOldestVoice;
902              this->iuiLastStolenKey = iuiOldestKey;              this->iuiLastStolenKey = iuiOldestKey;
             // put note-on event into voice-stealing queue, so it will be reprocessed after killed voice died  
             RTList<Event>::Iterator itStealEvent = pVoiceStealingQueue->allocAppend();  
             if (itStealEvent) {  
                 *itStealEvent = *itNoteOnEvent; // copy event  
                 itStealEvent->Param.Note.Layer = iLayer;  
                 itStealEvent->Param.Note.ReleaseTrigger = ReleaseTriggerVoice;  
             }  
             else dmsg(1,("Voice stealing queue full!\n"));  
903          }          }
904          else dmsg(1,("Event pool emtpy!\n"));          else dmsg(1,("Event pool emtpy!\n"));
905      }      }
906    
907      /**      /**
908       *  Immediately kills the voice given with pVoice (no matter if sustain is       *  Removes the given voice from the MIDI key's list of active voices.
909       *  pressed or not) and removes it from the MIDI key's list of active voice.       *  This method will be called when a voice went inactive, e.g. because
910       *  This method will e.g. be called if a voice went inactive by itself.       *  it finished to playback its sample, finished its release stage or
911         *  just was killed.
912       *       *
913       *  @param itVoice - points to the voice to be killed       *  @param itVoice - points to the voice to be freed
914       */       */
915      void Engine::KillVoiceImmediately(Pool<Voice>::Iterator& itVoice) {      void Engine::FreeVoice(Pool<Voice>::Iterator& itVoice) {
916          if (itVoice) {          if (itVoice) {
             if (itVoice->IsActive()) itVoice->KillImmediately();  
   
917              midi_key_info_t* pKey = &pMIDIKeyInfo[itVoice->MIDIKey];              midi_key_info_t* pKey = &pMIDIKeyInfo[itVoice->MIDIKey];
918    
919              uint keygroup = itVoice->KeyGroup;              uint keygroup = itVoice->KeyGroup;
# Line 831  namespace LinuxSampler { namespace gig { Line 921  namespace LinuxSampler { namespace gig {
921              // free the voice object              // free the voice object
922              pVoicePool->free(itVoice);              pVoicePool->free(itVoice);
923    
924              // check if there are no voices left on the MIDI key and update the key info if so              // if no other voices left and member of a key group, remove from key group
925              if (pKey->pActiveVoices->isEmpty()) {              if (pKey->pActiveVoices->isEmpty() && keygroup) {
926                  if (keygroup) { // if voice / key belongs to a key group                  uint** ppKeyGroup = &ActiveKeyGroups[keygroup];
927                      uint** ppKeyGroup = &ActiveKeyGroups[keygroup];                  if (*ppKeyGroup == &*pKey->itSelf) *ppKeyGroup = NULL; // remove key from key group
                     if (*ppKeyGroup == &*pKey->itSelf) *ppKeyGroup = NULL; // remove key from key group  
                 }  
                 pKey->Active = false;  
                 pActiveKeys->free(pKey->itSelf); // remove key from list of active keys  
                 pKey->itSelf = RTList<uint>::Iterator();  
                 pKey->ReleaseTrigger = false;  
                 pKey->pEvents->clear();  
                 dmsg(3,("Key has no more voices now\n"));  
928              }              }
929          }          }
930          else std::cerr << "Couldn't release voice! (pVoice == NULL)\n" << std::flush;          else std::cerr << "Couldn't release voice! (!itVoice)\n" << std::flush;
931        }
932    
933        /**
934         *  Called when there's no more voice left on a key, this call will
935         *  update the key info respectively.
936         *
937         *  @param pKey - key which is now inactive
938         */
939        void Engine::FreeKey(midi_key_info_t* pKey) {
940            if (pKey->pActiveVoices->isEmpty()) {
941                pKey->Active = false;
942                pActiveKeys->free(pKey->itSelf); // remove key from list of active keys
943                pKey->itSelf = RTList<uint>::Iterator();
944                pKey->ReleaseTrigger = false;
945                pKey->pEvents->clear();
946                dmsg(3,("Key has no more voices now\n"));
947            }
948            else dmsg(1,("gig::Engine: Oops, tried to free a key which contains voices.\n"));
949      }      }
950    
951      /**      /**
# Line 1082  namespace LinuxSampler { namespace gig { Line 1182  namespace LinuxSampler { namespace gig {
1182          return InstrumentFile;          return InstrumentFile;
1183      }      }
1184    
1185        String Engine::InstrumentName() {
1186            return InstrumentIdxName;
1187        }
1188    
1189      int Engine::InstrumentIndex() {      int Engine::InstrumentIndex() {
1190          return InstrumentIdx;          return InstrumentIdx;
1191      }      }
# Line 1095  namespace LinuxSampler { namespace gig { Line 1199  namespace LinuxSampler { namespace gig {
1199      }      }
1200    
1201      String Engine::Version() {      String Engine::Version() {
1202          String s = "$Revision: 1.15 $";          String s = "$Revision: 1.24 $";
1203          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
1204      }      }
1205    

Legend:
Removed from v.271  
changed lines
  Added in v.376

  ViewVC Help
Powered by ViewVC