Compare commits

..

No commits in common. "e68223f1e6e625e221631907fb2056f4f75782fb" and "86ce617f1458f1c6843ea7dba6c44d84a5aae119" have entirely different histories.

4 changed files with 67 additions and 75 deletions

View File

@ -1,30 +1,30 @@
import std/logging
import jacket import jacket
var jclient: ClientTPtr var jclient: ClientTPtr
var time: TimeT
var status: cint var status: cint
var log = newConsoleLogger(lvlInfo)
proc errorCb(msg: cstring) {.cdecl.} = jclient = clientOpen("test_jacket", NullOption.ord, addr status)
# Suppress verbose JACK error messges when server is not available by
# default. Pass ``lvlAll`` when creating the logger to enable them.
debug "JACK error: " & $msg
addHandler(log) echo "Server status: " & $status
setErrorFunction(errorCb)
jclient = clientOpen("test_jacket", NullOption.ord, status.addr)
debug "Server status: " & $status
if jclient == nil: if jclient == nil:
error getJackStatusErrorString(status) echo getJackStatusErrorString(status)
quit 1 quit 1
echo("JACK version: ", getVersionString()) time = getTime()
echo("Sample rate: ", jclient.getSampleRate) let ver = getVersionString()
echo("Buffer size: ", jclient.getBufferSize) echo "JACK version: " & $ver
echo("DSP load: ", jclient.cpuLoad, "%") let rate = getSampleRate(jclient)
echo("Server time: ", getTime()) echo "Sample rate: " & $rate
echo("Client name: ", jclient.getClientName) let bufsize = getBufferSize(jclient)
echo("RT enabled: ", if jclient.isRealtime > 0: "yes" else: "no") echo "Buffer size: " & $bufsize
let load = cpuLoad(jclient)
echo "DSP load: " & $load & "%"
echo "Server time: " & $time
let name = getClientName(jclient)
echo "Client name: " & $name
let rt = if isRealtime(jclient) > 0: "yes" else: "no"
echo "RT enabled: " & rt
discard jclient.clientClose discard clientClose(jclient)

View File

