/[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 285 by schoenebeck, Thu Oct 14 21:31:26 2004 UTC revision 293 by schoenebeck, Mon Oct 25 15:14:27 2004 UTC
# Line 398  namespace LinuxSampler { namespace gig { Line 398  namespace LinuxSampler { namespace gig {
398          }          }
399    
400    
401            // update time of start and end of this audio fragment (as events' time stamps relate to this)
402            pEventGenerator->UpdateFragmentTime(Samples);
403    
404    
405          // empty the event lists for the new fragment          // empty the event lists for the new fragment
406          pEvents->clear();          pEvents->clear();
407          pCCEvents->clear();          pCCEvents->clear();
# Line 412  namespace LinuxSampler { namespace gig { Line 416  namespace LinuxSampler { namespace gig {
416              }              }
417          }          }
418    
         // read and copy events from input queue  
         Event event = pEventGenerator->CreateEvent();  
         while (true) {  
             if (!pEventQueue->pop(&event) || pEvents->poolIsEmpty()) break;  
             *pEvents->allocAppend() = event;  
         }  
419    
420            // get all events from the input event queue which belong to the current fragment
421          // update time of start and end of this audio fragment (as events' time stamps relate to this)          {
422          pEventGenerator->UpdateFragmentTime(Samples);              RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader();
423                Event* pEvent;
424                while (true) {
425                    // get next event from input event queue
426                    if (!(pEvent = eventQueueReader.pop())) break;
427                    // if younger event reached, ignore that and all subsequent ones for now
428                    if (pEvent->FragmentPos() >= Samples) {
429                        eventQueueReader--;
430                        dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples));
431                        pEvent->ResetFragmentPos();
432                        break;
433                    }
434                    // copy event to internal event list
435                    if (pEvents->poolIsEmpty()) {
436                        dmsg(1,("Event pool emtpy!\n"));
437                        break;
438                    }
439                    *pEvents->allocAppend() = *pEvent;
440                }
441                eventQueueReader.free(); // free all copied events from input queue
442            }
443    
444    
445          // process events          // process events
# Line 494  namespace LinuxSampler { namespace gig { Line 512  namespace LinuxSampler { namespace gig {
512                          }                          }
513                      }                      }
514                  }                  }
515                  else dmsg(1,("Ouch, voice stealing didn't work out!\n"));                  else dmsg(1,("gig::Engine: ERROR, voice stealing didn't work out!\n"));
516              }              }
517          }          }
518          // reset voice stealing for the new fragment          // reset voice stealing for the new fragment
# Line 503  namespace LinuxSampler { namespace gig { Line 521  namespace LinuxSampler { namespace gig {
521          iuiLastStolenKey  = RTList<uint>::Iterator();          iuiLastStolenKey  = RTList<uint>::Iterator();
522    
523    
524            // free all keys which have no active voices left
525            {
526                RTList<uint>::Iterator iuiKey = pActiveKeys->first();
527                RTList<uint>::Iterator end    = pActiveKeys->end();
528                while (iuiKey != end) { // iterate through all active keys
529                    midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey];
530                    ++iuiKey;
531                    if (pKey->pActiveVoices->isEmpty()) FreeKey(pKey);
532                    #if DEVMODE
533                    else { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)
534                        RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();
535                        RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();
536                        for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
537                            if (itVoice->itKillEvent) {
538                                dmsg(1,("gig::Engine: ERROR, killed voice survived !!!\n"));
539                            }
540                        }
541                    }
542                    #endif // DEVMODE
543                }
544            }
545    
546    
547          // 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
548          // on the console for debugging purposes          // on the console for debugging purposes
549          ActiveVoiceCount = active_voices;          ActiveVoiceCount = active_voices;
# Line 629  namespace LinuxSampler { namespace gig { Line 670  namespace LinuxSampler { namespace gig {
670          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
671    
672          // allocate and trigger a new voice for the key          // allocate and trigger a new voice for the key
673          LaunchVoice(itNoteOnEventOnKeyList);          LaunchVoice(itNoteOnEventOnKeyList, 0, false, true);
674      }      }
675    
676      /**      /**
# Line 655  namespace LinuxSampler { namespace gig { Line 696  namespace LinuxSampler { namespace gig {
696    
697          // spawn release triggered voice(s) if needed          // spawn release triggered voice(s) if needed
698          if (pKey->ReleaseTrigger) {          if (pKey->ReleaseTrigger) {
699              LaunchVoice(itNoteOffEventOnKeyList, 0, true);              LaunchVoice(itNoteOffEventOnKeyList, 0, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples
700              pKey->ReleaseTrigger = false;              pKey->ReleaseTrigger = false;
701          }          }
702      }      }
# Line 694  namespace LinuxSampler { namespace gig { Line 735  namespace LinuxSampler { namespace gig {
735          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();
736          if (itNewVoice) {          if (itNewVoice) {
737              // launch the new voice              // launch the new voice
738              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice) < 0) {              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) {
739                  dmsg(1,("Triggering new voice failed!\n"));                  dmsg(1,("Triggering new voice failed!\n"));
740                  pKey->pActiveVoices->free(itNewVoice);                  pKey->pActiveVoices->free(itNewVoice);
741              }              }
# Line 820  namespace LinuxSampler { namespace gig { Line 861  namespace LinuxSampler { namespace gig {
861                  }                  }
862              }              }
863    
864                //FIXME: can be removed, just a sanity check for debugging
865                if (!itOldestVoice->IsActive()) dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n"));
866    
867              // now kill the selected voice              // now kill the selected voice
868              itOldestVoice->Kill(itNoteOnEvent);              itOldestVoice->Kill(itNoteOnEvent);
869              // 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
# Line 846  namespace LinuxSampler { namespace gig { Line 890  namespace LinuxSampler { namespace gig {
890              // free the voice object              // free the voice object
891              pVoicePool->free(itVoice);              pVoicePool->free(itVoice);
892    
893              // 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
894              if (pKey->pActiveVoices->isEmpty()) {              if (pKey->pActiveVoices->isEmpty() && keygroup) {
895                  if (keygroup) { // if voice / key belongs to a key group                  uint** ppKeyGroup = &ActiveKeyGroups[keygroup];
896                      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"));  
897              }              }
898          }          }
899          else std::cerr << "Couldn't release voice! (!itVoice)\n" << std::flush;          else std::cerr << "Couldn't release voice! (!itVoice)\n" << std::flush;
900      }      }
901    
902      /**      /**
903         *  Called when there's no more voice left on a key, this call will
904         *  update the key info respectively.
905         *
906         *  @param pKey - key which is now inactive
907         */
908        void Engine::FreeKey(midi_key_info_t* pKey) {
909            if (pKey->pActiveVoices->isEmpty()) {
910                pKey->Active = false;
911                pActiveKeys->free(pKey->itSelf); // remove key from list of active keys
912                pKey->itSelf = RTList<uint>::Iterator();
913                pKey->ReleaseTrigger = false;
914                pKey->pEvents->clear();
915                dmsg(3,("Key has no more voices now\n"));
916            }
917            else dmsg(1,("gig::Engine: Oops, tried to free a key which contains voices.\n"));
918        }
919    
920        /**
921       *  Reacts on supported control change commands (e.g. pitch bend wheel,       *  Reacts on supported control change commands (e.g. pitch bend wheel,
922       *  modulation wheel, aftertouch).       *  modulation wheel, aftertouch).
923       *       *
# Line 1110  namespace LinuxSampler { namespace gig { Line 1164  namespace LinuxSampler { namespace gig {
1164      }      }
1165    
1166      String Engine::Version() {      String Engine::Version() {
1167          String s = "$Revision: 1.16 $";          String s = "$Revision: 1.18 $";
1168          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
1169      }      }
1170    

Legend:
Removed from v.285  
changed lines
  Added in v.293

  ViewVC Help
Powered by ViewVC