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

Annotation of /linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 411 - (hide annotations) (download) (as text)
Sat Feb 26 02:01:14 2005 UTC (19 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5653 byte(s)
* design change: using now one sampler engine instance and one disk thread
  instance for all sampler channels that are connected to the same audio
  output device (and are using the same engine type of course)
* added EngineFactory / EngineChannelFactory to remove the annoying build
  dependencies e.g. of the lscpserver to the actual sampler engine
  implementations
* bumped version to 0.3.0 (current CVS state is still quite broken,
  previous, stable CVS version was tagged as "v0_2_0" and is also available
  as source tarball)

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 411 * Copyright (C) 2005 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * 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 *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__
25     #define __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__
26    
27     #include "../../common/global.h"
28    
29     #if DEBUG_HEADERS
30     # warning InstrumentResourceManager.h included
31     #endif // DEBUG_HEADERS
32    
33     #include "../../common/global.h"
34     #include "../../common/LinuxSamplerException.h"
35     #include "../../common/ResourceManager.h"
36 schoenebeck 203 #include "../../drivers/audio/AudioOutputDevice.h"
37 schoenebeck 53 #include "../../lib/fileloader/libgig/gig.h"
38    
39     // preload 64k samples = 128kB of data in RAM for 16 bit mono samples
40     #define NUM_RAM_PRELOAD_SAMPLES 32768
41    
42     //namespace libgig = gig;
43    
44     namespace LinuxSampler { namespace gig {
45    
46     typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer;
47    
48     }} // namespace LinuxSampler::gig
49    
50 schoenebeck 411 #include "EngineChannel.h"
51 schoenebeck 53 #include "Engine.h"
52    
53     namespace LinuxSampler { namespace gig {
54    
55     // just symbol prototyping
56 schoenebeck 411 class EngineChannel;
57 schoenebeck 53
58     /**
59     * Explicitly identifies a Gigasampler instrument.
60     */
61     struct instrument_id_t {
62     String FileName; ///< name of the file which contains the instrument
63     uint iInstrument; ///< index of the instrument in the instrument file
64    
65     // TODO: we should extend operator<() so it will be able to detect that file x and file y are actually the same files, e.g. because one of them is a symlink / share the same inode
66     bool operator<(const instrument_id_t& o) const {
67     return (iInstrument < o.iInstrument || (iInstrument == o.iInstrument && FileName < o.FileName));
68     }
69     };
70    
71     /** Gig instrument manager
72     *
73     * Manager to share gig instruments between multiple Gigasampler
74 schoenebeck 411 * engine channels. The engine channels Borrow() instruments when they
75     * need them and HandBack() when they don't need them anymore. The
76 schoenebeck 53 * InstrumentResourceManager loads the corresponding gig file and gig
77 schoenebeck 411 * instrument if needed, if it's already in use by another engine
78     * channel, then it just returns the same resource, if an gig
79     * instrument / file is not in use by any engine channel anymore, then
80     * it will be freed from memory.
81 schoenebeck 53 */
82     class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> {
83 schoenebeck 411 public:
84     virtual ~InstrumentResourceManager() {}
85 schoenebeck 53 protected:
86     virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
87     virtual void Destroy(::gig::Instrument* pResource, void* pArg);
88     virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
89     private:
90     struct instr_entry_t {
91     ::gig::File* pGig;
92     uint iInstrument;
93     uint MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument
94     };
95    
96     typedef ResourceConsumer< ::gig::File> GigConsumer;
97    
98     class GigResourceManager : public ResourceManager<String, ::gig::File> {
99     protected:
100     virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);
101     virtual void Destroy(::gig::File* pResource, void* pArg);
102     virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore
103 schoenebeck 411 public:
104     virtual ~GigResourceManager() {}
105 schoenebeck 53 } Gigs;
106    
107 schoenebeck 411 void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel);
108 schoenebeck 53 };
109    
110     /**
111     * Will be thrown by the InstrumentResourceManager on errors.
112     */
113     class InstrumentResourceManagerException : public LinuxSamplerException {
114     public:
115     InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {}
116     };
117    
118     }} // namespace LinuxSampler::gig
119    
120     #endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__

  ViewVC Help
Powered by ViewVC