23 |
#include "AudioOutputDeviceJack.h" |
#include "AudioOutputDeviceJack.h" |
24 |
#include "AudioOutputDeviceFactory.h" |
#include "AudioOutputDeviceFactory.h" |
25 |
|
|
26 |
|
#include <errno.h> |
27 |
|
|
28 |
#if HAVE_JACK |
#if HAVE_JACK |
29 |
|
|
30 |
namespace LinuxSampler { |
namespace LinuxSampler { |
45 |
} |
} |
46 |
|
|
47 |
void AudioOutputDeviceJack::AudioChannelJack::ParameterName::OnSetValue(String s) { |
void AudioOutputDeviceJack::AudioChannelJack::ParameterName::OnSetValue(String s) { |
48 |
String name = "LinuxSampler:" + s; |
if (jack_port_set_name(pChannel->hJackPort, s.c_str())) throw AudioOutputException("Failed to rename JACK port"); |
|
if (jack_port_set_name(pChannel->hJackPort, name.c_str())) throw AudioOutputException("Failed to rename JACK port"); |
|
49 |
} |
} |
50 |
|
|
51 |
|
|
66 |
} |
} |
67 |
|
|
68 |
std::vector<String> AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::PossibilitiesAsString() { |
std::vector<String> AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::PossibilitiesAsString() { |
69 |
const char** pPortNames = jack_get_ports(pChannel->pDevice->hJackClient, NULL, NULL, 0); |
const char** pPortNames = jack_get_ports(pChannel->pDevice->hJackClient, NULL, NULL, JackPortIsInput); |
70 |
if (!pPortNames) return std::vector<String>(); |
if (!pPortNames) return std::vector<String>(); |
71 |
std::vector<String> result; |
std::vector<String> result; |
72 |
for (int i = 0; pPortNames[i]; i++) result.push_back(pPortNames[i]); |
for (int i = 0; pPortNames[i]; i++) result.push_back(pPortNames[i]); |
75 |
} |
} |
76 |
|
|
77 |
void AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::OnSetValue(std::vector<String> vS) { |
void AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::OnSetValue(std::vector<String> vS) { |
78 |
String src_name = "LinuxSampler:" + pChannel->Parameters["NAME"]->Value(); |
// TODO: we should remove all existing bindings before we connect new ones here |
79 |
|
String src_name = "LinuxSampler:" + ((DeviceRuntimeParameterString*)pChannel->Parameters["NAME"])->ValueAsString(); |
80 |
for (int i = 0; i < vS.size(); i++) { |
for (int i = 0; i < vS.size(); i++) { |
81 |
String dst_name = vS[i]; |
String dst_name = vS[i]; |
82 |
if (jack_connect(pChannel->pDevice->hJackClient, src_name.c_str(), dst_name.c_str())) { |
int res = jack_connect(pChannel->pDevice->hJackClient, src_name.c_str(), dst_name.c_str()); |
83 |
throw AudioOutputException("Jack: Cannot connect to port '" + dst_name + "'"); |
if (res == EEXIST) throw AudioOutputException("Jack: Connection to port '" + dst_name + "' already established"); |
84 |
} |
else if (res) throw AudioOutputException("Jack: Cannot connect port '" + src_name + "' to port '" + dst_name + "'"); |
85 |
} |
} |
86 |
} |
} |
87 |
|
|
106 |
} |
} |
107 |
|
|
108 |
float* AudioOutputDeviceJack::AudioChannelJack::CreateJackPort(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException) { |
float* AudioOutputDeviceJack::AudioChannelJack::CreateJackPort(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException) { |
109 |
String port_id = "LinuxSampler:" + ToString(ChannelNr); |
String port_id = ToString(ChannelNr); |
110 |
hJackPort = jack_port_register(pDevice->hJackClient, port_id.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); |
hJackPort = jack_port_register(pDevice->hJackClient, port_id.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); |
111 |
if (!hJackPort) throw AudioOutputException("Jack: Cannot register Jack output port."); |
if (!hJackPort) throw AudioOutputException("Jack: Cannot register Jack output port."); |
112 |
return (float*) jack_port_get_buffer(hJackPort, pDevice->uiMaxSamplesPerCycle); |
return (float*) jack_port_get_buffer(hJackPort, pDevice->uiMaxSamplesPerCycle); |
137 |
|
|
138 |
// create audio channels |
// create audio channels |
139 |
AcquireChannels(((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt()); |
AcquireChannels(((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt()); |
140 |
|
|
141 |
|
// finally activate device if desired |
142 |
|
if (((DeviceCreationParameterBool*)Parameters["ACTIVE"])->ValueAsBool()) Play(); |
143 |
} |
} |
144 |
|
|
145 |
AudioOutputDeviceJack::~AudioOutputDeviceJack() { |
AudioOutputDeviceJack::~AudioOutputDeviceJack() { |
199 |
} |
} |
200 |
|
|
201 |
String AudioOutputDeviceJack::Version() { |
String AudioOutputDeviceJack::Version() { |
202 |
String s = "$Revision: 1.11 $"; |
String s = "$Revision: 1.13 $"; |
203 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
204 |
} |
} |
205 |
|
|