/[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 1555 by schoenebeck, Thu Dec 6 01:39:24 2007 UTC revision 1750 by schoenebeck, Thu Jul 10 15:00:38 2008 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
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-2007 Christian Schoenebeck                        *   *   Copyright (C) 2005-2008 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 74  namespace LinuxSampler { namespace gig { Line 74  namespace LinuxSampler { namespace gig {
74    
75      /**      /**
76       * Once an engine channel is disconnected from an audio output device,       * Once an engine channel is disconnected from an audio output device,
77       * it wil immediately call this method to unregister itself from the       * it will immediately call this method to unregister itself from the
78       * engine instance and if that engine instance is not used by any other       * engine instance and if that engine instance is not used by any other
79       * engine channel anymore, then that engine instance will be destroyed.       * engine channel anymore, then that engine instance will be destroyed.
80       *       *
# Line 108  namespace LinuxSampler { namespace gig { Line 108  namespace LinuxSampler { namespace gig {
108          pEventQueue        = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);          pEventQueue        = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0);
109          pEventPool         = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT);          pEventPool         = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT);
110          pVoicePool         = new Pool<Voice>(CONFIG_MAX_VOICES);          pVoicePool         = new Pool<Voice>(CONFIG_MAX_VOICES);
111          pDimRegionsInUse   = new ::gig::DimensionRegion*[CONFIG_MAX_VOICES + 1];          pDimRegionPool[0]  = new Pool< ::gig::DimensionRegion*>(CONFIG_MAX_VOICES);
112            pDimRegionPool[1]  = new Pool< ::gig::DimensionRegion*>(CONFIG_MAX_VOICES);
113          pVoiceStealingQueue = new RTList<Event>(pEventPool);          pVoiceStealingQueue = new RTList<Event>(pEventPool);
114          pGlobalEvents      = new RTList<Event>(pEventPool);          pGlobalEvents      = new RTList<Event>(pEventPool);
         InstrumentChangeQueue      = new RingBuffer<instrument_change_command_t,false>(1, 0);  
         InstrumentChangeReplyQueue = new RingBuffer<instrument_change_reply_t,false>(1, 0);  
115    
116          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()) {
117              iterVoice->SetEngine(this);              iterVoice->SetEngine(this);
# Line 145  namespace LinuxSampler { namespace gig { Line 144  namespace LinuxSampler { namespace gig {
144          if (pVoiceStealingQueue) delete pVoiceStealingQueue;          if (pVoiceStealingQueue) delete pVoiceStealingQueue;
145          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
146          if (pGlobalEvents) delete pGlobalEvents;          if (pGlobalEvents) delete pGlobalEvents;
147          if (InstrumentChangeQueue) delete InstrumentChangeQueue;          if (pDimRegionPool[0]) delete pDimRegionPool[0];
148          if (InstrumentChangeReplyQueue) delete InstrumentChangeReplyQueue;          if (pDimRegionPool[1]) delete pDimRegionPool[1];
         if (pDimRegionsInUse) delete[] pDimRegionsInUse;  
149          ResetSuspendedRegions();          ResetSuspendedRegions();
150          Unregister();          Unregister();
151      }      }
# Line 360  namespace LinuxSampler { namespace gig { Line 358  namespace LinuxSampler { namespace gig {
358          this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();          this->MaxSamplesPerCycle = pAudioOutputDevice->MaxSamplesPerCycle();
359          this->SampleRate         = pAudioOutputDevice->SampleRate();          this->SampleRate         = pAudioOutputDevice->SampleRate();
360    
361          // FIXME: audio drivers with varying fragment sizes might be a problem here          MinFadeOutSamples = int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1;
362          MaxFadeOutPos = MaxSamplesPerCycle - int(double(SampleRate) * CONFIG_EG_MIN_RELEASE_TIME) - 1;          if (MaxSamplesPerCycle < MinFadeOutSamples) {
         if (MaxFadeOutPos < 0) {  
363              std::cerr << "gig::Engine: WARNING, CONFIG_EG_MIN_RELEASE_TIME "              std::cerr << "gig::Engine: WARNING, CONFIG_EG_MIN_RELEASE_TIME "
364                        << "too big for current audio fragment size & sampling rate! "                        << "too big for current audio fragment size & sampling rate! "
365                        << "May lead to click sounds if voice stealing chimes in!\n" << std::flush;                        << "May lead to click sounds if voice stealing chimes in!\n" << std::flush;
366              // force volume ramp downs at the beginning of each fragment              // force volume ramp downs at the beginning of each fragment
367              MaxFadeOutPos = 0;              MinFadeOutSamples = MaxSamplesPerCycle;
368              // lower minimum release time              // lower minimum release time
369              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;              const float minReleaseTime = (float) MaxSamplesPerCycle / (float) SampleRate;
370              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()) {
# Line 460  namespace LinuxSampler { namespace gig { Line 457  namespace LinuxSampler { namespace gig {
457              // free request slot for next caller (and to make sure that              // free request slot for next caller (and to make sure that
458              // we're not going to process the same request in the next cycle)              // we're not going to process the same request in the next cycle)
459              pPendingRegionSuspension = NULL;              pPendingRegionSuspension = NULL;
460              // if no disk stream deletions are pending, awaker other side, as              // if no disk stream deletions are pending, awaken other side, as
461              // we're done in this case              // we're done in this case
462              if (!iPendingStreamDeletions) SuspensionChangeOngoing.Set(false);              if (!iPendingStreamDeletions) SuspensionChangeOngoing.Set(false);
463          }          }
# Line 613  namespace LinuxSampler { namespace gig { Line 610  namespace LinuxSampler { namespace gig {
610          ActiveVoiceCountTemp = 0;          ActiveVoiceCountTemp = 0;
611    
612          // handle instrument change commands          // handle instrument change commands
613          instrument_change_command_t command;          bool instrumentChanged = false;
614          if (InstrumentChangeQueue->pop(&command) > 0) {          for (int i = 0; i < engineChannels.size(); i++) {
615              EngineChannel* pEngineChannel = command.pEngineChannel;              EngineChannel* pEngineChannel = engineChannels[i];
             pEngineChannel->pInstrument = command.pInstrument;  
   
             //TODO: this is a lazy solution ATM and not safe in case somebody is currently editing the instrument we're currently switching to (we should store all suspended regions on instrument manager side and when switching to another instrument copy that list to the engine's local list of suspensions  
             ResetSuspendedRegions();  
616    
617              // iterate through all active voices and mark their              // as we're going to (carefully) write some status to the
618              // dimension regions as "in use". The instrument resource              // synchronized struct, we cast away the const
619              // manager may delete all of the instrument except the              EngineChannel::instrument_change_command_t& cmd =
620              // dimension regions and samples that are in use.                  const_cast<EngineChannel::instrument_change_command_t&>(pEngineChannel->InstrumentChangeCommandReader.Lock());
621              int i = 0;  
622              RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();              pEngineChannel->pDimRegionsInUse = cmd.pDimRegionsInUse;
623              RTList<uint>::Iterator end    = pEngineChannel->pActiveKeys->end();              pEngineChannel->pDimRegionsInUse->clear();
624              while (iuiKey != end) { // iterate through all active keys  
625                  midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];              if (cmd.bChangeInstrument) {
626                  ++iuiKey;                  // change instrument
627                    dmsg(5,("Engine: instrument change command received\n"));
628                    cmd.bChangeInstrument = false;
629                    pEngineChannel->pInstrument = cmd.pInstrument;
630                    instrumentChanged = true;
631    
632                    // Iterate through all active voices and mark them as
633                    // "orphans", which means that the dimension regions
634                    // and samples they use should be released to the
635                    // instrument resource manager when the voices die.
636                    int i = 0;
637                    RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first();
638                    RTList<uint>::Iterator end    = pEngineChannel->pActiveKeys->end();
639                    while (iuiKey != end) { // iterate through all active keys
640                        midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey];
641                        ++iuiKey;
642    
643                  RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();                      RTList<Voice>::Iterator itVoice     = pKey->pActiveVoices->first();
644                  RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();                      RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end();
645                  for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key                      for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
                     if (!itVoice->Orphan) {  
646                          itVoice->Orphan = true;                          itVoice->Orphan = true;
                         pDimRegionsInUse[i++] = itVoice->pDimRgn;  
647                      }                      }
648                  }                  }
649              }              }
650              pDimRegionsInUse[i] = 0; // end of list          }
651            if (instrumentChanged) {
652              // send a reply to the calling thread, which is waiting              //TODO: this is a lazy solution ATM and not safe in case somebody is currently editing the instrument we're currently switching to (we should store all suspended regions on instrument manager side and when switching to another instrument copy that list to the engine's local list of suspensions
653              instrument_change_reply_t reply;              ResetSuspendedRegions();
             InstrumentChangeReplyQueue->push(&reply);  
654          }          }
655    
656          // handle events on all engine channels          // handle events on all engine channels
# Line 688  namespace LinuxSampler { namespace gig { Line 693  namespace LinuxSampler { namespace gig {
693          // been deleted by the disk thread          // been deleted by the disk thread
694          if (iPendingStreamDeletions) ProcessPendingStreamDeletions();          if (iPendingStreamDeletions) ProcessPendingStreamDeletions();
695    
696            for (int i = 0; i < engineChannels.size(); i++) {
697                engineChannels[i]->InstrumentChangeCommandReader.Unlock();
698            }
699          FrameTime += Samples;          FrameTime += Samples;
700    
701          return 0;          return 0;
# Line 769  namespace LinuxSampler { namespace gig { Line 777  namespace LinuxSampler { namespace gig {
777                  // now render current voice                  // now render current voice
778                  itVoice->Render(Samples);                  itVoice->Render(Samples);
779                  if (itVoice->IsActive()) { // still active                  if (itVoice->IsActive()) { // still active
780                        if (!itVoice->Orphan) {
781                            *(pEngineChannel->pDimRegionsInUse->allocAppend()) = itVoice->pDimRgn;
782                        }
783                      ActiveVoiceCountTemp++;                      ActiveVoiceCountTemp++;
784                      voiceCount++;                      voiceCount++;
785    
# Line 809  namespace LinuxSampler { namespace gig { Line 820  namespace LinuxSampler { namespace gig {
820              if (itNewVoice) {              if (itNewVoice) {
821                  itNewVoice->Render(Samples);                  itNewVoice->Render(Samples);
822                  if (itNewVoice->IsActive()) { // still active                  if (itNewVoice->IsActive()) { // still active
823                        *(pEngineChannel->pDimRegionsInUse->allocAppend()) = itNewVoice->pDimRgn;
824                      ActiveVoiceCountTemp++;                      ActiveVoiceCountTemp++;
825                      pEngineChannel->SetVoiceCount(pEngineChannel->GetVoiceCount() + 1);                      pEngineChannel->SetVoiceCount(pEngineChannel->GetVoiceCount() + 1);
826    
# Line 844  namespace LinuxSampler { namespace gig { Line 856  namespace LinuxSampler { namespace gig {
856       *                         this audio fragment cycle       *                         this audio fragment cycle
857       */       */
858      void Engine::RouteAudio(EngineChannel* pEngineChannel, uint Samples) {      void Engine::RouteAudio(EngineChannel* pEngineChannel, uint Samples) {
859          // route master signal          // route dry signal
860          {          {
861              AudioChannel* pDstL = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelLeft);              AudioChannel* pDstL = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelLeft);
862              AudioChannel* pDstR = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelRight);              AudioChannel* pDstR = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelRight);
# Line 855  namespace LinuxSampler { namespace gig { Line 867  namespace LinuxSampler { namespace gig {
867          {          {
868              for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) {              for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) {
869                  FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend);                  FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend);
870                  // left channel                  for (int iChan = 0; iChan < 2; ++iChan) {
871                  const int iDstL = pFxSend->DestinationChannel(0);                      AudioChannel* pSource =
872                  if (iDstL < 0) {                          (iChan)
873                      dmsg(1,("Engine::RouteAudio() Error: invalid FX send (L) destination channel"));                              ? pEngineChannel->pChannelRight
874                  } else {                              : pEngineChannel->pChannelLeft;
875                      AudioChannel* pDstL = pAudioOutputDevice->Channel(iDstL);                      const int iDstChan = pFxSend->DestinationChannel(iChan);
876                      if (!pDstL) {                      if (iDstChan < 0) {
877                          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));
878                      } else pEngineChannel->pChannelLeft->MixTo(pDstL, Samples, pFxSend->Level());                          goto channel_cleanup;
879                  }                      }
880                  // right channel                      AudioChannel* pDstChan = NULL;
881                  const int iDstR = pFxSend->DestinationChannel(1);                      if (pFxSend->DestinationMasterEffectChain() >= 0) { // fx send routed to an internal master effect
882                  if (iDstR < 0) {                          EffectChain* pEffectChain =
883                      dmsg(1,("Engine::RouteAudio() Error: invalid FX send (R) destination channel"));                              pAudioOutputDevice->MasterEffectChain(
884                  } else {                                  pFxSend->DestinationMasterEffectChain()
885                      AudioChannel* pDstR = pAudioOutputDevice->Channel(iDstR);                              );
886                      if (!pDstR) {                          if (!pEffectChain) {
887                          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()));
888                      } else pEngineChannel->pChannelRight->MixTo(pDstR, Samples, pFxSend->Level());                              goto channel_cleanup;
889                            }
890                            Effect* pEffect =
891                                pEffectChain->GetEffect(
892                                    pFxSend->DestinationMasterEffect()
893                                );
894                            if (!pEffect) {
895                                dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination effect %d of effect chain %d", ((iChan) ? "R" : "L"), pFxSend->DestinationMasterEffect(), pFxSend->DestinationMasterEffectChain()));
896                                goto channel_cleanup;
897                            }
898                            pDstChan = pEffect->InputChannel(iDstChan);
899                        } else { // FX send routed directly to an audio output channel
900                            pDstChan = pAudioOutputDevice->Channel(iDstChan);
901                        }
902                        if (!pDstChan) {
903                            dmsg(1,("Engine::RouteAudio() Error: invalid FX send (%s) destination channel (%d->%d)", ((iChan) ? "R" : "L"), iChan, iDstChan));
904                            goto channel_cleanup;
905                        }
906                        pSource->MixTo(pDstChan, Samples, pFxSend->Level());
907                  }                  }
908              }              }
909          }          }
910            channel_cleanup:
911          // reset buffers with silence (zero out) for the next audio cycle          // reset buffers with silence (zero out) for the next audio cycle
912          pEngineChannel->pChannelLeft->Clear();          pEngineChannel->pChannelLeft->Clear();
913          pEngineChannel->pChannelRight->Clear();          pEngineChannel->pChannelRight->Clear();
# Line 1605  namespace LinuxSampler { namespace gig { Line 1636  namespace LinuxSampler { namespace gig {
1636      void Engine::ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) {      void Engine::ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) {
1637          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));
1638    
1639            // handle the "control triggered" MIDI rule: a control change
1640            // event can trigger a new note on or note off event
1641            if (pEngineChannel->pInstrument) {
1642    
1643                ::gig::MidiRule* rule;
1644                for (int i = 0 ; (rule = pEngineChannel->pInstrument->GetMidiRule(i)) ; i++) {
1645    
1646                    if (::gig::MidiRuleCtrlTrigger* ctrlTrigger =
1647                        dynamic_cast< ::gig::MidiRuleCtrlTrigger*>(rule)) {
1648                        if (itControlChangeEvent->Param.CC.Controller ==
1649                            ctrlTrigger->ControllerNumber) {
1650    
1651                            uint8_t oldCCValue = pEngineChannel->ControllerTable[
1652                                itControlChangeEvent->Param.CC.Controller];
1653                            uint8_t newCCValue = itControlChangeEvent->Param.CC.Value;
1654    
1655                            for (int i = 0 ; i < ctrlTrigger->Triggers ; i++) {
1656                                ::gig::MidiRuleCtrlTrigger::trigger_t* pTrigger =
1657                                      &ctrlTrigger->pTriggers[i];
1658    
1659                                // check if the controller has passed the
1660                                // trigger point in the right direction
1661                                if ((pTrigger->Descending &&
1662                                     oldCCValue > pTrigger->TriggerPoint &&
1663                                     newCCValue <= pTrigger->TriggerPoint) ||
1664                                    (!pTrigger->Descending &&
1665                                     oldCCValue < pTrigger->TriggerPoint &&
1666                                     newCCValue >= pTrigger->TriggerPoint)) {
1667    
1668                                    RTList<Event>::Iterator itNewEvent = pGlobalEvents->allocAppend();
1669                                    if (itNewEvent) {
1670                                        *itNewEvent = *itControlChangeEvent;
1671                                        itNewEvent->Param.Note.Key = pTrigger->Key;
1672    
1673                                        if (pTrigger->NoteOff || pTrigger->Velocity == 0) {
1674                                            itNewEvent->Type = Event::type_note_off;
1675                                            itNewEvent->Param.Note.Velocity = 100;
1676    
1677                                            ProcessNoteOff(pEngineChannel, itNewEvent);
1678                                        } else {
1679                                            itNewEvent->Type = Event::type_note_on;
1680                                            //TODO: if Velocity is 255, the triggered velocity should
1681                                            // depend on how fast the controller is moving
1682                                            itNewEvent->Param.Note.Velocity =
1683                                                pTrigger->Velocity == 255 ? 100 :
1684                                                pTrigger->Velocity;
1685    
1686                                            ProcessNoteOn(pEngineChannel, itNewEvent);
1687                                        }
1688                                    }
1689                                    else dmsg(1,("Event pool emtpy!\n"));
1690                                }
1691                            }
1692                        }
1693                    }
1694                }
1695            }
1696    
1697          // update controller value in the engine channel's controller table          // update controller value in the engine channel's controller table
1698          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;          pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value;
1699    
# Line 1638  namespace LinuxSampler { namespace gig { Line 1727  namespace LinuxSampler { namespace gig {
1727                  //TODO: not sample accurate yet                  //TODO: not sample accurate yet
1728                  pEngineChannel->GlobalPanLeft  = PanCurve[128 - itControlChangeEvent->Param.CC.Value];                  pEngineChannel->GlobalPanLeft  = PanCurve[128 - itControlChangeEvent->Param.CC.Value];
1729                  pEngineChannel->GlobalPanRight = PanCurve[itControlChangeEvent->Param.CC.Value];                  pEngineChannel->GlobalPanRight = PanCurve[itControlChangeEvent->Param.CC.Value];
1730                    pEngineChannel->iLastPanRequest = itControlChangeEvent->Param.CC.Value;
1731                  break;                  break;
1732              }              }
1733              case 64: { // sustain              case 64: { // sustain
# Line 1778  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 1799  namespace LinuxSampler { namespace gig { Line 1890  namespace LinuxSampler { namespace gig {
1890          if (exclusive_status != 0xF0)       goto free_sysex_data;          if (exclusive_status != 0xF0)       goto free_sysex_data;
1891    
1892          switch (id) {          switch (id) {
1893                case 0x7f: { // (Realtime) Universal Sysex (GM Standard)
1894                    uint8_t sysex_channel, sub_id1, sub_id2, val_msb, val_lsb;;
1895                    if (!reader.pop(&sysex_channel)) goto free_sysex_data;
1896                    if (!reader.pop(&sub_id1)) goto free_sysex_data;
1897                    if (!reader.pop(&sub_id2)) goto free_sysex_data;
1898                    if (!reader.pop(&val_lsb)) goto free_sysex_data;
1899                    if (!reader.pop(&val_msb)) goto free_sysex_data;
1900                    //TODO: for now we simply ignore the sysex channel, seldom used anyway
1901                    switch (sub_id1) {
1902                        case 0x04: // Device Control
1903                            switch (sub_id2) {
1904                                case 0x01: // Master Volume
1905                                    GLOBAL_VOLUME =
1906                                        double((uint(val_msb)<<7) | uint(val_lsb)) / 16383.0;
1907                                    break;
1908                            }
1909                            break;
1910                    }
1911                    break;
1912                }
1913              case 0x41: { // Roland              case 0x41: { // Roland
1914                  dmsg(3,("Roland Sysex\n"));                  dmsg(3,("Roland Sysex\n"));
1915                  uint8_t device_id, model_id, cmd_id;                  uint8_t device_id, model_id, cmd_id;
# Line 1835  namespace LinuxSampler { namespace gig { Line 1946  namespace LinuxSampler { namespace gig {
1946                              dmsg(3,("\t\t\tNew scale applied.\n"));                              dmsg(3,("\t\t\tNew scale applied.\n"));
1947                              break;                              break;
1948                          }                          }
1949                            case 0x15: { // chromatic / drumkit mode
1950                                dmsg(3,("\t\tMIDI Instrument Map Switch\n"));
1951                                uint8_t part = addr[1] & 0x0f;
1952                                uint8_t map;
1953                                if (!reader.pop(&map)) goto free_sysex_data;
1954                                for (int i = 0; i < engineChannels.size(); ++i) {
1955                                    EngineChannel* pEngineChannel = engineChannels[i];
1956                                    if (pEngineChannel->midiChannel == part ||
1957                                        pEngineChannel->midiChannel == midi_chan_all
1958                                    ) {
1959                                        try {
1960                                            pEngineChannel->SetMidiInstrumentMap(map);
1961                                        } catch (Exception e) {
1962                                            dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str()));
1963                                            goto free_sysex_data;
1964                                        } catch (...) {
1965                                            dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part));
1966                                            goto free_sysex_data;
1967                                        }
1968                                    }
1969                                }
1970                                dmsg(3,("\t\t\tApplied MIDI instrument map %d to part %d.\n", map, part));
1971                                break;
1972                            }
1973                      }                      }
1974                  }                  }
1975                  else if (addr[0] == 0x40 && (addr[1] & 0xf0) == 0x20) { // Part Parameters (2)                  else if (addr[0] == 0x40 && (addr[1] & 0xf0) == 0x20) { // Part Parameters (2)
# Line 1977  namespace LinuxSampler { namespace gig { Line 2112  namespace LinuxSampler { namespace gig {
2112      }      }
2113    
2114      String Engine::Version() {      String Engine::Version() {
2115          String s = "$Revision: 1.85 $";          String s = "$Revision: 1.94 $";
2116          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
2117      }      }
2118    
# Line 1986  namespace LinuxSampler { namespace gig { Line 2121  namespace LinuxSampler { namespace gig {
2121      }      }
2122    
2123      // static constant initializers      // static constant initializers
2124      const float* Engine::VolumeCurve(InitVolumeCurve());      const Engine::FloatTable Engine::VolumeCurve(InitVolumeCurve());
2125      const float* Engine::PanCurve(InitPanCurve());      const Engine::FloatTable Engine::PanCurve(InitPanCurve());
2126      const float* Engine::CrossfadeCurve(InitCrossfadeCurve());      const Engine::FloatTable Engine::CrossfadeCurve(InitCrossfadeCurve());
2127    
2128      float* Engine::InitVolumeCurve() {      float* Engine::InitVolumeCurve() {
2129          // line-segment approximation          // line-segment approximation
# Line 2027  namespace LinuxSampler { namespace gig { Line 2162  namespace LinuxSampler { namespace gig {
2162          return y;          return y;
2163      }      }
2164    
     /**  
      * Changes the instrument for an engine channel.  
      *  
      * @param pEngineChannel - engine channel on which the instrument  
      *                         should be changed  
      * @param pInstrument - new instrument  
      * @returns a list of dimension regions from the old instrument  
      *          that are still in use  
      */  
     ::gig::DimensionRegion** Engine::ChangeInstrument(EngineChannel* pEngineChannel, ::gig::Instrument* pInstrument) {  
         instrument_change_command_t command;  
         command.pEngineChannel = pEngineChannel;  
         command.pInstrument = pInstrument;  
         InstrumentChangeQueue->push(&command);  
   
         // wait for the audio thread to confirm that the instrument  
         // change has been done  
         instrument_change_reply_t reply;  
         while (InstrumentChangeReplyQueue->pop(&reply) == 0) {  
             usleep(10000);  
         }  
         return pDimRegionsInUse;  
     }  
   
2165  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.1555  
changed lines
  Added in v.1750

  ViewVC Help
Powered by ViewVC