@ -1,61 +1,55 @@
import std/[logging, os] import std/os
import jacket import jacket
var jclient: ClientTPtr var jclient: ClientTPtr
var status: cint var status: cint
var log = newConsoleLogger(lvlInfo)
proc errorCb(msg: cstring) {.cdecl.} =
# Suppress verbose JACK error messages when server is not available by
# default. Pass ``lvlAll`` when creating the logger to enable them.
debug "JACK error: " & $msg
proc cleanup() {.noconv.} = proc cleanup() {.noconv.} =
debug "Cleaning up..." echo "Cleaning up..."
if jclient != nil: if jclient != nil:
discard jclient.deactivate() discard deactivate(jclient)
discard jclient.clientClose() discard clientClose(jclient)
jclient = nil jclient = nil
quit QuitSuccess 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 = jclient.portById(portA) let portAPtr = portById(jclient, portA)
let portBPtr = jclient.portById(portB) let portBPtr = portById(jclient, portB)
if portAPtr != nil: if portAPtr != nil:
echo("Port A: ", portName(portAPtr)) echo "Port A: " & $portName(portAPtr)
else: else:
echo "Port A: <unknown>" echo "Port A: <unknown>"
if portAPtr != nil: if portAPtr != nil:
echo("Port B: ", portName(portBPtr)) echo "Port B: " & $portName(portBPtr)
else: else:
echo "Port B: <unknown>" echo "Port B: <unknown>"
echo("Action: ", if connect > 0: "connect" else: "disconnect") echo "Action: " & (if connect > 0: "connect" else: "disconnect")
addHandler(log) jclient = clientOpen("jacket_port_register", NoStartServer.ord, addr status)
setErrorFunction(errorCb)
jclient = clientOpen("jacket_port_register", NoStartServer.ord, status.addr) echo "Server status: " & $status
debug "Server status: " & $status
if jclient == nil: if jclient == nil:
error getJackStatusErrorString(status) echo getJackStatusErrorString(status)
quit 1 quit 1
setControlCHook(cleanup) setControlCHook(cleanup)
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0) discard portRegister(jclient, "in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0) discard portRegister(jclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
if jclient.setPortConnectCallback(portConnected, nil) != 0: if setPortConnectCallback(jclient, portConnected, nil) != 0:
error "Error: could not set port connection callback." echo "Error: could not set port connection callback."
if jclient.activate() == 0: discard activate(jclient)
while true:
sleep(50) while true:
sleep(50)
cleanup() cleanup()

View File

@ -1,37 +1,31 @@
import std/[logging, os] import std/os
import jacket import jacket
var jclient: ClientTPtr var jclient: ClientTPtr
var status: cint var status: cint
var log = newConsoleLogger(lvlInfo)
proc errorCb(msg: cstring) {.cdecl.} =
# Suppress verbose JACK error messages when server is not available by
# default. Pass ``lvlAll`` when creating the logger to enable them.
debug "JACK error: " & $msg
proc cleanup() {.noconv.} = proc cleanup() {.noconv.} =
debug "Cleaning up..." echo "Cleaning up..."
if jclient != nil: if jclient != nil:
discard jclient.clientClose discard clientClose(jclient)
jclient = nil jclient = nil
quit QuitSuccess quit 0
addHandler(log)
setErrorFunction(errorCb) jclient = clientOpen("jacket_port_register", NoStartServer.ord or UseExactName.ord, addr status)
jclient = clientOpen("jacket_port_register", NoStartServer.ord or UseExactName.ord, status.addr)
debug "Server status: " & $status echo "Server status: " & $status
if jclient == nil: if jclient == nil:
error getJackStatusErrorString(status) echo getJackStatusErrorString(status)
quit 1 quit 1
setControlCHook(cleanup) setControlCHook(cleanup)
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0) discard portRegister(jclient, "in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0) discard portRegister(jclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
while true: while true:
sleep(50) sleep(50)

View File

@ -1,22 +1,27 @@
# jacket.nim # jacket.nim
# Possible names/install locations of libjack, according to: # Possible names/install locations of libjack, according to
# https://github.com/x42/weakjack/blob/master/weak_libjack.c#L108 # https://github.com/x42/weakjack/blob/master/weak_libjack.c#L108
#
# MacOS:
# * /usr/local/lib/libjack.dylib
# * /opt/homebrew/lib/libjack.dylib
# * /opt/local/lib/libjack.dylib
# Win:
# * libjack64.dll
# * libjack.dll
# Unix:
# * libjack.so.0
proc getJackLibName: string = proc getJackLibName: string =
when system.hostOS == "windows": when system.hostOS == "windows":
when sizeof(int) == 4: result = "libjack.dll"
result = "libjack.dll"
else:
result = "libjack64.dll"
elif system.hostOS == "macosx": elif system.hostOS == "macosx":
result = "(|/usr/local/lib/|/opt/homebrew/lib/|/opt/local/lib/)libjack.dylib" result = "libjack.dylib"
else: else:
result = "libjack.so.0" result = "libjack.so.0"
{.push dynlib: getJackLibName().} {.push dynlib: getJackLibName().}
# ------------------------------ Constants --------------------------------
const const
JACK_MAX_FRAMES* = (4294967295'i64) JACK_MAX_FRAMES* = (4294967295'i64)
JACK_LOAD_INIT_LIMIT* = 1024 JACK_LOAD_INIT_LIMIT* = 1024
@ -38,6 +43,7 @@ type
PortT = distinct object PortT = distinct object
PortTPtr* = ptr PortT PortTPtr* = ptr PortT
type type
JackOptions* {.size: sizeof(cint) pure.} = enum JackOptions* {.size: sizeof(cint) pure.} = enum
NullOption = 0x00, NullOption = 0x00,
@ -50,7 +56,7 @@ type
type type
JackStatus* {.size: sizeof(cint).} = enum JackStatus* {.size: sizeof(cint).} = enum
Success = 0x00, Success = 0x00
Failure = 0x01, Failure = 0x01,
InvalidOption = 0x02, InvalidOption = 0x02,
NameNotUnique = 0x04, NameNotUnique = 0x04,
@ -449,8 +455,6 @@ proc setInfoFunction*(infoCallback: JackInfoCallback) {.importc: "jack_set_info_
{.pop.} {.pop.}
# --------------------------- Helper functions ----------------------------
proc getJackStatusErrorString*(status: cint): string = proc getJackStatusErrorString*(status: cint): string =
# Get JACK error status as string. # Get JACK error status as string.
if status == Success.ord: if status == Success.ord: