Add an option to auto-connect JACK ports
This commit is contained in:
+14
-11
@@ -384,15 +384,17 @@ void JackPlayback::start()
|
||||
if(jack_activate(mClient))
|
||||
throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to activate client"};
|
||||
|
||||
const char **ports{jack_get_ports(mClient, nullptr, nullptr,
|
||||
JackPortIsPhysical|JackPortIsInput)};
|
||||
if(ports == nullptr)
|
||||
const char *devname{mDevice->DeviceName.c_str()};
|
||||
if(ConfigValueBool(devname, "jack", "connect-ports").value_or(true))
|
||||
{
|
||||
jack_deactivate(mClient);
|
||||
throw al::backend_exception{ALC_INVALID_DEVICE, "No physical playback ports found"};
|
||||
}
|
||||
std::mismatch(mPort.begin(), mPort.end(), ports,
|
||||
[this](const jack_port_t *port, const char *pname) -> bool
|
||||
const char **ports{jack_get_ports(mClient, nullptr, nullptr,
|
||||
JackPortIsPhysical|JackPortIsInput)};
|
||||
if(ports == nullptr)
|
||||
{
|
||||
jack_deactivate(mClient);
|
||||
throw al::backend_exception{ALC_INVALID_DEVICE, "No physical playback ports found"};
|
||||
}
|
||||
auto connect_port = [this](const jack_port_t *port, const char *pname) -> bool
|
||||
{
|
||||
if(!port) return false;
|
||||
if(!pname)
|
||||
@@ -404,8 +406,10 @@ void JackPlayback::start()
|
||||
ERR("Failed to connect output port \"%s\" to \"%s\"\n", jack_port_name(port),
|
||||
pname);
|
||||
return true;
|
||||
});
|
||||
jack_free(ports);
|
||||
};
|
||||
std::mismatch(mPort.begin(), mPort.end(), ports, connect_port);
|
||||
jack_free(ports);
|
||||
}
|
||||
|
||||
/* Reconfigure buffer metrics in case the server changed it since the reset
|
||||
* (it won't change again after jack_activate), then allocate the ring
|
||||
@@ -415,7 +419,6 @@ void JackPlayback::start()
|
||||
mDevice->UpdateSize = jack_get_buffer_size(mClient);
|
||||
mDevice->BufferSize = mDevice->UpdateSize * 2;
|
||||
|
||||
const char *devname{mDevice->DeviceName.c_str()};
|
||||
ALuint bufsize{ConfigValueUInt(devname, "jack", "buffer-size").value_or(mDevice->UpdateSize)};
|
||||
bufsize = maxu(NextPowerOf2(bufsize), mDevice->UpdateSize);
|
||||
mDevice->BufferSize = bufsize + mDevice->UpdateSize;
|
||||
|
||||
@@ -469,6 +469,12 @@
|
||||
# backend, opening devices, etc).
|
||||
#spawn-server = false
|
||||
|
||||
## connect-ports:
|
||||
# Attempts to automatically connect the client ports to physical server ports.
|
||||
# Client ports that fail to connect will leave the remaining channels
|
||||
# unconnected and silent (the device format won't change to accommodate).
|
||||
#connect-ports = true
|
||||
|
||||
## buffer-size:
|
||||
# Sets the update buffer size, in samples, that the backend will keep buffered
|
||||
# to handle the server's real-time processing requests. This value must be a
|
||||
|
||||
Reference in New Issue
Block a user