From 73fca249f23bd236a00f1e9282709f456c23b9b8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 3 Mar 2019 17:04:01 +0100 Subject: .config/SuperCollider/functions.scd: Adding simple helper functions to connect/disconnect JACK clients by name:port_name. Adding function to add additional channels (above hardware in and outputs), which automatically increments Server.local.options.num{In,Out}putBuschannels. --- .config/SuperCollider/functions.scd | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .config/SuperCollider/functions.scd diff --git a/.config/SuperCollider/functions.scd b/.config/SuperCollider/functions.scd new file mode 100644 index 0000000..fecd1a0 --- /dev/null +++ b/.config/SuperCollider/functions.scd @@ -0,0 +1,58 @@ +postln('Loading custom functions.'); + +/* + * JACK specific helper functions + * + */ +// disconnect a port +~jackDisconnectPort = { + arg source, sourceChannel, destination, destinationChannel; + ("jack_disconnect "++source++":"++sourceChannel++" "++destination++":"++destinationChannel).unixCmd({ + arg exitCode; + if(exitCode != 0, { + postln("Disconnecting "++source++":"++sourceChannel++" from "++destination++":"++destinationChannel++" was unsuccessful!"); + }); + }); +}; + +// connect a port +~jackConnectPort = { + arg source, sourceChannel, destination, destinationChannel; + ("jack_connect "++source++":"++sourceChannel++" "++destination++":"++destinationChannel).unixCmd({ + arg exitCode; + if(exitCode != 0, { + postln("Connecting "++source++":"++sourceChannel++" from "++destination++":"++destinationChannel++" was unsuccessful!"); + }); + }); +}; + +// returns the amount of ports of a given client +~jackClientPorts = { + arg clientName; + ("jack_lsp "++clientName++"| wc -l").unixCmdGetStdOut.asInt; +}; + +// adds one or more channels to Server.local.options.num{In,Out}putBusChannels +// makes the tuple available in ~additionalChannels Dictionairy +~addAdditionalChannels = { + arg type, name, channels; + if( name.class == Symbol && channels.isArray, { + switch (type, + \input, { + ~additionalChannels.at(\inputs).add(name -> channels); + postln("Added additional input channels for '"++name++"': "++channels.asString); + Server.local.options.numInputBusChannels = Server.local.options.numInputBusChannels + channels.size; + postln("Setting numInputBusChannels to "++Server.local.options.numInputBusChannels); + }, + \output, { + ~additionalChannels.at(\outputs).add(name -> channels); + postln("Added additional output channels for '"++name++"': "++channels.asString); + Server.local.options.numOutputBusChannels = Server.local.options.numOutputBusChannels + channels.size; + postln("Setting numOutputBusChannels to "++Server.local.options.numOutputBusChannels); + }, + { postln("Expecting \input or \output as type, got "++type.asString); + }); + },{ + postln('Expecting type Symbol for name and type Array for channels.'); + }); +}; -- cgit v1.2.3-70-g09d2