/[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 775 by schoenebeck, Wed Sep 21 14:30:43 2005 UTC revision 880 by schoenebeck, Tue Jun 27 22:57:37 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 116  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 165  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 191  namespace LinuxSampler { namespace gig { Line 197  namespace LinuxSampler { namespace gig {
197          // delete all input events          // delete all input events
198          pEventQueue->init();          pEventQueue->init();
199          pSysexBuffer->init();          pSysexBuffer->init();
200            if (sysexDisabled) MidiInputPort::AddSysexListener(this);
201            ResetInternalMutex.Unlock();
202      }      }
203    
204      /**      /**
# Line 220  namespace LinuxSampler { namespace gig { Line 228  namespace LinuxSampler { namespace gig {
228          }          }
229          catch (AudioOutputException e) {          catch (AudioOutputException e) {
230              String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message();              String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message();
231              throw LinuxSamplerException(msg);              throw Exception(msg);
232          }          }
233    
234          this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();          this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();
# Line 600  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          {          {
643              const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument;              const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument;
644              if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)              if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)
645                  pEngineChannel->CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) /                  pEngineChannel->CurrentKeyDimension = float(key - pInstrument->DimensionKeyRange.low) /
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 644  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 661  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 687  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      /**      /**
# Line 782  namespace LinuxSampler { namespace gig { Line 877  namespace LinuxSampler { namespace gig {
877                      DimValues[i] = (uint) ReleaseTriggerVoice;                      DimValues[i] = (uint) ReleaseTriggerVoice;
878                      break;                      break;
879                  case ::gig::dimension_keyboard:                  case ::gig::dimension_keyboard:
880                      DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension;                      DimValues[i] = (uint) (pEngineChannel->CurrentKeyDimension * pRegion->pDimensionDefinitions[i].zones);
881                      break;                      break;
882                  case ::gig::dimension_roundrobin:                  case ::gig::dimension_roundrobin:
883                      DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on                      DimValues[i] = (uint) pEngineChannel->pMIDIKeyInfo[MIDIKey].RoundRobinIndex; // incremented for each note on
# Line 1141  namespace LinuxSampler { namespace gig { Line 1236  namespace LinuxSampler { namespace gig {
1236          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1237    
1238          switch (itControlChangeEvent->Param.CC.Controller) {          switch (itControlChangeEvent->Param.CC.Controller) {
1239                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                    break;
1242                }
1243              case 7: { // volume              case 7: { // volume
1244                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1245                  pEngineChannel->GlobalVolume = (float) itControlChangeEvent->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) itControlChangeEvent->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 (itControlChangeEvent->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 1178  namespace LinuxSampler { namespace gig { Line 1276  namespace LinuxSampler { namespace gig {
1276                      }                      }
1277                  }                  }
1278                  if (itControlChangeEvent->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 1189  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 = *itControlChangeEvent; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
# Line 1214  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                    #if CONFIG_PROCESS_ALL_NOTES_OFF
1361                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);                  ReleaseAllVoices(pEngineChannel, itControlChangeEvent);
1362                    #endif // CONFIG_PROCESS_ALL_NOTES_OFF
1363                    break;
1364                }
1365                case 126: { // mono mode on
1366                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1367                    pEngineChannel->SoloMode = true;
1368                    break;
1369                }
1370                case 127: { // poly mode on
1371                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1372                    pEngineChannel->SoloMode = false;
1373                  break;                  break;
1374              }              }
1375          }          }
# Line 1357  namespace LinuxSampler { namespace gig { Line 1512  namespace LinuxSampler { namespace gig {
1512          }          }
1513      }      }
1514    
1515        /**
1516         * Determines whether the specified voice should be released.
1517         *
1518         * @param pEngineChannel - The engine channel on which the voice should be checked
1519         * @param Key - The key number
1520         * @returns true if the specified should be released, false otherwise.
1521         */
1522        bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) {
1523            if (pEngineChannel->SustainPedal) return false;
1524    
1525            if (pEngineChannel->SostenutoPedal) {
1526                for (int i = 0; i < SostenutoKeyCount; i++)
1527                    if (Key == SostenutoKeys[i]) return false;
1528            }
1529    
1530            return true;
1531        }
1532    
1533      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
1534          return ActiveVoiceCount;          return ActiveVoiceCount;
1535      }      }
# Line 1394  namespace LinuxSampler { namespace gig { Line 1567  namespace LinuxSampler { namespace gig {
1567      }      }
1568    
1569      String Engine::Version() {      String Engine::Version() {
1570          String s = "$Revision: 1.54 $";          String s = "$Revision: 1.63 $";
1571          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
1572      }      }
1573    
1574        // static constant initializers
1575        const float* Engine::VolumeCurve(InitVolumeCurve());
1576        const float* Engine::PanCurve(InitPanCurve());
1577        const float* Engine::CrossfadeCurve(InitCrossfadeCurve());
1578    
1579        float* Engine::InitVolumeCurve() {
1580            // line-segment approximation
1581            const float segments[] = {
1582                0, 0, 2, 0.0046, 16, 0.016, 31, 0.051, 45, 0.115, 54.5, 0.2,
1583                64.5, 0.39, 74, 0.74, 92, 1.03, 114, 1.94, 119.2, 2.2, 127, 2.2
1584            };
1585            return InitCurve(segments);
1586        }
1587    
1588        float* Engine::InitPanCurve() {
1589            // line-segment approximation
1590            const float segments[] = {
1591                0, 0, 1, 0,
1592                2, 0.05, 31.5, 0.7, 51, 0.851, 74.5, 1.12,
1593                127, 1.41, 128, 1.41
1594            };
1595            return InitCurve(segments, 129);
1596        }
1597    
1598        float* Engine::InitCrossfadeCurve() {
1599            // line-segment approximation
1600            const float segments[] = {
1601                0, 0, 1, 0.03, 10, 0.1, 51, 0.58, 127, 1
1602            };
1603            return InitCurve(segments);
1604        }
1605    
1606        float* Engine::InitCurve(const float* segments, int size) {
1607            float* y = new float[size];
1608            for (int x = 0 ; x < size ; x++) {
1609                if (x > segments[2]) segments += 2;
1610                y[x] = segments[1] + (x - segments[0]) *
1611                    (segments[3] - segments[1]) / (segments[2] - segments[0]);
1612            }
1613            return y;
1614        }
1615    
1616  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.775  
changed lines
  Added in v.880

  ViewVC Help
Powered by ViewVC