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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2012 - (show annotations) (download) (as text)
Fri Oct 23 17:53:17 2009 UTC (14 years, 6 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 5520 byte(s)
* Refactoring: moved the independent code from
  the Gigasampler format engine to base classes
* SFZ format engine: experimental code (not usable yet)
* SoundFont format engine: experimental code (not usable yet)
* Fixed crash which may occur when MIDI key + transpose is out of range

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2009 Christian Schoenebeck *
7 * Copyright (C) 2009 Grigor Iliev *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, write to the Free Software *
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
22 * MA 02111-1307 USA *
23 ***************************************************************************/
24
25 #ifndef __LS_SFZ_INSTRUMENTRESOURCEMANAGER_H__
26 #define __LS_SFZ_INSTRUMENTRESOURCEMANAGER_H__
27
28 #include "../../common/global.h"
29
30 #include "sfz.h"
31
32 #include "../../common/global.h"
33 #include "../../common/Pool.h"
34 #include "../../common/ResourceManager.h"
35 #include "../../drivers/audio/AudioOutputDevice.h"
36 #include "../InstrumentManagerBase.h"
37 #include "../common/Sample.h"
38 #include "../../common/ArrayList.h"
39
40 namespace LinuxSampler { namespace sfz {
41
42 typedef ResourceConsumer< ::sfz::Instrument> InstrumentConsumer;
43
44 }} // namespace LinuxSampler::sfz
45
46 #include "../../plugins/InstrumentEditor.h"
47
48 namespace LinuxSampler { namespace sfz {
49 class Engine;
50 class EngineChannel;
51
52 /** @brief sfz instrument manager
53 *
54 * Manager to share sfz instruments between multiple sfz
55 * engine channels. The engine channels Borrow() instruments when they
56 * need them and HandBack() when they don't need them anymore. The
57 * InstrumentResourceManager loads the corresponding sfz file and sfz
58 * instrument if needed, if it's already in use by another engine
59 * channel, then it just returns the same resource, if a sfz
60 * instrument / file is not needed anymore, then it will be freed from
61 * memory.
62 */
63 class InstrumentResourceManager : public InstrumentManagerDefaultImpl< ::sfz::File, ::sfz::Instrument, ::sfz::Region, Sample> {
64 public:
65 InstrumentResourceManager() : Sfzs(this) {}
66 virtual ~InstrumentResourceManager() {}
67
68 // implementation of derived abstract methods from 'InstrumentManager'
69 virtual std::vector<instrument_id_t> Instruments();
70 virtual String GetInstrumentName(instrument_id_t ID);
71 virtual std::vector<instrument_id_t> GetInstrumentFileContent(String File) throw (InstrumentManagerException);
72 virtual instrument_info_t GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException);
73
74 ::sfz::SampleManager* GetSampleManager() { return &Sfzs.sampleManager; }
75
76 protected:
77 // implementation of derived abstract methods from 'ResourceManager'
78 virtual ::sfz::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
79 virtual void Destroy(::sfz::Instrument* pResource, void* pArg);
80 virtual void OnBorrow(::sfz::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
81 virtual void DeleteRegionIfNotUsed(::sfz::Region* pRegion, region_info_t* pRegInfo);
82 virtual void DeleteSampleIfNotUsed(Sample* pSample, region_info_t* pRegInfo);
83 private:
84 typedef ResourceConsumer< ::sfz::File> SfzConsumer;
85
86 class SfzResourceManager : public ResourceManager<String, ::sfz::File> {
87 protected:
88 // implementation of derived abstract methods from 'ResourceManager'
89 virtual ::sfz::File* Create(String Key, SfzConsumer* pConsumer, void*& pArg);
90 virtual void Destroy(::sfz::File* pResource, void* pArg);
91 virtual void OnBorrow(::sfz::File* pResource, SfzConsumer* pConsumer, void*& pArg) {} // ignore
92 public:
93 SfzResourceManager(InstrumentResourceManager* parent) : parent(parent) {}
94 virtual ~SfzResourceManager() {}
95 friend class InstrumentResourceManager;
96 private:
97 InstrumentResourceManager* parent;
98 ::sfz::SampleManager sampleManager;
99 } Sfzs;
100 };
101
102 }} // namespace LinuxSampler::sfz
103
104 #endif // __LS_SFZ_INSTRUMENTRESOURCEMANAGER_H__

  ViewVC Help
Powered by ViewVC