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 * |
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 * |
26 |
|
|
27 |
#include "../../common/global.h" |
#include "../../common/global.h" |
28 |
|
|
29 |
#if DEBUG_HEADERS |
#include <gig.h> |
|
# warning InstrumentResourceManager.h included |
|
|
#endif // DEBUG_HEADERS |
|
30 |
|
|
31 |
#include "../../common/global.h" |
#include "../../common/global.h" |
32 |
#include "../../common/LinuxSamplerException.h" |
#include "../../common/Exception.h" |
33 |
#include "../../common/ResourceManager.h" |
#include "../../common/ResourceManager.h" |
34 |
#include "../../drivers/audio/AudioOutputDevice.h" |
#include "../../drivers/audio/AudioOutputDevice.h" |
35 |
#include "../../lib/fileloader/libgig/gig.h" |
#include "../InstrumentManager.h" |
|
|
|
|
// preload 64k samples = 128kB of data in RAM for 16 bit mono samples |
|
|
#define NUM_RAM_PRELOAD_SAMPLES 32768 |
|
36 |
|
|
37 |
//namespace libgig = gig; |
//namespace libgig = gig; |
38 |
|
|
42 |
|
|
43 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |
44 |
|
|
45 |
|
#include "EngineChannel.h" |
46 |
#include "Engine.h" |
#include "Engine.h" |
47 |
|
|
48 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
49 |
|
|
50 |
// just symbol prototyping |
// just symbol prototyping |
51 |
class Engine; |
class EngineChannel; |
|
|
|
|
/** |
|
|
* 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)); |
|
|
} |
|
|
}; |
|
52 |
|
|
53 |
/** Gig instrument manager |
/** @brief Gig instrument manager |
54 |
* |
* |
55 |
* Manager to share gig instruments between multiple Gigasampler |
* Manager to share gig instruments between multiple Gigasampler |
56 |
* engines. The engines Borrow() instruments when they need them and |
* engine channels. The engine channels Borrow() instruments when they |
57 |
* HandBack() when they don't need them anymore. The |
* need them and HandBack() when they don't need them anymore. The |
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, then |
* instrument if needed, if it's already in use by another engine |
60 |
* it just returns the same resource, if an gig instrument / file is not |
* channel, then it just returns the same resource, if an gig |
61 |
* in use by any engine anymore, then it will be freed from memory. |
* instrument / file is not needed anymore, then it will be freed from |
62 |
|
* memory. |
63 |
*/ |
*/ |
64 |
class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> { |
class InstrumentResourceManager : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument> { |
65 |
public: |
public: |
66 |
virtual ~InstrumentResourceManager() {} |
virtual ~InstrumentResourceManager() {} |
67 |
|
static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress); |
68 |
|
|
69 |
|
// implementation of derived abstract methods from 'InstrumentManager' |
70 |
|
virtual std::vector<instrument_id_t> Instruments(); |
71 |
|
virtual InstrumentManager::mode_t GetMode(const instrument_id_t& ID); |
72 |
|
virtual void SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode); |
73 |
|
virtual float GetVolume(const instrument_id_t& ID); |
74 |
|
virtual void SetVolume(const instrument_id_t& ID, float Volume); |
75 |
|
virtual String GetInstrumentName(instrument_id_t ID); |
76 |
protected: |
protected: |
77 |
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
78 |
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
79 |
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
80 |
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 |
|
|
}; |
|
|
|
|
81 |
typedef ResourceConsumer< ::gig::File> GigConsumer; |
typedef ResourceConsumer< ::gig::File> GigConsumer; |
82 |
|
|
83 |
class GigResourceManager : public ResourceManager<String, ::gig::File> { |
class GigResourceManager : public ResourceManager<String, ::gig::File> { |
85 |
virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg); |
virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg); |
86 |
virtual void Destroy(::gig::File* pResource, void* pArg); |
virtual void Destroy(::gig::File* pResource, void* pArg); |
87 |
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore |
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore |
88 |
public: |
public: |
89 |
virtual ~GigResourceManager() {} |
virtual ~GigResourceManager() {} |
90 |
} Gigs; |
} Gigs; |
91 |
|
|
92 |
void CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine); |
void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel); |
93 |
}; |
}; |
94 |
|
|
95 |
/** |
/** |
96 |
* Will be thrown by the InstrumentResourceManager on errors. |
* Will be thrown by the InstrumentResourceManager on errors. |
97 |
*/ |
*/ |
98 |
class InstrumentResourceManagerException : public LinuxSamplerException { |
class InstrumentResourceManagerException : public Exception { |
99 |
public: |
public: |
100 |
InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {} |
InstrumentResourceManagerException(String msg) : Exception(msg) {} |
101 |
}; |
}; |
102 |
|
|
103 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |