25 |
namespace LinuxSampler { |
namespace LinuxSampler { |
26 |
|
|
27 |
InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) { |
InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) { |
28 |
|
eventHandler.pThread = this; |
29 |
} |
} |
30 |
|
|
31 |
InstrumentManagerThread::~InstrumentManagerThread() { |
InstrumentManagerThread::~InstrumentManagerThread() { |
44 |
*/ |
*/ |
45 |
void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) { |
void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) { |
46 |
dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex)); |
dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex)); |
47 |
|
|
48 |
|
static bool listenerRegistered = false; |
49 |
|
if (!listenerRegistered) { |
50 |
|
pEngineChannel->GetSampler()->AddChannelCountListener(&eventHandler); |
51 |
|
listenerRegistered = true; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
// already tell the engine which instrument to load |
// already tell the engine which instrument to load |
56 |
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex); |
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex); |
57 |
|
|
108 |
// grab a new command from the queue |
// grab a new command from the queue |
109 |
mutex.Lock(); |
mutex.Lock(); |
110 |
cmd = queue.front(); |
cmd = queue.front(); |
111 |
|
queue.pop_front(); |
112 |
mutex.Unlock(); |
mutex.Unlock(); |
113 |
|
|
114 |
try { |
try { |
127 |
} catch (...) { |
} catch (...) { |
128 |
std::cerr << "InstrumentManagerThread: some exception occured, could not finish task\n" << std::flush; |
std::cerr << "InstrumentManagerThread: some exception occured, could not finish task\n" << std::flush; |
129 |
} |
} |
|
|
|
|
// remove processed command from queue |
|
|
mutex.Lock(); |
|
|
queue.pop_front(); |
|
|
mutex.Unlock(); |
|
130 |
} |
} |
131 |
|
|
132 |
// nothing left to do, sleep until new jobs arrive |
// nothing left to do, sleep until new jobs arrive |
137 |
conditionJobsLeft.Unlock(); |
conditionJobsLeft.Unlock(); |
138 |
} |
} |
139 |
} |
} |
140 |
|
|
141 |
|
void InstrumentManagerThread::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) { |
142 |
|
/* |
143 |
|
Removing from the queue an eventual scheduled loading of an instrument |
144 |
|
to a sampler channel which is going to be removed. |
145 |
|
*/ |
146 |
|
pThread->mutex.Lock(); |
147 |
|
std::list<command_t>::iterator it; |
148 |
|
for (it = pThread->queue.begin(); it != pThread->queue.end();){ |
149 |
|
if ((*it).type != command_t::DIRECT_LOAD) { ++it; continue; } |
150 |
|
if ((*it).pEngineChannel == pChannel->GetEngineChannel()) { |
151 |
|
it = pThread->queue.erase(it); |
152 |
|
// we don't break here because the same engine channel could |
153 |
|
// occur more than once in the queue, so don't make optimizations |
154 |
|
} else { |
155 |
|
++it; |
156 |
|
} |
157 |
|
} |
158 |
|
pThread->mutex.Unlock(); |
159 |
|
} |
160 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |