21 |
#include "InstrumentManagerThread.h" |
#include "InstrumentManagerThread.h" |
22 |
|
|
23 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
24 |
|
#include "EngineChannelFactory.h" |
25 |
|
|
26 |
namespace LinuxSampler { |
namespace LinuxSampler { |
27 |
|
|
99 |
int InstrumentManagerThread::Main() { |
int InstrumentManagerThread::Main() { |
100 |
while (true) { |
while (true) { |
101 |
|
|
102 |
#if CONFIG_PTHREAD_TESTCANCEL |
#if CONFIG_PTHREAD_TESTCANCEL |
103 |
TestCancel(); |
TestCancel(); |
104 |
#endif |
#endif |
105 |
|
|
106 |
while (!queue.empty()) { |
while (!queue.empty()) { |
107 |
command_t cmd; |
command_t cmd; |
115 |
try { |
try { |
116 |
switch (cmd.type) { |
switch (cmd.type) { |
117 |
case command_t::DIRECT_LOAD: |
case command_t::DIRECT_LOAD: |
118 |
|
EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, false); |
119 |
cmd.pEngineChannel->LoadInstrument(); |
cmd.pEngineChannel->LoadInstrument(); |
120 |
|
EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, true); |
121 |
break; |
break; |
122 |
case command_t::INSTR_MODE: |
case command_t::INSTR_MODE: |
123 |
cmd.pManager->SetMode(cmd.instrumentId, cmd.mode); |
cmd.pManager->SetMode(cmd.instrumentId, cmd.mode); |
127 |
} |
} |
128 |
} catch (Exception e) { |
} catch (Exception e) { |
129 |
e.PrintMessage(); |
e.PrintMessage(); |
130 |
|
if (cmd.type == command_t::DIRECT_LOAD) { |
131 |
|
EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, true); |
132 |
|
} |
133 |
} catch (...) { |
} catch (...) { |
134 |
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; |
135 |
|
if (cmd.type == command_t::DIRECT_LOAD) { |
136 |
|
EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, true); |
137 |
|
} |
138 |
} |
} |
139 |
} |
} |
140 |
|
|
145 |
// unlock condition object so it can be turned again by other thread |
// unlock condition object so it can be turned again by other thread |
146 |
conditionJobsLeft.Unlock(); |
conditionJobsLeft.Unlock(); |
147 |
} |
} |
148 |
|
return 0; |
149 |
} |
} |
150 |
|
|
151 |
void InstrumentManagerThread::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) { |
void InstrumentManagerThread::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) { |
152 |
/* |
/* |
153 |
Removing from the queue an eventual scheduled loading of an instrument |
Removing from the queue an eventual scheduled loading of an instrument |
167 |
} |
} |
168 |
pThread->mutex.Unlock(); |
pThread->mutex.Unlock(); |
169 |
} |
} |
170 |
|
|
171 |
|
int InstrumentManagerThread::StopThread() { |
172 |
|
// This is a fix for Mac OS X, where SignalStopThread doesn't |
173 |
|
// wake up a thread waiting for a condition variable. |
174 |
|
SignalStopThread(); // send stop signal, but don't wait |
175 |
|
conditionJobsLeft.Set(true); // wake thread |
176 |
|
return Thread::StopThread(); // then wait for it to cancel |
177 |
|
} |
178 |
|
|
179 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |