refactor: some style improvemnts in examples
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
parent
eff627e4ec
commit
b8d5119d03
|
@ -1,32 +1,30 @@
|
||||||
import std/strformat
|
|
||||||
|
|
||||||
import jacket
|
import jacket
|
||||||
|
|
||||||
var client: ClientTPtr
|
var jclient: ClientTPtr
|
||||||
var time: TimeT
|
var time: TimeT
|
||||||
var status: cint
|
var status: cint
|
||||||
|
|
||||||
client = clientOpen("test_jacket", ord(NullOption), addr status)
|
jclient = clientOpen("test_jacket", NullOption.ord, addr status)
|
||||||
|
|
||||||
echo fmt"Server status: {status}"
|
echo "Server status: " & $status
|
||||||
|
|
||||||
if client == nil:
|
if jclient == nil:
|
||||||
echo getJackStatusErrorString(status)
|
echo getJackStatusErrorString(status)
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
time = getTime()
|
time = getTime()
|
||||||
var ver = getVersionString()
|
let ver = getVersionString()
|
||||||
echo fmt"JACK version: {ver}"
|
echo "JACK version: " & $ver
|
||||||
var rate = getSampleRate(client)
|
let rate = getSampleRate(jclient)
|
||||||
echo fmt"Sample rate: {rate}"
|
echo "Sample rate: " & $rate
|
||||||
var bufsize = getBufferSize(client)
|
let bufsize = getBufferSize(jclient)
|
||||||
echo fmt"Buffer size: {bufsize}"
|
echo "Buffer size: " & $bufsize
|
||||||
var load = cpuLoad(client)
|
let load = cpuLoad(jclient)
|
||||||
echo fmt"DSP load: {load}%"
|
echo "DSP load: " & $load & "%"
|
||||||
echo fmt"Server time: {time}"
|
echo "Server time: " & $time
|
||||||
var name = getClientName(client)
|
let name = getClientName(jclient)
|
||||||
echo fmt"Client name: {name}"
|
echo "Client name: " & $name
|
||||||
var rt = if isRealtime(client) > 0: "yes" else: "no"
|
let rt = if isRealtime(jclient) > 0: "yes" else: "no"
|
||||||
echo fmt"RT enabled: {rt}"
|
echo "RT enabled: " & rt
|
||||||
|
|
||||||
discard clientClose(client)
|
discard clientClose(jclient)
|
||||||
|
|
|
@ -1,55 +1,51 @@
|
||||||
import std/[strformat, os]
|
import std/os
|
||||||
|
|
||||||
import jacket
|
import jacket
|
||||||
|
|
||||||
var client: ClientTPtr
|
var jclient: ClientTPtr
|
||||||
var status: cint
|
var status: cint
|
||||||
|
|
||||||
proc cleanup() {.noconv.} =
|
proc cleanup() {.noconv.} =
|
||||||
echo "Cleaning up..."
|
echo "Cleaning up..."
|
||||||
|
|
||||||
if client != nil:
|
if jclient != nil:
|
||||||
discard deactivate(client)
|
discard deactivate(jclient)
|
||||||
discard clientClose(client)
|
discard clientClose(jclient)
|
||||||
client = nil
|
jclient = nil
|
||||||
|
|
||||||
quit 0
|
quit 0
|
||||||
|
|
||||||
proc portConnected(portA: PortIdT; portB: PortIdT; connect: cint; arg: pointer) {.cdecl.} =
|
proc portConnected(portA: PortIdT; portB: PortIdT; connect: cint; arg: pointer) {.cdecl.} =
|
||||||
let portAPtr = portById(client, portA)
|
let portAPtr = portById(jclient, portA)
|
||||||
let portBPtr = portById(client, portB)
|
let portBPtr = portById(jclient, portB)
|
||||||
|
|
||||||
if portAPtr != nil:
|
if portAPtr != nil:
|
||||||
let portAName = portName(portAPtr)
|
echo "Port A: " & $portName(portAPtr)
|
||||||
echo fmt"Port A: {portAName}"
|
|
||||||
else:
|
else:
|
||||||
echo "Port A: <unknown>"
|
echo "Port A: <unknown>"
|
||||||
|
|
||||||
if portAPtr != nil:
|
if portAPtr != nil:
|
||||||
let portBName = portName(portBPtr)
|
echo "Port B: " & $portName(portBPtr)
|
||||||
echo fmt"Port B: {portBName}"
|
|
||||||
else:
|
else:
|
||||||
echo "Port B: <unknown>"
|
echo "Port B: <unknown>"
|
||||||
|
|
||||||
let action = if connect > 0: "connect" else: "disconnect"
|
echo "Action: " & (if connect > 0: "connect" else: "disconnect")
|
||||||
echo fmt"Action: {action}"
|
|
||||||
|
|
||||||
|
|
||||||
client = clientOpen("jacket_port_register", ord(NoStartServer) or ord(UseExactName), addr status)
|
jclient = clientOpen("jacket_port_register", NoStartServer.ord, addr status)
|
||||||
|
|
||||||
echo fmt"Server status: {status}"
|
echo "Server status: " & $status
|
||||||
|
|
||||||
if client == nil:
|
if jclient == nil:
|
||||||
echo getJackStatusErrorString(status)
|
echo getJackStatusErrorString(status)
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
discard portRegister(client, "in_1", JACK_DEFAULT_AUDIO_TYPE, ord(PortIsInput), 0)
|
discard portRegister(jclient, "in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
||||||
discard portRegister(client, "out_1", JACK_DEFAULT_AUDIO_TYPE, ord(PortIsOutput), 0)
|
discard portRegister(jclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
||||||
|
|
||||||
if setPortConnectCallback(client, portConnected, nil) != 0:
|
if setPortConnectCallback(jclient, portConnected, nil) != 0:
|
||||||
echo "Error: could not set port connection callback."
|
echo "Error: could not set port connection callback."
|
||||||
|
|
||||||
discard activate(client)
|
discard activate(jclient)
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
sleep(50)
|
sleep(50)
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
import std/[strformat, os]
|
import std/os
|
||||||
|
|
||||||
import jacket
|
import jacket
|
||||||
|
|
||||||
var client: ClientTPtr
|
var jclient: ClientTPtr
|
||||||
var status: cint
|
var status: cint
|
||||||
|
|
||||||
proc cleanup() {.noconv.} =
|
proc cleanup() {.noconv.} =
|
||||||
echo "Cleaning up..."
|
echo "Cleaning up..."
|
||||||
if client != nil:
|
|
||||||
discard clientClose(client)
|
if jclient != nil:
|
||||||
client = nil
|
discard clientClose(jclient)
|
||||||
|
jclient = nil
|
||||||
|
|
||||||
quit 0
|
quit 0
|
||||||
|
|
||||||
|
|
||||||
client = clientOpen("jacket_port_register", ord(NoStartServer) or ord(UseExactName), addr status)
|
jclient = clientOpen("jacket_port_register", NoStartServer.ord or UseExactName.ord, addr status)
|
||||||
|
|
||||||
echo fmt"Server status: {status}"
|
echo "Server status: " & $status
|
||||||
|
|
||||||
if client == nil:
|
if jclient == nil:
|
||||||
echo getJackStatusErrorString(status)
|
echo getJackStatusErrorString(status)
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
setControlCHook(cleanup)
|
setControlCHook(cleanup)
|
||||||
|
|
||||||
discard portRegister(client, "in_1", JACK_DEFAULT_AUDIO_TYPE, ord(PortIsInput), 0)
|
discard portRegister(jclient, "in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
||||||
discard portRegister(client, "out_1", JACK_DEFAULT_AUDIO_TYPE, ord(PortIsOutput), 0)
|
discard portRegister(jclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
sleep(50)
|
sleep(50)
|
||||||
|
|
Loading…
Reference in New Issue