/[svn]/linuxsampler/trunk/src/engines/AbstractEngine.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/AbstractEngine.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2137 by schoenebeck, Mon Oct 4 12:20:23 2010 UTC revision 2611 by schoenebeck, Mon Jun 9 19:20:37 2014 UTC
# Line 4  Line 4 
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-2008 Christian Schoenebeck                         *   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *
7   *   Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev        *   *   Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev        *
8     *   Copyright (C) 2013-2014 Christian Schoenebeck and Andreas Persson     *
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   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 26  Line 27 
27  #include "AbstractEngineChannel.h"  #include "AbstractEngineChannel.h"
28  #include "EngineFactory.h"  #include "EngineFactory.h"
29  #include "../common/global_private.h"  #include "../common/global_private.h"
30    #include "../effects/EffectFactory.h"
31    
32  namespace LinuxSampler {  namespace LinuxSampler {
33    
# Line 59  namespace LinuxSampler { Line 61  namespace LinuxSampler {
61          } else { // create a new engine (and disk thread) instance for the given audio output device          } else { // create a new engine (and disk thread) instance for the given audio output device
62              dmsg(4,("Creating new Engine.\n"));              dmsg(4,("Creating new Engine.\n"));
63              pEngine = (AbstractEngine*) EngineFactory::Create(pChannel->EngineName());              pEngine = (AbstractEngine*) EngineFactory::Create(pChannel->EngineName());
64                pEngine->CreateInstrumentScriptVM();
65              pEngine->Connect(pDevice);              pEngine->Connect(pDevice);
66              engines[pChannel->GetEngineFormat()][pDevice] = pEngine;              engines[pChannel->GetEngineFormat()][pDevice] = pEngine;
67          }          }
# Line 80  namespace LinuxSampler { Line 83  namespace LinuxSampler {
83          FrameTime          = 0;          FrameTime          = 0;
84          RandomSeed         = 0;          RandomSeed         = 0;
85          pDedicatedVoiceChannelLeft = pDedicatedVoiceChannelRight = NULL;          pDedicatedVoiceChannelLeft = pDedicatedVoiceChannelRight = NULL;
86            pScriptVM          = NULL;
87      }      }
88    
89      AbstractEngine::~AbstractEngine() {      AbstractEngine::~AbstractEngine() {
# Line 90  namespace LinuxSampler { Line 94  namespace LinuxSampler {
94          if (pSysexBuffer) delete pSysexBuffer;          if (pSysexBuffer) delete pSysexBuffer;
95          if (pDedicatedVoiceChannelLeft) delete pDedicatedVoiceChannelLeft;          if (pDedicatedVoiceChannelLeft) delete pDedicatedVoiceChannelLeft;
96          if (pDedicatedVoiceChannelRight) delete pDedicatedVoiceChannelRight;          if (pDedicatedVoiceChannelRight) delete pDedicatedVoiceChannelRight;
97            if (pScriptVM) delete pScriptVM;
98          Unregister();          Unregister();
99      }      }
100    
101        void AbstractEngine::CreateInstrumentScriptVM() {
102            dmsg(2,("Created sampler format independent instrument script VM.\n"));
103            if (pScriptVM) return;
104            pScriptVM = new InstrumentScriptVM; // format independent script runner
105        }
106    
107      /**      /**
108       * Once an engine channel is disconnected from an audio output device,       * Once an engine channel is disconnected from an audio output device,
109       * it will immediately call this method to unregister itself from the       * it will immediately call this method to unregister itself from the
# Line 164  namespace LinuxSampler { Line 175  namespace LinuxSampler {
175       */       */
176      void AbstractEngine::ResetScaleTuning() {      void AbstractEngine::ResetScaleTuning() {
177          memset(&ScaleTuning[0], 0x00, 12);          memset(&ScaleTuning[0], 0x00, 12);
178            ScaleTuningChanged.raise();
179      }      }
180    
181      /**      /**
# Line 307  namespace LinuxSampler { Line 319  namespace LinuxSampler {
319              AudioChannel* pDstChan = NULL;              AudioChannel* pDstChan = NULL;
320              if (pFxSend->DestinationEffectChain() >= 0) { // fx send routed to an internal send effect              if (pFxSend->DestinationEffectChain() >= 0) { // fx send routed to an internal send effect
321                  EffectChain* pEffectChain =                  EffectChain* pEffectChain =
322                      pAudioOutputDevice->SendEffectChain(                      pAudioOutputDevice->SendEffectChainByID(
323                          pFxSend->DestinationEffectChain()                          pFxSend->DestinationEffectChain()
324                      );                      );
325                  if (!pEffectChain) {                  if (!pEffectChain) {
# Line 345  namespace LinuxSampler { Line 357  namespace LinuxSampler {
357       */       */
358      uint8_t AbstractEngine::GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize) {      uint8_t AbstractEngine::GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize) {
359          RingBuffer<uint8_t,false>::NonVolatileReader reader = AddrReader;          RingBuffer<uint8_t,false>::NonVolatileReader reader = AddrReader;
360          uint bytes = 3 /*addr*/ + DataSize;          uint bytes = 3 /*addr*/ + DataSize;        
         uint8_t addr_and_data[bytes];  
         reader.read(&addr_and_data[0], bytes);  
361          uint8_t sum = 0;          uint8_t sum = 0;
362          for (uint i = 0; i < bytes; i++) sum += addr_and_data[i];          uint8_t c;
363            for (uint i = 0; i < bytes; ++i) {
364                if (!reader.pop(&c)) break;
365                sum += c;
366            }
367          return 128 - sum % 128;          return 128 - sum % 128;
368      }      }
369    
# Line 358  namespace LinuxSampler { Line 372  namespace LinuxSampler {
372       *       *
373       * @param ScaleTunes - detuning of all twelve semitones (in cents)       * @param ScaleTunes - detuning of all twelve semitones (in cents)
374       */       */
375      void AbstractEngine::AdjustScale(int8_t ScaleTunes[12]) {      void AbstractEngine::AdjustScaleTuning(const int8_t ScaleTunes[12]) {
376          memcpy(&this->ScaleTuning[0], &ScaleTunes[0], 12); //TODO: currently not sample accurate          memcpy(&this->ScaleTuning[0], &ScaleTunes[0], 12);
377            ScaleTuningChanged.raise();
378        }
379        
380        void AbstractEngine::GetScaleTuning(int8_t* pScaleTunes) {
381            memcpy(pScaleTunes, &this->ScaleTuning[0], 12);
382      }      }
383    
384      uint AbstractEngine::VoiceCount() {      uint AbstractEngine::VoiceCount() {
# Line 375  namespace LinuxSampler { Line 394  namespace LinuxSampler {
394      }      }
395    
396      /**      /**
397       *  Moves pitchbend event from the general (input) event list to the engine       *  Stores the latest pitchbend event as current pitchbend scalar value.
      *  channel's event list. It will actually processed later by the  
      *  respective voice.  
398       *       *
399       *  @param pEngineChannel - engine channel on which this event occured on       *  @param pEngineChannel - engine channel on which this event occured on
400       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event       *  @param itPitchbendEvent - absolute pitch value and time stamp of the event
# Line 414  namespace LinuxSampler { Line 431  namespace LinuxSampler {
431          Event event             = pEventGenerator->CreateEvent();          Event event             = pEventGenerator->CreateEvent();
432          event.Type              = Event::type_sysex;          event.Type              = Event::type_sysex;
433          event.Param.Sysex.Size  = Size;          event.Param.Sysex.Size  = Size;
434            memset(&event.Format, 0, sizeof(event.Format)); // init format speific stuff with zeroes
435          event.pEngineChannel    = NULL; // as Engine global event          event.pEngineChannel    = NULL; // as Engine global event
436          event.pMidiInputPort    = pSender;          event.pMidiInputPort    = pSender;
437          if (pEventQueue->write_space() > 0) {          if (pEventQueue->write_space() > 0) {
# Line 506  namespace LinuxSampler { Line 524  namespace LinuxSampler {
524                          for (int i = 0; i < engineChannels.size(); ++i) {                          for (int i = 0; i < engineChannels.size(); ++i) {
525                              AbstractEngineChannel* pEngineChannel                              AbstractEngineChannel* pEngineChannel
526                                  = static_cast<AbstractEngineChannel*>(engineChannels[i]);                                  = static_cast<AbstractEngineChannel*>(engineChannels[i]);
527                              if (pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort) {                              Sync< ArrayList<MidiInputPort*> > midiInputs = pEngineChannel->midiInputs.front();
528                                  KillAllVoices(pEngineChannel, itSysexEvent);                              for (int k = 0; k < midiInputs->size(); ++k) {
529                                  pEngineChannel->ResetControllers();                                  if ((*midiInputs)[k] == itSysexEvent->pMidiInputPort) {
530                                        KillAllVoices(pEngineChannel, itSysexEvent);
531                                        pEngineChannel->ResetControllers();
532                                        break;
533                                    }
534                              }                              }
535                          }                          }
536                      }                      }
# Line 529  namespace LinuxSampler { Line 551  namespace LinuxSampler {
551                              if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data;                              if (GSCheckSum(checksum_reader, 12)) goto free_sysex_data;
552                              #endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM                              #endif // CONFIG_ASSERT_GS_SYSEX_CHECKSUM
553                              for (int i = 0; i < 12; i++) scale_tunes[i] -= 64;                              for (int i = 0; i < 12; i++) scale_tunes[i] -= 64;
554                              AdjustScale((int8_t*) scale_tunes);                              AdjustScaleTuning((int8_t*) scale_tunes);
555                              dmsg(3,("\t\t\tNew scale applied.\n"));                              dmsg(3,("\t\t\tNew scale applied.\n"));
556                              break;                              break;
557                          }                          }
# Line 541  namespace LinuxSampler { Line 563  namespace LinuxSampler {
563                              for (int i = 0; i < engineChannels.size(); ++i) {                              for (int i = 0; i < engineChannels.size(); ++i) {
564                                  AbstractEngineChannel* pEngineChannel                                  AbstractEngineChannel* pEngineChannel
565                                      = static_cast<AbstractEngineChannel*>(engineChannels[i]);                                      = static_cast<AbstractEngineChannel*>(engineChannels[i]);
566                                  if (                                  if (pEngineChannel->midiChannel == part ||
567                                      (pEngineChannel->midiChannel == part ||                                      pEngineChannel->midiChannel == midi_chan_all)
568                                       pEngineChannel->midiChannel == midi_chan_all) &&                                  {  
569                                       pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort                                      Sync< ArrayList<MidiInputPort*> > midiInputs = pEngineChannel->midiInputs.front();
570                                  ) {                                      for (int k = 0; k < midiInputs->size(); ++k) {
571                                      try {                                          if ((*midiInputs)[k] == itSysexEvent->pMidiInputPort) {
572                                          pEngineChannel->SetMidiInstrumentMap(map);                                              try {
573                                      } catch (Exception e) {                                                  pEngineChannel->SetMidiInstrumentMap(map);
574                                          dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str()));                                              } catch (Exception e) {
575                                          goto free_sysex_data;                                                  dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d: %s\n", map, part, e.Message().c_str()));
576                                      } catch (...) {                                                  goto free_sysex_data;
577                                          dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part));                                              } catch (...) {
578                                          goto free_sysex_data;                                                  dmsg(2,("\t\t\tCould not apply MIDI instrument map %d to part %d (unknown exception)\n", map, part));
579                                                    goto free_sysex_data;
580                                                }
581                                                break;
582                                            }
583                                      }                                      }
584                                  }                                  }
585                              }                              }

Legend:
Removed from v.2137  
changed lines
  Added in v.2611

  ViewVC Help
Powered by ViewVC