24 |
#include "../common/global.h" |
#include "../common/global.h" |
25 |
#include "../common/Thread.h" |
#include "../common/Thread.h" |
26 |
#include "../common/Condition.h" |
#include "../common/Condition.h" |
27 |
#include "../common/RingBuffer.h" |
#include "../common/Mutex.h" |
28 |
#include "../Sampler.h" |
#include "../Sampler.h" |
29 |
|
#include "../EventListeners.h" |
30 |
#include "InstrumentManager.h" |
#include "InstrumentManager.h" |
31 |
|
|
32 |
/// Maximum numbers of instruments waiting to be loaded by the InstrumentLoader. |
#include <list> |
|
#define INSTRUMENT_LOADER_QUEUE_SIZE 200 |
|
33 |
|
|
34 |
namespace LinuxSampler { |
namespace LinuxSampler { |
35 |
|
|
41 |
* to the API. |
* to the API. |
42 |
*/ |
*/ |
43 |
class InstrumentManagerThread : public Thread { |
class InstrumentManagerThread : public Thread { |
44 |
|
friend class EventHandler; |
45 |
|
|
46 |
public: |
public: |
47 |
InstrumentManagerThread(); |
InstrumentManagerThread(); |
48 |
void StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel); |
void StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel); |
49 |
void StartSettingMode(InstrumentManager* pManager, const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode); |
void StartSettingMode(InstrumentManager* pManager, const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode); |
50 |
virtual ~InstrumentManagerThread(); |
virtual ~InstrumentManagerThread(); |
51 |
|
#ifdef __APPLE__ |
52 |
|
int StopThread(); |
53 |
|
#endif |
54 |
protected: |
protected: |
55 |
struct command_t { |
struct command_t { |
56 |
enum cmd_type_t { |
enum cmd_type_t { |
64 |
}; |
}; |
65 |
|
|
66 |
// Instance variables. |
// Instance variables. |
67 |
RingBuffer<command_t>* pQueue; ///< queue with commands for loading new instruments. |
std::list<command_t> queue; ///< queue with commands for loading new instruments. |
68 |
Condition conditionJobsLeft; ///< synchronizer to block this thread until a new job arrives |
Mutex mutex; ///< for making the queue thread safe |
69 |
|
Condition conditionJobsLeft; ///< synchronizer to block this thread until a new job arrives |
70 |
|
|
71 |
int Main(); ///< Implementation of virtual method from class Thread. |
int Main(); ///< Implementation of virtual method from class Thread. |
72 |
|
private: |
73 |
|
class EventHandler : public ChannelCountAdapter { |
74 |
|
public: |
75 |
|
InstrumentManagerThread* pThread; |
76 |
|
virtual void ChannelToBeRemoved(SamplerChannel* pChannel); |
77 |
|
}; |
78 |
|
|
79 |
|
EventHandler eventHandler; |
80 |
}; |
}; |
81 |
|
|
82 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |