From 662ef7983bd6f8685d0776f331c722c41bda2321 Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Tue, 22 Nov 2016 20:53:13 +0100 Subject: [PATCH] add Jack option to leave ports unconnected --- soundio/soundio.h | 12 ++++++++++++ src/jack.c | 40 ++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/soundio/soundio.h b/soundio/soundio.h index 9890ba6..093dd9c 100644 --- a/soundio/soundio.h +++ b/soundio/soundio.h @@ -608,6 +608,12 @@ struct SoundIoOutStream { /// to an error code. Possible error codes are: /// * #SoundIoErrorIncompatibleDevice enum SoundIoError layout_error; + + /// Optional: Whether to leave the software outputs unconnected. + /// If this is set to `true`, JACK will not immediately connect the output + /// of this stream to the output ports of the sound card. + /// Defaults to `false`. + bool unconnected; }; /// The size of this struct is not part of the API or ABI. @@ -690,6 +696,12 @@ struct SoundIoInStream { /// If setting the channel layout fails for some reason, this field is set /// to an error code. Possible error codes are: #SoundIoErrorIncompatibleDevice enum SoundIoError layout_error; + + /// Optional: Whether to leave the software inputs unconnected. + /// If this is set to `true`, JACK will not immediately connect the input + /// of this stream to the input ports of the sound card. + /// Defaults to `false`. + bool unconnected; }; /// See also ::soundio_version_major, ::soundio_version_minor, ::soundio_version_patch diff --git a/src/jack.c b/src/jack.c index fff441f..9ff0603 100644 --- a/src/jack.c +++ b/src/jack.c @@ -542,15 +542,17 @@ static enum SoundIoError outstream_start_jack(struct SoundIoPrivate *si, struct if ((err = jack_activate(osj->client))) return SoundIoErrorStreaming; - for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) { - struct SoundIoOutStreamJackPort *osjp = &osj->ports[ch]; - const char *dest_port_name = osjp->dest_port_name; - // allow unconnected ports - if (!dest_port_name) - continue; - const char *source_port_name = jack_port_name(osjp->source_port); - if ((err = jack_connect(osj->client, source_port_name, dest_port_name))) - return SoundIoErrorStreaming; + if (!outstream->unconnected) { + for (int ch = 0; ch < outstream->layout.channel_count; ch += 1) { + struct SoundIoOutStreamJackPort *osjp = &osj->ports[ch]; + const char *dest_port_name = osjp->dest_port_name; + // allow unconnected ports + if (!dest_port_name) + continue; + const char *source_port_name = jack_port_name(osjp->source_port); + if ((err = jack_connect(osj->client, source_port_name, dest_port_name))) + return SoundIoErrorStreaming; + } } return 0; @@ -762,15 +764,17 @@ static enum SoundIoError instream_start_jack(struct SoundIoPrivate *si, struct S if ((err = jack_activate(isj->client))) return SoundIoErrorStreaming; - for (int ch = 0; ch < instream->layout.channel_count; ch += 1) { - struct SoundIoInStreamJackPort *isjp = &isj->ports[ch]; - const char *source_port_name = isjp->source_port_name; - // allow unconnected ports - if (!source_port_name) - continue; - const char *dest_port_name = jack_port_name(isjp->dest_port); - if ((err = jack_connect(isj->client, source_port_name, dest_port_name))) - return SoundIoErrorStreaming; + if (!instream->unconnected) { + for (int ch = 0; ch < instream->layout.channel_count; ch += 1) { + struct SoundIoInStreamJackPort *isjp = &isj->ports[ch]; + const char *source_port_name = isjp->source_port_name; + // allow unconnected ports + if (!source_port_name) + continue; + const char *dest_port_name = jack_port_name(isjp->dest_port); + if ((err = jack_connect(isj->client, source_port_name, dest_port_name))) + return SoundIoErrorStreaming; + } } return 0;