feat: implement converters for enums
Allows to pass enum values directly for cint/culong params Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
parent
0bfb23b6ff
commit
9645542176
|
@ -58,10 +58,10 @@ proc processCb(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
|
|||
outbuf[i] = inpbuf[i]
|
||||
|
||||
# Create JACK Client ptr
|
||||
jackClient = clientOpen("passthru", NullOption.ord, status.addr)
|
||||
jackClient = clientOpen("passthru", NullOption, status.addr)
|
||||
# Register audio input and output ports
|
||||
inpPort = jackClient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
|
||||
outPort = jackClient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
||||
inpPort = jackClient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput, 0)
|
||||
outPort = jackClient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0)
|
||||
# Set JACK callbacks
|
||||
jackClient.onShutdown(shutdownCb)
|
||||
discard jackClient.setProcessCallback(processCb, nil)
|
||||
|
|
|
@ -11,7 +11,7 @@ proc errorCb(msg: cstring) {.cdecl.} =
|
|||
|
||||
addHandler(log)
|
||||
setErrorFunction(errorCb)
|
||||
var jclient = clientOpen("jacket_info", NullOption.ord, status.addr)
|
||||
var jclient = clientOpen("jacket_info", NullOption, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
|
|
@ -14,7 +14,7 @@ proc errorCb(msg: cstring) {.cdecl.} =
|
|||
|
||||
addHandler(log)
|
||||
setErrorFunction(errorCb)
|
||||
let jclient = clientOpen("jacket_property", NullOption.ord, status.addr)
|
||||
let jclient = clientOpen("jacket_property", NullOption, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
|
|
@ -52,7 +52,7 @@ proc main() =
|
|||
|
||||
# Create JACK client
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
@ -74,7 +74,7 @@ proc main() =
|
|||
jclient.onShutdown(shutdownCb)
|
||||
|
||||
# Create output port
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0)
|
||||
|
||||
# Activate JACK client ...
|
||||
if jclient.activate() == 0:
|
||||
|
|
|
@ -110,7 +110,7 @@ proc processCb*(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
|
|||
proc main() =
|
||||
# Create JACK client
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
@ -138,7 +138,7 @@ proc main() =
|
|||
jclient.onShutdown(shutdownCb)
|
||||
|
||||
# Create output port
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0)
|
||||
|
||||
# Activate JACK client ...
|
||||
if jclient.activate() == 0:
|
||||
|
|
|
@ -83,7 +83,7 @@ proc main() =
|
|||
|
||||
# Create JACK client
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
@ -110,7 +110,7 @@ proc main() =
|
|||
jclient.onShutdown(shutdownCb)
|
||||
|
||||
# Create output port
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0)
|
||||
|
||||
# Activate JACK client ...
|
||||
if jclient.activate() == 0:
|
||||
|
|
|
@ -73,22 +73,21 @@ proc midiEventPrinterProc() =
|
|||
stdout.flushFile()
|
||||
|
||||
proc processCb*(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
|
||||
var event: MidiEvent
|
||||
let inbuf = portGetBuffer(midiPort, nFrames)
|
||||
let count = midiGetEventCount(inbuf)
|
||||
|
||||
for i in 0..<count:
|
||||
if midiEventGet(event.addr, inbuf, i.uint32) == 0:
|
||||
midiEventChan.send(event)
|
||||
# trySend does not work: https://github.com/nim-lang/threading/issues/30
|
||||
#if not midiEventChan.trySend(event):
|
||||
# warn "MIDI event channel overflow!"
|
||||
if not midiEventChan.trySend(event):
|
||||
warn "MIDI event channel overflow!"
|
||||
|
||||
proc main() =
|
||||
addHandler(log)
|
||||
|
||||
# Create JACK client
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer.ord or UseExactName.ord, status.addr)
|
||||
jclient = clientOpen("jacket_midi_print", NoStartServer or UseExactName, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
@ -115,7 +114,7 @@ proc main() =
|
|||
jclient.onShutdown(shutdownCb)
|
||||
|
||||
# Create output port
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0)
|
||||
midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput, 0)
|
||||
|
||||
# Activate JACK client ...
|
||||
if jclient.activate() == 0:
|
||||
|
|
|
@ -45,7 +45,7 @@ proc portConnected(portA: PortId; portB: PortId; connect: cint; arg: pointer) {.
|
|||
|
||||
addHandler(log)
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_port_connect_cb", NoStartServer.ord, status.addr)
|
||||
jclient = clientOpen("jacket_port_connect_cb", NoStartServer, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
@ -57,8 +57,8 @@ when defined(windows):
|
|||
else:
|
||||
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
||||
|
||||
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("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput, 0)
|
||||
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0)
|
||||
|
||||
if jclient.setPortConnectCallback(portConnected) != 0:
|
||||
error "Error: could not set JACK port connection callback."
|
||||
|
|
|
@ -28,7 +28,7 @@ proc shutdownCb(arg: pointer = nil) {.cdecl.} =
|
|||
|
||||
addHandler(log)
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_port_register", NoStartServer.ord or UseExactName.ord, status.addr)
|
||||
jclient = clientOpen("jacket_port_register", NoStartServer or UseExactName, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
@ -40,8 +40,8 @@ when defined(windows):
|
|||
else:
|
||||
setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM)
|
||||
|
||||
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("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput, 0)
|
||||
discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0)
|
||||
|
||||
jclient.onShutdown(shutdownCb)
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ addHandler(log)
|
|||
|
||||
# Create JACK client
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_sine", NoStartServer.ord or UseExactName.ord, status.addr)
|
||||
jclient = clientOpen("jacket_sine", NoStartServer or UseExactName, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
@ -101,7 +101,7 @@ if jclient.setProcessCallback(processCb, osc.addr) != 0:
|
|||
jclient.onShutdown(shutdownCb)
|
||||
|
||||
# Create output port
|
||||
outPort = jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)
|
||||
outPort = jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput, 0)
|
||||
|
||||
# Activate JACK client ...
|
||||
if jclient.activate() == 0:
|
||||
|
|
|
@ -16,7 +16,7 @@ proc errorCb(msg: cstring) {.cdecl.} =
|
|||
|
||||
addHandler(log)
|
||||
setErrorFunction(errorCb)
|
||||
jclient = clientOpen("jacket_info", NullOption.ord, status.addr)
|
||||
jclient = clientOpen("jacket_info", NullOption, status.addr)
|
||||
debug "JACK server status: " & $status
|
||||
|
||||
if jclient == nil:
|
||||
|
|
|
@ -232,6 +232,12 @@ type
|
|||
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 ------------------------------
|
||||
|
||||
# void jack_get_version(int *major_ptr, int *minor_ptr, int *micro_ptr, int *proto_ptr)
|
||||
|
@ -739,33 +745,33 @@ proc setInfoFunction*(infoCallback: InfoCallback) {.importc: "jack_set_info_func
|
|||
|
||||
proc getJackStatusErrorString*(status: cint): string =
|
||||
# Get JACK error status as string.
|
||||
if status == Success.ord:
|
||||
if status == Success:
|
||||
return ""
|
||||
|
||||
if status == Failure.ord:
|
||||
if status == Failure:
|
||||
# Only include this generic message if no other error status is set
|
||||
result = "Overall operation failed"
|
||||
if (status and InvalidOption.ord) > 0:
|
||||
if (status and InvalidOption) > 0:
|
||||
result.add("\nThe operation contained an invalid and unsupported option")
|
||||
if (status and NameNotUnique.ord) > 0:
|
||||
if (status and NameNotUnique) > 0:
|
||||
result.add("\nThe desired client name was not unique")
|
||||
if (status and ServerStarted.ord) > 0:
|
||||
if (status and ServerStarted) > 0:
|
||||
result.add("\nThe JACK server was started as a result of this operation")
|
||||
if (status and ServerFailed.ord) > 0:
|
||||
if (status and ServerFailed) > 0:
|
||||
result.add("\nUnable to connect to the JACK server")
|
||||
if (status and ServerError.ord) > 0:
|
||||
if (status and ServerError) > 0:
|
||||
result.add("\nCommunication error with the JACK server")
|
||||
if (status and NoSuchClient.ord) > 0:
|
||||
if (status and NoSuchClient) > 0:
|
||||
result.add("\nRequested client does not exist")
|
||||
if (status and LoadFailure.ord) > 0:
|
||||
if (status and LoadFailure) > 0:
|
||||
result.add("\nUnable to load internal client")
|
||||
if (status and InitFailure.ord) > 0:
|
||||
if (status and InitFailure) > 0:
|
||||
result.add("\nUnable to initialize client")
|
||||
if (status and ShmFailure.ord) > 0:
|
||||
if (status and ShmFailure) > 0:
|
||||
result.add("\nUnable to access shared memory")
|
||||
if (status and VersionError.ord) > 0:
|
||||
if (status and VersionError) > 0:
|
||||
result.add("\nClient's protocol version does not match")
|
||||
if (status and BackendError.ord) > 0:
|
||||
if (status and BackendError) > 0:
|
||||
result.add("\nBackend Error")
|
||||
if (status and ClientZombie.ord) > 0:
|
||||
if (status and ClientZombie) > 0:
|
||||
result.add("\nClient is being shutdown against its will")
|
||||
|
|
Loading…
Reference in New Issue