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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2326 - (hide annotations) (download) (as text)
Thu Mar 8 19:40:14 2012 UTC (12 years, 1 month ago) by persson
File MIME type: text/x-c++hdr
File size: 5261 byte(s)
* bugfix: instrument loading crashed for sfz and sf2 in Ardour (#176)
* more thread safety fixes for the instrument loading thread

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 persson 2326 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7     * Copyright (C) 2009 - 2012 Christian Schoenebeck and Grigor Iliev *
8 iliev 2012 * *
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_SF2_INSTRUMENTRESOURCEMANAGER_H__
26     #define __LS_SF2_INSTRUMENTRESOURCEMANAGER_H__
27    
28     #include "../../common/global.h"
29    
30 iliev 2018 #include <SF.h>
31 iliev 2012
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/ArrayList.h"
38    
39     namespace LinuxSampler { namespace sf2 {
40    
41 iliev 2027 typedef ResourceConsumer< ::sf2::Preset> InstrumentConsumer;
42 iliev 2012
43     }} // namespace LinuxSampler::sf2
44    
45     #include "../../plugins/InstrumentEditor.h"
46    
47     namespace LinuxSampler { namespace sf2 {
48     class Engine;
49     class EngineChannel;
50    
51     /** @brief sf2 instrument manager
52     *
53     * Manager to share sf2 instruments between multiple sf2
54     * engine channels. The engine channels Borrow() instruments when they
55     * need them and HandBack() when they don't need them anymore. The
56     * InstrumentResourceManager loads the corresponding sf2 file and sf2
57     * instrument if needed, if it's already in use by another engine
58     * channel, then it just returns the same resource, if a sf2
59     * instrument / file is not needed anymore, then it will be freed from
60     * memory.
61     */
62 persson 2326 class InstrumentResourceManager : public InstrumentManagerBase< ::sf2::File, ::sf2::Preset, ::sf2::Region, ::sf2::Sample> {
63 iliev 2012 public:
64     InstrumentResourceManager() : Sf2s(this) {}
65     virtual ~InstrumentResourceManager() {}
66    
67     // implementation of derived abstract methods from 'InstrumentManager'
68     virtual String GetInstrumentName(instrument_id_t ID);
69     virtual std::vector<instrument_id_t> GetInstrumentFileContent(String File) throw (InstrumentManagerException);
70     virtual instrument_info_t GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException);
71    
72     protected:
73     // implementation of derived abstract methods from 'ResourceManager'
74 iliev 2027 virtual ::sf2::Preset* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
75     virtual void Destroy(::sf2::Preset* pResource, void* pArg);
76 iliev 2012 virtual void DeleteRegionIfNotUsed(::sf2::Region* pRegion, region_info_t* pRegInfo);
77     virtual void DeleteSampleIfNotUsed(::sf2::Sample* pSample, region_info_t* pRegInfo);
78     private:
79     typedef ResourceConsumer< ::sf2::File> Sf2Consumer;
80    
81     class Sf2ResourceManager : public ResourceManager<String, ::sf2::File> {
82     protected:
83     // implementation of derived abstract methods from 'ResourceManager'
84     virtual ::sf2::File* Create(String Key, Sf2Consumer* pConsumer, void*& pArg);
85     virtual void Destroy(::sf2::File* pResource, void* pArg);
86     virtual void OnBorrow(::sf2::File* pResource, Sf2Consumer* pConsumer, void*& pArg) {} // ignore
87     public:
88     Sf2ResourceManager(InstrumentResourceManager* parent) : parent(parent) {}
89     virtual ~Sf2ResourceManager() {}
90     friend class InstrumentResourceManager;
91     private:
92     InstrumentResourceManager* parent;
93     } Sf2s;
94    
95 iliev 2027 int GetSfInstrumentCount(::sf2::File* pFile);
96     ::sf2::Preset* GetSfInstrument(::sf2::File* pFile, int idx);
97 iliev 2012 };
98    
99     }} // namespace LinuxSampler::sf2
100    
101     #endif // __LS_SF2_INSTRUMENTRESOURCEMANAGER_H__

  ViewVC Help
Powered by ViewVC