/[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 831 by persson, Sat Jan 28 16:55:30 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 139  namespace LinuxSampler { namespace gig { Line 129  namespace LinuxSampler { namespace gig {
129              delete pVoicePool;              delete pVoicePool;
130          }          }
131          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
         if (pMainFilterParameters) delete[] pMainFilterParameters;  
         if (pBasicFilterParameters) delete[] pBasicFilterParameters;  
         if (pSynthesisParameters[0]) free(pSynthesisParameters[0]);  
132          if (pVoiceStealingQueue) delete pVoiceStealingQueue;          if (pVoiceStealingQueue) delete pVoiceStealingQueue;
133          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
134          EngineFactory::Destroy(this);          EngineFactory::Destroy(this);
# Line 203  namespace LinuxSampler { namespace gig { Line 190  namespace LinuxSampler { namespace gig {
190    
191          // delete all input events          // delete all input events
192          pEventQueue->init();          pEventQueue->init();
193            pSysexBuffer->init();
194      }      }
195    
196      /**      /**
# Line 249  namespace LinuxSampler { namespace gig { Line 237  namespace LinuxSampler { namespace gig {
237              // lower minimum release time              // lower minimum release time
238              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;
239              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()) {
240                  iterVoice->pEG1->CalculateFadeOutCoeff(minReleaseTime, SampleRate);                  iterVoice->EG1.CalculateFadeOutCoeff(minReleaseTime, SampleRate);
241              }              }
242              pVoicePool->clear();              pVoicePool->clear();
243          }          }
# Line 277  namespace LinuxSampler { namespace gig { Line 265  namespace LinuxSampler { namespace gig {
265          if (pEventGenerator) delete pEventGenerator;          if (pEventGenerator) delete pEventGenerator;
266          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());          pEventGenerator = new EventGenerator(pAudioOut->SampleRate());
267    
         // (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()];  
   
268          dmsg(1,("Starting disk thread..."));          dmsg(1,("Starting disk thread..."));
269          pDiskThread->StartThread();          pDiskThread->StartThread();
270          dmsg(1,("OK\n"));          dmsg(1,("OK\n"));
# Line 629  namespace LinuxSampler { namespace gig { Line 600  namespace LinuxSampler { namespace gig {
600          #endif          #endif
601    
602          const int key = itNoteOnEvent->Param.Note.Key;          const int key = itNoteOnEvent->Param.Note.Key;
603            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key];
604    
605            // move note on event to the key's own event list
606            RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
607    
608            // if Solo Mode then kill all already active voices
609            if (pEngineChannel->SoloMode) {
610                Pool<uint>::Iterator itYoungestKey = pEngineChannel->pActiveKeys->last();
611                if (itYoungestKey) {
612                    const int iYoungestKey = *itYoungestKey;
613                    const midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[iYoungestKey];
614                    if (pOtherKey->Active) {
615                        // get final portamento position of currently active voice
616                        if (pEngineChannel->PortamentoMode) {
617                            RTList<Voice>::Iterator itVoice = pOtherKey->pActiveVoices->last();
618                            if (itVoice) itVoice->UpdatePortamentoPos(itNoteOnEventOnKeyList);
619                        }
620                        // kill all voices on the (other) key
621                        RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first();
622                        RTList<Voice>::Iterator end               = pOtherKey->pActiveVoices->end();
623                        for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
624                            if (itVoiceToBeKilled->Type != Voice::type_release_trigger)
625                                itVoiceToBeKilled->Kill(itNoteOnEventOnKeyList);
626                        }
627                    }
628                }
629                // set this key as 'currently active solo key'
630                pEngineChannel->SoloKey = key;
631            }
632    
633          // Change key dimension value if key is in keyswitching area          // Change key dimension value if key is in keyswitching area
634          {          {
# Line 638  namespace LinuxSampler { namespace gig { Line 638  namespace LinuxSampler { namespace gig {
638                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);
639          }          }
640    
         midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key];  
   
641          pKey->KeyPressed = true; // the MIDI key was now pressed down          pKey->KeyPressed = true; // the MIDI key was now pressed down
642          pKey->Velocity   = itNoteOnEvent->Param.Note.Velocity;          pKey->Velocity   = itNoteOnEventOnKeyList->Param.Note.Velocity;
643          pKey->NoteOnTime = FrameTime + itNoteOnEvent->FragmentPos(); // will be used to calculate note length          pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length
644    
645          // cancel release process of voices on this key if needed          // cancel release process of voices on this key if needed
646          if (pKey->Active && !pEngineChannel->SustainPedal) {          if (pKey->Active && !pEngineChannel->SustainPedal) {
647              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();
648              if (itCancelReleaseEvent) {              if (itCancelReleaseEvent) {
649                  *itCancelReleaseEvent = *itNoteOnEvent;                  // copy event                  *itCancelReleaseEvent = *itNoteOnEventOnKeyList;         // copy event
650                  itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type                  itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type
651              }              }
652              else dmsg(1,("Event pool emtpy!\n"));              else dmsg(1,("Event pool emtpy!\n"));
653          }          }
654    
         // move note on event to the key's own event list  
         RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);  
   
655          // allocate and trigger new voice(s) for the key          // allocate and trigger new voice(s) for the key
656          {          {
657              // 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 668  namespace LinuxSampler { namespace gig {
668          if (!pKey->Active && !pKey->VoiceTheftsQueued)          if (!pKey->Active && !pKey->VoiceTheftsQueued)
669              pKey->pEvents->free(itNoteOnEventOnKeyList);              pKey->pEvents->free(itNoteOnEventOnKeyList);
670    
671            if (!pEngineChannel->SoloMode || pEngineChannel->PortamentoPos < 0.0f) pEngineChannel->PortamentoPos = (float) key;
672          pKey->RoundRobinIndex++;          pKey->RoundRobinIndex++;
673      }      }
674    
# Line 690  namespace LinuxSampler { namespace gig { Line 686  namespace LinuxSampler { namespace gig {
686          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
687          #endif          #endif
688    
689          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];          const int iKey = itNoteOffEvent->Param.Note.Key;
690            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[iKey];
691          pKey->KeyPressed = false; // the MIDI key was now released          pKey->KeyPressed = false; // the MIDI key was now released
692    
693          // release voices on this key if needed          // move event to the key's own event list
694          if (pKey->Active && !pEngineChannel->SustainPedal) {          RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);
             itNoteOffEvent->Type = Event::type_release; // transform event type  
695    
696              // move event to the key's own event list          bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key);
697              RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);  
698            // in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any)
699            if (pEngineChannel->SoloMode) { //TODO: this feels like too much code just for handling solo mode :P
700                bool bOtherKeysPressed = false;
701                if (iKey == pEngineChannel->SoloKey) {
702                    pEngineChannel->SoloKey = -1;
703                    // if there's still a key pressed down, respawn a voice (group) on the highest key
704                    for (int i = 127; i > 0; i--) {
705                        midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[i];
706                        if (pOtherKey->KeyPressed) {
707                            bOtherKeysPressed = true;
708                            // make the other key the new 'currently active solo key'
709                            pEngineChannel->SoloKey = i;
710                            // get final portamento position of currently active voice
711                            if (pEngineChannel->PortamentoMode) {
712                                RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first();
713                                if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList);
714                            }
715                            // create a pseudo note on event
716                            RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend();
717                            if (itPseudoNoteOnEvent) {
718                                // copy event
719                                *itPseudoNoteOnEvent = *itNoteOffEventOnKeyList;
720                                // transform event to a note on event
721                                itPseudoNoteOnEvent->Type                = Event::type_note_on;
722                                itPseudoNoteOnEvent->Param.Note.Key      = i;
723                                itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;
724                                // allocate and trigger new voice(s) for the other key
725                                {
726                                    // first, get total amount of required voices (dependant on amount of layers)
727                                    ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(i);
728                                    if (pRegion) {
729                                        int voicesRequired = pRegion->Layers;
730                                        // now launch the required amount of voices
731                                        for (int iLayer = 0; iLayer < voicesRequired; iLayer++)
732                                            LaunchVoice(pEngineChannel, itPseudoNoteOnEvent, iLayer, false, true, false);
733                                    }
734                                }
735                                // if neither a voice was spawned or postponed then remove note on event from key again
736                                if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued)
737                                    pOtherKey->pEvents->free(itPseudoNoteOnEvent);
738    
739                            } else dmsg(1,("Could not respawn voice, no free event left\n"));
740                            break; // done
741                        }
742                    }
743                }
744                if (bOtherKeysPressed) {
745                    if (pKey->Active) { // kill all voices on this key
746                        bShouldRelease = false; // no need to release, as we kill it here
747                        RTList<Voice>::Iterator itVoiceToBeKilled = pKey->pActiveVoices->first();
748                        RTList<Voice>::Iterator end               = pKey->pActiveVoices->end();
749                        for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
750                            if (itVoiceToBeKilled->Type != Voice::type_release_trigger)
751                                itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList);
752                        }
753                    }
754                } else pEngineChannel->PortamentoPos = -1.0f;
755            }
756    
757            // if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed
758            if (bShouldRelease) {
759                itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type
760    
761              // spawn release triggered voice(s) if needed              // spawn release triggered voice(s) if needed
762              if (pKey->ReleaseTrigger) {              if (pKey->ReleaseTrigger) {
# Line 716  namespace LinuxSampler { namespace gig { Line 774  namespace LinuxSampler { namespace gig {
774                  }                  }
775                  pKey->ReleaseTrigger = false;                  pKey->ReleaseTrigger = false;
776              }              }
   
             // 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);  
777          }          }
778    
779            // if neither a voice was spawned or postponed on this key then remove note off event from key again
780            if (!pKey->Active && !pKey->VoiceTheftsQueued)
781                pKey->pEvents->free(itNoteOffEventOnKeyList);
782      }      }
783    
784      /**      /**
785       *  Moves pitchbend event from the general (input) event list to the pitch       *  Moves pitchbend event from the general (input) event list to the engine
786       *  event list.       *  channel's event list. It will actually processed later by the
787         *  respective voice.
788       *       *
789       *  @param pEngineChannel - engine channel on which this event occured on       *  @param pEngineChannel - engine channel on which this event occured on
790       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event
791       */       */
792      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {
793          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]);  
794      }      }
795    
796      /**      /**
# Line 1169  namespace LinuxSampler { namespace gig { Line 1227  namespace LinuxSampler { namespace gig {
1227          // update controller value in the engine channel's controller table          // update controller value in the engine channel's controller table
1228          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1229    
1230          // move event from the unsorted event list to the control change event list          switch (itControlChangeEvent->Param.CC.Controller) {
1231          Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pCCEvents);              case 5: { // portamento time
1232                    pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN;
1233          switch (itControlChangeEventOnCCList->Param.CC.Controller) {                  break;
1234                }
1235              case 7: { // volume              case 7: { // volume
1236                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1237                  pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f;                  pEngineChannel->GlobalVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value] *  CONFIG_GLOBAL_ATTENUATION;
1238                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag
1239                  break;                  break;
1240              }              }
1241              case 10: { // panpot              case 10: { // panpot
1242                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1243                  const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64;                  pEngineChannel->GlobalPanLeft  = PanCurve[128 - itControlChangeEvent->Param.CC.Value];
1244                  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;  
1245                  break;                  break;
1246              }              }
1247              case 64: { // sustain              case 64: { // sustain
1248                  if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {
1249                      dmsg(4,("PEDAL DOWN\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
1250                      pEngineChannel->SustainPedal = true;                      pEngineChannel->SustainPedal = true;
1251    
1252                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1202  namespace LinuxSampler { namespace gig { Line 1260  namespace LinuxSampler { namespace gig {
1260                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed) {
1261                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1262                              if (itNewEvent) {                              if (itNewEvent) {
1263                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1264                                  itNewEvent->Type = Event::type_cancel_release; // transform event type                                  itNewEvent->Type = Event::type_cancel_release; // transform event type
1265                              }                              }
1266                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
1267                          }                          }
1268                      }                      }
1269                  }                  }
1270                  if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {
1271                      dmsg(4,("PEDAL UP\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL UP\n"));
1272                      pEngineChannel->SustainPedal = false;                      pEngineChannel->SustainPedal = false;
1273    
1274                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1221  namespace LinuxSampler { namespace gig { Line 1279  namespace LinuxSampler { namespace gig {
1279                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1280                      for (; iuiKey; ++iuiKey) {                      for (; iuiKey; ++iuiKey) {
1281                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1282                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed && ShouldReleaseVoice(pEngineChannel, *iuiKey)) {
1283                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1284                              if (itNewEvent) {                              if (itNewEvent) {
1285                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1286                                    itNewEvent->Type = Event::type_release; // transform event type
1287                                }
1288                                else dmsg(1,("Event pool emtpy!\n"));
1289                            }
1290                        }
1291                    }
1292                    break;
1293                }
1294                case 65: { // portamento on / off
1295                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1296                    pEngineChannel->PortamentoMode = itControlChangeEvent->Param.CC.Value >= 64;
1297                    break;
1298                }
1299                case 66: { // sostenuto
1300                    if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) {
1301                        dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n"));
1302                        pEngineChannel->SostenutoPedal = true;
1303    
1304                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1305                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1306                        #endif
1307    
1308                        SostenutoKeyCount = 0;
1309                        // Remeber the pressed keys
1310                        RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1311                        for (; iuiKey; ++iuiKey) {
1312                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1313                            if (pKey->KeyPressed && SostenutoKeyCount < 128) SostenutoKeys[SostenutoKeyCount++] = *iuiKey;
1314                        }
1315                    }
1316                    if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SostenutoPedal) {
1317                        dmsg(4,("SOSTENUTO (CENTER) PEDAL UP\n"));
1318                        pEngineChannel->SostenutoPedal = false;
1319    
1320                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1321                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1322                        #endif
1323    
1324                        // release voices if the damper pedal is up and their respective key is not pressed
1325                        for (int i = 0; i < SostenutoKeyCount; i++) {
1326                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[SostenutoKeys[i]];
1327                            if (!pKey->KeyPressed && !pEngineChannel->SustainPedal) {
1328                                RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1329                                if (itNewEvent) {
1330                                    *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1331                                  itNewEvent->Type = Event::type_release; // transform event type                                  itNewEvent->Type = Event::type_release; // transform event type
1332                              }                              }
1333                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
# Line 1238  namespace LinuxSampler { namespace gig { Line 1341  namespace LinuxSampler { namespace gig {
1341              // Channel Mode Messages              // Channel Mode Messages
1342    
1343              case 120: { // all sound off              case 120: { // all sound off
1344                  KillAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  KillAllVoices(pEngineChannel, itControlChangeEvent);
1345                  break;                  break;
1346              }              }
1347              case 121: { // reset all controllers              case 121: { // reset all controllers
# Line 1246  namespace LinuxSampler { namespace gig { Line 1349  namespace LinuxSampler { namespace gig {
1349                  break;                  break;
1350              }              }
1351              case 123: { // all notes off              case 123: { // all notes off
1352                  ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);
1353                    break;
1354                }
1355                case 126: { // mono mode on
1356                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1357                    pEngineChannel->SoloMode = true;
1358                    break;
1359                }
1360                case 127: { // poly mode on
1361                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1362                    pEngineChannel->SoloMode = false;
1363                  break;                  break;
1364              }              }
1365          }          }
# Line 1390  namespace LinuxSampler { namespace gig { Line 1503  namespace LinuxSampler { namespace gig {
1503      }      }
1504    
1505      /**      /**
1506       * Initialize the parameter sequence for the modulation destination given by       * Determines whether the specified voice should be released.
1507       * by 'dst' with the constant value given by val.       *
1508       */       * @param pEngineChannel - The engine channel on which the voice should be checked
1509      void Engine::ResetSynthesisParameters(Event::destination_t dst, float val) {       * @param Key - The key number
1510          int maxsamples = pAudioOutputDevice->MaxSamplesPerCycle();       * @returns true if the specified should be released, false otherwise.
1511          float* m = &pSynthesisParameters[dst][0];       */
1512          for (int i = 0; i < maxsamples; i += 4) {      bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) {
1513             m[i]   = val;          if (pEngineChannel->SustainPedal) return false;
1514             m[i+1] = val;  
1515             m[i+2] = val;          if (pEngineChannel->SostenutoPedal) {
1516             m[i+3] = val;              for (int i = 0; i < SostenutoKeyCount; i++)
1517                    if (Key == SostenutoKeys[i]) return false;
1518          }          }
1519    
1520            return true;
1521      }      }
1522    
1523      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
# Line 1441  namespace LinuxSampler { namespace gig { Line 1557  namespace LinuxSampler { namespace gig {
1557      }      }
1558    
1559      String Engine::Version() {      String Engine::Version() {
1560          String s = "$Revision: 1.51 $";          String s = "$Revision: 1.58 $";
1561          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
1562      }      }
1563    
1564        // static constant initializers
1565        const float* Engine::VolumeCurve(InitVolumeCurve());
1566        const float* Engine::PanCurve(InitPanCurve());
1567    
1568        float* Engine::InitVolumeCurve() {
1569            // line-segment approximation
1570            const float segments[] = {
1571                0, 0, 2, 0.0046, 16, 0.016, 31, 0.051, 45, 0.115, 54.5, 0.2,
1572                64.5, 0.39, 74, 0.74, 92, 1.03, 114, 1.94, 119.2, 2.2, 127, 2.2
1573            };
1574            return InitCurve(segments);
1575        }
1576    
1577        float* Engine::InitPanCurve() {
1578            // line-segment approximation
1579            const float segments[] = {
1580                0, 0, 1, 0,
1581                2, 0.05, 31.5, 0.7, 51, 0.851, 74.5, 1.12,
1582                127, 1.41, 128, 1.41
1583            };
1584            return InitCurve(segments, 129);
1585        }
1586    
1587        float* Engine::InitCurve(const float* segments, int size) {
1588            float* y = new float[size];
1589            for (int x = 0 ; x < size ; x++) {
1590                if (x > segments[2]) segments += 2;
1591                y[x] = segments[1] + (x - segments[0]) *
1592                    (segments[3] - segments[1]) / (segments[2] - segments[0]);
1593            }
1594            return y;
1595        }
1596    
1597  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

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

  ViewVC Help
Powered by ViewVC