2022-10-06 04:18:57 +02:00
|
|
|
import std/[strformat, os]
|
|
|
|
|
|
|
|
import jacket
|
|
|
|
|
|
|
|
var client: ClientTPtr
|
|
|
|
var status: cint
|
|
|
|
|
|
|
|
proc cleanup() {.noconv.} =
|
|
|
|
echo "Cleaning up..."
|
2022-10-06 04:42:42 +02:00
|
|
|
|
2022-10-06 04:18:57 +02:00
|
|
|
if client != nil:
|
|
|
|
discard deactivate(client)
|
|
|
|
discard clientClose(client)
|
|
|
|
client = nil
|
2022-10-06 04:42:42 +02:00
|
|
|
|
2022-10-06 04:18:57 +02:00
|
|
|
quit 0
|
|
|
|
|
2022-10-06 05:10:49 +02:00
|
|
|
proc portConnected(portA: PortIdT; portB: PortIdT; connect: cint; arg: pointer) {.cdecl.} =
|
2022-10-06 04:18:57 +02:00
|
|
|
let portAPtr = portById(client, portA)
|
|
|
|
let portBPtr = portById(client, portB)
|
|
|
|
|
|
|
|
if portAPtr != nil:
|
|
|
|
let portAName = portName(portAPtr)
|
|
|
|
echo fmt"Port A: {portAName}"
|
|
|
|
else:
|
|
|
|
echo "Port A: <unknown>"
|
|
|
|
|
|
|
|
if portAPtr != nil:
|
|
|
|
let portBName = portName(portBPtr)
|
|
|
|
echo fmt"Port B: {portBName}"
|
|
|
|
else:
|
|
|
|
echo "Port B: <unknown>"
|
|
|
|
|
2022-10-06 04:42:42 +02:00
|
|
|
let action = if connect > 0: "connect" else: "disconnect"
|
2022-10-06 04:18:57 +02:00
|
|
|
echo fmt"Action: {action}"
|
|
|
|
|
|
|
|
|
|
|
|
client = clientOpen("jacket_port_register", ord(NoStartServer) or ord(UseExactName), addr status)
|
|
|
|
|
|
|
|
echo fmt"Server status: {status}"
|
|
|
|
|
|
|
|
if client == nil:
|
|
|
|
echo getJackStatusErrorString(status)
|
|
|
|
quit 1
|
|
|
|
|
|
|
|
discard portRegister(client, "in_1", JACK_DEFAULT_AUDIO_TYPE, ord(PortIsInput), 0)
|
|
|
|
discard portRegister(client, "out_1", JACK_DEFAULT_AUDIO_TYPE, ord(PortIsOutput), 0)
|
|
|
|
|
|
|
|
if setPortConnectCallback(client, portConnected, nil) != 0:
|
|
|
|
echo "Error: could not set port connection callback."
|
|
|
|
|
|
|
|
discard activate(client)
|
|
|
|
|
|
|
|
while true:
|
|
|
|
sleep(50)
|
|
|
|
|
|
|
|
cleanup()
|