/[svn]/linuxsampler/trunk/src/engines/InstrumentManagerBase.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/InstrumentManagerBase.h

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

revision 2326 by persson, Thu Mar 8 19:40:14 2012 UTC revision 2837 by persson, Sun Aug 23 06:14:00 2015 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 - 2012 Christian Schoenebeck and Grigor Iliev      *   *   Copyright (C) 2009 - 2015 Christian Schoenebeck and Grigor Iliev      *
8   *                                                                         *   *                                                                         *
9   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
10   *   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 25  Line 25 
25  #ifndef __LS_INSTRUMENTMANAGERBASE_H__  #ifndef __LS_INSTRUMENTMANAGERBASE_H__
26  #define __LS_INSTRUMENTMANAGERBASE_H__  #define __LS_INSTRUMENTMANAGERBASE_H__
27    
28  #include "InstrumentManager.h"  #include "common/AbstractInstrumentManager.h"
29    #include "../drivers/audio/AudioOutputDeviceFactory.h"
30  #include "AbstractEngine.h"  #include "AbstractEngine.h"
31  #include "AbstractEngineChannel.h"  #include "AbstractEngineChannel.h"
 #include "../common/ResourceManager.h"  
 #include "../common/global_private.h"  
 #include "../drivers/audio/AudioOutputDeviceFactory.h"  
