Compare commits

..

No commits in common. "1444154ca4ad58360a62a99d64519e9980a10a60" and "0bfb23b6ffffc342866f9793506b8408384a5b53" have entirely different histories.

14 changed files with 44 additions and 131 deletions

View File

@ -58,10 +58,10 @@ proc processCb(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
outbuf[i] = inpbuf[i] outbuf[i] = inpbuf[i]
# Create JACK Client ptr # Create JACK Client ptr
jackClient = clientOpen("passthru", NullOption, status.addr) jackClient = clientOpen("passthru", NullOption.ord, status.addr)
# Register audio input and output ports # Register audio input and output ports
inpPort = jackClient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput, 0) inpPort = jackClient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
outPort = jackClient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0) outPort = jackClient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
# Set JACK callbacks # Set JACK callbacks
jackClient.onShutdown(shutdownCb) jackClient.onShutdown(shutdownCb)
discard jackClient.setProcessCallback(processCb, nil) discard jackClient.setProcessCallback(processCb, nil)

View File

@ -11,7 +11,7 @@ proc errorCb(msg: cstring) {.cdecl.} =
addHandler(log) addHandler(log)
setErrorFunction(errorCb) setErrorFunction(errorCb)
var jclient = clientOpen("jacket_info", NullOption, status.addr) var jclient = clientOpen("jacket_info", NullOption.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:

View File

@ -14,7 +14,7 @@ proc errorCb(msg: cstring) {.cdecl.} =
addHandler(log) addHandler(log)
setErrorFunction(errorCb) setErrorFunction(errorCb)
let jclient = clientOpen("jacket_property", NullOption, status.addr) let jclient = clientOpen("jacket_property", NullOption.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:

View File

@ -52,7 +52,7 @@ proc main() =
# Create JACK client # Create JACK client
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr) jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:
@ -74,7 +74,7 @@ proc main() =
jclient.onShutdown(shutdownCb) jclient.onShutdown(shutdownCb)
# Create output port # Create output port
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0) midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
# Activate JACK client ... # Activate JACK client ...
if jclient.activate() == 0: if jclient.activate() == 0:

View File

@ -110,7 +110,7 @@ proc processCb*(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
proc main() = proc main() =
# Create JACK client # Create JACK client
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr) jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:
@ -138,7 +138,7 @@ proc main() =
jclient.onShutdown(shutdownCb) jclient.onShutdown(shutdownCb)
# Create output port # Create output port
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0) midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
# Activate JACK client ... # Activate JACK client ...
if jclient.activate() == 0: if jclient.activate() == 0:

View File

@ -83,7 +83,7 @@ proc main() =
# Create JACK client # Create JACK client
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr) jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:
@ -110,7 +110,7 @@ proc main() =
jclient.onShutdown(shutdownCb) jclient.onShutdown(shutdownCb)
# Create output port # Create output port
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0) midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
# Activate JACK client ... # Activate JACK client ...
if jclient.activate() == 0: if jclient.activate() == 0:

View File

@ -4,13 +4,14 @@
# nimble install threading # nimble install threading
# #
import std/[logging, os, strformat] import std/[isolation, logging, os, strformat]
import threading/channels import threading/channels
import signal import signal
import jacket import jacket
var var
jclient: ClientP jclient: ClientP
event: MidiEvent
midiPort: PortP midiPort: PortP
midiEventChan: Chan[MidiEvent] midiEventChan: Chan[MidiEvent]
midiEventPrinter: Thread[void] midiEventPrinter: Thread[void]
@ -31,8 +32,8 @@ proc cleanup() =
debug "Stopping MIDI event printer thread..." debug "Stopping MIDI event printer thread..."
# Receiving an invalid event causes receiving thread to wake up and # Receiving an invalid event causes receiving thread to wake up and
# break its endless loop # break its endless loop
let event = MidiEvent(size: 0) event.size = 0
discard midiEventChan.trySend(event) midiEventChan.send(event)
midiEventPrinter.joinThread() midiEventPrinter.joinThread()
@ -72,21 +73,22 @@ proc midiEventPrinterProc() =
stdout.flushFile() stdout.flushFile()
proc processCb*(nFrames: NFrames, arg: pointer): cint {.cdecl.} = proc processCb*(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
var event: MidiEvent
let inbuf = portGetBuffer(midiPort, nFrames) let inbuf = portGetBuffer(midiPort, nFrames)
let count = midiGetEventCount(inbuf) let count = midiGetEventCount(inbuf)
for i in 0..<count: for i in 0..<count:
if midiEventGet(event.addr, inbuf, i.uint32) == 0: if midiEventGet(event.addr, inbuf, i.uint32) == 0:
if not midiEventChan.trySend(event): midiEventChan.send(event)
warn "MIDI event channel overflow!" # trySend does not work: https://github.com/nim-lang/threading/issues/30
#if not midiEventChan.trySend(event):
# warn "MIDI event channel overflow!"
proc main() = proc main() =
addHandler(log) addHandler(log)
# Create JACK client # Create JACK client
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr) jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:
@ -113,7 +115,7 @@ proc main() =
jclient.onShutdown(shutdownCb) jclient.onShutdown(shutdownCb)
# Create output port # Create output port
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0) midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
# Activate JACK client ... # Activate JACK client ...
if jclient.activate() == 0: if jclient.activate() == 0:

