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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 386 - (show annotations) (download) (as text)
Thu Feb 17 10:45:30 2005 UTC (15 years, 7 months ago) by letz
File MIME type: text/x-c++hdr
File size: 5447 byte(s)
Add missing virtual destructor

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

  ViewVC Help
Powered by ViewVC