39 |
pMidiInputDevice = NULL; |
pMidiInputDevice = NULL; |
40 |
pAudioOutputDevice = NULL; |
pAudioOutputDevice = NULL; |
41 |
midiPort = 0; |
midiPort = 0; |
42 |
midiChannel = MidiInputDevice::MidiInputPort::midi_chan_all; |
midiChannel = MidiInputPort::midi_chan_all; |
43 |
iIndex = -1; |
iIndex = -1; |
44 |
} |
} |
45 |
|
|
46 |
SamplerChannel::~SamplerChannel() { |
SamplerChannel::~SamplerChannel() { |
47 |
if (pEngine) { |
if (pEngine) { |
48 |
MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
49 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine); |
50 |
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine); |
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine); |
51 |
delete pEngine; |
delete pEngine; |
66 |
} |
} |
67 |
|
|
68 |
// dereference midi input port. |
// dereference midi input port. |
69 |
MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
70 |
// disconnect old engine |
// disconnect old engine |
71 |
if (pEngine) { |
if (pEngine) { |
72 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine); |
97 |
SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel); |
SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel); |
98 |
} |
} |
99 |
|
|
100 |
void SamplerChannel::SetMidiInputChannel(MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) { |
void SamplerChannel::SetMidiInputChannel(MidiInputPort::midi_chan_t MidiChannel) { |
101 |
SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel); |
SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel); |
102 |
} |
} |
103 |
|
|
104 |
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int MidiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) { |
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel) { |
105 |
// dereference old midi input port. |
// dereference old midi input port. |
106 |
MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
107 |
// disconnect old device port |
// disconnect old device port |
108 |
if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine); |
if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine); |
109 |
// new device, port and channel |
// new device, port and channel |
110 |
pMidiInputDevice = pDevice; |
pMidiInputDevice = pDevice; |
111 |
this->midiPort = MidiPort; |
this->midiPort = iMidiPort; |
112 |
this->midiChannel = MidiChannel; |
this->midiChannel = MidiChannel; |
113 |
// connect new device port |
// connect new device port |
114 |
pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
115 |
if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel); |
if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel); |
116 |
// Ooops. |
// Ooops. |
117 |
if (pMidiInputPort == NULL) |
if (pMidiInputPort == NULL) |
118 |
throw LinuxSamplerException("There is no MIDI input port with index " + ToString(MidiPort) + "."); |
throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + "."); |
119 |
} |
} |
120 |
|
|
121 |
Engine* SamplerChannel::GetEngine() { |
Engine* SamplerChannel::GetEngine() { |
122 |
return pEngine; |
return pEngine; |
123 |
} |
} |
124 |
|
|
125 |
MidiInputDevice::MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() { |
MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() { |
126 |
return this->midiChannel; |
return this->midiChannel; |
127 |
} |
} |
128 |
|
|
129 |
int SamplerChannel::GetMidiInputPort() { |
int SamplerChannel::GetMidiInputPort() { |
130 |
MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
131 |
return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1); |
return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1); |
132 |
} |
} |
133 |
|
|
153 |
throw LinuxSamplerException("Internal error: SamplerChannel index not found"); |
throw LinuxSamplerException("Internal error: SamplerChannel index not found"); |
154 |
} |
} |
155 |
|
|
156 |
MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int MidiPort) { |
MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int iMidiPort) { |
157 |
MidiInputDevice::MidiInputPort *pMidiInputPort = NULL; |
MidiInputPort* pMidiInputPort = NULL; |
158 |
if (pMidiInputDevice) |
if (pMidiInputDevice) |
159 |
pMidiInputPort = pMidiInputDevice->GetPort(MidiPort); |
pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort); |
160 |
return pMidiInputPort; |
return pMidiInputPort; |
161 |
} |
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
// ****************************************************************** |
// ****************************************************************** |
166 |
// * Sampler |
// * Sampler |
167 |
|
|
169 |
} |
} |
170 |
|
|
171 |
Sampler::~Sampler() { |
Sampler::~Sampler() { |
172 |
// delete sampler channels |
Reset(); |
|
{ |
|
|
SamplerChannelMap::iterator iter = mSamplerChannels.begin(); |
|
|
for (; iter != mSamplerChannels.end(); iter++) delete iter->second; |
|
|
} |
|
|
|
|
|
// delete midi input devices |
|
|
{ |
|
|
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
|
|
for (; iter != mMidiInputDevices.end(); iter++) { |
|
|
MidiInputDevice* pDevice = iter->second; |
|
|
pDevice->StopListen(); |
|
|
delete pDevice; |
|
|
} |
|
|
} |
|
|
|
|
|
// delete audio output devices |
|
|
{ |
|
|
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
|
|
for (; iter != mAudioOutputDevices.end(); iter++) { |
|
|
AudioOutputDevice* pDevice = iter->second; |
|
|
pDevice->Stop(); |
|
|
delete pDevice; |
|
|
} |
|
|
} |
|
173 |
} |
} |
174 |
|
|
175 |
uint Sampler::SamplerChannels() { |
uint Sampler::SamplerChannels() { |
321 |
return pDevice; |
return pDevice; |
322 |
} |
} |
323 |
|
|
324 |
|
void Sampler::Reset() { |
325 |
|
// delete sampler channels |
326 |
|
try { |
327 |
|
SamplerChannelMap::iterator iter = mSamplerChannels.begin(); |
328 |
|
for (; iter != mSamplerChannels.end(); iter++) { |
329 |
|
RemoveSamplerChannel(iter->second); |
330 |
|
} |
331 |
|
} |
332 |
|
catch(...) { |
333 |
|
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush; |
334 |
|
exit(EXIT_FAILURE); |
335 |
|
} |
336 |
|
|
337 |
|
// delete midi input devices |
338 |
|
try { |
339 |
|
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
340 |
|
for (; iter != mMidiInputDevices.end(); iter++) { |
341 |
|
DestroyMidiInputDevice(iter->second); |
342 |
|
} |
343 |
|
} |
344 |
|
catch(...) { |
345 |
|
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush; |
346 |
|
exit(EXIT_FAILURE); |
347 |
|
} |
348 |
|
|
349 |
|
// delete audio output devices |
350 |
|
try { |
351 |
|
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
352 |
|
for (; iter != mAudioOutputDevices.end(); iter++) { |
353 |
|
DestroyAudioOutputDevice(iter->second); |
354 |
|
} |
355 |
|
} |
356 |
|
catch(...) { |
357 |
|
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush; |
358 |
|
exit(EXIT_FAILURE); |
359 |
|
} |
360 |
|
} |
361 |
|
|
362 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |