3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 Christian Schoenebeck * |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
64 |
} |
} |
65 |
} |
} |
66 |
|
|
67 |
void SamplerChannel::SetEngineType(String EngineType) throw (LinuxSamplerException) { |
void SamplerChannel::SetEngineType(String EngineType) throw (Exception) { |
68 |
dmsg(2,("SamplerChannel: Assigning engine type...")); |
dmsg(2,("SamplerChannel: Assigning engine type...")); |
69 |
|
|
70 |
// create new engine channel |
// create new engine channel |
71 |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
72 |
if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type"); |
if (!pNewEngineChannel) throw Exception("Unknown engine type"); |
73 |
|
|
74 |
//FIXME: hack to allow fast retrieval of engine channel's sampler channel index |
//FIXME: hack to allow fast retrieval of engine channel's sampler channel index |
75 |
pNewEngineChannel->iSamplerChannelIndex = Index(); |
pNewEngineChannel->iSamplerChannelIndex = Index(); |
141 |
} |
} |
142 |
|
|
143 |
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) { |
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) { |
144 |
if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned."); |
if (!pDevice) throw Exception("No MIDI input device assigned."); |
145 |
|
|
146 |
// get old and new midi input port |
// get old and new midi input port |
147 |
MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
160 |
if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel); |
if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel); |
161 |
// Ooops. |
// Ooops. |
162 |
if (pNewMidiInputPort == NULL) |
if (pNewMidiInputPort == NULL) |
163 |
throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + "."); |
throw Exception("There is no MIDI input port with index " + ToString(iMidiPort) + "."); |
164 |
} |
} |
165 |
|
|
166 |
EngineChannel* SamplerChannel::GetEngineChannel() { |
EngineChannel* SamplerChannel::GetEngineChannel() { |
199 |
} |
} |
200 |
} |
} |
201 |
|
|
202 |
throw LinuxSamplerException("Internal error: SamplerChannel index not found"); |
throw Exception("Internal error: SamplerChannel index not found"); |
203 |
} |
} |
204 |
|
|
205 |
MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) { |
MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) { |
249 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i)); |
250 |
return pChannel; |
return pChannel; |
251 |
} |
} |
252 |
throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index."); |
throw Exception("Internal error: could not find unoccupied sampler channel index."); |
253 |
} |
} |
254 |
|
|
255 |
// we have not reached the index limit so we just add the channel past the highest index |
// we have not reached the index limit so we just add the channel past the highest index |
289 |
return AudioOutputDeviceFactory::AvailableDrivers(); |
return AudioOutputDeviceFactory::AvailableDrivers(); |
290 |
} |
} |
291 |
|
|
292 |
AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
std::vector<String> Sampler::AvailableMidiInputDrivers() { |
293 |
|
return MidiInputDeviceFactory::AvailableDrivers(); |
294 |
|
} |
295 |
|
|
296 |
|
std::vector<String> Sampler::AvailableEngineTypes() { |
297 |
|
return EngineFactory::AvailableEngineTypes(); |
298 |
|
} |
299 |
|
|
300 |
|
AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception) { |
301 |
// create new device |
// create new device |
302 |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
303 |
|
|
328 |
return mMidiInputDevices; |
return mMidiInputDevices; |
329 |
} |
} |
330 |
|
|
331 |
void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException) { |
void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) { |
332 |
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
333 |
for (; iter != mAudioOutputDevices.end(); iter++) { |
for (; iter != mAudioOutputDevices.end(); iter++) { |
334 |
if (iter->second == pDevice) { |
if (iter->second == pDevice) { |
335 |
// check if there are still sampler engines connected to this device |
// check if there are still sampler engines connected to this device |
336 |
for (uint i = 0; i < SamplerChannels(); i++) |
for (uint i = 0; i < SamplerChannels(); i++) |
337 |
if (GetSamplerChannel(i)->GetAudioOutputDevice() == pDevice) throw LinuxSamplerException("Sampler channel " + ToString(i) + " is still connected to the audio output device."); |
if (GetSamplerChannel(i)->GetAudioOutputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the audio output device."); |
338 |
|
|
339 |
// disable device |
// disable device |
340 |
pDevice->Stop(); |
pDevice->Stop(); |
350 |
} |
} |
351 |
} |
} |
352 |
|
|
353 |
void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException) { |
void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) { |
354 |
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
355 |
for (; iter != mMidiInputDevices.end(); iter++) { |
for (; iter != mMidiInputDevices.end(); iter++) { |
356 |
if (iter->second == pDevice) { |
if (iter->second == pDevice) { |
357 |
// check if there are still sampler engines connected to this device |
// check if there are still sampler engines connected to this device |
358 |
for (uint i = 0; i < SamplerChannels(); i++) |
for (uint i = 0; i < SamplerChannels(); i++) |
359 |
if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw LinuxSamplerException("Sampler channel " + ToString(i) + " is still connected to the midi input device."); |
if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the midi input device."); |
360 |
|
|
361 |
// disable device |
// disable device |
362 |
pDevice->StopListen(); |
pDevice->StopListen(); |
372 |
} |
} |
373 |
} |
} |
374 |
|
|
375 |
MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception) { |
376 |
// create new device |
// create new device |
377 |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
378 |
|
|