2022-10-06 16:28:25 +02:00
|
|
|
import std/os
|
2022-10-06 04:18:57 +02:00
|
|
|
import jacket
|
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
var jclient: ClientTPtr
|
2022-10-06 04:18:57 +02:00
|
|
|
var status: cint
|
|
|
|
|
|
|
|
proc cleanup() {.noconv.} =
|
|
|
|
echo "Cleaning up..."
|
2022-10-06 04:42:42 +02:00
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
if jclient != nil:
|
|
|
|
discard deactivate(jclient)
|
|
|
|
discard clientClose(jclient)
|
|
|
|
jclient = 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 16:28:25 +02:00
|
|
|
let portAPtr = portById(jclient, portA)
|
|
|
|
let portBPtr = portById(jclient, portB)
|
2022-10-06 04:18:57 +02:00
|
|
|
|
|
|
|
if portAPtr != nil:
|
2022-10-06 16:28:25 +02:00
|
|
|
echo "Port A: " & $portName(portAPtr)
|
2022-10-06 04:18:57 +02:00
|
|
|
else:
|
|
|
|
echo "Port A: <unknown>"
|
|
|
|
|
|
|
|
if portAPtr != nil:
|
2022-10-06 16:28:25 +02:00
|
|
|
echo "Port B: " & $portName(portBPtr)
|
2022-10-06 04:18:57 +02:00
|
|
|
else:
|
|
|
|
echo "Port B: <unknown>"
|
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
echo "Action: " & (if connect > 0: "connect" else: "disconnect")
|
2022-10-06 04:18:57 +02:00
|
|
|
|
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
jclient = clientOpen("jacket_port_register", NoStartServer.ord, addr status)
|
2022-10-06 04:18:57 +02:00
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
echo "Server status: " & $status
|
2022-10-06 04:18:57 +02:00
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
if jclient == nil:
|
2022-10-06 04:18:57 +02:00
|
|
|
echo getJackStatusErrorString(status)
|
|
|
|
quit 1
|
|
|
|
|
2022-10-06 16:41:23 +02:00
|
|
|
setControlCHook(cleanup)
|
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
discard portRegister(jclient, "in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
|
|
|
discard portRegister(jclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
2022-10-06 04:18:57 +02:00
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
if setPortConnectCallback(jclient, portConnected, nil) != 0:
|
2022-10-06 04:18:57 +02:00
|
|
|
echo "Error: could not set port connection callback."
|
|
|
|
|
2022-10-06 16:28:25 +02:00
|
|
|
discard activate(jclient)
|
2022-10-06 04:18:57 +02:00
|
|
|
|
|
|
|
while true:
|
|
|
|
sleep(50)
|
|
|
|
|
|
|
|
cleanup()
|