/[svn]/linuxsampler/trunk/src/Sampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/Sampler.cpp

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

revision 1933 by persson, Sun May 10 09:31:51 2009 UTC revision 1934 by schoenebeck, Sun Jul 12 10:35:55 2009 UTC
# Line 70  namespace LinuxSampler { Line 70  namespace LinuxSampler {
70    
71      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {
72          dmsg(2,("SamplerChannel: Assigning engine type..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
73            
74          if (pEngineChannel) {          if (pEngineChannel) {
75              if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) {              if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) {
76                  dmsg(2,("OK\n"));                  dmsg(2,("OK\n"));
# Line 555  namespace LinuxSampler { Line 555  namespace LinuxSampler {
555          // create new device          // create new device
556          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);
557    
         // add new audio device to the audio device list  
         for (uint i = 0; ; i++) { // seek for a free place starting from the beginning  
             if (!mAudioOutputDevices[i]) {  
                 mAudioOutputDevices[i] = pDevice;  
                 break;  
             }  
         }  
   
558          fireAudioDeviceCountChanged(AudioOutputDevices());          fireAudioDeviceCountChanged(AudioOutputDevices());
559          return pDevice;          return pDevice;
560      }      }
561    
562      uint Sampler::AudioOutputDevices() {      uint Sampler::AudioOutputDevices() {
563          return mAudioOutputDevices.size();          return AudioOutputDeviceFactory::Devices().size();
564      }      }
565    
566      uint Sampler::MidiInputDevices() {      uint Sampler::MidiInputDevices() {
567          return mMidiInputDevices.size();          return MidiInputDeviceFactory::Devices().size();
568      }      }
569    
570      std::map<uint, AudioOutputDevice*> Sampler::GetAudioOutputDevices() {      std::map<uint, AudioOutputDevice*> Sampler::GetAudioOutputDevices() {
571          return mAudioOutputDevices;          return AudioOutputDeviceFactory::Devices();
572      }      }
573    
574      std::map<uint, MidiInputDevice*> Sampler::GetMidiInputDevices() {      std::map<uint, MidiInputDevice*> Sampler::GetMidiInputDevices() {
575          return mMidiInputDevices;          return MidiInputDeviceFactory::Devices();
576      }      }
577    
578      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) {      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) {
579          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();          if (pDevice) {
580          for (; iter != mAudioOutputDevices.end(); iter++) {              // check if there are still sampler engines connected to this device
581              if (iter->second == pDevice) {              for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
582                  // check if there are still sampler engines connected to this device                   iterChan != mSamplerChannels.end(); iterChan++
583                  for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();              ) if (iterChan->second->GetAudioOutputDevice() == pDevice) throw Exception("Sampler channel " + ToString(iterChan->first) + " is still connected to the audio output device.");
584                       iterChan != mSamplerChannels.end(); iterChan++)  
585                      if (iterChan->second->GetAudioOutputDevice() == pDevice) throw Exception("Sampler channel " + ToString(iterChan->first) + " is still connected to the audio output device.");              //TODO: should we add fireAudioDeviceToBeDestroyed() here ?
586                AudioOutputDeviceFactory::Destroy(pDevice);
587                  // disable device              fireAudioDeviceCountChanged(AudioOutputDevices());
                 pDevice->Stop();  
   
                 // remove device from the device list  
                 mAudioOutputDevices.erase(iter);  
   
                 // destroy and free device from memory  
                 delete pDevice;  
   
                 fireAudioDeviceCountChanged(AudioOutputDevices());  
                 break;  
             }  
588          }          }
589      }      }
590    
# Line 613  namespace LinuxSampler { Line 594  namespace LinuxSampler {
594           * to the element that is being erased. So we need to copy the map           * to the element that is being erased. So we need to copy the map
595           * by calling GetAudioOutputDevices() to prevent that.           * by calling GetAudioOutputDevices() to prevent that.
596           */           */
597          AudioOutputDeviceMap devs = GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devs = GetAudioOutputDevices();
598          AudioOutputDeviceMap::iterator iter = devs.begin();          std::map<uint, AudioOutputDevice*>::iterator iter = devs.begin();
599          for(; iter != devs.end(); iter++) {          for (; iter != devs.end(); iter++) {
600              DestroyAudioOutputDevice(iter->second);              AudioOutputDevice* pDevice = iter->second;
601    
602                // skip non-autonomous devices
603                if (!pDevice->isAutonomousDevice()) continue;
604    
605                DestroyAudioOutputDevice(pDevice);
606          }          }
607      }      }
608    
609      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) {      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) {
610          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();          if (pDevice) {
611          for (; iter != mMidiInputDevices.end(); iter++) {              // check if there are still sampler engines connected to this device
612              if (iter->second == pDevice) {              for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
613                  // check if there are still sampler engines connected to this device                   iterChan != mSamplerChannels.end(); iterChan++
614                  for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();              ) if (iterChan->second->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(iterChan->first) + " is still connected to the midi input device.");
615                       iterChan != mSamplerChannels.end(); iterChan++)  
616                      if (iterChan->second->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(iterChan->first) + " is still connected to the midi input device.");              fireMidiDeviceToBeDestroyed(pDevice);
617                MidiInputDeviceFactory::Destroy(pDevice);
618                  fireMidiDeviceToBeDestroyed(pDevice);              fireMidiDeviceCountChanged(MidiInputDevices());
   
                 // disable device  
                 pDevice->StopListen();  
   
                 // remove device from the device list  
                 mMidiInputDevices.erase(iter);  
   
                 // destroy and free device from memory  
                 delete pDevice;  
   
                 fireMidiDeviceCountChanged(MidiInputDevices());  
                 break;  
             }  
619          }          }
620      }      }
621    
# Line 652  namespace LinuxSampler { Line 625  namespace LinuxSampler {
625           * to the element that is being erased. So we need to copy the map           * to the element that is being erased. So we need to copy the map
626           * by calling GetMidiInputDevices() to prevent that.           * by calling GetMidiInputDevices() to prevent that.
627           */           */
628          MidiInputDeviceMap devs = GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devs = GetMidiInputDevices();
629          MidiInputDeviceMap::iterator iter = devs.begin();          std::map<uint, MidiInputDevice*>::iterator iter = devs.begin();
630          for(; iter != devs.end(); iter++) {          for (; iter != devs.end(); iter++) {
631              DestroyMidiInputDevice(iter->second);              MidiInputDevice* pDevice = iter->second;
632    
633                // skip non-autonomous devices
634                if (!pDevice->isAutonomousDevice()) continue;
635    
636                DestroyMidiInputDevice(pDevice);
637          }          }
638      }      }
639    
# Line 663  namespace LinuxSampler { Line 641  namespace LinuxSampler {
641          // create new device          // create new device
642          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
643    
         // add new device to the midi device list  
         for (uint i = 0; ; i++) { // seek for a free place starting from the beginning  
                 if (!mMidiInputDevices[i]) {  
                         mMidiInputDevices[i] = pDevice;  
                         break;  
                 }  
         }  
   
