From 9645542176536865feb4b8db40bbf949a3ae736f Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Tue, 14 May 2024 23:47:13 +0200 Subject: [PATCH] feat: implement converters for enums Allows to pass enum values directly for cint/culong params Signed-off-by: Christopher Arndt --- README.md | 6 ++-- examples/jacket_info.nim | 2 +- examples/jacket_list_all_properties.nim | 2 +- examples/jacket_midi_print.nim | 4 +-- examples/jacket_midi_print_ringbuffer.nim | 4 +-- examples/jacket_midi_print_thread.nim | 4 +-- examples/jacket_midi_print_threading.nim | 11 ++++---- examples/jacket_port_connect_cb.nim | 6 ++-- examples/jacket_port_register.nim | 6 ++-- examples/jacket_sine.nim | 4 +-- examples/jacket_transport_query.nim | 2 +- src/jacket.nim | 34 +++++++++++++---------- 12 files changed, 45 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 78a6c5a..d8ac621 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/examples/jacket_info.nim b/examples/jacket_info.nim index 993ffc1..ebe0e12 100644 --- a/examples/jacket_info.nim +++ b/examples/jacket_info.nim @@ -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: diff --git a/examples/jacket_list_all_properties.nim b/examples/jacket_list_all_properties.nim index 05cf9ee..c34b2cd 100644 --- a/examples/jacket_list_all_properties.nim +++ b/examples/jacket_list_all_properties.nim @@ -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: diff --git a/examples/jacket_midi_print.nim b/examples/jacket_midi_print.nim index 5568105..40f011c 100644 --- a/examples/jacket_midi_print.nim +++ b/examples/jacket_midi_print.nim @@ -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: diff --git a/examples/jacket_midi_print_ringbuffer.nim b/examples/jacket_midi_print_ringbuffer.nim index 087e202..50c204a 100644 --- a/examples/jacket_midi_print_ringbuffer.nim +++ b/examples/jacket_midi_print_ringbuffer.nim @@ -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: diff --git a/examples/jacket_midi_print_thread.nim b/examples/jacket_midi_print_thread.nim index 2e4e0ea..268b5b7 100644 --- a/examples/jacket_midi_print_thread.nim +++ b/examples/jacket_midi_print_thread.nim @@ -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: diff --git a/examples/jacket_midi_print_threading.nim b/examples/jacket_midi_print_threading.nim index 6cad156..0b63b09 100644 --- a/examples/jacket_midi_print_threading.nim +++ b/examples/jacket_midi_print_threading.nim @@ -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.. 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")