/[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 505 - (show annotations) (download) (as text)
Tue May 3 01:00:25 2005 UTC (18 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5626 byte(s)
fixed libgig include rules

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 Christian Schoenebeck *
7 * *
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 <gig.h>
34
35 #include "../../common/global.h"
36 #include "../../common/LinuxSamplerException.h"
37 #include "../../common/ResourceManager.h"
38 #include "../../drivers/audio/AudioOutputDevice.h"
39
40 // preload 64k samples = 128kB of data in RAM for 16 bit mono samples
41 #define NUM_RAM_PRELOAD_SAMPLES 32768
42
43 //namespace libgig = gig;
44
45 namespace LinuxSampler { namespace gig {
46
47 typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer;
48
49 }} // namespace LinuxSampler::gig
50
51 #include "EngineChannel.h"
52 #include "Engine.h"
53
54 namespace LinuxSampler { namespace gig {
55
56 // just symbol prototyping
57 class EngineChannel;
58
59 /**
60 * Explicitly identifies a Gigasampler instrument.
61 */
62 struct instrument_id_t {
63 String FileName; ///< name of the file which contains the instrument
64 uint iInstrument; ///< index of the instrument in the instrument file
65
66 // 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
67 bool operator<(const instrument_id_t& o) const {
68 return (iInstrument < o.iInstrument || (iInstrument == o.iInstrument && FileName < o.FileName));
69 }
70 };
71
72 /** Gig instrument manager
73 *
74 * Manager to share gig instruments between multiple Gigasampler
75 * engine channels. The engine channels Borrow() instruments when they
76 * need them and HandBack() when they don't need them anymore. The
77 * InstrumentResourceManager loads the corresponding gig file and gig
78 * instrument if needed, if it's already in use by another engine
79 * channel, then it just returns the same resource, if an gig
80 * instrument / file is not in use by any engine channel anymore, then
81 * it will be freed from memory.
82 */
83 class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> {
84 public:
85 virtual ~InstrumentResourceManager() {}
86 protected:
87 virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
88 virtual void Destroy(::gig::Instrument* pResource, void* pArg);
89 virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
90 private:
91 struct instr_entry_t {
92 ::gig::File* pGig;
93 uint iInstrument;
94 uint MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument
95 };
96
97 typedef ResourceConsumer< ::gig::File> GigConsumer;
98
99 class GigResourceManager : public ResourceManager<String, ::gig::File> {
100 protected:
101 virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);
102 virtual void Destroy(::gig::File* pResource, void* pArg);
103 virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore
104 public:
105 virtual ~GigResourceManager() {}
106 } Gigs;
107
108 void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel);
109 };
110
111 /**
112 * Will be thrown by the InstrumentResourceManager on errors.
113 */
114 class InstrumentResourceManagerException : public LinuxSamplerException {
115 public:
116 InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {}
117 };
118
119 }} // namespace LinuxSampler::gig
120
121 #endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__

  ViewVC Help
Powered by ViewVC