/[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 517 - (show annotations) (download) (as text)
Sun May 8 00:26:21 2005 UTC (14 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5709 byte(s)
* implemented progress indicator for loading instruments
  (can be polled with "GET CHANNEL INFO", field "INSTRUMENT_STATUS")

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 static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress);
87 protected:
88 virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
89 virtual void Destroy(::gig::Instrument* pResource, void* pArg);
90 virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
91 private:
92 struct instr_entry_t {
93 ::gig::File* pGig;
94 uint iInstrument;
95 uint MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument
96 };
97
98 typedef ResourceConsumer< ::gig::File> GigConsumer;
99
100 class GigResourceManager : public ResourceManager<String, ::gig::File> {
101 protected:
102 virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);
103 virtual void Destroy(::gig::File* pResource, void* pArg);
104 virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore
105 public:
106 virtual ~GigResourceManager() {}
107 } Gigs;
108
109 void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel);
110 };
111
112 /**
113 * Will be thrown by the InstrumentResourceManager on errors.
114 */
115 class InstrumentResourceManagerException : public LinuxSamplerException {
116 public:
117 InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {}
118 };
119
120 }} // namespace LinuxSampler::gig
121
122 #endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__

  ViewVC Help
Powered by ViewVC