SCLOrkJack:
Filter:
SCLOrkTools/Classes (extension) | Quarks > SCLOrkTools

SCLOrkJack
ExtensionExtension

Utility to manage Jack connections (Linux only)

Description

You can use SCLOrkJack to manage and save Jack connections (audio and MIDI). It also contains a few built-in connection presets commonly used in SCLOrk.

The class assumes SuperCollider is running on a Linux computer with the Jack Audio Connection Kit handling both audio and MIDI (the default setup in the Santa Clara Laptop Orchestra). It assumes that ALSA MIDI connections are visible to Jack through the a2jmidid tool (in SCLOrk, our QJackCtl is set to run a2jmidid -e & at start up).

SCLOrkJack is inspired by jmess by Juan Pablo-Caceres and SCJConnection by Marije Baalman. Like SCJConnection, SCLOrkJack is an encapsulation of calls to the command line tools jack_connect, jack_disconnect, and jack_lsp.

Basic usage:

Class Methods

.list

Lists all available ports, prepending "AUDIO:" or "MIDI:" before each line for convenience.

.listPorts

List all available ports but without prepending AUDIO: or MIDI: before each line.

.listSources

Lists all available source ("readable") ports.

.listDestinations

Lists all available destination ("writable") ports.

.listConnections

Lists all existing connections.

.listProperties

Lists all available ports and their respective properties (e.g., 'input' or 'output', 'physical', etc).

.listTypes

Lists all available ports and their respective types (e.g., '32 bit float mono audio', '8 bit raw midi').

.connect

Connects two ports.

Arguments:

from

(String) A valid audio or MIDI port.

to

(String) A valid audio or MIDI port.

.disconnect

Disconnects two ports.

Arguments:

from

(String) A valid audio or MIDI port.

to

(String) A valid audio or MIDI port.

.disconnectAll

Disconnects all current connections, audio and MIDI.

.saveCurrentConnections

Opens a dialog box where you can specify file name and location to save the list of current connections. Contents of the file will simply be an Array. Use extension *.scd like any other SuperCollider file.

.loadConnectionsFromFile

Make connections as specified in the file provided. Typically this will be a file you previously saved using saveCurrentConnections.

Arguments:

path

Optional path to the connections file you wish to load. If a path to a file is not provided, a dialog box will open to select one.

.connectAllFrom

Connects ports from given connections list (audio & midi).

NOTE: Typically you do not need to use this method directly. You can use it if for some reason you do not want to save your connections as a separate file to be reloaded later. In this case, you should write your connectionArray manually; or use saveCurrentConnections to generate and save your connectionArray into a file, then copy the contents of the file and paste it directly as argument to this method.

Arguments:

connectionArray

A List or Array specifying ports to be connected. It should be organized this way: [["from1", "to1", "to2"], ["from2", "to1", "to6"] ...], where each sub-array contains a source at index 0, and corresponding destinations at indices 1 and above.

.preset

Allows user to recall connection presets that are commonly used in SCLOrk.

Arguments:

symbol

A Symbol, name of the preset. Available presets are:

\quneo connects the QuNeo MIDI controller to and from SuperCollider.

\nano connects the Korg nanoKONTROL2 MIDI controller to and from SuperCollider.

\recording connects SuperCollider:out_1 to system:playback_2, and disconnects SuperCollider:out_2 from system:playback_2 (this is the typical SCLOrk set-up for recording, where we send the same mono signal that goes to the single speaker to output 2 of the audio interface, which then goes directly to a recording interface).

.collectPorts

Returns an Array with all available ports.

Returns:

an Array

.collectSources

Like collectPorts, but only returns ports that are sources ("readable"), not destinations ("writable").

Returns:

an Array

.collectConnections

Returns a list of connections. Each sub-array contains a source port (at index 0) followed by the destination port(s) connected to it.

NOTE: Unlike the raw output of jack_lsp -c, which contains duplicate connections (i.e., both from>to and to>from are listed), this method returns a clean list with no duplicates.

Returns:

an Array of Arrays

.collectTypes

Returns an Array of Arrays with all available ports and their types.

.collectProperties

Returns an Array of Arrays with all ports and their corresponding properties.

.a2jTest

Takes a port name as String; checks if it starts with "a2j"; if so, proceed to check whether there is an existing port on this machine that is essentially identical in name, except for possibly a different number in the middle.

NOTE: In Linux, ALSA MIDI connections may change numbers in impredictable ways. A MIDI controller may get the number [20], while at another machine it may get the number [24] instead. Thus, for example, the port name of a nano controller may be a2j:nanoKONTROL2 [20] (capture): nanoKONTROL2 MIDI 1 on my machine, but a2j:nanoKONTROL2 [120] (capture): nanoKONTROL2 MIDI 1 on your machine. If you save connections from one machine and want to replicate them in other machines, this unexpected number change will lead to a failed connection. This method fixed that by comparing the two strings and returning the one that actually exists on the computer at hand.

Arguments:

candidatePort

The port name (as String) that you want to check.

Returns:

(String) the actual existing a2j port, if any; or just candidatePort if not a2j.

.collecta2j

Returns an Array with all available a2j MIDI port names.

.isAvailable

Returns true if the port name currently exists, false otherwise.

Arguments:

port

A port name as a String

Returns:

a Boolean

.waitForMIDI

Checks if MIDIClient.init has been initialized. If not, attempt to initialize it.

Arguments:

onComplete

Function to be evaluated after MIDI has been initialized.

lag

How many seconds to wait for MIDIClient.init to finish initializing (default is 3).

Examples