3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* 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 * |
* it under the terms of the GNU General Public License as published by * |
29 |
#include <gig.h> |
#include <gig.h> |
30 |
|
|
31 |
#include "../../common/global.h" |
#include "../../common/global.h" |
|
#include "../../common/Exception.h" |
|
32 |
#include "../../common/ResourceManager.h" |
#include "../../common/ResourceManager.h" |
33 |
#include "../../drivers/audio/AudioOutputDevice.h" |
#include "../../drivers/audio/AudioOutputDevice.h" |
34 |
|
#include "../InstrumentManager.h" |
35 |
|
|
36 |
//namespace libgig = gig; |
//namespace libgig = gig; |
37 |
|
|
43 |
|
|
44 |
#include "EngineChannel.h" |
#include "EngineChannel.h" |
45 |
#include "Engine.h" |
#include "Engine.h" |
46 |
|
#include "../InstrumentEditor.h" |
47 |
|
|
48 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
49 |
|
|
50 |
// just symbol prototyping |
// just symbol prototyping |
51 |
class EngineChannel; |
class EngineChannel; |
52 |
|
|
53 |
/** |
/** @brief Gig instrument manager |
|
* Explicitly identifies a Gigasampler instrument. |
|
|
*/ |
|
|
struct instrument_id_t { |
|
|
String FileName; ///< name of the file which contains the instrument |
|
|
uint iInstrument; ///< index of the instrument in the instrument file |
|
|
|
|
|
// 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 |
|
|
bool operator<(const instrument_id_t& o) const { |
|
|
return (iInstrument < o.iInstrument || (iInstrument == o.iInstrument && FileName < o.FileName)); |
|
|
} |
|
|
}; |
|
|
|
|
|
/** Gig instrument manager |
|
54 |
* |
* |
55 |
* Manager to share gig instruments between multiple Gigasampler |
* Manager to share gig instruments between multiple Gigasampler |
56 |
* engine channels. The engine channels Borrow() instruments when they |
* engine channels. The engine channels Borrow() instruments when they |
58 |
* InstrumentResourceManager loads the corresponding gig file and gig |
* InstrumentResourceManager loads the corresponding gig file and gig |
59 |
* instrument if needed, if it's already in use by another engine |
* instrument if needed, if it's already in use by another engine |
60 |
* channel, then it just returns the same resource, if an gig |
* channel, then it just returns the same resource, if an gig |
61 |
* instrument / file is not in use by any engine channel anymore, then |
* instrument / file is not needed anymore, then it will be freed from |
62 |
* it will be freed from memory. |
* memory. |
63 |
*/ |
*/ |
64 |
class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> { |
class InstrumentResourceManager : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument>, public InstrumentEditorListener { |
65 |
public: |
public: |
66 |
|
InstrumentResourceManager() : Gigs(this) {} |
67 |
virtual ~InstrumentResourceManager() {} |
virtual ~InstrumentResourceManager() {} |
68 |
static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress); |
static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress); |
69 |
|
|
70 |
|
// implementation of derived abstract methods from 'InstrumentManager' |
71 |
|
virtual std::vector<instrument_id_t> Instruments(); |
72 |
|
virtual InstrumentManager::mode_t GetMode(const instrument_id_t& ID); |
73 |
|
virtual void SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode); |
74 |
|
virtual String GetInstrumentName(instrument_id_t ID); |
75 |
|
virtual String GetInstrumentTypeName(instrument_id_t ID); |
76 |
|
virtual String GetInstrumentTypeVersion(instrument_id_t ID); |
77 |
|
virtual void LaunchInstrumentEditor(instrument_id_t ID) throw (InstrumentManagerException); |
78 |
|
|
79 |
|
// implementation of derived abstract method from 'InstrumentEditorListener' |
80 |
|
virtual void OnInstrumentEditorQuit(InstrumentEditor* pSender); |
81 |
|
|
82 |
|
void HandBackInstrument(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, |
83 |
|
::gig::DimensionRegion** dimRegionsInUse); |
84 |
|
void HandBackDimReg(::gig::DimensionRegion* pDimReg); |
85 |
|
|
86 |
protected: |
protected: |
87 |
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
88 |
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
89 |
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
90 |
private: |
private: |
|
struct instr_entry_t { |
|
|
::gig::File* pGig; |
|
|
uint iInstrument; |
|
|
uint MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument |
|
|
}; |
|
|
|
|
91 |
typedef ResourceConsumer< ::gig::File> GigConsumer; |
typedef ResourceConsumer< ::gig::File> GigConsumer; |
92 |
|
|
93 |
class GigResourceManager : public ResourceManager<String, ::gig::File> { |
class GigResourceManager : public ResourceManager<String, ::gig::File> { |
96 |
virtual void Destroy(::gig::File* pResource, void* pArg); |
virtual void Destroy(::gig::File* pResource, void* pArg); |
97 |
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore |
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore |
98 |
public: |
public: |
99 |
|
GigResourceManager(InstrumentResourceManager* parent) : parent(parent) {} |
100 |
virtual ~GigResourceManager() {} |
virtual ~GigResourceManager() {} |
101 |
|
private: |
102 |
|
InstrumentResourceManager* parent; |
103 |
} Gigs; |
} Gigs; |
104 |
|
|
105 |
void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel); |
void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel); |
|
}; |
|
106 |
|
|
107 |
/** |
struct dimreg_info_t { |
108 |
* Will be thrown by the InstrumentResourceManager on errors. |
int refCount; |
109 |
*/ |
::gig::File* file; |
110 |
class InstrumentResourceManagerException : public Exception { |
::RIFF::File* riff; |
111 |
public: |
}; |
112 |
InstrumentResourceManagerException(String msg) : Exception(msg) {} |
Mutex DimRegInfoMutex; ///< protects the DimRegInfo and SampleRefCount maps from concurrent access by the instrument loader and disk threads |
113 |
|
std::map< ::gig::DimensionRegion*, dimreg_info_t> DimRegInfo; ///< contains dimension regions that are still in use but belong to released instrument |
114 |
|
std::map< ::gig::Sample*, int> SampleRefCount; ///< contains samples that are still in use but belong to a released instrument |
115 |
|
|
116 |
|
Mutex InstrumentEditorProxiesMutex; ///< protects the 'InstrumentEditorProxies' map |
117 |
|
std::map<InstrumentEditor*, InstrumentConsumer*> InstrumentEditorProxies; ///< here we store the objects that react on instrument specific notifications on behalf of the respective instrument editor |
118 |
}; |
}; |
119 |
|
|
120 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |