24 |
|
|
25 |
#include "Sampler.h" |
#include "Sampler.h" |
26 |
|
|
27 |
#include "audiodriver/AudioOutputDeviceFactory.h" |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
28 |
#include "mididriver/MidiInputDeviceFactory.h" |
#include "drivers/midi/MidiInputDeviceFactory.h" |
29 |
#include "engines/gig/Engine.h" |
#include "engines/gig/Engine.h" |
30 |
|
|
31 |
namespace LinuxSampler { |
namespace LinuxSampler { |
36 |
SamplerChannel::SamplerChannel(Sampler* pS) { |
SamplerChannel::SamplerChannel(Sampler* pS) { |
37 |
pSampler = pS; |
pSampler = pS; |
38 |
pEngine = NULL; |
pEngine = NULL; |
39 |
pMidiInputPort = NULL; |
pMidiInputDevice = NULL; |
40 |
pAudioOutputDevice = NULL; |
pAudioOutputDevice = NULL; |
41 |
|
midiPort = 0; |
42 |
|
midiChannel = MidiInputDevice::MidiInputPort::midi_chan_all; |
43 |
iIndex = -1; |
iIndex = -1; |
|
midiChannel = MidiInputDevice::MidiInputPort::midi_chan_all; |
|
44 |
} |
} |
45 |
|
|
46 |
SamplerChannel::~SamplerChannel() { |
SamplerChannel::~SamplerChannel() { |
47 |
if (pEngine) { |
if (pEngine) { |
48 |
|
MidiInputDevice::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; |
65 |
throw LinuxSamplerException("Unknown engine type"); |
throw LinuxSamplerException("Unknown engine type"); |
66 |
} |
} |
67 |
|
|
68 |
|
// dereference midi input port. |
69 |
|
MidiInputDevice::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); |
76 |
|
|
77 |
// connect new engine |
// connect new engine |
78 |
pEngine = pNewEngine; |
pEngine = pNewEngine; |
79 |
if (pMidiInputPort) pMidiInputPort->Connect(pNewEngine, (MidiInputDevice::MidiInputPort::midi_chan_t) Index()); |
if (pMidiInputPort) pMidiInputPort->Connect(pNewEngine, this->midiChannel); |
80 |
if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine); |
if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine); |
81 |
dmsg(2,("OK\n")); |
dmsg(2,("OK\n")); |
82 |
} |
} |
84 |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
85 |
// disconnect old device |
// disconnect old device |
86 |
if (pAudioOutputDevice && pEngine) pAudioOutputDevice->Disconnect(pEngine); |
if (pAudioOutputDevice && pEngine) pAudioOutputDevice->Disconnect(pEngine); |
|
|
|
87 |
// connect new device |
// connect new device |
88 |
pAudioOutputDevice = pDevice; |
pAudioOutputDevice = pDevice; |
89 |
if (pEngine) pAudioOutputDevice->Connect(pEngine); |
if (pEngine) pAudioOutputDevice->Connect(pEngine); |
90 |
} |
} |
91 |
|
|
92 |
void SamplerChannel::SetMidiInputPort(MidiInputDevice* pDevice, int midiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) { |
void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) { |
93 |
// disconnect old port |
SetMidiInput(pDevice, this->midiPort, this->midiChannel); |
94 |
if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine); |
} |
95 |
|
|
96 |
// connect new port |
void SamplerChannel::SetMidiInputPort(int MidiPort) { |
97 |
pMidiInputPort = pDevice->GetPort(midiPort); |
SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel); |
98 |
if (!pMidiInputPort) |
} |
99 |
throw LinuxSamplerException("MIDI port doesn't exist"); |
|
100 |
if (pEngine) { |
void SamplerChannel::SetMidiInputChannel(MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) { |
101 |
pMidiInputPort->Connect(pEngine, MidiChannel); |
SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel); |
102 |
this->midiChannel = MidiChannel; |
} |
103 |
} |
|
104 |
|
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int MidiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) { |
105 |
|
// dereference old midi input port. |
106 |
|
MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
107 |
|
// disconnect old device port |
108 |
|
if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine); |
109 |
|
// new device, port and channel |
110 |
|
pMidiInputDevice = pDevice; |
111 |
|
this->midiPort = MidiPort; |
112 |
|
this->midiChannel = MidiChannel; |
113 |
|
// connect new device port |
114 |
|
pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
115 |
|
if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel); |
116 |
|
// Ooops. |
117 |
|
if (pMidiInputPort == NULL) |
118 |
|
throw LinuxSamplerException("There is no MIDI input port with index " + ToString(MidiPort) + "."); |
119 |
} |
} |
120 |
|
|
121 |
Engine* SamplerChannel::GetEngine() { |
Engine* SamplerChannel::GetEngine() { |
122 |
return pEngine; |
return pEngine; |
123 |
} |
} |
124 |
|
|
125 |
MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputPort() { |
MidiInputDevice::MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() { |
126 |
return pMidiInputPort; |
return this->midiChannel; |
127 |
|
} |
128 |
|
|
129 |
|
int SamplerChannel::GetMidiInputPort() { |
130 |
|
MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
131 |
|
return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1); |
132 |
} |
} |
133 |
|
|
134 |
AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() { |
AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() { |
136 |
} |
} |
137 |
|
|
138 |
MidiInputDevice* SamplerChannel::GetMidiInputDevice() { |
MidiInputDevice* SamplerChannel::GetMidiInputDevice() { |
139 |
MidiInputDevice::MidiInputPort* port = GetMidiInputPort(); |
return pMidiInputDevice; |
|
if (!port) |
|
|
return NULL; |
|
|
return port->GetDevice(); |
|
140 |
} |
} |
141 |
|
|
142 |
uint SamplerChannel::Index() { |
uint SamplerChannel::Index() { |
153 |
throw LinuxSamplerException("SamplerChannel index not found"); |
throw LinuxSamplerException("SamplerChannel index not found"); |
154 |
} |
} |
155 |
|
|
156 |
|
MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int MidiPort) { |
157 |
|
MidiInputDevice::MidiInputPort *pMidiInputPort = NULL; |
158 |
|
if (pMidiInputDevice) |
159 |
|
pMidiInputPort = pMidiInputDevice->GetPort(MidiPort); |
160 |
|
return pMidiInputPort; |
161 |
|
} |
162 |
|
|
163 |
// ****************************************************************** |
// ****************************************************************** |
164 |
// * Sampler |
// * Sampler |
234 |
// create new device |
// create new device |
235 |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
236 |
|
|
|
// activate device |
|
|
pDevice->Play(); |
|
|
|
|
237 |
// add new audio device to the audio device list |
// add new audio device to the audio device list |
238 |
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
239 |
if (!mAudioOutputDevices[i]) { |
if (!mAudioOutputDevices[i]) { |
305 |
// create new device |
// create new device |
306 |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters); |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters); |
307 |
|
|
|
// activate device |
|
|
pDevice->Listen(); |
|
|
|
|
308 |
// add new device to the midi device list |
// add new device to the midi device list |
309 |
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
310 |
if (!mMidiInputDevices[i]) { |
if (!mMidiInputDevices[i]) { |