31 |
|
|
32 |
/* Common parameters for now they'll have to be registered here. */ |
/* Common parameters for now they'll have to be registered here. */ |
33 |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive); |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive); |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterSampleRate); |
|
34 |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels); |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels); |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
// *************** ParameterName *************** |
39 |
|
// * |
40 |
|
|
41 |
|
AudioOutputDeviceJack::AudioChannelJack::ParameterName::ParameterName(AudioChannelJack* pChannel) : AudioChannel::ParameterName(ToString(pChannel->ChannelNr)) { |
42 |
|
this->pChannel = pChannel; |
43 |
|
} |
44 |
|
|
45 |
|
void AudioOutputDeviceJack::AudioChannelJack::ParameterName::OnSetValue(String s) { |
46 |
|
String name = "LinuxSampler:" + s; |
47 |
|
if (jack_port_set_name(pChannel->hJackPort, name.c_str())) throw AudioOutputException("Failed to rename JACK port"); |
48 |
|
} |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
// *************** ParameterJackBindings *************** |
53 |
|
// * |
54 |
|
|
55 |
|
AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::ParameterJackBindings(AudioChannelJack* pChannel) : DeviceRuntimeParameterStrings(std::vector<String>()) { |
56 |
|
this->pChannel = pChannel; |
57 |
|
} |
58 |
|
|
59 |
|
String AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::Description() { |
60 |
|
return "Bindings to other JACK clients"; |
61 |
|
} |
62 |
|
|
63 |
|
bool AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::Fix() { |
64 |
|
return false; |
65 |
|
} |
66 |
|
|
67 |
|
std::vector<String> AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::PossibilitiesAsString() { |
68 |
|
const char** pPortNames = jack_get_ports(pChannel->pDevice->hJackClient, NULL, NULL, 0); |
69 |
|
if (!pPortNames) return std::vector<String>(); |
70 |
|
std::vector<String> result; |
71 |
|
for (int i = 0; pPortNames[i]; i++) result.push_back(pPortNames[i]); |
72 |
|
//free(pPortNames); FIXME: pPortNames should be freed here |
73 |
|
return result; |
74 |
|
} |
75 |
|
|
76 |
|
void AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::OnSetValue(std::vector<String> vS) { |
77 |
|
String src_name = "LinuxSampler:" + pChannel->Parameters["NAME"]->Value(); |
78 |
|
for (int i = 0; i < vS.size(); i++) { |
79 |
|
String dst_name = vS[i]; |
80 |
|
if (jack_connect(pChannel->pDevice->hJackClient, src_name.c_str(), dst_name.c_str())) { |
81 |
|
throw AudioOutputException("Jack: Cannot connect to port '" + dst_name + "'"); |
82 |
|
} |
83 |
|
} |
84 |
|
} |
85 |
|
|
86 |
|
String AudioOutputDeviceJack::AudioChannelJack::ParameterJackBindings::Name() { |
87 |
|
return "JACK_BINDINGS"; |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
// *************** AudioChannelJack *************** |
93 |
|
// * |
94 |
|
|
95 |
|
AudioOutputDeviceJack::AudioChannelJack::AudioChannelJack(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException) : AudioChannel(ChannelNr, CreateJackPort(ChannelNr, pDevice), pDevice->uiMaxSamplesPerCycle) { |
96 |
|
this->pDevice = pDevice; |
97 |
|
this->ChannelNr = ChannelNr; |
98 |
|
Parameters["NAME"] = new ParameterName(this); |
99 |
|
Parameters["JACK_BINDINGS"] = new ParameterJackBindings(this); |
100 |
|
} |
101 |
|
|
102 |
|
AudioOutputDeviceJack::AudioChannelJack::~AudioChannelJack() { |
103 |
|
//TODO: delete JACK port |
104 |
|
} |
105 |
|
|
106 |
|
float* AudioOutputDeviceJack::AudioChannelJack::CreateJackPort(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException) { |
107 |
|
String port_id = "LinuxSampler:" + ToString(ChannelNr); |
108 |
|
hJackPort = jack_port_register(pDevice->hJackClient, port_id.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); |
109 |
|
if (!hJackPort) throw AudioOutputException("Jack: Cannot register Jack output port."); |
110 |
|
return (float*) jack_port_get_buffer(hJackPort, pDevice->uiMaxSamplesPerCycle); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
// *************** AudioOutputDeviceJack *************** |
116 |
|
// * |
117 |
|
|
118 |
/** |
/** |
119 |
* Open and initialize connection to the JACK system. |
* Open and initialize connection to the JACK system. |
120 |
* |
* |
122 |
* @throws AudioOutputException on error |
* @throws AudioOutputException on error |
123 |
* @see AcquireChannels() |
* @see AcquireChannels() |
124 |
*/ |
*/ |
125 |
AudioOutputDeviceJack::AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(std::map<String,DeviceCreationParameter*>()) { |
AudioOutputDeviceJack::AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters) { |
126 |
if ((hJackClient = jack_client_new("LinuxSampler")) == 0) |
if ((hJackClient = jack_client_new("LinuxSampler")) == 0) |
127 |
throw AudioOutputException("Seems Jack server not running."); |
throw AudioOutputException("Seems Jack server not running."); |
128 |
|
|
133 |
|
|
134 |
uiMaxSamplesPerCycle = jack_get_buffer_size(hJackClient); |
uiMaxSamplesPerCycle = jack_get_buffer_size(hJackClient); |
135 |
|
|
136 |
#if 0 |
// create audio channels |
137 |
// create amount of audio channels and jack output ports we need for autoconnect |
AcquireChannels(((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt()); |
|
for (uint p = 0; p < AutoConnectPorts; p++) { |
|
|
// create jack output port |
|
|
std::stringstream portid; portid << "LinuxSampler:" << p; |
|
|
jack_port_t* newport; |
|
|
if (newport = jack_port_register(hJackClient, portid.str().c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)) { |
|
|
hJackPorts.push_back(newport); |
|
|
} |
|
|
else throw AudioOutputException("Jack: Cannot register Jack output port."); |
|
|
|
|
|
// create LS audio channel |
|
|
std::stringstream chanid; chanid << "Jack:" << p; |
|
|
Channels.push_back(new AudioChannel((float*) jack_port_get_buffer(newport, uiMaxSamplesPerCycle), uiMaxSamplesPerCycle, chanid.str())); |
|
|
|
|
|
// autoconnect port |
|
|
if (jack_connect(hJackClient, portid.str().c_str(), AutoConnectPortIDs[p].c_str())) { |
|
|
std::stringstream err; err << "Jack: Cannot auto connect port " << p; |
|
|
throw AudioOutputException(err.str()); |
|
|
} |
|
|
} |
|
|
#endif |
|
138 |
} |
} |
139 |
|
|
140 |
AudioOutputDeviceJack::~AudioOutputDeviceJack() { |
AudioOutputDeviceJack::~AudioOutputDeviceJack() { |
|
// destroy all audio channels |
|
|
for (int c = 0; c < Channels.size(); c++) delete Channels[c]; |
|
141 |
// destroy jack client |
// destroy jack client |
142 |
jack_client_close(hJackClient); |
jack_client_close(hJackClient); |
143 |
} |
} |
169 |
csIsPlaying.PushAndUnlock(false); |
csIsPlaying.PushAndUnlock(false); |
170 |
} |
} |
171 |
|
|
172 |
void AudioOutputDeviceJack::AcquireChannels(uint uiChannels) { |
AudioChannel* AudioOutputDeviceJack::CreateChannel(uint ChannelNr) { |
173 |
if (uiChannels > this->Channels.size()) { |
return new AudioChannelJack(ChannelNr, this); |
|
for (int c = this->Channels.size(); c < uiChannels; c++) { |
|
|
// create new jack output port |
|
|
std::stringstream portid; portid << "LinuxSampler:" << c; |
|
|
jack_port_t* newport; |
|
|
if (newport = jack_port_register(hJackClient, portid.str().c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)) { |
|
|
hJackPorts.push_back(newport); |
|
|
} |
|
|
else throw AudioOutputException("Jack: Cannot register Jack output port."); |
|
|
|
|
|
// create LS audio channel |
|
|
std::stringstream chanid; chanid << "Jack:" << c; |
|
|
Channels.push_back(new AudioChannel((float*) jack_port_get_buffer(newport, uiMaxSamplesPerCycle), uiMaxSamplesPerCycle, chanid.str())); |
|
|
} |
|
|
} |
|
174 |
} |
} |
175 |
|
|
176 |
uint AudioOutputDeviceJack::MaxSamplesPerCycle() { |
uint AudioOutputDeviceJack::MaxSamplesPerCycle() { |
194 |
} |
} |
195 |
|
|
196 |
String AudioOutputDeviceJack::Version() { |
String AudioOutputDeviceJack::Version() { |
197 |
String s = "$Revision: 1.10 $"; |
String s = "$Revision: 1.11 $"; |
198 |
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 |
199 |
} |
} |
200 |
|
|