644          fireMidiDeviceCreated(pDevice);          fireMidiDeviceCreated(pDevice);
645          fireMidiDeviceCountChanged(MidiInputDevices());          fireMidiDeviceCountChanged(MidiInputDevices());
646          return pDevice;          return pDevice;
# Line 701  namespace LinuxSampler { Line 671  namespace LinuxSampler {
671      void Sampler::Reset() {      void Sampler::Reset() {
672          // delete sampler channels          // delete sampler channels
673          try {          try {
674              RemoveAllSamplerChannels();              RemoveAllSamplerChannels();
675          }          }
676          catch(...) {          catch(...) {
677              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush;              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush;
# Line 710  namespace LinuxSampler { Line 680  namespace LinuxSampler {
680    
681          // delete midi input devices          // delete midi input devices
682          try {          try {
683              DestroyAllMidiInputDevices();              DestroyAllMidiInputDevices();
684          }          }
685          catch(...) {          catch(...) {
686              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush;              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush;
# Line 719  namespace LinuxSampler { Line 689  namespace LinuxSampler {
689    
690          // delete audio output devices          // delete audio output devices
691          try {          try {
692              DestroyAllAudioOutputDevices();              DestroyAllAudioOutputDevices();
693          }          }
694          catch(...) {          catch(...) {
695              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;
# Line 766  namespace LinuxSampler { Line 736  namespace LinuxSampler {
736                  fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount());                  fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount());
737                  fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage());                  fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage());
738              }              }
739                
740              fireTotalStreamCountChanged(GetDiskStreamCount());              fireTotalStreamCountChanged(GetDiskStreamCount());
741              fireTotalVoiceCountChanged(GetVoiceCount());              fireTotalVoiceCountChanged(GetVoiceCount());
742    

Legend:
Removed from v.1933  
changed lines
  Added in v.1934

  ViewVC Help
Powered by ViewVC