/[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 716 by iliev, Sun Jul 24 06:57:30 2005 UTC revision 846 by persson, Sun Mar 19 16:38:22 2006 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 Christian Schoenebeck                              *   *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   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 29  Line 29 
29    
30  #include "Engine.h"  #include "Engine.h"
31    
 #if defined(__APPLE__)  
 # include <stdlib.h>  
 #else  
 # include <malloc.h>  
 #endif  
   
32  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
33    
34      InstrumentResourceManager Engine::instruments;      InstrumentResourceManager Engine::instruments;
# Line 114  namespace LinuxSampler { namespace gig { Line 108  namespace LinuxSampler { namespace gig {
108          }          }
109          pVoicePool->clear();          pVoicePool->clear();
110    
         pSynthesisParameters[0] = NULL; // we allocate when an audio device is connected  
         pBasicFilterParameters  = NULL;  
         pMainFilterParameters   = NULL;  
   
111          ResetInternal();          ResetInternal();
112          ResetScaleTuning();          ResetScaleTuning();
113      }      }
# Line 126  namespace LinuxSampler { namespace gig { Line 116  namespace LinuxSampler { namespace gig {
116       * Destructor       * Destructor
117       */       */
118      Engine::~Engine() {      Engine::~Engine() {
119            MidiInputPort::RemoveSysexListener(this);
120          if (pDiskThread) {          if (pDiskThread) {
121              dmsg(1,("Stopping disk thread..."));              dmsg(1,("Stopping disk thread..."));
122              pDiskThread->StopThread();              pDiskThread->StopThread();
# Line 139  namespace LinuxSampler { namespace gig { Line 130  namespace LinuxSampler { namespace gig {
130              delete pVoicePool;              delete pVoicePool;
131          }          }
132          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
         if (pMainFilterParameters) delete[] pMainFilterParameters;  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
133          if (pVoiceStealingQueue) delete pVoiceStealingQueue;          if (pVoiceStealingQueue) delete pVoiceStealingQueue;
134          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
135          EngineFactory::Destroy(this);          EngineFactory::Destroy(this);
# Line 178  namespace LinuxSampler { namespace gig { Line 166  namespace LinuxSampler { namespace gig {
166    
167      /**      /**
168       *  Reset all voices and disk thread and clear input event queue and all       *  Reset all voices and disk thread and clear input event queue and all
169       *  control and status variables. This method is not thread safe!       *  control and status variables. This method is protected by a mutex.
170       */       */
171      void Engine::ResetInternal() {      void Engine::ResetInternal() {
172            ResetInternalMutex.Lock();
173    
174            // make sure that the engine does not get any sysex messages
175            // while it's reseting
176            bool sysexDisabled = MidiInputPort::RemoveSysexListener(this);
177          ActiveVoiceCount    = 0;          ActiveVoiceCount    = 0;
178          ActiveVoiceCountMax = 0;          ActiveVoiceCountMax = 0;
179    
# Line 203  namespace LinuxSampler { namespace gig { Line 196  namespace LinuxSampler { namespace gig {
196    
197          // delete all input events          // delete all input events
198          pEventQueue->init();          pEventQueue->init();
199            pSysexBuffer->init();
200            if (sysexDisabled) MidiInputPort::AddSysexListener(this);
201            ResetInternalMutex.Unlock();
202      }      }
203    
204      /**      /**
# Line 249  namespace LinuxSampler { namespace gig { Line 245  namespace LinuxSampler { namespace gig {
245              // lower minimum release time              // lower minimum release time
246              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;
247              for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {              for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) {
248                  iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate);                  iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate);
249              }              }
250              pVoicePool->clear();              pVoicePool->clear();
251          }          }
# Line 277  namespace LinuxSampler { namespace gig { Line 273  namespace LinuxSampler { namespace gig {
273          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
274          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());
275    
         // (re)allocate synthesis parameter matrix  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
   
         #if defined(__APPLE__)  
         pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle());  
         #else  
         pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()));  
         #endif  
         for (int dst = 1; dst < Event::destination_count; dst++)  
             pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle();  
   
         // (re)allocate biquad filter parameter sequence  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pMainFilterParameters)  delete[] pMainFilterParameters;  
         pBasicFilterParameters = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
         pMainFilterParameters  = new biquad_param_t[pAudioOut->MaxSamplesPerCycle()];  
   
276          dmsg(1,("Starting disk thread..."));          dmsg(1,("Starting disk thread..."));
277          pDiskThread->StartThread();          pDiskThread->StartThread();
278          dmsg(1,("OK\n"));          dmsg(1,("OK\n"));
# Line 629  namespace LinuxSampler { namespace gig { Line 608  namespace LinuxSampler { namespace gig {
608          #endif          #endif
609    
610          const int key = itNoteOnEvent->Param.Note.Key;          const int key = itNoteOnEvent->Param.Note.Key;
611            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key];
612    
613            // move note on event to the key's own event list
614            RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
615    
616            // if Solo Mode then kill all already active voices
617            if (pEngineChannel->SoloMode) {
618                Pool<uint>::Iterator itYoungestKey = pEngineChannel->pActiveKeys->last();
619                if (itYoungestKey) {
620                    const int iYoungestKey = *itYoungestKey;
621                    const midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[iYoungestKey];
622                    if (pOtherKey->Active) {
623                        // get final portamento position of currently active voice
624                        if (pEngineChannel->PortamentoMode) {
625                            RTList<Voice>::Iterator itVoice = pOtherKey->pActiveVoices->last();
626                            if (itVoice) itVoice->UpdatePortamentoPos(itNoteOnEventOnKeyList);
627                        }
628                        // kill all voices on the (other) key
629                        RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first();
630                        RTList<Voice>::Iterator end               = pOtherKey->pActiveVoices->end();
631                        for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
632                            if (itVoiceToBeKilled->Type != Voice::type_release_trigger)
633                                itVoiceToBeKilled->Kill(itNoteOnEventOnKeyList);
634                        }
635                    }
636                }
637                // set this key as 'currently active solo key'
638                pEngineChannel->SoloKey = key;
639            }
640    
641          // Change key dimension value if key is in keyswitching area          // Change key dimension value if key is in keyswitching area
642          {          {
# Line 638  namespace LinuxSampler { namespace gig { Line 646  namespace LinuxSampler { namespace gig {
646                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);
647          }          }
648    
         midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key];  
   
649          pKey->KeyPressed = true; // the MIDI key was now pressed down          pKey->KeyPressed = true; // the MIDI key was now pressed down
650          pKey->Velocity   = itNoteOnEvent->Param.Note.Velocity;          pKey->Velocity   = itNoteOnEventOnKeyList->Param.Note.Velocity;
651          pKey->NoteOnTime = FrameTime + itNoteOnEvent->FragmentPos(); // will be used to calculate note length          pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length
652    
653          // cancel release process of voices on this key if needed          // cancel release process of voices on this key if needed
654          if (pKey->Active && !pEngineChannel->SustainPedal) {          if (pKey->Active && !pEngineChannel->SustainPedal) {
655              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();
656              if (itCancelReleaseEvent) {              if (itCancelReleaseEvent) {
657                  *itCancelReleaseEvent = *itNoteOnEvent;                  // copy event                  *itCancelReleaseEvent = *itNoteOnEventOnKeyList;         // copy event
658                  itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type                  itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type
659              }              }
660              else dmsg(1,("Event pool emtpy!\n"));              else dmsg(1,("Event pool emtpy!\n"));
661          }          }
662    
         // move note on event to the key's own event list  
         RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);  
   
663          // allocate and trigger new voice(s) for the key          // allocate and trigger new voice(s) for the key
664          {          {
665              // first, get total amount of required voices (dependant on amount of layers)              // first, get total amount of required voices (dependant on amount of layers)
# Line 673  namespace LinuxSampler { namespace gig { Line 676  namespace LinuxSampler { namespace gig {
676          if (!pKey->Active && !pKey->VoiceTheftsQueued)          if (!pKey->Active && !pKey->VoiceTheftsQueued)
677              pKey->pEvents->free(itNoteOnEventOnKeyList);              pKey->pEvents->free(itNoteOnEventOnKeyList);
678    
679            if (!pEngineChannel->SoloMode || pEngineChannel->PortamentoPos < 0.0f) pEngineChannel->PortamentoPos = (float) key;
680          pKey->RoundRobinIndex++;          pKey->RoundRobinIndex++;
681      }      }
682    
# Line 690  namespace LinuxSampler { namespace gig { Line 694  namespace LinuxSampler { namespace gig {
694          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
695          #endif          #endif
696    
697          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];          const int iKey = itNoteOffEvent->Param.Note.Key;
698            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[iKey];
699          pKey->KeyPressed = false; // the MIDI key was now released          pKey->KeyPressed = false; // the MIDI key was now released
700    
701          // release voices on this key if needed          // move event to the key's own event list
702          if (pKey->Active && !pEngineChannel->SustainPedal) {          RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);
             itNoteOffEvent->Type = Event::type_release; // transform event type  
703    
704              // move event to the key's own event list          bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key);
705              RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);  
706            // in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any)
707            if (pEngineChannel->SoloMode) { //TODO: this feels like too much code just for handling solo mode :P
708                bool bOtherKeysPressed = false;
709                if (iKey == pEngineChannel->SoloKey) {
710                    pEngineChannel->SoloKey = -1;
711                    // if there's still a key pressed down, respawn a voice (group) on the highest key
712                    for (int i = 127; i > 0; i--) {
713                        midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[i];
714                        if (pOtherKey->KeyPressed) {
715                            bOtherKeysPressed = true;
716                            // make the other key the new 'currently active solo key'
717                            pEngineChannel->SoloKey = i;
718                            // get final portamento position of currently active voice
719                            if (pEngineChannel->PortamentoMode) {
720                                RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first();
721                                if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList);
722                            }
723                            // create a pseudo note on event
724                            RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend();
725                            if (itPseudoNoteOnEvent) {
726                                // copy event
727                                *itPseudoNoteOnEvent = *itNoteOffEventOnKeyList;
728                                // transform event to a note on event
729                                itPseudoNoteOnEvent->Type                = Event::type_note_on;
730                                itPseudoNoteOnEvent->Param.Note.Key      = i;
731                                itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;
732                                // allocate and trigger new voice(s) for the other key
733                                {
734                                    // first, get total amount of required voices (dependant on amount of layers)
735                                    ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(i);
736                                    if (pRegion) {
737                                        int voicesRequired = pRegion->Layers;
738                                        // now launch the required amount of voices
739                                        for (int iLayer = 0; iLayer < voicesRequired; iLayer++)
740                                            LaunchVoice(pEngineChannel, itPseudoNoteOnEvent, iLayer, false, true, false);
741                                    }
742                                }
743                                // if neither a voice was spawned or postponed then remove note on event from key again
744                                if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued)
745                                    pOtherKey->pEvents->free(itPseudoNoteOnEvent);
746    
747                            } else dmsg(1,("Could not respawn voice, no free event left\n"));
748                            break; // done
749                        }
750                    }
751                }
752                if (bOtherKeysPressed) {
753                    if (pKey->Active) { // kill all voices on this key
754                        bShouldRelease = false; // no need to release, as we kill it here
755                        RTList<Voice>::Iterator itVoiceToBeKilled = pKey->pActiveVoices->first();
756                        RTList<Voice>::Iterator end               = pKey->pActiveVoices->end();
757                        for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
758                            if (itVoiceToBeKilled->Type != Voice::type_release_trigger)
759                                itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList);
760                        }
761                    }
762                } else pEngineChannel->PortamentoPos = -1.0f;
763            }
764    
765            // if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed
766            if (bShouldRelease) {
767                itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type
768    
769              // spawn release triggered voice(s) if needed              // spawn release triggered voice(s) if needed
770              if (pKey->ReleaseTrigger) {              if (pKey->ReleaseTrigger) {
# Line 716  namespace LinuxSampler { namespace gig { Line 782  namespace LinuxSampler { namespace gig {
782                  }                  }
783                  pKey->ReleaseTrigger = false;                  pKey->ReleaseTrigger = false;
784              }              }
   
             // if neither a voice was spawned or postponed then remove note off event from key again  
             if (!pKey->Active && !pKey->VoiceTheftsQueued)  
                 pKey->pEvents->free(itNoteOffEventOnKeyList);  
785          }          }
786    
787            // if neither a voice was spawned or postponed on this key then remove note off event from key again
788            if (!pKey->Active && !pKey->VoiceTheftsQueued)
789                pKey->pEvents->free(itNoteOffEventOnKeyList);
790      }      }
791    
792      /**      /**
793       *  Moves pitchbend event from the general (input) event list to the pitch       *  Moves pitchbend event from the general (input) event list to the engine
794       *  event list.       *  channel's event list. It will actually processed later by the
795         *  respective voice.
796       *       *
797       *  @param pEngineChannel - engine channel on which this event occured on       *  @param pEngineChannel - engine channel on which this event occured on
798       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event
799       */       */
800      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {
801          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value
         itPitchbendEvent.moveToEndOf(pEngineChannel->pSynthesisEvents[Event::destination_vco]);  
802      }      }
803    
804      /**      /**
# Line 1169  namespace LinuxSampler { namespace gig { Line 1235  namespace LinuxSampler { namespace gig {
1235          // update controller value in the engine channel's controller table          // update controller value in the engine channel's controller table
1236          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1237    
1238          // move event from the unsorted event list to the control change event list          switch (itControlChangeEvent->Param.CC.Controller) {
1239          Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents);              case 5: { // portamento time
1240                    pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN;
1241          switch (itControlChangeEventOnCCList->Param.CC.Controller) {                  break;
1242                }
1243              case 7: { // volume              case 7: { // volume
1244                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1245                  pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f;                  pEngineChannel->GlobalVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value] *  CONFIG_GLOBAL_ATTENUATION;
1246                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag
1247                  break;                  break;
1248              }              }
1249              case 10: { // panpot              case 10: { // panpot
1250                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1251                  const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64;                  pEngineChannel->GlobalPanLeft  = PanCurve[128 - itControlChangeEvent->Param.CC.Value];
1252                  pEngineChannel->GlobalPanLeft  = 1.0f - float(RTMath::Max(pan, 0)) /  63.0f;                  pEngineChannel->GlobalPanRight = PanCurve[itControlChangeEvent->Param.CC.Value];
                 pEngineChannel->GlobalPanRight = 1.0f - float(RTMath::Min(pan, 0)) / -64.0f;  
1253                  break;                  break;
1254              }              }
1255              case 64: { // sustain              case 64: { // sustain
1256                  if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {
1257                      dmsg(4,("PEDAL DOWN\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
1258                      pEngineChannel->SustainPedal = true;                      pEngineChannel->SustainPedal = true;
1259    
1260                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1202  namespace LinuxSampler { namespace gig { Line 1268  namespace LinuxSampler { namespace gig {
1268                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed) {
1269                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1270                              if (itNewEvent) {                              if (itNewEvent) {
1271                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1272                                  itNewEvent->Type = Event::type_cancel_release; // transform event type                                  itNewEvent->Type = Event::type_cancel_release; // transform event type
1273                              }                              }
1274                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
1275                          }                          }
1276                      }                      }
1277                  }                  }
1278                  if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {
1279                      dmsg(4,("PEDAL UP\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL UP\n"));
1280                      pEngineChannel->SustainPedal = false;                      pEngineChannel->SustainPedal = false;
1281    
1282                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1221  namespace LinuxSampler { namespace gig { Line 1287  namespace LinuxSampler { namespace gig {
1287                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1288                      for (; iuiKey; ++iuiKey) {                      for (; iuiKey; ++iuiKey) {
1289                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1290                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed && ShouldReleaseVoice(pEngineChannel, *iuiKey)) {
1291                                RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1292                                if (itNewEvent) {
1293                                    *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1294                                    itNewEvent->Type = Event::type_release; // transform event type
1295                                }
1296                                else dmsg(1,("Event pool emtpy!\n"));
1297                            }
1298                        }
1299                    }
1300                    break;
1301                }
1302                case 65: { // portamento on / off
1303                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1304                    pEngineChannel->PortamentoMode = itControlChangeEvent->Param.CC.Value >= 64;
1305                    break;
1306                }
1307                case 66: { // sostenuto
1308                    if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) {
1309                        dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n"));
1310                        pEngineChannel->SostenutoPedal = true;
1311    
1312                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1313                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1314                        #endif
1315    
1316                        SostenutoKeyCount = 0;
1317                        // Remeber the pressed keys
1318                        RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1319                        for (; iuiKey; ++iuiKey) {
1320                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1321                            if (pKey->KeyPressed && SostenutoKeyCount < 128) SostenutoKeys[SostenutoKeyCount++] = *iuiKey;
1322                        }
1323                    }
1324                    if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SostenutoPedal) {
1325                        dmsg(4,("SOSTENUTO (CENTER) PEDAL UP\n"));
1326                        pEngineChannel->SostenutoPedal = false;
1327    
1328                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1329                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1330                        #endif
1331    
1332                        // release voices if the damper pedal is up and their respective key is not pressed
1333                        for (int i = 0; i < SostenutoKeyCount; i++) {
1334                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[SostenutoKeys[i]];
1335                            if (!pKey->KeyPressed && !pEngineChannel->SustainPedal) {
1336                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1337                              if (itNewEvent) {                              if (itNewEvent) {
1338                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1339                                  itNewEvent->Type = Event::type_release; // transform event type                                  itNewEvent->Type = Event::type_release; // transform event type
1340                              }                              }
1341                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
# Line 1238  namespace LinuxSampler { namespace gig { Line 1349  namespace LinuxSampler { namespace gig {
1349              // Channel Mode Messages              // Channel Mode Messages
1350    
1351              case 120: { // all sound off              case 120: { // all sound off
1352                  KillAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  KillAllVoices(pEngineChannel, itControlChangeEvent);
1353                  break;                  break;
1354              }              }
1355              case 121: { // reset all controllers              case 121: { // reset all controllers
# Line 1246  namespace LinuxSampler { namespace gig { Line 1357  namespace LinuxSampler { namespace gig {
1357                  break;                  break;
1358              }              }
1359              case 123: { // all notes off              case 123: { // all notes off
1360                  ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);
1361                    break;
1362                }
1363                case 126: { // mono mode on
1364                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1365                    pEngineChannel->SoloMode = true;
1366                    break;
1367                }
1368                case 127: { // poly mode on
1369                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1370                    pEngineChannel->SoloMode = false;
1371                  break;                  break;
1372              }              }
1373          }          }
# Line 1390  namespace LinuxSampler { namespace gig { Line 1511  namespace LinuxSampler { namespace gig {
1511      }      }
1512    
1513      /**      /**
1514       * Initialize the parameter sequence for the modulation destination given by       * Determines whether the specified voice should be released.
1515       * by 'dst' with the constant value given by val.       *
1516       */       * @param pEngineChannel - The engine channel on which the voice should be checked
1517      void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) {       * @param Key - The key number
1518          int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle();       * @returns true if the specified should be released, false otherwise.
1519          float* m = &pSynthesisParameters[dst][0];       */
1520          for (int i = 0; i < maxsamples; i += 4) {      bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) {
1521             m[i]   = val;          if (pEngineChannel->SustainPedal) return false;
1522             m[i+1] = val;  
1523             m[i+2] = val;          if (pEngineChannel->SostenutoPedal) {
1524             m[i+3] = val;              for (int i = 0; i < SostenutoKeyCount; i++)
1525                    if (Key == SostenutoKeys[i]) return false;
1526          }          }
1527    
1528            return true;
1529      }      }
1530    
1531      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
# Line 1441  namespace LinuxSampler { namespace gig { Line 1565  namespace LinuxSampler { namespace gig {
1565      }      }
1566    
1567      String Engine::Version() {      String Engine::Version() {
1568          String s = "$Revision: 1.51 $";          String s = "$Revision: 1.60 $";
1569          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
1570      }      }
1571    
1572        // static constant initializers
1573        const float* Engine::VolumeCurve(InitVolumeCurve());
1574        const float* Engine::PanCurve(InitPanCurve());
1575        const float* Engine::CrossfadeCurve(InitCrossfadeCurve());
1576    
1577        float* Engine::InitVolumeCurve() {
1578            // line-segment approximation
1579            const float segments[] = {
1580                0, 0, 2, 0.0046, 16, 0.016, 31, 0.051, 45, 0.115, 54.5, 0.2,
1581                64.5, 0.39, 74, 0.74, 92, 1.03, 114, 1.94, 119.2, 2.2, 127, 2.2
1582            };
1583            return InitCurve(segments);
1584        }
1585    
1586        float* Engine::InitPanCurve() {
1587            // line-segment approximation
1588            const float segments[] = {
1589                0, 0, 1, 0,
1590                2, 0.05, 31.5, 0.7, 51, 0.851, 74.5, 1.12,
1591                127, 1.41, 128, 1.41
1592            };
1593            return InitCurve(segments, 129);
1594        }
1595    
1596        float* Engine::InitCrossfadeCurve() {
1597            // line-segment approximation
1598            const float segments[] = {
1599                0, 0, 1, 0.03, 10, 0.1, 51, 0.58, 127, 1
1600            };
1601            return InitCurve(segments);
1602        }
1603    
1604        float* Engine::InitCurve(const float* segments, int size) {
1605            float* y = new float[size];
1606            for (int x = 0 ; x < size ; x++) {
1607                if (x > segments[2]) segments += 2;
1608                y[x] = segments[1] + (x - segments[0]) *
1609                    (segments[3] - segments[1]) / (segments[2] - segments[0]);
1610            }
1611            return y;
1612        }
1613    
1614  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.716  
changed lines
  Added in v.846

  ViewVC Help
Powered by ViewVC