View File

@ -1,82 +0,0 @@
## Simple JACK client, which just passes audio through
## from its single (mono) input to its single (mono) output.
import std/[logging, os]
import signal
import jacket
var
jclient: ClientP
status: cint
exitSignalled: bool = false
inpPort, outPort: PortP
log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
type JackBufferP = ptr UncheckedArray[DefaultAudioSample]
proc errorCb(msg: cstring) {.cdecl.} =
# Suppress verbose JACK error messages when server is not available by
# default. Compile in non-release mode or pass ``lvlDebug`` or lower
# when creating the logger above to enable them.
debug "JACK error: " & $msg
proc cleanup(sig: cint = 0) =
debug "Cleaning up..."
if jclient != nil:
discard jclient.deactivate()
discard jclient.clientClose()
jclient = nil
proc signalCb(sig: cint) {.noconv.} =
debug "Received signal: " & $sig
exitSignalled = true
proc shutdownCb(arg: pointer = nil) {.cdecl.} =
warn "JACK server has shut down."
exitSignalled = true
proc processCb(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
var inpbuf = cast[JackBufferP](portGetBuffer(inpPort, nFrames))
var outbuf = cast[JackBufferP](portGetBuffer(outPort, nFrames))
# copy samples from input to output buffer
for i in 0 ..< nFrames:
outbuf[i] = inpbuf[i]
addHandler(log)
# Create JACK Client ptr
setErrorFunction(errorCb)
jclient = clientOpen("passthru", NullOption, status.addr)
debug "JACK server status: " & $status
if jclient == nil:
error getJackStatusErrorString(status)
quit 1
# Register audio input and output ports
inpPort = jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput, 0)
outPort = jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0)
# Register JACK callbacks
jclient.onShutdown(shutdownCb)
if jclient.setProcessCallback(processCb, nil) != 0:
error "Could not set JACK process callback function."
cleanup()
quit QuitFailure
# Handle signals
when defined(windows):
setSignalProc(signalCb, SIGABRT, SIGINT, SIGTERM)
else:
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
# Activate JACK client ...
if jclient.activate() == 0:
# ... and keep running until a signal is received
while not exitSignalled:
sleep(50)
# Deactivate client and close server connection
cleanup()

View File

@ -45,7 +45,7 @@ proc portConnected(portA: PortId; portB: PortId; connect: cint; arg: pointer) {.
addHandler(log) addHandler(log)
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_port_connect_cb", NoStartServer, status.addr) jclient = clientOpen("jacket_port_connect_cb", NoStartServer.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:
@ -57,8 +57,8 @@ when defined(windows):
else: else:
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM) setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput, 0) discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0) discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
if jclient.setPortConnectCallback(portConnected) != 0: if jclient.setPortConnectCallback(portConnected) != 0:
error "Error: could not set JACK port connection callback." error "Error: could not set JACK port connection callback."

View File

@ -28,7 +28,7 @@ proc shutdownCb(arg: pointer = nil) {.cdecl.} =
addHandler(log) addHandler(log)
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_port_register", NoStartServer or UseExactName, status.addr) jclient = clientOpen("jacket_port_register", NoStartServer.ord or UseExactName.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:
@ -40,8 +40,8 @@ when defined(windows):
else: else:
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM) setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput, 0) discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0) discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
jclient.onShutdown(shutdownCb) jclient.onShutdown(shutdownCb)

View File

@ -74,7 +74,7 @@ addHandler(log)
# Create JACK client # Create JACK client
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_sine", NoStartServer or UseExactName, status.addr) jclient = clientOpen("jacket_sine", NoStartServer.ord or UseExactName.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:
@ -101,7 +101,7 @@ if jclient.setProcessCallback(processCb, osc.addr) != 0:
jclient.onShutdown(shutdownCb) jclient.onShutdown(shutdownCb)
# Create output port # Create output port
outPort = jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0) outPort = jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
# Activate JACK client ... # Activate JACK client ...
if jclient.activate() == 0: if jclient.activate() == 0:

View File

@ -16,7 +16,7 @@ proc errorCb(msg: cstring) {.cdecl.} =
addHandler(log) addHandler(log)
setErrorFunction(errorCb) setErrorFunction(errorCb)
jclient = clientOpen("jacket_info", NullOption, status.addr) jclient = clientOpen("jacket_info", NullOption.ord, status.addr)
debug "JACK server status: " & $status debug "JACK server status: " & $status
if jclient == nil: if jclient == nil:

View File

@ -1 +0,0 @@
--path:"../src/"

View File

@ -232,12 +232,6 @@ type
PropertyChangeCallback* = proc (subject: Uuid, key: cstring, change: PropertyChange, arg: pointer) {.cdecl.} PropertyChangeCallback* = proc (subject: Uuid, key: cstring, change: PropertyChange, arg: pointer) {.cdecl.}
# ------------------------- Converters for Enums --------------------------
converter jackIntEnumToCInt*[T: JackOptions | JackStatus | LatencyCallbackMode |
PositionBits | TransportState | PropertyChange](x: T): cint = x.ord.cint
converter portFlagsToCULong*(x: PortFlags): culong = x.ord.culong
# ----------------------------- Version info ------------------------------ # ----------------------------- Version info ------------------------------
# void jack_get_version(int *major_ptr, int *minor_ptr, int *micro_ptr, int *proto_ptr) # void jack_get_version(int *major_ptr, int *minor_ptr, int *micro_ptr, int *proto_ptr)
@ -745,33 +739,33 @@ proc setInfoFunction*(infoCallback: InfoCallback) {.importc: "jack_set_info_func
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: if status == Success.ord:
return "" return ""
if status == Failure: if status == Failure.ord:
# Only include this generic message if no other error status is set # Only include this generic message if no other error status is set
result = "Overall operation failed" result = "Overall operation failed"
if (status and InvalidOption) > 0: if (status and InvalidOption.ord) > 0:
result.add("\nThe operation contained an invalid and unsupported option") result.add("\nThe operation contained an invalid and unsupported option")
if (status and NameNotUnique) > 0: if (status and NameNotUnique.ord) > 0:
result.add("\nThe desired client name was not unique") result.add("\nThe desired client name was not unique")
if (status and ServerStarted) > 0: if (status and ServerStarted.ord) > 0:
result.add("\nThe JACK server was started as a result of this operation") result.add("\nThe JACK server was started as a result of this operation")
if (status and ServerFailed) > 0: if (status and ServerFailed.ord) > 0:
result.add("\nUnable to connect to the JACK server") result.add("\nUnable to connect to the JACK server")
if (status and ServerError) > 0: if (status and ServerError.ord) > 0:
result.add("\nCommunication error with the JACK server") result.add("\nCommunication error with the JACK server")
if (status and NoSuchClient) > 0: if (status and NoSuchClient.ord) > 0:
result.add("\nRequested client does not exist") result.add("\nRequested client does not exist")
if (status and LoadFailure) > 0: if (status and LoadFailure.ord) > 0:
result.add("\nUnable to load internal client") result.add("\nUnable to load internal client")
if (status and InitFailure) > 0: if (status and InitFailure.ord) > 0:
result.add("\nUnable to initialize client") result.add("\nUnable to initialize client")
if (status and ShmFailure) > 0: if (status and ShmFailure.ord) > 0:
result.add("\nUnable to access shared memory") result.add("\nUnable to access shared memory")
if (status and VersionError) > 0: if (status and VersionError.ord) > 0:
result.add("\nClient's protocol version does not match") result.add("\nClient's protocol version does not match")
if (status and BackendError) > 0: if (status and BackendError.ord) > 0:
result.add("\nBackend Error") result.add("\nBackend Error")
if (status and ClientZombie) > 0: if (status and ClientZombie.ord) > 0:
result.add("\nClient is being shutdown against its will") result.add("\nClient is being shutdown against its will")