/[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 2043 by persson, Sat Jan 9 09:37:01 2010 UTC revision 2879 by schoenebeck, Tue Apr 19 14:07:53 2016 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
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-2008 Christian Schoenebeck                         *
7   *   Copyright (C) 2009 Grigor Iliev                                       *   *   Copyright (C) 2009-2010 Christian Schoenebeck and 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 24  Line 24 
24    
25  #include "Engine.h"  #include "Engine.h"
26  #include "EngineChannel.h"  #include "EngineChannel.h"
27    #include "InstrumentScriptVM.h"
28    
29  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
30      Engine::Format Engine::GetEngineFormat() { return GIG; }      Engine::Format Engine::GetEngineFormat() { return GIG; }
31    
32        void Engine::CreateInstrumentScriptVM() {
33            dmsg(2,("gig::Engine created Giga format scriptvm\n"));
34            if (pScriptVM) return;
35            pScriptVM = new InstrumentScriptVM; // gig format specific extended script runner
36        }
37    
38      /**      /**
39       *  Reacts on supported control change commands (e.g. pitch bend wheel,       *  Reacts on supported control change commands (e.g. pitch bend wheel,
40       *  modulation wheel, aftertouch).       *  modulation wheel, aftertouch).
# Line 109  namespace LinuxSampler { namespace gig { Line 116  namespace LinuxSampler { namespace gig {
116          ProcessFxSendControllers(pChannel, itControlChangeEvent);          ProcessFxSendControllers(pChannel, itControlChangeEvent);
117      }      }
118    
119        void Engine::ProcessChannelPressure(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itChannelPressureEvent) {
120            // if required: engine global aftertouch handling (apart from the per voice handling)
121        }
122    
123        void Engine::ProcessPolyphonicKeyPressure(LinuxSampler::EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNotePressureEvent) {
124            // if required: engine global aftertouch handling (apart from the per voice handling)
125        }
126    
127      DiskThread* Engine::CreateDiskThread() {      DiskThread* Engine::CreateDiskThread() {
128          return new DiskThread (          return new DiskThread (
129              iMaxDiskStreams,              iMaxDiskStreams,
# Line 125  namespace LinuxSampler { namespace gig { Line 140  namespace LinuxSampler { namespace gig {
140          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);
141          // first, get total amount of required voices (dependant on amount of layers)          // first, get total amount of required voices (dependant on amount of layers)
142          ::gig::Region* pRegion = pChannel->pInstrument->GetRegion(itNoteOnEvent->Param.Note.Key);          ::gig::Region* pRegion = pChannel->pInstrument->GetRegion(itNoteOnEvent->Param.Note.Key);
143          if (pRegion && !RegionSuspended(pRegion)) {          if (!pRegion || RegionSuspended(pRegion))
144              int voicesRequired = pRegion->Layers;              return;
145              // now launch the required amount of voices          const int voicesRequired = pRegion->Layers;
146              for (int i = 0; i < voicesRequired; i++)          if (voicesRequired <= 0)
147                return;
148    
149            NoteIterator itNote = GetNotePool()->fromID(itNoteOnEvent->Param.Note.ID);
150            if (!itNote) {
151                dmsg(1,("gig::Engine: No Note object for triggering new voices!\n"));
152                return;
153            }
154    
155            // now launch the required amount of voices
156            for (int i = 0; i < voicesRequired; i++) {
157                VoiceIterator itNewVoice =
158                  LaunchVoice(pChannel, itNoteOnEvent, i, false, true, HandleKeyGroupConflicts);                  LaunchVoice(pChannel, itNoteOnEvent, i, false, true, HandleKeyGroupConflicts);
159                if (!itNewVoice) continue;
160                itNewVoice.moveToEndOf(itNote->pActiveVoices);
161          }          }
162      }      }
163    
# Line 141  namespace LinuxSampler { namespace gig { Line 169  namespace LinuxSampler { namespace gig {
169          MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];          MidiKey* pKey = &pChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];
170          // first, get total amount of required voices (dependant on amount of layers)          // first, get total amount of required voices (dependant on amount of layers)
171          ::gig::Region* pRegion = pChannel->pInstrument->GetRegion(itNoteOffEvent->Param.Note.Key);          ::gig::Region* pRegion = pChannel->pInstrument->GetRegion(itNoteOffEvent->Param.Note.Key);
172          if (pRegion) {          if (!pRegion)
173              int voicesRequired = pRegion->Layers;              return;
174            const int voicesRequired = pRegion->Layers;
175            if (voicesRequired <= 0)
176                return;
177    
178            NoteIterator itNote = GetNotePool()->fromID(itNoteOffEvent->Param.Note.ID);
179            if (!itNote) {
180                dmsg(1,("gig::Engine: No Note object for triggering new release voices!\n"));
181                return;
182            }
183    
184              // MIDI note-on velocity is used instead of note-off velocity          // MIDI note-on velocity is used instead of note-off velocity
185              itNoteOffEvent->Param.Note.Velocity = pKey->Velocity;          itNoteOffEvent->Param.Note.Velocity = pKey->Velocity;
186    
187              // now launch the required amount of voices          // now launch the required amount of voices
188              for (int i = 0; i < voicesRequired; i++)          for (int i = 0; i < voicesRequired; i++) {
189                VoiceIterator itNewVoice =
190                  LaunchVoice(pChannel, itNoteOffEvent, i, true, false, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples                  LaunchVoice(pChannel, itNoteOffEvent, i, true, false, false); //FIXME: for the moment we don't perform voice stealing for release triggered samples
191                if (!itNewVoice) continue;
192                itNewVoice.moveToEndOf(itNote->pActiveVoices);
193          }          }
194      }      }
195    
# Line 163  namespace LinuxSampler { namespace gig { Line 203  namespace LinuxSampler { namespace gig {
203      ) {      ) {
204          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);          EngineChannel* pChannel = static_cast<EngineChannel*>(pEngineChannel);
205          int MIDIKey = itNoteOnEvent->Param.Note.Key;          int MIDIKey = itNoteOnEvent->Param.Note.Key;
206          EngineChannel::MidiKey* pKey  = &pChannel->pMIDIKeyInfo[MIDIKey];          //EngineChannel::MidiKey* pKey  = &pChannel->pMIDIKeyInfo[MIDIKey];
207          ::gig::Region* pRegion = pChannel->pInstrument->GetRegion(MIDIKey);          ::gig::Region* pRegion = pChannel->pInstrument->GetRegion(MIDIKey);
208    
209          // if nothing defined for this key          // if nothing defined for this key
210          if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do          if (!pRegion) return Pool<Voice>::Iterator(); // nothing to do
211    
212          // only mark the first voice of a layered voice (group) to be in a          int iKeyGroup = pRegion->KeyGroup;
213          // key group, so the layered voices won't kill each other          // only need to send a group event from the first voice in a layered region,
214          int iKeyGroup = (iLayer == 0 && !ReleaseTriggerVoice) ? pRegion->KeyGroup : 0;          // as all layers in a region always belongs to the same key group
215            if (HandleKeyGroupConflicts && iLayer == 0) pChannel->HandleKeyGroupConflicts(iKeyGroup, itNoteOnEvent);
         if (HandleKeyGroupConflicts) pChannel->HandleKeyGroupConflicts(iKeyGroup, itNoteOnEvent);  
216    
217          Voice::type_t VoiceType = Voice::type_normal;          Voice::type_t VoiceType = Voice::type_normal;
218    
# Line 209  namespace LinuxSampler { namespace gig { Line 248  namespace LinuxSampler { namespace gig {
248                      DimValues[i] = uint(pChannel->RoundRobinIndex % pRegion->pDimensionDefinitions[i].zones); // RoundRobinIndex is incremented for each note on                      DimValues[i] = uint(pChannel->RoundRobinIndex % pRegion->pDimensionDefinitions[i].zones); // RoundRobinIndex is incremented for each note on
249                      break;                      break;
250                  case ::gig::dimension_random:                  case ::gig::dimension_random:
251                      RandomSeed   = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator                      DimValues[i] = uint(Random() * pRegion->pDimensionDefinitions[i].zones);
252                      DimValues[i] = uint(RandomSeed / 4294967296.0f * pRegion->pDimensionDefinitions[i].zones);                      break;
253                    case ::gig::dimension_smartmidi:
254                        DimValues[i] = 0;
255                      break;                      break;
256                  case ::gig::dimension_modwheel:                  case ::gig::dimension_modwheel:
257                      DimValues[i] = pChannel->ControllerTable[1];                      DimValues[i] = pChannel->ControllerTable[1];
# Line 292  namespace LinuxSampler { namespace gig { Line 333  namespace LinuxSampler { namespace gig {
333          // return if this is a release triggered voice and there is no          // return if this is a release triggered voice and there is no
334          // releasetrigger dimension (could happen if an instrument          // releasetrigger dimension (could happen if an instrument
335          // change has occured between note on and off)          // change has occured between note on and off)
336          if (ReleaseTriggerVoice && VoiceType != Voice::type_release_trigger) return Pool<Voice>::Iterator();          if (ReleaseTriggerVoice && !(VoiceType & Voice::type_release_trigger)) return Pool<Voice>::Iterator();
337    
338            NoteIterator itNote = GetNotePool()->fromID(itNoteOnEvent->Param.Note.ID);
339    
340          ::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues);          ::gig::DimensionRegion* pDimRgn;
341            if (!itNote->Format.Gig.DimMask) { // normal case ...
342                pDimRgn = pRegion->GetDimensionRegionByValue(DimValues);
343            } else { // some dimension zones were overridden (i.e. by instrument script) ...
344                dmsg(3,("trigger with dim mask=%d val=%d\n", itNote->Format.Gig.DimMask, itNote->Format.Gig.DimBits));
345                int index = pRegion->GetDimensionRegionIndexByValue(DimValues);
346                index &= ~itNote->Format.Gig.DimMask;
347                index |=  itNote->Format.Gig.DimBits & itNote->Format.Gig.DimMask;
348                pDimRgn = pRegion->pDimensionRegions[index & 255];
349            }
350            if (!pDimRgn) return Pool<Voice>::Iterator(); // error (could not resolve dimension region)
351    
352          // no need to continue if sample is silent          // no need to continue if sample is silent
353          if (!pDimRgn->pSample || !pDimRgn->pSample->SamplesTotal) return Pool<Voice>::Iterator();          if (!pDimRgn->pSample || !pDimRgn->pSample->SamplesTotal) return Pool<Voice>::Iterator();
354    
355          // allocate a new voice for the key          // allocate a new voice for the key
356          Pool<Voice>::Iterator itNewVoice = pKey->pActiveVoices->allocAppend();          Pool<Voice>::Iterator itNewVoice = GetVoicePool()->allocAppend();
357    
358          int res = InitNewVoice (          int res = InitNewVoice (
359                  pChannel, pDimRgn, itNoteOnEvent, VoiceType, iLayer,                  pChannel, pDimRgn, itNoteOnEvent, VoiceType, iLayer,
# Line 320  namespace LinuxSampler { namespace gig { Line 373  namespace LinuxSampler { namespace gig {
373      }      }
374    
375      String Engine::Version() {      String Engine::Version() {
376          String s = "$Revision: 1.107 $";          String s = "$Revision$";
377          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
378      }      }
379    

Legend:
Removed from v.2043  
changed lines
  Added in v.2879

  ViewVC Help
Powered by ViewVC