/[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 287 by schoenebeck, Sat Oct 16 17:38:03 2004 UTC
# Line 494  namespace LinuxSampler { namespace gig { Line 494  namespace LinuxSampler { namespace gig {
494                          }                          }
495                      }                      }
496                  }                  }
497                  else dmsg(1,("Ouch, voice stealing didn't work out!\n"));                  else dmsg(1,("gig::Engine: ERROR, voice stealing didn't work out!\n"));
498              }              }
499          }          }
500          // reset voice stealing for the new fragment          // reset voice stealing for the new fragment
# Line 503  namespace LinuxSampler { namespace gig { Line 503  namespace LinuxSampler { namespace gig {
503          iuiLastStolenKey  = RTList<uint>::Iterator();          iuiLastStolenKey  = RTList<uint>::Iterator();
504    
505    
506            // free all keys which have no active voices left
507            {
508                RTList<uint>::Iterator iuiKey = pActiveKeys->first();
509                RTList<uint>::Iterator end    = pActiveKeys->end();
510                while (iuiKey != end) { // iterate through all active keys
511                    midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey];
512                    ++iuiKey;
513                    if (pKey->pActiveVoices->isEmpty()) FreeKey(pKey);
514                    #if DEVMODE
515                    else { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)
516                        RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();
517                        RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();
518                        for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
519                            if (itVoice->itKillEvent) {
520                                dmsg(1,("gig::Engine: ERROR, killed voice survived !!!\n"));
521                            }
522                        }
523                    }
524                    #endif // DEVMODE
525                }
526            }
527    
528    
529          // 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
530          // on the console for debugging purposes          // on the console for debugging purposes
531          ActiveVoiceCount = active_voices;          ActiveVoiceCount = active_voices;
# Line 629  namespace LinuxSampler { namespace gig { Line 652  namespace LinuxSampler { namespace gig {
652          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);          RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
653    
654          // allocate and trigger a new voice for the key          // allocate and trigger a new voice for the key
655          LaunchVoice(itNoteOnEventOnKeyList);          LaunchVoice(itNoteOnEventOnKeyList, 0, false, true);
656      }      }
657    
658      /**      /**
# Line 655  namespace LinuxSampler { namespace gig { Line 678  namespace LinuxSampler { namespace gig {
678    
679          // spawn release triggered voice(s) if needed          // spawn release triggered voice(s) if needed
680          if (pKey->ReleaseTrigger) {          if (pKey->ReleaseTrigger) {
681              LaunchVoice(itNoteOffEventOnKeyList, 0, true);              LaunchVoice(itNoteOffEventOnKeyList, 0, true, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples
682              pKey->ReleaseTrigger = false;              pKey->ReleaseTrigger = false;
683          }          }
684      }      }
# Line 694  namespace LinuxSampler { namespace gig { Line 717  namespace LinuxSampler { namespace gig {
717          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();
718          if (itNewVoice) {          if (itNewVoice) {
719              // launch the new voice              // launch the new voice
720              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice) < 0) {              if (itNewVoice->Trigger(itNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice, VoiceStealing) < 0) {
721                  dmsg(1,("Triggering new voice failed!\n"));                  dmsg(1,("Triggering new voice failed!\n"));
722                  pKey->pActiveVoices->free(itNewVoice);                  pKey->pActiveVoices->free(itNewVoice);
723              }              }
# Line 820  namespace LinuxSampler { namespace gig { Line 843  namespace LinuxSampler { namespace gig {
843                  }                  }
844              }              }
845    
846                //FIXME: can be removed, just a sanity check for debugging
847                if (!itOldestVoice->IsActive()) dmsg(1,("gig::Engine: ERROR, tried to steal a voice which was not active !!!\n"));
848    
849              // now kill the selected voice              // now kill the selected voice
850              itOldestVoice->Kill(itNoteOnEvent);              itOldestVoice->Kill(itNoteOnEvent);
851              // 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 872  namespace LinuxSampler { namespace gig {
872              // free the voice object              // free the voice object
873              pVoicePool->free(itVoice);              pVoicePool->free(itVoice);
874    
875              // 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
876              if (pKey->pActiveVoices->isEmpty()) {              if (pKey->pActiveVoices->isEmpty() && keygroup) {
877                  if (keygroup) { // if voice / key belongs to a key group                  uint** ppKeyGroup = &ActiveKeyGroups[keygroup];
878                      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"));  
879              }              }
880          }          }
881          else std::cerr << "Couldn't release voice! (!itVoice)\n" << std::flush;          else std::cerr << "Couldn't release voice! (!itVoice)\n" << std::flush;
882      }      }
883    
884      /**      /**
885         *  Called when there's no more voice left on a key, this call will
886         *  update the key info respectively.
887         *
888         *  @param pKey - key which is now inactive
889         */
890        void Engine::FreeKey(midi_key_info_t* pKey) {
891            if (pKey->pActiveVoices->isEmpty()) {
892                pKey->Active = false;
893                pActiveKeys->free(pKey->itSelf); // remove key from list of active keys
894                pKey->itSelf = RTList<uint>::Iterator();
895                pKey->ReleaseTrigger = false;
896                pKey->pEvents->clear();
897                dmsg(3,("Key has no more voices now\n"));
898            }
899            else dmsg(1,("gig::Engine: Oops, tried to free a key which contains voices.\n"));
900        }
901    
902        /**
903       *  Reacts on supported control change commands (e.g. pitch bend wheel,       *  Reacts on supported control change commands (e.g. pitch bend wheel,
904       *  modulation wheel, aftertouch).       *  modulation wheel, aftertouch).
905       *       *
# Line 1110  namespace LinuxSampler { namespace gig { Line 1146  namespace LinuxSampler { namespace gig {
1146      }      }
1147    
1148      String Engine::Version() {      String Engine::Version() {
1149          String s = "$Revision: 1.16 $";          String s = "$Revision: 1.17 $";
1150          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
1151      }      }
1152    

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

  ViewVC Help
Powered by ViewVC