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

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

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

revision 554 by schoenebeck, Thu May 19 19:25:14 2005 UTC revision 947 by schoenebeck, Mon Nov 27 21:34:55 2006 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 Christian Schoenebeck                              *   *   Copyright (C) 2005, 2006 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 34  Line 34 
34    
35  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
36    
37        // data stored as long as an instrument resource exists
38        struct instr_entry_t {
39            InstrumentManager::instrument_id_t ID;
40            ::gig::File*                       pGig;
41            uint                               MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument
42        };
43    
44      // some data needed for the libgig callback function      // some data needed for the libgig callback function
45      struct progress_callback_arg_t {      struct progress_callback_arg_t {
46          InstrumentResourceManager* pManager;          InstrumentResourceManager*          pManager;
47          instrument_id_t*           pInstrumentKey;          InstrumentManager::instrument_id_t* pInstrumentKey;
48      };      };
49    
50      /**      /**
# Line 57  namespace LinuxSampler { namespace gig { Line 64  namespace LinuxSampler { namespace gig {
64          pArg->pManager->DispatchResourceProgressEvent(*pArg->pInstrumentKey, localProgress);          pArg->pManager->DispatchResourceProgressEvent(*pArg->pInstrumentKey, localProgress);
65      }      }
66    
67        std::vector<InstrumentResourceManager::instrument_id_t> InstrumentResourceManager::Instruments() {
68            return Entries();
69        }
70    
71        InstrumentManager::mode_t InstrumentResourceManager::GetMode(const instrument_id_t& ID) {
72            return static_cast<InstrumentManager::mode_t>(AvailabilityMode(ID));
73        }
74    
75        void InstrumentResourceManager::SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode) {
76            dmsg(2,("gig::InstrumentResourceManager: setting mode for %s (Index=%d) to %d\n",ID.FileName.c_str(),ID.Index,Mode));
77            SetAvailabilityMode(ID, static_cast<ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument>::mode_t>(Mode));
78        }
79    
80        float InstrumentResourceManager::GetVolume(const instrument_id_t& ID) {
81            void* pCustomData = CustomData(ID);
82            const float fVolume = (pCustomData) ? *((float*)pCustomData) /* stored value */ : 1.0f /* default value */;
83            return fVolume;
84        }
85    
86        void InstrumentResourceManager::SetVolume(const instrument_id_t& ID, float Volume) {
87            void* pCustomData = CustomData(ID);
88            if (Volume == 1.0f) { // if default volume ...
89                if (pCustomData) { // ... delete volume entry if necessary
90                    delete (float*)pCustomData;
91                    SetCustomData(ID, NULL);
92                }
93            } else { // if not default volume
94                if (!pCustomData) { // create volume entry if necessary
95                    pCustomData = new float;
96                    SetCustomData(ID, pCustomData);
97                }
98                *((float*)pCustomData) = Volume;
99            }
100        }
101    
102        String InstrumentResourceManager::GetInstrumentName(instrument_id_t ID) {
103            return ""; // TODO: ...
104        }
105    
106      ::gig::Instrument* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) {      ::gig::Instrument* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) {
107          // get gig file from inernal gig file manager          // get gig file from inernal gig file manager
108          ::gig::File* pGig = Gigs.Borrow(Key.FileName, (GigConsumer*) Key.iInstrument); // conversion kinda hackish :/          ::gig::File* pGig = Gigs.Borrow(Key.FileName, (GigConsumer*) Key.Index); // conversion kinda hackish :/
109    
110          // we pass this to the progress callback mechanism of libgig          // we pass this to the progress callback mechanism of libgig
111          progress_callback_arg_t callbackArg;          progress_callback_arg_t callbackArg;
# Line 70  namespace LinuxSampler { namespace gig { Line 116  namespace LinuxSampler { namespace gig {
116          progress.callback = OnInstrumentLoadingProgress;          progress.callback = OnInstrumentLoadingProgress;
117          progress.custom   = &callbackArg;          progress.custom   = &callbackArg;
118    
119          dmsg(1,("Loading gig instrument..."));          dmsg(1,("Loading gig instrument ('%s',%d)...",Key.FileName.c_str(),Key.Index));
120          ::gig::Instrument* pInstrument = pGig->GetInstrument(Key.iInstrument, &progress);          ::gig::Instrument* pInstrument = pGig->GetInstrument(Key.Index, &progress);
121          if (!pInstrument) {          if (!pInstrument) {
122              std::stringstream msg;              std::stringstream msg;
123              msg << "There's no instrument with index " << Key.iInstrument << ".";              msg << "There's no instrument with index " << Key.Index << ".";
124              throw InstrumentResourceManagerException(msg.str());              throw InstrumentResourceManagerException(msg.str());
125          }          }
126          pGig->GetFirstSample(); // just to force complete instrument loading          pGig->GetFirstSample(); // just to force complete instrument loading
# Line 87  namespace LinuxSampler { namespace gig { Line 133  namespace LinuxSampler { namespace gig {
133          while (pRgn) {          while (pRgn) {
134              // we randomly schedule 90% for the .gig file loading and the remaining 10% now for sample caching              // we randomly schedule 90% for the .gig file loading and the remaining 10% now for sample caching
135              const float localProgress = 0.9f + 0.1f * (float) iRegion / (float) pInstrument->Regions;              const float localProgress = 0.9f + 0.1f * (float) iRegion / (float) pInstrument->Regions;
136              DispatchResourceProgressEvent(Key, localProgress);                          DispatchResourceProgressEvent(Key, localProgress);
137                
138              if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) {              if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) {
139                  dmsg(2,("C"));                  dmsg(2,("C"));
140                  CacheInitialSamples(pRgn->GetSample(), dynamic_cast<gig::EngineChannel*>(pConsumer));                  CacheInitialSamples(pRgn->GetSample(), (gig::EngineChannel*) pConsumer);
141              }              }
142              for (uint i = 0; i < pRgn->DimensionRegions; i++) {              for (uint i = 0; i < pRgn->DimensionRegions; i++) {
143                  CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, dynamic_cast<gig::EngineChannel*>(pConsumer));                  CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, (gig::EngineChannel*) pConsumer);
144              }              }
145    
146              pRgn = pInstrument->GetNextRegion();              pRgn = pInstrument->GetNextRegion();
# Line 105  namespace LinuxSampler { namespace gig { Line 151  namespace LinuxSampler { namespace gig {
151    
152          // we need the following for destruction later          // we need the following for destruction later
153          instr_entry_t* pEntry = new instr_entry_t;          instr_entry_t* pEntry = new instr_entry_t;
154          pEntry->iInstrument   = Key.iInstrument;          pEntry->ID.FileName   = Key.FileName;
155            pEntry->ID.Index      = Key.Index;
156          pEntry->pGig          = pGig;          pEntry->pGig          = pGig;
157    
158          gig::EngineChannel* pEngineChannel = dynamic_cast<gig::EngineChannel*>(pConsumer);          gig::EngineChannel* pEngineChannel = (gig::EngineChannel*) pConsumer;
159          // and we save this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond'          // and we save this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond'
160          pEntry->MaxSamplesPerCycle =          pEntry->MaxSamplesPerCycle =
161              (pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()              (pEngineChannel && pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()
162                                            : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;                                            : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;
163          pArg = pEntry;          pArg = pEntry;
164    
# Line 120  namespace LinuxSampler { namespace gig { Line 167  namespace LinuxSampler { namespace gig {
167    
168      void InstrumentResourceManager::Destroy( ::gig::Instrument* pResource, void* pArg) {      void InstrumentResourceManager::Destroy( ::gig::Instrument* pResource, void* pArg) {
169          instr_entry_t* pEntry = (instr_entry_t*) pArg;          instr_entry_t* pEntry = (instr_entry_t*) pArg;
170          Gigs.HandBack(pEntry->pGig, (GigConsumer*) pEntry->iInstrument); // conversion kinda hackish :/          // remove volume entry if necessary
171            void* pCustomData = CustomData(pEntry->ID);
172            if (pCustomData) {
173                delete (float*)pCustomData;
174                SetCustomData(pEntry->ID, NULL);
175            }
176            // we don't need the .gig file here anymore
177            Gigs.HandBack(pEntry->pGig, (GigConsumer*) pEntry->ID.Index); // conversion kinda hackish :/
178          delete pEntry;          delete pEntry;
179      }      }
180    
# Line 158  namespace LinuxSampler { namespace gig { Line 212  namespace LinuxSampler { namespace gig {
212              // border, to allow the interpolator do it's work even at the end of              // border, to allow the interpolator do it's work even at the end of
213              // the sample.              // the sample.
214              const uint maxSamplesPerCycle =              const uint maxSamplesPerCycle =
215                  (pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()                  (pEngineChannel && pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()
216                                                : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;                                                : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;
217              const uint neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3;              const uint neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3;
218              const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->FrameSize;              const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->FrameSize;

Legend:
Removed from v.554  
changed lines
  Added in v.947

  ViewVC Help
Powered by ViewVC