/[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 738 by schoenebeck, Tue Aug 16 17:14:25 2005 UTC revision 947 by schoenebeck, Mon Nov 27 21:34:55 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 190  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 219  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 320  namespace LinuxSampler { namespace gig { Line 329  namespace LinuxSampler { namespace gig {
329      }      }
330    
331      /**      /**
332       *  Let this engine proceed to render the given amount of sample points. The       * Let this engine proceed to render the given amount of sample points.
333       *  calculated audio data of all voices of this engine will be placed into       * The engine will iterate through all engine channels and render audio
334       *  the engine's audio sum buffer which has to be copied and eventually be       * for each engine channel independently. The calculated audio data of
335       *  converted to the appropriate value range by the audio output class (e.g.       * all voices of each engine channel will be placed into the audio sum
336       *  AlsaIO or JackIO) right after.       * buffers of the respective audio output device, connected to the
337         * respective engine channel.
338       *       *
339       *  @param Samples - number of sample points to be rendered       *  @param Samples - number of sample points to be rendered
340       *  @returns       0 on success       *  @returns       0 on success
341       */       */
342      int Engine::RenderAudio(uint Samples) {      int Engine::RenderAudio(uint Samples) {
343          dmsg(5,("RenderAudio(Samples=%d)\n", Samples));          dmsg(7,("RenderAudio(Samples=%d)\n", Samples));
344    
345          // return if engine disabled          // return if engine disabled
346          if (EngineDisabled.Pop()) {          if (EngineDisabled.Pop()) {
# Line 599  namespace LinuxSampler { namespace gig { Line 609  namespace LinuxSampler { namespace gig {
609          #endif          #endif
610    
611          const int key = itNoteOnEvent->Param.Note.Key;          const int key = itNoteOnEvent->Param.Note.Key;
612            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key];
613    
614            // move note on event to the key's own event list
615            RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);
616    
617            // if Solo Mode then kill all already active voices
618            if (pEngineChannel->SoloMode) {
619                Pool<uint>::Iterator itYoungestKey = pEngineChannel->pActiveKeys->last();
620                if (itYoungestKey) {
621                    const int iYoungestKey = *itYoungestKey;
622                    const midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[iYoungestKey];
623                    if (pOtherKey->Active) {
624                        // get final portamento position of currently active voice
625                        if (pEngineChannel->PortamentoMode) {
626                            RTList<Voice>::Iterator itVoice = pOtherKey->pActiveVoices->last();
627                            if (itVoice) itVoice->UpdatePortamentoPos(itNoteOnEventOnKeyList);
628                        }
629                        // kill all voices on the (other) key
630                        RTList<Voice>::Iterator itVoiceToBeKilled = pOtherKey->pActiveVoices->first();
631                        RTList<Voice>::Iterator end               = pOtherKey->pActiveVoices->end();
632                        for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
633                            if (itVoiceToBeKilled->Type != Voice::type_release_trigger)
634                                itVoiceToBeKilled->Kill(itNoteOnEventOnKeyList);
635                        }
636                    }
637                }
638                // set this key as 'currently active solo key'
639                pEngineChannel->SoloKey = key;
640            }
641    
642          // Change key dimension value if key is in keyswitching area          // Change key dimension value if key is in keyswitching area
643          {          {
644              const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument;              const ::gig::Instrument* pInstrument = pEngineChannel->pInstrument;
645              if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)              if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high)
646                  pEngineChannel->CurrentKeyDimension = ((key - pInstrument->DimensionKeyRange.low) * 128) /                  pEngineChannel->CurrentKeyDimension = float(key - pInstrument->DimensionKeyRange.low) /
647                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);                      (pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1);
648          }          }
649    
         midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key];  
   
650          pKey->KeyPressed = true; // the MIDI key was now pressed down          pKey->KeyPressed = true; // the MIDI key was now pressed down
651          pKey->Velocity   = itNoteOnEvent->Param.Note.Velocity;          pKey->Velocity   = itNoteOnEventOnKeyList->Param.Note.Velocity;
652          pKey->NoteOnTime = FrameTime + itNoteOnEvent->FragmentPos(); // will be used to calculate note length          pKey->NoteOnTime = FrameTime + itNoteOnEventOnKeyList->FragmentPos(); // will be used to calculate note length
653    
654          // cancel release process of voices on this key if needed          // cancel release process of voices on this key if needed
655          if (pKey->Active && !pEngineChannel->SustainPedal) {          if (pKey->Active && !pEngineChannel->SustainPedal) {
656              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();              RTList<Event>::Iterator itCancelReleaseEvent = pKey->pEvents->allocAppend();
657              if (itCancelReleaseEvent) {              if (itCancelReleaseEvent) {
658                  *itCancelReleaseEvent = *itNoteOnEvent;                  // copy event                  *itCancelReleaseEvent = *itNoteOnEventOnKeyList;         // copy event
659                  itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type                  itCancelReleaseEvent->Type = Event::type_cancel_release; // transform event type
660              }              }
661              else dmsg(1,("Event pool emtpy!\n"));              else dmsg(1,("Event pool emtpy!\n"));
662          }          }
663    
         // move note on event to the key's own event list  
         RTList<Event>::Iterator itNoteOnEventOnKeyList = itNoteOnEvent.moveToEndOf(pKey->pEvents);  
   
