63 |
PluginGlobal::~PluginGlobal() { |
PluginGlobal::~PluginGlobal() { |
64 |
pEventThread->StopThread(); |
pEventThread->StopThread(); |
65 |
pLSCPServer->StopThread(); |
pLSCPServer->StopThread(); |
66 |
|
pLSCPServer->RemoveListeners(); |
67 |
|
|
68 |
delete pEventThread; |
delete pEventThread; |
69 |
delete pSampler; |
delete pSampler; |
93 |
|
|
94 |
PluginGlobal* Plugin::global = 0; |
PluginGlobal* Plugin::global = 0; |
95 |
|
|
96 |
Plugin::Plugin() : |
Plugin::Plugin(bool bDoPreInit) : |
97 |
pAudioDevice(0), |
pAudioDevice(0), |
98 |
pMidiDevice(0) { |
pMidiDevice(0) { |
99 |
|
bPreInitDone = false; |
100 |
|
if (bDoPreInit) PreInit(); |
101 |
|
} |
102 |
|
|
103 |
|
void Plugin::PreInit() { |
104 |
|
if (bPreInitDone) return; |
105 |
|
|
106 |
|
bPreInitDone = true; |
107 |
if (!global) { |
if (!global) { |
108 |
global = new PluginGlobal; |
global = new PluginGlobal; |
109 |
} |
} |
110 |
global->RefCount++; |
global->RefCount++; |
111 |
} |
} |
112 |
|
|
113 |
void Plugin::Init(int SampleRate, int FragmentSize) { |
void Plugin::Init(int SampleRate, int FragmentSize, int Channels) { |
114 |
std::map<String, String> params; |
std::map<String, String> params; |
115 |
params["SAMPLERATE"] = ToString(SampleRate); |
params["SAMPLERATE"] = ToString(SampleRate); |
116 |
params["FRAGMENTSIZE"] = ToString(FragmentSize); |
params["FRAGMENTSIZE"] = ToString(FragmentSize); |
117 |
|
if (Channels > 0) params["CHANNELS"] = ToString(Channels); |
118 |
pAudioDevice = dynamic_cast<AudioOutputDevicePlugin*>( |
pAudioDevice = dynamic_cast<AudioOutputDevicePlugin*>( |
119 |
global->pSampler->CreateAudioOutputDevice(AudioOutputDevicePlugin::Name(), params)); |
global->pSampler->CreateAudioOutputDevice(AudioOutputDevicePlugin::Name(), params)); |
120 |
|
|
127 |
RemoveChannels(); |
RemoveChannels(); |
128 |
if (pAudioDevice) global->pSampler->DestroyAudioOutputDevice(pAudioDevice); |
if (pAudioDevice) global->pSampler->DestroyAudioOutputDevice(pAudioDevice); |
129 |
if (pMidiDevice) global->pSampler->DestroyMidiInputDevice(pMidiDevice); |
if (pMidiDevice) global->pSampler->DestroyMidiInputDevice(pMidiDevice); |
130 |
if (--global->RefCount == 0) { |
if (bPreInitDone) { |
131 |
delete global; |
if (--global->RefCount == 0) { |
132 |
global = 0; |
delete global; |
133 |
|
global = 0; |
134 |
|
} |
135 |
} |
} |
136 |
} |
} |
137 |
|
|
167 |
} |
} |
168 |
|
|
169 |
void Plugin::RemoveChannels() { |
void Plugin::RemoveChannels() { |
170 |
|
if(global == NULL) return; |
171 |
|
|
172 |
std::map<uint, SamplerChannel*> channels = global->pSampler->GetSamplerChannels(); |
std::map<uint, SamplerChannel*> channels = global->pSampler->GetSamplerChannels(); |
173 |
|
|
174 |
for (std::map<uint, SamplerChannel*>::iterator iter = channels.begin() ; |
for (std::map<uint, SamplerChannel*>::iterator iter = channels.begin() ; |
175 |
iter != channels.end() ; iter++) { |
iter != channels.end() ; iter++) { |
176 |
if (iter->second->GetAudioOutputDevice() == pAudioDevice) { |
if (iter->second->GetAudioOutputDevice() == pAudioDevice) { |