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

Diff of /linuxsampler/trunk/src/engines/gig/EngineChannel.cpp

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

revision 1001 by schoenebeck, Wed Dec 27 16:17:08 2006 UTC revision 1040 by schoenebeck, Wed Feb 7 15:41:31 2007 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, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 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 163  namespace LinuxSampler { namespace gig { Line 163  namespace LinuxSampler { namespace gig {
163       * @see PrepareLoadInstrument()       * @see PrepareLoadInstrument()
164       */       */
165      void EngineChannel::LoadInstrument() {      void EngineChannel::LoadInstrument() {
166            ::gig::Instrument* oldInstrument = pInstrument;
         if (pEngine) pEngine->DisableAndLock();  
   
         ResetInternal();  
167    
168          // free old instrument          // free old instrument
169          if (pInstrument) {          if (oldInstrument) {
170              // give old instrument back to instrument manager              if (pEngine) {
171              Engine::instruments.HandBack(pInstrument, this);                  // make sure we don't trigger any new notes with the
172                    // old instrument
173                    ::gig::DimensionRegion** dimRegionsInUse = pEngine->ChangeInstrument(this, 0);
174    
175                    // give old instrument back to instrument manager, but
176                    // keep the dimension regions and samples that are in
177                    // use
178                    Engine::instruments.HandBackInstrument(oldInstrument, this, dimRegionsInUse);
179                } else {
180                    Engine::instruments.HandBack(oldInstrument, this);
181                }
182          }          }
183    
184          // delete all key groups          // delete all key groups
185          ActiveKeyGroups.clear();          ActiveKeyGroups.clear();
186    
187          // request gig instrument from instrument manager          // request gig instrument from instrument manager
188            ::gig::Instrument* newInstrument;
189          try {          try {
190              InstrumentManager::instrument_id_t instrid;              InstrumentManager::instrument_id_t instrid;
191              instrid.FileName  = InstrumentFile;              instrid.FileName  = InstrumentFile;
192              instrid.Index     = InstrumentIdx;              instrid.Index     = InstrumentIdx;
193              pInstrument = Engine::instruments.Borrow(instrid, this);              newInstrument = Engine::instruments.Borrow(instrid, this);
194              if (!pInstrument) {              if (!newInstrument) {
195                  InstrumentStat = -1;                  throw InstrumentResourceManagerException("resource was not created");
                 dmsg(1,("no instrument loaded!!!\n"));  
                 exit(EXIT_FAILURE);  
196              }              }
197          }          }
198          catch (RIFF::Exception e) {          catch (RIFF::Exception e) {
# Line 205  namespace LinuxSampler { namespace gig { Line 211  namespace LinuxSampler { namespace gig {
211          }          }
212    
213          // rebuild ActiveKeyGroups map with key groups of current instrument          // rebuild ActiveKeyGroups map with key groups of current instrument
214          for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion())          for (::gig::Region* pRegion = newInstrument->GetFirstRegion(); pRegion; pRegion = newInstrument->GetNextRegion())
215              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;              if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL;
216    
217          InstrumentIdxName = pInstrument->pInfo->Name;          InstrumentIdxName = newInstrument->pInfo->Name;
218          InstrumentStat = 100;          InstrumentStat = 100;
219    
220          // inform audio driver for the need of two channels          if (pEngine) pEngine->ChangeInstrument(this, newInstrument);
221          try {          else pInstrument = newInstrument;
             if (pEngine && pEngine->pAudioOutputDevice)  
                 pEngine->pAudioOutputDevice->AcquireChannels(2); // gig Engine only stereo  
         }  
         catch (AudioOutputException e) {  
             String msg = "Audio output device unable to provide 2 audio channels, cause: " + e.Message();  
             throw Exception(msg);  
         }  
   
         if (pEngine) pEngine->Enable();  
222      }      }
223    
224      /**      /**
# Line 282  namespace LinuxSampler { namespace gig { Line 279  namespace LinuxSampler { namespace gig {
279              pChannelLeft  = new AudioChannel(0, pAudioOut->MaxSamplesPerCycle());              pChannelLeft  = new AudioChannel(0, pAudioOut->MaxSamplesPerCycle());
280              pChannelRight = new AudioChannel(1, pAudioOut->MaxSamplesPerCycle());              pChannelRight = new AudioChannel(1, pAudioOut->MaxSamplesPerCycle());
281          }          }
282            if (pEngine->EngineDisabled.GetUnsafe()) pEngine->Enable();
283          MidiInputPort::AddSysexListener(pEngine);          MidiInputPort::AddSysexListener(pEngine);
284      }      }
285    
# Line 629  namespace LinuxSampler { namespace gig { Line 627  namespace LinuxSampler { namespace gig {
627          Pitch          = 0;          Pitch          = 0;
628          SustainPedal   = false;          SustainPedal   = false;
629          SostenutoPedal = false;          SostenutoPedal = false;
630          GlobalVolume   = CONFIG_GLOBAL_ATTENUATION;          GlobalVolume   = 1.0f;
631          MidiVolume     = 1.0;          MidiVolume     = 1.0;
632          GlobalPanLeft  = 1.0f;          GlobalPanLeft  = 1.0f;
633          GlobalPanRight = 1.0f;          GlobalPanRight = 1.0f;
634          // set all MIDI controller values to zero          // set all MIDI controller values to zero
635          memset(ControllerTable, 0x00, 129);          memset(ControllerTable, 0x00, 129);
636            // reset all FX Send levels
637            for (
638                std::vector<FxSend*>::iterator iter = fxSends.begin();
639                iter != fxSends.end(); iter++
640            ) {
641                (*iter)->Reset();
642            }
643      }      }
644    
645      /**      /**

Legend:
Removed from v.1001  
changed lines
  Added in v.1040

  ViewVC Help
Powered by ViewVC