/[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 1646 by persson, Sun Jan 20 15:04:51 2008 UTC revision 1722 by schoenebeck, Thu Apr 10 17:41:32 2008 UTC
# Line 857  namespace LinuxSampler { namespace gig { Line 857  namespace LinuxSampler { namespace gig {
857       *                         this audio fragment cycle       *                         this audio fragment cycle
858       */       */
859      void Engine::RouteAudio(EngineChannel* pEngineChannel, uint Samples) {      void Engine::RouteAudio(EngineChannel* pEngineChannel, uint Samples) {
860          // route master signal          // route dry signal
861          {          {
862              AudioChannel* pDstL = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelLeft);              AudioChannel* pDstL = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelLeft);
863              AudioChannel* pDstR = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelRight);              AudioChannel* pDstR = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelRight);
# Line 868  namespace LinuxSampler { namespace gig { Line 868  namespace LinuxSampler { namespace gig {
868          {          {
869              for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) {              for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) {
870                  FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend);                  FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend);
871                  // left channel                  for (int iChan = 0; iChan < 2; ++iChan) {
872                  const int iDstL = pFxSend->DestinationChannel(0);                      AudioChannel* pSource =
873                  if (iDstL < 0) {                          (iChan)
874                      dmsg(1,("Engine::RouteAudio() Error: invalid FX send (L) destination channel"));                              ? pEngineChannel->pChannelRight
875                  } else {                              : pEngineChannel->pChannelLeft;
876                      AudioChannel* pDstL = pAudioOutputDevice->Channel(iDstL);                      const int iDstChan = pFxSend->DestinationChannel(iChan);
877                      if (!pDstL) {                      if (iDstChan < 0) {
878                          dmsg(1,("Engine::RouteAudio() Error: invalid FX send (L) destination channel"));                          dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination channel (%d->%d)", ((iChan) ? "R" : "L"), iChan, iDstChan));
879                      } else pEngineChannel->pChannelLeft->MixTo(pDstL, Samples, pFxSend->Level());                          goto channel_cleanup;
880                  }                      }
881                  // right channel                      AudioChannel* pDstChan = NULL;
882                  const int iDstR = pFxSend->DestinationChannel(1);                      if (pFxSend->DestinationMasterEffectChain() >= 0) { // fx send routed to an internal master effect
883                  if (iDstR < 0) {                          EffectChain* pEffectChain =
884                      dmsg(1,("Engine::RouteAudio() Error: invalid FX send (R) destination channel"));                              pAudioOutputDevice->MasterEffectChain(
885                  } else {                                  pFxSend->DestinationMasterEffectChain()
886                      AudioChannel* pDstR = pAudioOutputDevice->Channel(iDstR);                              );
887                      if (!pDstR) {                          if (!pEffectChain) {
888                          dmsg(1,("Engine::RouteAudio() Error: invalid FX send (R) destination channel"));                              dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination effect chain %d", ((iChan) ? "R" : "L"), pFxSend->DestinationMasterEffectChain()));
889                      } else pEngineChannel->pChannelRight->MixTo(pDstR, Samples, pFxSend->Level());                              goto channel_cleanup;
890                            }
891                            Effect* pEffect =
892                                pEffectChain->GetEffect(
893                                    pFxSend->DestinationMasterEffect()
894                                );
895                            if (!pEffect) {
896                                dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination effect %d of effect chain %d", ((iChan) ? "R" : "L"), pFxSend->DestinationMasterEffect(), pFxSend->DestinationMasterEffectChain()));
897                                goto channel_cleanup;
898                            }
899                            pDstChan = pEffect->InputChannel(iDstChan);
900                        } else { // FX send routed directly to an audio output channel
901                            pDstChan = pAudioOutputDevice->Channel(iDstChan);
902                        }
903                        if (!pDstChan) {
904                            dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination channel (%d->%d)", ((iChan) ? "R" : "L"), iChan, iDstChan));
905                            goto channel_cleanup;
906                        }
907                        pSource->MixTo(pDstChan, Samples, pFxSend->Level());
908                  }                  }
909              }              }
910          }          }
911            channel_cleanup:
912          // reset buffers with silence (zero out) for the next audio cycle          // reset buffers with silence (zero out) for the next audio cycle
913          pEngineChannel->pChannelLeft->Clear();          pEngineChannel->pChannelLeft->Clear();
914          pEngineChannel->pChannelRight->Clear();          pEngineChannel->pChannelRight->Clear();
# Line 1618  namespace LinuxSampler { namespace gig { Line 1637  namespace LinuxSampler { namespace gig {
1637      void Engine::ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) {      void Engine::ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) {
1638          dmsg(4,("Engine::ContinuousController cc=%d v=%d\n", itControlChangeEvent->Param.CC.Controller, itControlChangeEvent->Param.CC.Value));          dmsg(4,("Engine::ContinuousController cc=%d v=%d\n", itControlChangeEvent->Param.CC.Controller, itControlChangeEvent->Param.CC.Value));
1639    
1640            // handle the "control triggered" MIDI rule: a control change
1641            // event can trigger a new note on or note off event
1642            if (pEngineChannel->pInstrument) {
1643    
1644                ::gig::MidiRule* rule;
1645                for (int i = 0 ; (rule = pEngineChannel->pInstrument->GetMidiRule(i)) ; i++) {
1646    
1647                    if (::gig::MidiRuleCtrlTrigger* ctrlTrigger =
1648                        dynamic_cast< ::gig::MidiRuleCtrlTrigger*>(rule)) {
1649                        if (itControlChangeEvent->Param.CC.Controller ==
1650                            ctrlTrigger->ControllerNumber) {
1651    
1652                            uint8_t oldCCValue = pEngineChannel->ControllerTable[
1653                                itControlChangeEvent->Param.CC.Controller];
1654                            uint8_t newCCValue = itControlChangeEvent->Param.CC.Value;
1655    
1656                            for (int i = 0 ; i < ctrlTrigger->Triggers ; i++) {
1657                                ::gig::MidiRuleCtrlTrigger::trigger_t* pTrigger =
1658                                      &ctrlTrigger->pTriggers[i];
1659    
1660                                // check if the controller has passed the
1661                                // trigger point in the right direction
1662                                if ((pTrigger->Descending &&
1663                                     oldCCValue > pTrigger->TriggerPoint &&
1664                                     newCCValue <= pTrigger->TriggerPoint) ||
1665                                    (!pTrigger->Descending &&
1666                                     oldCCValue < pTrigger->TriggerPoint &&
1667                                     newCCValue >= pTrigger->TriggerPoint)) {
1668    
1669                                    RTList<Event>::Iterator itNewEvent = pGlobalEvents->allocAppend();
1670                                    if (itNewEvent) {
1671                                        *itNewEvent = *itControlChangeEvent;
1672                                        itNewEvent->Param.Note.Key = pTrigger->Key;
1673    
1674                                        if (pTrigger->NoteOff || pTrigger->Velocity == 0) {
1675                                            itNewEvent->Type = Event::type_note_off;
1676                                            itNewEvent->Param.Note.Velocity = 100;
1677    
1678                                            ProcessNoteOff(pEngineChannel, itNewEvent);
1679                                        } else {
1680                                            itNewEvent->Type = Event::type_note_on;
1681                                            //TODO: if Velocity is 255, the triggered velocity should
1682                                            // depend on how fast the controller is moving
1683                                            itNewEvent->Param.Note.Velocity =
1684                                                pTrigger->Velocity == 255 ? 100 :
1685                                                pTrigger->Velocity;
1686    
1687                                            ProcessNoteOn(pEngineChannel, itNewEvent);
1688                                        }
1689                                    }
1690                                    else dmsg(1,("Event pool emtpy!\n"));
1691                                }
1692                            }
1693                        }
1694                    }
1695                }
1696            }
1697    
1698          // update controller value in the engine channel's controller table          // update controller value in the engine channel's controller table
1699          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1700    
# Line 1791  namespace LinuxSampler { namespace gig { Line 1868  namespace LinuxSampler { namespace gig {
1868          if (!pEngineChannel->fxSends.empty()) {          if (!pEngineChannel->fxSends.empty()) {
1869              for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) {              for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) {
1870                  FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend);                  FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend);
1871                  if (pFxSend->MidiController() == itControlChangeEvent->Param.CC.Controller)                  if (pFxSend->MidiController() == itControlChangeEvent->Param.CC.Controller) {
1872                      pFxSend->SetLevel(itControlChangeEvent->Param.CC.Value);                      pFxSend->SetLevel(itControlChangeEvent->Param.CC.Value);
1873                      pFxSend->SetInfoChanged(true);                      pFxSend->SetInfoChanged(true);
1874                    }
1875              }              }
1876          }          }
1877      }      }
# Line 1990  namespace LinuxSampler { namespace gig { Line 2068  namespace LinuxSampler { namespace gig {
2068      }      }
2069    
2070      String Engine::Version() {      String Engine::Version() {
2071          String s = "$Revision: 1.87 $";          String s = "$Revision: 1.90 $";
2072          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
2073      }      }
2074    

Legend:
Removed from v.1646  
changed lines
  Added in v.1722

  ViewVC Help
Powered by ViewVC