32    
33  // We need to know the maximum number of sample points which are going to  // We need to know the maximum number of sample points which are going to
34  // be processed for each render cycle of the audio output driver, to know  // be processed for each render cycle of the audio output driver, to know
# Line 42  Line 40 
40  namespace LinuxSampler {  namespace LinuxSampler {
41    
42      template <class F /* Instrument File */, class I /* Instrument */, class R /* Regions */, class S /*Sample */>      template <class F /* Instrument File */, class I /* Instrument */, class R /* Regions */, class S /*Sample */>
43      class InstrumentManagerBase : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, I> {      class InstrumentManagerBase : public AbstractInstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, I> {
44          public:          public:
45              struct region_info_t {              struct region_info_t {
46                  int    refCount;                  int    refCount;
# Line 56  namespace LinuxSampler { Line 54  namespace LinuxSampler {
54    
55              typedef ResourceConsumer<I> InstrumentConsumer;              typedef ResourceConsumer<I> InstrumentConsumer;
56    
57              InstrumentManagerBase() { }              InstrumentManagerBase() : AbstractInstrumentManager() { }
58              virtual ~InstrumentManagerBase() { }              virtual ~InstrumentManagerBase() { }
59    
60              virtual InstrumentEditor* LaunchInstrumentEditor(instrument_id_t ID, void* pUserData = NULL) throw (InstrumentManagerException) {              virtual InstrumentEditor* LaunchInstrumentEditor(EngineChannel* pEngineChannel, instrument_id_t ID, void* pUserData = NULL) throw (InstrumentManagerException) OVERRIDE {
61                   throw InstrumentManagerException(                   throw InstrumentManagerException(
62                      "Instrument editing is not supported for this instrument format"                      "Instrument editing is not supported for this instrument format"
63                  );                  );
64              }              }
65    
66              virtual String GetInstrumentDataStructureName(instrument_id_t ID) {              virtual String GetInstrumentDataStructureName(instrument_id_t ID) OVERRIDE {
67                  throw InstrumentManagerException("Not implemented");                  throw InstrumentManagerException("Not implemented");
68              }              }
69    
70              virtual String GetInstrumentDataStructureVersion(instrument_id_t ID) {              virtual String GetInstrumentDataStructureVersion(instrument_id_t ID) OVERRIDE {
71                  throw InstrumentManagerException("Not implemented");                  throw InstrumentManagerException("Not implemented");
72              }              }
73    
# Line 85  namespace LinuxSampler { Line 83  namespace LinuxSampler {
83                  InstrumentConsumer*  pConsumer,                  InstrumentConsumer*  pConsumer,
84                  RTList<R*>*          pRegionsInUse                  RTList<R*>*          pRegionsInUse
85              ) {              ) {
86                  RegionInfoMutex.Lock();                  LockGuard lock(RegionInfoMutex);
87                  for (typename RTList<R*>::Iterator i = pRegionsInUse->first() ; i != pRegionsInUse->end() ; i++) {                  for (typename RTList<R*>::Iterator i = pRegionsInUse->first() ; i != pRegionsInUse->end() ; i++) {
88                      RegionInfo[*i].refCount++;                      RegionInfo[*i].refCount++;
89                      SampleRefCount[(*i)->pSample]++;                      SampleRefCount[(*i)->pSample]++;
90                  }                  }
91                  HandBack(pResource, pConsumer, true);                  this->HandBack(pResource, pConsumer, true);
                 RegionInfoMutex.Unlock();  
92              }              }
93    
94              /**              /**
# Line 99  namespace LinuxSampler { Line 96  namespace LinuxSampler {
96               * was previously handed back.               * was previously handed back.
97               */               */
98              virtual void HandBackRegion(R* pRegion) {              virtual void HandBackRegion(R* pRegion) {
99                  RegionInfoMutex.Lock();                  LockGuard lock(RegionInfoMutex);
100                  if (RegionInfo.find(pRegion) == RegionInfo.end()) {                  if (RegionInfo.find(pRegion) == RegionInfo.end()) {
101                      std::cerr << "Handing back unknown region. This is a BUG!!!" << std::endl;                      std::cerr << "Handing back unknown region. This is a BUG!!!" << std::endl;
102                  }                  }
# Line 117  namespace LinuxSampler { Line 114  namespace LinuxSampler {
114                      }                      }
115                      RegionInfo.erase(pRegion);                      RegionInfo.erase(pRegion);
116                  }                  }
                 RegionInfoMutex.Unlock();  
117              }              }
118    
119              virtual InstrumentManager::mode_t GetMode(const InstrumentManager::instrument_id_t& ID) {              virtual InstrumentManager::mode_t GetMode(const InstrumentManager::instrument_id_t& ID) OVERRIDE {
120                  return static_cast<InstrumentManager::mode_t>(ResourceManager<instrument_id_t, I>::AvailabilityMode(ID));                  return static_cast<InstrumentManager::mode_t>(ResourceManager<instrument_id_t, I>::AvailabilityMode(ID));
121              }              }
122    
123              virtual void SetMode(const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode) {              virtual void SetMode(const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode) OVERRIDE {
124                  dmsg(2,("InstrumentManagerBase: setting mode for %s (Index=%d) to %d\n",ID.FileName.c_str(),ID.Index,Mode));                  dmsg(2,("InstrumentManagerBase: setting mode for %s (Index=%d) to %d\n",ID.FileName.c_str(),ID.Index,Mode));
125                  SetAvailabilityMode(ID, static_cast<typename ResourceManager<instrument_id_t, I>::mode_t>(Mode));                  this->SetAvailabilityMode(ID, static_cast<typename ResourceManager<instrument_id_t, I>::mode_t>(Mode));
126              }              }
127    
128      protected:      protected:
# Line 216  namespace LinuxSampler { Line 212  namespace LinuxSampler {
212                      const uint neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3;                      const uint neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3;
213                      const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->GetFrameSize();                      const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->GetFrameSize();
214                      if (currentlyCachedSilenceSamples < neededSilenceSamples) {                      if (currentlyCachedSilenceSamples < neededSilenceSamples) {
215                          dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %d)\n", pSample->GetName().c_str(), pSample->GetTotalFrameCount()));                          dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %ld)\n", pSample->GetName().c_str(), pSample->GetTotalFrameCount()));
216                          typename S::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(neededSilenceSamples);                          typename S::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(neededSilenceSamples);
217                          dmsg(4,("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize));                          dmsg(4,("Cached %lu Bytes, %lu silence bytes.\n", buf.Size, buf.NullExtensionSize));
218                      }                      }
219                  }                  }
220                  else { // we only cache CONFIG_PRELOAD_SAMPLES and stream the other sample points from disk                  else { // we only cache CONFIG_PRELOAD_SAMPLES and stream the other sample points from disk
# Line 241  namespace LinuxSampler { Line 237  namespace LinuxSampler {
237    
238                  if (pEntry->MaxSamplesPerCycle < maxSamplesPerCycle) {                  if (pEntry->MaxSamplesPerCycle < maxSamplesPerCycle) {
239                      dmsg(1,("Completely reloading instrument due to insufficient precached samples ...\n"));                      dmsg(1,("Completely reloading instrument due to insufficient precached samples ...\n"));
240                      Update(pResource, pConsumer);                      this->Update(pResource, pConsumer);
241                  }                  }
242              }              }
243      };      };

Legend:
Removed from v.2326  
changed lines
  Added in v.2837

  ViewVC Help
Powered by ViewVC