1 |
/*************************************************************************** |
2 |
* * |
3 |
* Copyright (C) 2005 - 2012 Christian Schoenebeck * |
4 |
* * |
5 |
* This library is free software; you can redistribute it and/or modify * |
6 |
* it under the terms of the GNU General Public License as published by * |
7 |
* the Free Software Foundation; either version 2 of the License, or * |
8 |
* (at your option) any later version. * |
9 |
* * |
10 |
* This library is distributed in the hope that it will be useful, * |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 |
* GNU General Public License for more details. * |
14 |
* * |
15 |
* You should have received a copy of the GNU General Public License * |
16 |
* along with this library; if not, write to the Free Software * |
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
18 |
* MA 02111-1307 USA * |
19 |
***************************************************************************/ |
20 |
|
21 |
#ifndef __LS_INSTRUMENTLOADER_H__ |
22 |
#define __LS_INSTRUMENTLOADER_H__ |
23 |
|
24 |
#include "../common/global.h" |
25 |
#include "../common/Thread.h" |
26 |
#include "../common/Condition.h" |
27 |
#include "../common/Mutex.h" |
28 |
#include "../Sampler.h" |
29 |
#include "../EventListeners.h" |
30 |
#include "InstrumentManager.h" |
31 |
|
32 |
#include <list> |
33 |
|
34 |
namespace LinuxSampler { |
35 |
|
36 |
/** @brief Used by InstrumentManager for background tasks. |
37 |
* |
38 |
* This class is just an encapsulation of tasks that should be done by |
39 |
* the InstrumentManager in the background, that is in a separate thread |
40 |
* without blocking the calling thread. This class is thus not exported |
41 |
* to the API. |
42 |
*/ |
43 |
class InstrumentManagerThread : public Thread { |
44 |
friend class EventHandler; |
45 |
|
46 |
public: |
47 |
InstrumentManagerThread(); |
48 |
void StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel); |
49 |
void StartSettingMode(InstrumentManager* pManager, const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode); |
50 |
virtual ~InstrumentManagerThread(); |
51 |
#if (defined(__APPLE__) && !defined(__x86_64__)) || defined(WIN32) |
52 |
int StopThread(); |
53 |
#endif |
54 |
protected: |
55 |
struct command_t { |
56 |
enum cmd_type_t { |
57 |
DIRECT_LOAD, ///< command was created by a StartNewLoad() call |
58 |
INSTR_MODE ///< command was created by a StartSettingMode() call |
59 |
} type; |
60 |
EngineChannel* pEngineChannel; ///< only for DIRECT_LOAD commands |
61 |
InstrumentManager* pManager; ///< only for INSTR_MODE commands |
62 |
InstrumentManager::instrument_id_t instrumentId; ///< for both DIRECT_LOAD and INSTR_MODE |
63 |
InstrumentManager::mode_t mode; ///< only for INSTR_MODE commands |
64 |
}; |
65 |
|
66 |
// Instance variables. |
67 |
std::list<command_t> queue; ///< queue with commands for loading new instruments. |
68 |
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. |
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 |
83 |
|
84 |
#endif // __LS_INSTRUMENTLOADER_H__ |