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

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

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

revision 2012 by iliev, Fri Oct 23 17:53:17 2009 UTC revision 2086 by persson, Sun Apr 25 12:51:30 2010 UTC
# Line 4  Line 4 
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck    *   *   Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck    *
6   *   Copyright (C) 2005-2009 Christian Schoenebeck                         *   *   Copyright (C) 2005-2009 Christian Schoenebeck                         *
7   *   Copyright (C) 2009 Grigor Iliev                                       *   *   Copyright (C) 2009-2010 Grigor Iliev                                  *
8   *                                                                         *   *                                                                         *
9   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
10   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 79  namespace LinuxSampler { namespace sfz { Line 79  namespace LinuxSampler { namespace sfz {
79          int      bend     = pChannel->Pitch;          int      bend     = pChannel->Pitch;
80          uint8_t  chanaft  = pChannel->ControllerTable[128];          uint8_t  chanaft  = pChannel->ControllerTable[128];
81          uint8_t* cc       = pChannel->ControllerTable;          uint8_t* cc       = pChannel->ControllerTable;
82          ::sfz::trigger_t trig = TRIGGER_ATTACK;          ::sfz::trigger_t trig = TRIGGER_ATTACK |
83                  ((pChannel->LastKey != -1 &&
84                    pChannel->PressedKeys[pChannel->LastKey] &&
85                    pChannel->LastKey != key) ?
86                   TRIGGER_LEGATO : TRIGGER_FIRST);
87    
88          pChannel->regionsTemp = pChannel->pInstrument->GetRegionsOnKey (          pChannel->regionsTemp = pChannel->pInstrument->GetRegionsOnKey (
89              chan, key, vel, bend, 0, chanaft, 0, 0, 0, trig, cc,              chan, key, vel, bend, 0, chanaft, 0, 0, Random(), trig, cc,
90              0.0f, 1, pChannel->PressedKeys, pChannel->LastKeySwitch, pChannel->LastKey              0.0f, pChannel->PressedKeys, pChannel->LastKeySwitch, pChannel->LastKey
91          );          );
92    
93          for (int i = 0; i < pChannel->regionsTemp.size(); i++) {          for (int i = 0; i < pChannel->regionsTemp.size(); i++) {
# Line 100  namespace LinuxSampler { namespace sfz { Line 104  namespace LinuxSampler { namespace sfz {
104          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);
105          uint8_t  chan     = pChannel->MidiChannel();          uint8_t  chan     = pChannel->MidiChannel();
106          int      key      = itNoteOffEvent->Param.Note.Key;          int      key      = itNoteOffEvent->Param.Note.Key;
107          uint8_t  vel      = itNoteOffEvent->Param.Note.Velocity;  
108            // MIDI note-on velocity is used instead of note-off velocity
109            uint8_t  vel      = pChannel->pMIDIKeyInfo[key].Velocity;
110            itNoteOffEvent->Param.Note.Velocity = vel;
111    
112          int      bend     = pChannel->Pitch;          int      bend     = pChannel->Pitch;
113          uint8_t  chanaft  = pChannel->ControllerTable[128];          uint8_t  chanaft  = pChannel->ControllerTable[128];
114          uint8_t* cc       = pChannel->ControllerTable;          uint8_t* cc       = pChannel->ControllerTable;
115          ::sfz::trigger_t trig = TRIGGER_RELEASE;          ::sfz::trigger_t trig = TRIGGER_RELEASE;
116    
117          pChannel->regionsTemp = pChannel->pInstrument->GetRegionsOnKey (          pChannel->regionsTemp = pChannel->pInstrument->GetRegionsOnKey (
118              chan, key, vel, bend, 0, chanaft, 0, 0, 0, trig, cc, 0.0f, 0, NULL, 0, 0              chan, key, vel, bend, 0, chanaft, 0, 0, Random(), trig, cc,
119                0.0f, pChannel->PressedKeys, pChannel->LastKeySwitch, pChannel->LastKey
120          );          );
121    
122          // now launch the required amount of voices          // now launch the required amount of voices
# Line 127  namespace LinuxSampler { namespace sfz { Line 136  namespace LinuxSampler { namespace sfz {
136          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);
137          int key = itNoteOnEvent->Param.Note.Key;          int key = itNoteOnEvent->Param.Note.Key;
138          EngineChannel::MidiKey* pKey  = &pChannel->pMIDIKeyInfo[key];          EngineChannel::MidiKey* pKey  = &pChannel->pMIDIKeyInfo[key];
139          /*::gig::Region* pRegion = pChannel->pInstrument->GetRegion(MIDIKey);          Voice::type_t VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal;
   
         // if nothing defined for this key  
         if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do  
   
         // only mark the first voice of a layered voice (group) to be in a  
         // key group, so the layered voices won't kill each other  
         int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0;  
   
         // handle key group (a.k.a. exclusive group) conflicts  
         if (HandleKeyGroupConflicts) {  
             if (iKeyGroup) { // if this voice / key belongs to a key group  
                 uint** ppKeyGroup = &pChannel->ActiveKeyGroups[iKeyGroup];  
                 if (*ppKeyGroup) { // if there's already an active key in that key group  
                     EngineChannel::MidiKey* pOtherKey = &pChannel->pMIDIKeyInfo[**ppKeyGroup];  
                     // kill all voices on the (other) key  
                     RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first();  
                     RTList<Voice>::Iterator end               = pOtherKey->pActiveVoices->end();  
                     for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {  
                         if (itVoiceToBeKilled->Type != Voice::type_release_trigger) {  
                             itVoiceToBeKilled->Kill(itNoteOnEvent);  
                             --VoiceSpawnsLeft; //FIXME: just a hack, we should better check in StealVoice() if the voice was killed due to key conflict  
                         }  
                     }  
                 }  
             }  
         }*/ // TODO: ^^^  
   
         Voice::type_t VoiceType = Voice::type_normal;  
140    
141          Pool<Voice>::Iterator itNewVoice;          Pool<Voice>::Iterator itNewVoice;
142          ::sfz::Region* pRgn = pChannel->regionsTemp[iLayer];          ::sfz::Region* pRgn = pChannel->regionsTemp[iLayer];
143    
144          // no need to process if sample is silent          // no need to process if sample is silent
145          if (!pRgn->GetSample() || !pRgn->GetSample()->GetTotalFrameCount()) itNewVoice;          if (!pRgn->GetSample() || !pRgn->GetSample()->GetTotalFrameCount()) return Pool<Voice>::Iterator();
146    
147            // only mark the first voice of a layered voice (group) to be in a
148            // key group, so the layered voices won't kill each other
149            int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRgn->group : 0;
150            if (HandleKeyGroupConflicts) pChannel->HandleKeyGroupConflicts(iKeyGroup, itNoteOnEvent, pRgn->off_mode == ::sfz::OFF_NORMAL);
151    
152          // allocate a new voice for the key          // allocate a new voice for the key
153          itNewVoice = pKey->pActiveVoices->allocAppend();          itNewVoice = pKey->pActiveVoices->allocAppend();
154          if (itNewVoice) {          int res = InitNewVoice (
155              // launch the new voice                  pChannel, pRgn, itNoteOnEvent, VoiceType, iLayer,
156              if (itNewVoice->Trigger(pChannel, itNoteOnEvent, pChannel->Pitch, pRgn, VoiceType, 0 /* iKeyGroup */) < 0) {                  iKeyGroup, ReleaseTriggerVoice, VoiceStealing, itNewVoice
157                  dmsg(4,("Voice not triggered\n"));          );
158                  pKey->pActiveVoices->free(itNewVoice);          if (!res) return itNewVoice;
             }  
             else { // on success  
                 --VoiceSpawnsLeft;  
                 if (!pKey->Active) { // mark as active key  
                     pKey->Active = true;  
                     pKey->itSelf = pChannel->pActiveKeys->allocAppend();  
                     *pKey->itSelf = itNoteOnEvent->Param.Note.Key;  
                 }  
                 if (itNewVoice->KeyGroup) {  
                     uint** ppKeyGroup = &pChannel->ActiveKeyGroups[itNewVoice->KeyGroup];  
                     *ppKeyGroup = &*pKey->itSelf; // put key as the (new) active key to its key group  
                 }  
                 if (itNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s)  
                 return itNewVoice; // success  
             }  
         }  
         else if (VoiceStealing) {  
             // try to steal one voice  
             int result = StealVoice(pChannel, itNoteOnEvent);  
             if (!result) { // voice stolen successfully  
                 // 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;  
                     pKey->VoiceTheftsQueued++;  
                 }  
                 else dmsg(1,("Voice stealing queue full!\n"));  
             }  
         }  
159    
160          // return if this is a release triggered voice and there is no          // return if this is a release triggered voice and there is no
161          // releasetrigger dimension (could happen if an instrument          // releasetrigger dimension (could happen if an instrument
162          // change has occured between note on and off)          // change has occured between note on and off)
163          //if (ReleaseTriggerVoice && VoiceType != Voice::type_release_trigger) return Pool<Voice>::Iterator();          //if (ReleaseTriggerVoice && VoiceType != Voice::type_release_trigger) return Pool<Voice>::Iterator();
164    
165                    return Pool<Voice>::Iterator(); // no free voice or error
   
         return itNewVoice;  
166      }      }
167    
168      bool Engine::DiskStreamSupported() {      bool Engine::DiskStreamSupported() {
# Line 221  namespace LinuxSampler { namespace sfz { Line 174  namespace LinuxSampler { namespace sfz {
174      }      }
175    
176      String Engine::Version() {      String Engine::Version() {
177          String s = "$Revision: 1.1 $";          String s = "$Revision: 1.7 $";
178          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
179      }      }
180    

Legend:
Removed from v.2012  
changed lines
  Added in v.2086

  ViewVC Help
Powered by ViewVC