refactor: more example tweaking and rename all to have 'jacket_' prefix
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
parent
25bf6b31cf
commit
bffc611cdd
|
@ -12,8 +12,8 @@ proc errorCb(msg: cstring) {.cdecl.} =
|
||||||
|
|
||||||
addHandler(log)
|
addHandler(log)
|
||||||
setErrorFunction(errorCb)
|
setErrorFunction(errorCb)
|
||||||
jclient = clientOpen("test_jacket", NullOption.ord, status.addr)
|
jclient = clientOpen("jacket_info", NullOption.ord, status.addr)
|
||||||
debug "Server status: " & $status
|
debug "JACK server status: " & $status
|
||||||
|
|
||||||
if jclient == nil:
|
if jclient == nil:
|
||||||
error getJackStatusErrorString(status)
|
error getJackStatusErrorString(status)
|
|
@ -4,22 +4,28 @@ import signal
|
||||||
|
|
||||||
var jclient: ClientTPtr
|
var jclient: ClientTPtr
|
||||||
var status: cint
|
var status: cint
|
||||||
|
var exitSignalled: bool = false
|
||||||
var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
|
var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
|
||||||
|
|
||||||
|
proc cleanup(sig: cint = 0) =
|
||||||
|
debug "Cleaning up..."
|
||||||
|
if jclient != nil:
|
||||||
|
discard jclient.deactivate()
|
||||||
|
discard jclient.clientClose()
|
||||||
|
jclient = nil
|
||||||
|
|
||||||
proc errorCb(msg: cstring) {.cdecl.} =
|
proc errorCb(msg: cstring) {.cdecl.} =
|
||||||
# Suppress verbose JACK error messages when server is not available by
|
# Suppress verbose JACK error messages when server is not available by
|
||||||
# default. Pass ``lvlAll`` when creating the logger to enable them.
|
# default. Pass ``lvlAll`` when creating the logger to enable them.
|
||||||
debug "JACK error: " & $msg
|
debug "JACK error: " & $msg
|
||||||
|
|
||||||
proc cleanup(sig: cint = 0) {.noconv.} =
|
proc signalCb(sig: cint) {.noconv.} =
|
||||||
debug "Cleaning up..."
|
info "Received signal: " & $sig
|
||||||
|
exitSignalled = true
|
||||||
|
|
||||||
if jclient != nil:
|
proc shutdownCb(arg: pointer = nil) {.cdecl.} =
|
||||||
discard jclient.deactivate()
|
info "JACK server has shut down."
|
||||||
discard jclient.clientClose()
|
exitSignalled = true
|
||||||
jclient = nil
|
|
||||||
|
|
||||||
quit QuitSuccess
|
|
||||||
|
|
||||||
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 = jclient.portById(portA)
|
||||||
|
@ -40,26 +46,28 @@ proc portConnected(portA: PortIdT; portB: PortIdT; connect: cint; arg: pointer)
|
||||||
|
|
||||||
addHandler(log)
|
addHandler(log)
|
||||||
setErrorFunction(errorCb)
|
setErrorFunction(errorCb)
|
||||||
jclient = clientOpen("jacket_port_register", NoStartServer.ord, status.addr)
|
jclient = clientOpen("jacket_port_connect_cb", NoStartServer.ord, status.addr)
|
||||||
debug "Server status: " & $status
|
debug "JACK server status: " & $status
|
||||||
|
|
||||||
if jclient == nil:
|
if jclient == nil:
|
||||||
error getJackStatusErrorString(status)
|
error getJackStatusErrorString(status)
|
||||||
quit 1
|
quit QuitFailure
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
setSignalProc(cleanup, SIGABRT, SIGINT, SIGTERM)
|
setSignalProc(signalCb, SIGABRT, SIGINT, SIGTERM)
|
||||||
else:
|
else:
|
||||||
setSignalProc(cleanup, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
||||||
|
|
||||||
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
||||||
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
||||||
|
|
||||||
if jclient.setPortConnectCallback(portConnected, nil) != 0:
|
if jclient.setPortConnectCallback(portConnected, nil) != 0:
|
||||||
error "Error: could not set port connection callback."
|
error "Error: could not set JACK port connection callback."
|
||||||
|
|
||||||
|
jclient.onShutdown(shutdownCb, nil)
|
||||||
|
|
||||||
if jclient.activate() == 0:
|
if jclient.activate() == 0:
|
||||||
while true:
|
while not exitSignalled:
|
||||||
sleep(50)
|
sleep(50)
|
||||||
|
|
||||||
cleanup() # normally not reached
|
cleanup()
|
|
@ -4,40 +4,48 @@ import jacket
|
||||||
|
|
||||||
var jclient: ClientTPtr
|
var jclient: ClientTPtr
|
||||||
var status: cint
|
var status: cint
|
||||||
|
var exitSignalled: bool = false
|
||||||
var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
|
var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
|
||||||
|
|
||||||
|
proc cleanup(sig: cint = 0) =
|
||||||
|
debug "Cleaning up..."
|
||||||
|
if jclient != nil:
|
||||||
|
discard jclient.clientClose()
|
||||||
|
jclient = nil
|
||||||
|
|
||||||
proc errorCb(msg: cstring) {.cdecl.} =
|
proc errorCb(msg: cstring) {.cdecl.} =
|
||||||
# Suppress verbose JACK error messages when server is not available by
|
# Suppress verbose JACK error messages when server is not available by
|
||||||
# default. Pass ``lvlAll`` when creating the logger to enable them.
|
# default. Pass ``lvlAll`` when creating the logger to enable them.
|
||||||
debug "JACK error: " & $msg
|
debug "JACK error: " & $msg
|
||||||
|
|
||||||
proc cleanup(sig: cint = 0) {.noconv.} =
|
proc signalCb(sig: cint) {.noconv.} =
|
||||||
debug "Cleaning up..."
|
info "Received signal: " & $sig
|
||||||
|
exitSignalled = true
|
||||||
if jclient != nil:
|
|
||||||
discard jclient.clientClose
|
|
||||||
jclient = nil
|
|
||||||
|
|
||||||
quit QuitSuccess
|
proc shutdownCb(arg: pointer = nil) {.cdecl.} =
|
||||||
|
info "JACK server has shut down."
|
||||||
|
exitSignalled = true
|
||||||
|
|
||||||
addHandler(log)
|
addHandler(log)
|
||||||
setErrorFunction(errorCb)
|
setErrorFunction(errorCb)
|
||||||
jclient = clientOpen("jacket_port_register", NoStartServer.ord or UseExactName.ord, status.addr)
|
jclient = clientOpen("jacket_port_register", NoStartServer.ord or UseExactName.ord, status.addr)
|
||||||
debug "Server status: " & $status
|
debug "JACK server status: " & $status
|
||||||
|
|
||||||
if jclient == nil:
|
if jclient == nil:
|
||||||
error getJackStatusErrorString(status)
|
error getJackStatusErrorString(status)
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
setSignalProc(cleanup, SIGABRT, SIGINT, SIGTERM)
|
setSignalProc(signalCb, SIGABRT, SIGINT, SIGTERM)
|
||||||
else:
|
else:
|
||||||
setSignalProc(cleanup, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
||||||
|
|
||||||
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
||||||
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
||||||
|
|
||||||
while true:
|
jclient.onShutdown(shutdownCb, nil)
|
||||||
|
|
||||||
|
while not exitSignalled:
|
||||||
sleep(50)
|
sleep(50)
|
||||||
|
|
||||||
cleanup() # normally not reached
|
cleanup()
|
|
@ -5,6 +5,7 @@ import jacket
|
||||||
var jclient: ClientTPtr
|
var jclient: ClientTPtr
|
||||||
var outPort: PortTPtr
|
var outPort: PortTPtr
|
||||||
var status: cint
|
var status: cint
|
||||||
|
var exitSignalled: bool = false
|
||||||
var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
|
var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -40,24 +41,25 @@ proc tick(osc: SineOscPtr): float =
|
||||||
if osc.phase >= tableSize:
|
if osc.phase >= tableSize:
|
||||||
osc.phase -= tableSize
|
osc.phase -= tableSize
|
||||||
|
|
||||||
proc errorCb(msg: cstring) {.cdecl.} =
|
proc cleanup() =
|
||||||
# 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(sig: cint = 0) {.noconv.} =
|
|
||||||
debug "Cleaning up..."
|
debug "Cleaning up..."
|
||||||
|
|
||||||
if jclient != nil:
|
if jclient != nil:
|
||||||
discard jclient.deactivate()
|
discard jclient.deactivate()
|
||||||
discard jclient.clientClose()
|
discard jclient.clientClose()
|
||||||
jclient = nil
|
jclient = nil
|
||||||
|
|
||||||
quit QuitSuccess
|
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 signalCb(sig: cint) {.noconv.} =
|
||||||
|
info "Received signal: " & $sig
|
||||||
|
exitSignalled = true
|
||||||
|
|
||||||
proc shutdownCb(arg: pointer = nil) {.cdecl.} =
|
proc shutdownCb(arg: pointer = nil) {.cdecl.} =
|
||||||
debug "JACK server has shut down"
|
info "JACK server has shut down."
|
||||||
cleanup()
|
exitSignalled = true
|
||||||
|
|
||||||
proc processCb(nFrames: NFramesT, arg: pointer): cint {.cdecl.} =
|
proc processCb(nFrames: NFramesT, arg: pointer): cint {.cdecl.} =
|
||||||
var outbuf = cast[JackBufferPtr](portGetBuffer(outPort, nFrames))
|
var outbuf = cast[JackBufferPtr](portGetBuffer(outPort, nFrames))
|
||||||
|
@ -86,9 +88,9 @@ var osc = initSineOsc(sampleRate, sineFreq)
|
||||||
|
|
||||||
# Set up signal handlers to clean up on exit
|
# Set up signal handlers to clean up on exit
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
setSignalProc(cleanup, SIGABRT, SIGINT, SIGTERM)
|
setSignalProc(signalCb, SIGABRT, SIGINT, SIGTERM)
|
||||||
else:
|
else:
|
||||||
setSignalProc(cleanup, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
||||||
|
|
||||||
# Register JACK callbacks
|
# Register JACK callbacks
|
||||||
if jclient.setProcessCallback(processCb, osc.addr) != 0:
|
if jclient.setProcessCallback(processCb, osc.addr) != 0:
|
||||||
|
@ -103,7 +105,7 @@ outPort = jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.or
|
||||||
# Activate JACK client ...
|
# Activate JACK client ...
|
||||||
if jclient.activate() == 0:
|
if jclient.activate() == 0:
|
||||||
# ... and keep running until a signal is received
|
# ... and keep running until a signal is received
|
||||||
while true:
|
while not exitSignalled:
|
||||||
sleep(50)
|
sleep(50)
|
||||||
|
|
||||||
cleanup() # normally not reached
|
cleanup()
|
||||||
|
|
Loading…
Reference in New Issue