664          // allocate and trigger new voice(s) for the key          // allocate and trigger new voice(s) for the key
665          {          {
666              // 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 643  namespace LinuxSampler { namespace gig { Line 677  namespace LinuxSampler { namespace gig {
677          if (!pKey->Active && !pKey->VoiceTheftsQueued)          if (!pKey->Active && !pKey->VoiceTheftsQueued)
678              pKey->pEvents->free(itNoteOnEventOnKeyList);              pKey->pEvents->free(itNoteOnEventOnKeyList);
679    
680            if (!pEngineChannel->SoloMode || pEngineChannel->PortamentoPos < 0.0f) pEngineChannel->PortamentoPos = (float) key;
681          pKey->RoundRobinIndex++;          pKey->RoundRobinIndex++;
682      }      }
683    
# Line 660  namespace LinuxSampler { namespace gig { Line 695  namespace LinuxSampler { namespace gig {
695          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted          if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
696          #endif          #endif
697    
698          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[itNoteOffEvent->Param.Note.Key];          const int iKey = itNoteOffEvent->Param.Note.Key;
699            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[iKey];
700          pKey->KeyPressed = false; // the MIDI key was now released          pKey->KeyPressed = false; // the MIDI key was now released
701    
702          // release voices on this key if needed          // move event to the key's own event list
703          if (pKey->Active && !pEngineChannel->SustainPedal) {          RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);
             itNoteOffEvent->Type = Event::type_release; // transform event type  
704    
705              // move event to the key's own event list          bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key);
706              RTList<Event>::Iterator itNoteOffEventOnKeyList = itNoteOffEvent.moveToEndOf(pKey->pEvents);  
707            // in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any)
708            if (pEngineChannel->SoloMode) { //TODO: this feels like too much code just for handling solo mode :P
709                bool bOtherKeysPressed = false;
710                if (iKey == pEngineChannel->SoloKey) {
711                    pEngineChannel->SoloKey = -1;
712                    // if there's still a key pressed down, respawn a voice (group) on the highest key
713                    for (int i = 127; i > 0; i--) {
714                        midi_key_info_t* pOtherKey = &pEngineChannel->pMIDIKeyInfo[i];
715                        if (pOtherKey->KeyPressed) {
716                            bOtherKeysPressed = true;
717                            // make the other key the new 'currently active solo key'
718                            pEngineChannel->SoloKey = i;
719                            // get final portamento position of currently active voice
720                            if (pEngineChannel->PortamentoMode) {
721                                RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first();
722                                if (itVoice) itVoice->UpdatePortamentoPos(itNoteOffEventOnKeyList);
723                            }
724                            // create a pseudo note on event
725                            RTList<Event>::Iterator itPseudoNoteOnEvent = pOtherKey->pEvents->allocAppend();
726                            if (itPseudoNoteOnEvent) {
727                                // copy event
728                                *itPseudoNoteOnEvent = *itNoteOffEventOnKeyList;
729                                // transform event to a note on event
730                                itPseudoNoteOnEvent->Type                = Event::type_note_on;
731                                itPseudoNoteOnEvent->Param.Note.Key      = i;
732                                itPseudoNoteOnEvent->Param.Note.Velocity = pOtherKey->Velocity;
733                                // allocate and trigger new voice(s) for the other key
734                                {
735                                    // first, get total amount of required voices (dependant on amount of layers)
736                                    ::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(i);
737                                    if (pRegion) {
738                                        int voicesRequired = pRegion->Layers;
739                                        // now launch the required amount of voices
740                                        for (int iLayer = 0; iLayer < voicesRequired; iLayer++)
741                                            LaunchVoice(pEngineChannel, itPseudoNoteOnEvent, iLayer, false, true, false);
742                                    }
743                                }
744                                // if neither a voice was spawned or postponed then remove note on event from key again
745                                if (!pOtherKey->Active && !pOtherKey->VoiceTheftsQueued)
746                                    pOtherKey->pEvents->free(itPseudoNoteOnEvent);
747    
748                            } else dmsg(1,("Could not respawn voice, no free event left\n"));
749                            break; // done
750                        }
751                    }
752                }
753                if (bOtherKeysPressed) {
754                    if (pKey->Active) { // kill all voices on this key
755                        bShouldRelease = false; // no need to release, as we kill it here
756                        RTList<Voice>::Iterator itVoiceToBeKilled = pKey->pActiveVoices->first();
757                        RTList<Voice>::Iterator end               = pKey->pActiveVoices->end();
758                        for (; itVoiceToBeKilled != end; ++itVoiceToBeKilled) {
759                            if (itVoiceToBeKilled->Type != Voice::type_release_trigger)
760                                itVoiceToBeKilled->Kill(itNoteOffEventOnKeyList);
761                        }
762                    }
763                } else pEngineChannel->PortamentoPos = -1.0f;
764            }
765    
766            // if no solo mode (the usual case) or if solo mode and no other key pressed, then release voices on this key if needed
767            if (bShouldRelease) {
768                itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type
769    
770              // spawn release triggered voice(s) if needed              // spawn release triggered voice(s) if needed
771              if (pKey->ReleaseTrigger) {              if (pKey->ReleaseTrigger) {
# Line 686  namespace LinuxSampler { namespace gig { Line 783  namespace LinuxSampler { namespace gig {
783                  }                  }
784                  pKey->ReleaseTrigger = false;                  pKey->ReleaseTrigger = false;
785              }              }
   
             // 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);  
786          }          }
787    
788            // if neither a voice was spawned or postponed on this key then remove note off event from key again
789            if (!pKey->Active && !pKey->VoiceTheftsQueued)
790                pKey->pEvents->free(itNoteOffEventOnKeyList);
791      }      }
792    
793      /**      /**
# Line 703  namespace LinuxSampler { namespace gig { Line 800  namespace LinuxSampler { namespace gig {
800       */       */
801      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {      void Engine::ProcessPitchbend(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent) {
802          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value          pEngineChannel->Pitch = itPitchbendEvent->Param.Pitch.Pitch; // store current pitch value
         itPitchbendEvent.moveToEndOf(pEngineChannel->pEvents);  
803      }      }
804    
805      /**      /**
# Line 775  namespace LinuxSampler { namespace gig { Line 871  namespace LinuxSampler { namespace gig {
871                      DimValues[i] = itNoteOnEvent->Param.Note.Velocity;                      DimValues[i] = itNoteOnEvent->Param.Note.Velocity;
872                      break;                      break;
873                  case ::gig::dimension_channelaftertouch:                  case ::gig::dimension_channelaftertouch:
874                      DimValues[i] = 0; //TODO: we currently ignore this dimension                      DimValues[i] = pEngineChannel->ControllerTable[128];
875                      break;                      break;
876                  case ::gig::dimension_releasetrigger:                  case ::gig::dimension_releasetrigger:
877                      VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal;                      VoiceType = (ReleaseTriggerVoice) ? Voice::type_release_trigger : (!iLayer) ? Voice::type_release_trigger_required : Voice::type_normal;
878                      DimValues[i] = (uint) ReleaseTriggerVoice;                      DimValues[i] = (uint) ReleaseTriggerVoice;
879                      break;                      break;
880                  case ::gig::dimension_keyboard:                  case ::gig::dimension_keyboard:
881                      DimValues[i] = (uint) pEngineChannel->CurrentKeyDimension;                      DimValues[i] = (uint) (pEngineChannel->CurrentKeyDimension * pRegion->pDimensionDefinitions[i].zones);
882                      break;                      break;
883                  case ::gig::dimension_roundrobin:                  case ::gig::dimension_roundrobin:
884                      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 1140  namespace LinuxSampler { namespace gig { Line 1236  namespace LinuxSampler { namespace gig {
1236          // update controller value in the engine channel's controller table          // update controller value in the engine channel's controller table
1237          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1238    
1239          // move event from the import event list to the engine channel's CC and pitchbend event list          switch (itControlChangeEvent->Param.CC.Controller) {
1240          Pool<Event>::Iterator itControlChangeEventOnCCList = itControlChangeEvent.moveToEndOf(pEngineChannel->pEvents);              case 5: { // portamento time
1241                    pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN;
1242          switch (itControlChangeEventOnCCList->Param.CC.Controller) {                  break;
1243                }
1244              case 7: { // volume              case 7: { // volume
1245                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1246                  pEngineChannel->GlobalVolume = (float) itControlChangeEventOnCCList->Param.CC.Value / 127.0f;                  pEngineChannel->MidiVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value];
1247                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag                  pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag
1248                  break;                  break;
1249              }              }
1250              case 10: { // panpot              case 10: { // panpot
1251                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1252                  const int pan = (int) itControlChangeEventOnCCList->Param.CC.Value - 64;                  pEngineChannel->GlobalPanLeft  = PanCurve[128 - itControlChangeEvent->Param.CC.Value];
1253                  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;  
1254                  break;                  break;
1255              }              }
1256              case 64: { // sustain              case 64: { // sustain
1257                  if (itControlChangeEventOnCCList->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) {
1258                      dmsg(4,("PEDAL DOWN\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n"));
1259                      pEngineChannel->SustainPedal = true;                      pEngineChannel->SustainPedal = true;
1260    
1261                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1173  namespace LinuxSampler { namespace gig { Line 1269  namespace LinuxSampler { namespace gig {
1269                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed) {
1270                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1271                              if (itNewEvent) {                              if (itNewEvent) {
1272                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1273                                  itNewEvent->Type = Event::type_cancel_release; // transform event type                                  itNewEvent->Type = Event::type_cancel_release; // transform event type
1274                              }                              }
1275                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
1276                          }                          }
1277                      }                      }
1278                  }                  }
1279                  if (itControlChangeEventOnCCList->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {                  if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) {
1280                      dmsg(4,("PEDAL UP\n"));                      dmsg(4,("DAMPER (RIGHT) PEDAL UP\n"));
1281                      pEngineChannel->SustainPedal = false;                      pEngineChannel->SustainPedal = false;
1282    
1283                      #if !CONFIG_PROCESS_MUTED_CHANNELS                      #if !CONFIG_PROCESS_MUTED_CHANNELS
# Line 1192  namespace LinuxSampler { namespace gig { Line 1288  namespace LinuxSampler { namespace gig {
1288                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();                      RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1289                      for (; iuiKey; ++iuiKey) {                      for (; iuiKey; ++iuiKey) {
1290                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];                          midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1291                          if (!pKey->KeyPressed) {                          if (!pKey->KeyPressed && ShouldReleaseVoice(pEngineChannel, *iuiKey)) {
1292                                RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1293                                if (itNewEvent) {
1294                                    *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1295                                    itNewEvent->Type = Event::type_release; // transform event type
1296                                }
1297                                else dmsg(1,("Event pool emtpy!\n"));
1298                            }
1299                        }
1300                    }
1301                    break;
1302                }
1303                case 65: { // portamento on / off
1304                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1305                    pEngineChannel->PortamentoMode = itControlChangeEvent->Param.CC.Value >= 64;
1306                    break;
1307                }
1308                case 66: { // sostenuto
1309                    if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) {
1310                        dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n"));
1311                        pEngineChannel->SostenutoPedal = true;
1312    
1313                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1314                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1315                        #endif
1316    
1317                        SostenutoKeyCount = 0;
1318                        // Remeber the pressed keys
1319                        RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
1320                        for (; iuiKey; ++iuiKey) {
1321                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
1322                            if (pKey->KeyPressed && SostenutoKeyCount < 128) SostenutoKeys[SostenutoKeyCount++] = *iuiKey;
1323                        }
1324                    }
1325                    if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SostenutoPedal) {
1326                        dmsg(4,("SOSTENUTO (CENTER) PEDAL UP\n"));
1327                        pEngineChannel->SostenutoPedal = false;
1328    
1329                        #if !CONFIG_PROCESS_MUTED_CHANNELS
1330                        if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted
1331                        #endif
1332    
1333                        // release voices if the damper pedal is up and their respective key is not pressed
1334                        for (int i = 0; i < SostenutoKeyCount; i++) {
1335                            midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[SostenutoKeys[i]];
1336                            if (!pKey->KeyPressed && !pEngineChannel->SustainPedal) {
1337                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();                              RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend();
1338                              if (itNewEvent) {                              if (itNewEvent) {
1339                                  *itNewEvent = *itControlChangeEventOnCCList; // copy event to the key's own event list                                  *itNewEvent = *itControlChangeEvent; // copy event to the key's own event list
1340                                  itNewEvent->Type = Event::type_release; // transform event type                                  itNewEvent->Type = Event::type_release; // transform event type
1341                              }                              }
1342                              else dmsg(1,("Event pool emtpy!\n"));                              else dmsg(1,("Event pool emtpy!\n"));
# Line 1209  namespace LinuxSampler { namespace gig { Line 1350  namespace LinuxSampler { namespace gig {
1350              // Channel Mode Messages              // Channel Mode Messages
1351    
1352              case 120: { // all sound off              case 120: { // all sound off
1353                  KillAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  KillAllVoices(pEngineChannel, itControlChangeEvent);
1354                  break;                  break;
1355              }              }
1356              case 121: { // reset all controllers              case 121: { // reset all controllers
# Line 1217  namespace LinuxSampler { namespace gig { Line 1358  namespace LinuxSampler { namespace gig {
1358                  break;                  break;
1359              }              }
1360              case 123: { // all notes off              case 123: { // all notes off
1361                  ReleaseAllVoices(pEngineChannel, itControlChangeEventOnCCList);                  #if CONFIG_PROCESS_ALL_NOTES_OFF
1362                    ReleaseAllVoices(pEngineChannel, itControlChangeEvent);
1363                    #endif // CONFIG_PROCESS_ALL_NOTES_OFF
1364                    break;
1365                }
1366                case 126: { // mono mode on
1367                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1368                    pEngineChannel->SoloMode = true;
1369                    break;
1370                }
1371                case 127: { // poly mode on
1372                    KillAllVoices(pEngineChannel, itControlChangeEvent);
1373                    pEngineChannel->SoloMode = false;
1374                  break;                  break;
1375              }              }
1376          }          }
# Line 1360  namespace LinuxSampler { namespace gig { Line 1513  namespace LinuxSampler { namespace gig {
1513          }          }
1514      }      }
1515    
1516        /**
1517         * Determines whether the specified voice should be released.
1518         *
1519         * @param pEngineChannel - The engine channel on which the voice should be checked
1520         * @param Key - The key number
1521         * @returns true if the specified should be released, false otherwise.
1522         */
1523        bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) {
1524            if (pEngineChannel->SustainPedal) return false;
1525    
1526            if (pEngineChannel->SostenutoPedal) {
1527                for (int i = 0; i < SostenutoKeyCount; i++)
1528                    if (Key == SostenutoKeys[i]) return false;
1529            }
1530    
1531            return true;
1532        }
1533    
1534      uint Engine::VoiceCount() {      uint Engine::VoiceCount() {
1535          return ActiveVoiceCount;          return ActiveVoiceCount;
1536      }      }
# Line 1397  namespace LinuxSampler { namespace gig { Line 1568  namespace LinuxSampler { namespace gig {
1568      }      }
1569    
1570      String Engine::Version() {      String Engine::Version() {
1571          String s = "$Revision: 1.52 $";          String s = "$Revision: 1.66 $";
1572          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
1573      }      }
1574    
1575        InstrumentManager* Engine::GetInstrumentManager() {
1576            return &instruments;
1577        }
1578    
1579        // static constant initializers
1580        const float* Engine::VolumeCurve(InitVolumeCurve());
1581        const float* Engine::PanCurve(InitPanCurve());
1582        const float* Engine::CrossfadeCurve(InitCrossfadeCurve());
1583    
1584        float* Engine::InitVolumeCurve() {
1585            // line-segment approximation
1586            const float segments[] = {
1587                0, 0, 2, 0.0046, 16, 0.016, 31, 0.051, 45, 0.115, 54.5, 0.2,
1588                64.5, 0.39, 74, 0.74, 92, 1.03, 114, 1.94, 119.2, 2.2, 127, 2.2
1589            };
1590            return InitCurve(segments);
1591        }
1592    
1593        float* Engine::InitPanCurve() {
1594            // line-segment approximation
1595            const float segments[] = {
1596                0, 0, 1, 0,
1597                2, 0.05, 31.5, 0.7, 51, 0.851, 74.5, 1.12,
1598                127, 1.41, 128, 1.41
1599            };
1600            return InitCurve(segments, 129);
1601        }
1602    
1603        float* Engine::InitCrossfadeCurve() {
1604            // line-segment approximation
1605            const float segments[] = {
1606                0, 0, 1, 0.03, 10, 0.1, 51, 0.58, 127, 1
1607            };
1608            return InitCurve(segments);
1609        }
1610    
1611        float* Engine::InitCurve(const float* segments, int size) {
1612            float* y = new float[size];
1613            for (int x = 0 ; x < size ; x++) {
1614                if (x > segments[2]) segments += 2;
1615                y[x] = segments[1] + (x - segments[0]) *
1616                    (segments[3] - segments[1]) / (segments[2] - segments[0]);
1617            }
1618            return y;
1619        }
1620    
1621  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.738  
changed lines
  Added in v.947

  ViewVC Help
Powered by ViewVC