/[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 630 by persson, Sat Jun 11 14:51:49 2005 UTC revision 649 by schoenebeck, Wed Jun 15 00:01:28 2005 UTC
# Line 184  namespace LinuxSampler { namespace gig { Line 184  namespace LinuxSampler { namespace gig {
184    
185          // reset voice stealing parameters          // reset voice stealing parameters
186          pVoiceStealingQueue->clear();          pVoiceStealingQueue->clear();
187          itLastStolenVoice  = RTList<Voice>::Iterator();          itLastStolenVoice          = RTList<Voice>::Iterator();
188          iuiLastStolenKey   = RTList<uint>::Iterator();          itLastStolenVoiceGlobally  = RTList<Voice>::Iterator();
189          pLastStolenChannel = NULL;          iuiLastStolenKey           = RTList<uint>::Iterator();
190            iuiLastStolenKeyGlobally   = RTList<uint>::Iterator();
191            pLastStolenChannel         = NULL;
192    
193          // reset to normal chromatic scale (means equal temper)          // reset to normal chromatic scale (means equal temper)
194          memset(&ScaleTuning[0], 0x00, 12);          memset(&ScaleTuning[0], 0x00, 12);
# Line 406  namespace LinuxSampler { namespace gig { Line 408  namespace LinuxSampler { namespace gig {
408    
409          // reset voice stealing for the next audio fragment          // reset voice stealing for the next audio fragment
410          pVoiceStealingQueue->clear();          pVoiceStealingQueue->clear();
         itLastStolenVoice  = RTList<Voice>::Iterator();  
         iuiLastStolenKey   = RTList<uint>::Iterator();  
         pLastStolenChannel = NULL;  
411    
412          // just some statistics about this engine instance          // just some statistics about this engine instance
413          ActiveVoiceCount = ActiveVoiceCountTemp;          ActiveVoiceCount = ActiveVoiceCountTemp;
# Line 458  namespace LinuxSampler { namespace gig { Line 457  namespace LinuxSampler { namespace gig {
457                  }                  }
458              }              }
459          }          }
460    
461            // reset voice stealing for the next engine channel (or next audio fragment)
462            itLastStolenVoice         = RTList<Voice>::Iterator();
463            itLastStolenVoiceGlobally = RTList<Voice>::Iterator();
464            iuiLastStolenKey          = RTList<uint>::Iterator();
465            iuiLastStolenKeyGlobally  = RTList<uint>::Iterator();
466            pLastStolenChannel        = NULL;
467      }      }
468    
469      /**      /**
# Line 816  namespace LinuxSampler { namespace gig { Line 822  namespace LinuxSampler { namespace gig {
822                  // from the same engine channel                  // from the same engine channel
823                  // (caution: must stay after 'oldestvoiceonkey' algorithm !)                  // (caution: must stay after 'oldestvoiceonkey' algorithm !)
824                  case voice_steal_algo_oldestkey: {                  case voice_steal_algo_oldestkey: {
825                        // if we already stole in this fragment, try to proceed on same key
826                      if (this->itLastStolenVoice) {                      if (this->itLastStolenVoice) {
827                          itSelectedVoice = this->itLastStolenVoice;                          itSelectedVoice = this->itLastStolenVoice;
828                          ++itSelectedVoice;                          do {
829                          if (itSelectedVoice) break; // selection succeeded                              ++itSelectedVoice;
830                          RTList<uint>::Iterator iuiSelectedKey = this->iuiLastStolenKey;                          } while (itSelectedVoice && !itSelectedVoice->hasRendered()); // proceed iterating if voice was created in this fragment cycle
831                          ++iuiSelectedKey;                          // found a "stealable" voice ?
832                          if (iuiSelectedKey) {                          if (itSelectedVoice && itSelectedVoice->hasRendered()) {
833                              this->iuiLastStolenKey = iuiSelectedKey;                              // remember which voice we stole, so we can simply proceed on next voice stealing
834                              midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey];                              this->itLastStolenVoice = itSelectedVoice;
835                              itSelectedVoice = pSelectedKey->pActiveVoices->first();                              break; // selection succeeded
836                            }
837                        }
838                        // get (next) oldest key
839                        RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKey) ? ++this->iuiLastStolenKey : pEngineChannel->pActiveKeys->first();
840                        while (iuiSelectedKey) {
841                            midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey];
842                            itSelectedVoice = pSelectedKey->pActiveVoices->first();                        
843                            // proceed iterating if voice was created in this fragment cycle
844                            while (itSelectedVoice && !itSelectedVoice->hasRendered()) ++itSelectedVoice;
845                            // found a "stealable" voice ?
846                            if (itSelectedVoice && itSelectedVoice->hasRendered()) {
847                                // remember which voice on which key we stole, so we can simply proceed on next voice stealing
848                                this->iuiLastStolenKey  = iuiSelectedKey;
849                                this->itLastStolenVoice = itSelectedVoice;
850                              break; // selection succeeded                              break; // selection succeeded
851                          }                          }
852                            ++iuiSelectedKey; // get next oldest key
853                      }                      }
854                      break;                      break;
855                  }                  }
# Line 842  namespace LinuxSampler { namespace gig { Line 864  namespace LinuxSampler { namespace gig {
864    
865              // if we couldn't steal a voice from the same engine channel then              // if we couldn't steal a voice from the same engine channel then
866              // steal oldest voice on the oldest key from any other engine channel              // steal oldest voice on the oldest key from any other engine channel
867              if (!itSelectedVoice) {              // (the smaller engine channel number, the higher priority)
868                  EngineChannel* pSelectedChannel = (pLastStolenChannel) ? pLastStolenChannel : pEngineChannel;              if (!itSelectedVoice || !itSelectedVoice->hasRendered()) {
869                  int iChannelIndex = pSelectedChannel->iEngineIndexSelf;                  EngineChannel* pSelectedChannel;
870                    int            iChannelIndex;
871                    // select engine channel
872                    if (pLastStolenChannel) {
873                        pSelectedChannel = pLastStolenChannel;
874                        iChannelIndex    = pSelectedChannel->iEngineIndexSelf;
875                    } else { // pick the engine channel followed by this engine channel
876                        iChannelIndex    = (pEngineChannel->iEngineIndexSelf + 1) % engineChannels.size();
877                        pSelectedChannel = engineChannels[iChannelIndex];
878                    }
879                    // iterate through engine channels
880                  while (true) {                  while (true) {
881                      RTList<uint>::Iterator iuiSelectedKey = pSelectedChannel->pActiveKeys->first();                      // if we already stole in this fragment, try to proceed on same key
882                      if (iuiSelectedKey) {                      if (this->itLastStolenVoiceGlobally) {
883                          midi_key_info_t* pSelectedKey = &pSelectedChannel->pMIDIKeyInfo[*iuiSelectedKey];                          itSelectedVoice = this->itLastStolenVoiceGlobally;
884                          itSelectedVoice    = pSelectedKey->pActiveVoices->first();                          do {
885                          iuiLastStolenKey   = iuiSelectedKey;                              ++itSelectedVoice;
886                          pLastStolenChannel = pSelectedChannel;                          } while (itSelectedVoice && !itSelectedVoice->hasRendered()); // proceed iterating if voice was created in this fragment cycle
887                          break; // selection succeeded                          // break if selection succeeded
888                            if (itSelectedVoice && itSelectedVoice->hasRendered()) {
889                                // remember which voice we stole, so we can simply proceed on next voice stealing
890                                this->itLastStolenVoiceGlobally = itSelectedVoice;
891                                break; // selection succeeded
892                            }
893                      }                      }
894                        // get (next) oldest key
895                        RTList<uint>::Iterator iuiSelectedKey = (this->iuiLastStolenKey) ? ++this->iuiLastStolenKey : pSelectedChannel->pActiveKeys->first();
896                        while (iuiSelectedKey) {
897                            midi_key_info_t* pSelectedKey = &pEngineChannel->pMIDIKeyInfo[*iuiSelectedKey];
898                            itSelectedVoice = pSelectedKey->pActiveVoices->first();
899                            // proceed iterating if voice was created in this fragment cycle
900                            while (itSelectedVoice && !itSelectedVoice->hasRendered()) ++itSelectedVoice;
901                            // found a "stealable" voice ?
902                            if (itSelectedVoice && itSelectedVoice->hasRendered()) {
903                                // remember which voice on which key on which engine channel we stole, so we can simply proceed on next voice stealing
904                                this->iuiLastStolenKeyGlobally  = iuiSelectedKey;
905                                this->itLastStolenVoiceGlobally = itSelectedVoice;
906                                this->pLastStolenChannel        = pSelectedChannel;
907                                break; // selection succeeded
908                            }
909                            ++iuiSelectedKey; // get next key on current engine channel
910                        }
911                        // get next engine channel
912                      iChannelIndex    = (iChannelIndex + 1) % engineChannels.size();                      iChannelIndex    = (iChannelIndex + 1) % engineChannels.size();
913                      pSelectedChannel =  engineChannels[iChannelIndex];                      pSelectedChannel = engineChannels[iChannelIndex];
914                  }                  }
915              }              }
916    
# Line 867  namespace LinuxSampler { namespace gig { Line 922  namespace LinuxSampler { namespace gig {
922              #endif // CONFIG_DEVMODE              #endif // CONFIG_DEVMODE
923    
924              // now kill the selected voice              // now kill the selected voice
925              itSelectedVoice->Kill(itNoteOnEvent);              itSelectedVoice->Kill(itNoteOnEvent);            
   
             // remember which voice we stole, so we can simply proceed for the next voice stealing  
             itLastStolenVoice = itSelectedVoice;  
926    
927              --VoiceTheftsLeft;              --VoiceTheftsLeft;
928    
# Line 1203  namespace LinuxSampler { namespace gig { Line 1255  namespace LinuxSampler { namespace gig {
1255      }      }
1256    
1257      String Engine::Version() {      String Engine::Version() {
1258          String s = "$Revision: 1.40 $";          String s = "$Revision: 1.41 $";
1259          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
1260      }      }
1261    

Legend:
Removed from v.630  
changed lines
  Added in v.649

  ViewVC Help
Powered by ViewVC