From 61b0405f3e4aa57db571c6d9e3838dd53c4a355f Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Tue, 6 Jun 2023 02:40:02 +0200 Subject: [PATCH] feat: make callback functions user arg optional Signed-off-by: Christopher Arndt --- examples/jacket_midi_print.nim | 4 +-- examples/jacket_midi_print_thread.nim | 4 +-- examples/jacket_midi_print_threading.nim | 4 +-- examples/jacket_port_connect_cb.nim | 4 +-- examples/jacket_port_register.nim | 2 +- examples/jacket_sine.nim | 2 +- src/jacket.nim | 34 ++++++++++++------------ 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/jacket_midi_print.nim b/examples/jacket_midi_print.nim index f207ff5..ab23561 100644 --- a/examples/jacket_midi_print.nim +++ b/examples/jacket_midi_print.nim @@ -66,12 +66,12 @@ proc main() = setSignalProc(signalCb, SIGABRT, SIGHUP, SIGINT, SIGQUIT, SIGTERM) # Register JACK callbacks - if jclient.setProcessCallback(processCb, nil) != 0: + if jclient.setProcessCallback(processCb) != 0: error "Could not set JACK process callback function." cleanup() quit QuitFailure - jclient.onShutdown(shutdownCb, nil) + jclient.onShutdown(shutdownCb) # Create output port midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0) diff --git a/examples/jacket_midi_print_thread.nim b/examples/jacket_midi_print_thread.nim index c803556..f77d3b2 100644 --- a/examples/jacket_midi_print_thread.nim +++ b/examples/jacket_midi_print_thread.nim @@ -102,12 +102,12 @@ proc main() = createThread(midiEventPrinter, midiEventPrinterProc) # Register JACK callbacks - if jclient.setProcessCallback(processCb, nil) != 0: + if jclient.setProcessCallback(processCb) != 0: error "Could not set JACK process callback function." cleanup() quit QuitFailure - jclient.onShutdown(shutdownCb, nil) + jclient.onShutdown(shutdownCb) # Create output port midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0) diff --git a/examples/jacket_midi_print_threading.nim b/examples/jacket_midi_print_threading.nim index e11fe1f..6fa0508 100644 --- a/examples/jacket_midi_print_threading.nim +++ b/examples/jacket_midi_print_threading.nim @@ -107,12 +107,12 @@ proc main() = createThread(midiEventPrinter, midiEventPrinterProc) # Register JACK callbacks - if jclient.setProcessCallback(processCb, nil) != 0: + if jclient.setProcessCallback(processCb) != 0: error "Could not set JACK process callback function." cleanup() quit QuitFailure - jclient.onShutdown(shutdownCb, nil) + jclient.onShutdown(shutdownCb) # Create output port midiPort = jclient.portRegister("midi_in", JACK_DEFAULT_MIDI_TYPE, PortIsInput.ord, 0) diff --git a/examples/jacket_port_connect_cb.nim b/examples/jacket_port_connect_cb.nim index 4eafe47..2104a74 100644 --- a/examples/jacket_port_connect_cb.nim +++ b/examples/jacket_port_connect_cb.nim @@ -60,10 +60,10 @@ else: discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0) discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0) -if jclient.setPortConnectCallback(portConnected, nil) != 0: +if jclient.setPortConnectCallback(portConnected) != 0: error "Error: could not set JACK port connection callback." -jclient.onShutdown(shutdownCb, nil) +jclient.onShutdown(shutdownCb) if jclient.activate() == 0: while not exitSignalled: diff --git a/examples/jacket_port_register.nim b/examples/jacket_port_register.nim index 7852b7f..7e3f989 100644 --- a/examples/jacket_port_register.nim +++ b/examples/jacket_port_register.nim @@ -43,7 +43,7 @@ else: discard jclient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0) discard jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0) -jclient.onShutdown(shutdownCb, nil) +jclient.onShutdown(shutdownCb) while not exitSignalled: sleep(50) diff --git a/examples/jacket_sine.nim b/examples/jacket_sine.nim index f392124..9cfa9d6 100644 --- a/examples/jacket_sine.nim +++ b/examples/jacket_sine.nim @@ -98,7 +98,7 @@ if jclient.setProcessCallback(processCb, osc.addr) != 0: cleanup() quit QuitFailure -jclient.onShutdown(shutdownCb, nil) +jclient.onShutdown(shutdownCb) # Create output port outPort = jclient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0) diff --git a/src/jacket.nim b/src/jacket.nim index 4bf74fe..bad9604 100644 --- a/src/jacket.nim +++ b/src/jacket.nim @@ -328,51 +328,51 @@ void jack_internal_client_close (const char *client_name) # ------------------------------- Callbacks ------------------------------- -proc setProcessThread*(client: ClientP; threadCallback: ThreadCallback; arg: pointer): cint {. +proc setProcessThread*(client: ClientP; threadCallback: ThreadCallback; arg: pointer = nil): cint {. importc: "jack_set_process_thread".} -proc setThreadInitCallback*(client: ClientP; threadInitCallback: ThreadInitCallback; arg: pointer): cint {. +proc setThreadInitCallback*(client: ClientP; threadInitCallback: ThreadInitCallback; arg: pointer = nil): cint {. importc: "jack_set_thread_init_callback".} -proc onShutdown*(client: ClientP; shutdownCallback: ShutdownCallback; arg: pointer) {. +proc onShutdown*(client: ClientP; shutdownCallback: ShutdownCallback; arg: pointer = nil) {. importc: "jack_on_shutdown".} -proc onInfoShutdown*(client: ClientP; shutdownCallback: InfoShutdownCallback; arg: pointer) {. +proc onInfoShutdown*(client: ClientP; shutdownCallback: InfoShutdownCallback; arg: pointer = nil) {. importc: "jack_on_info_shutdown".} -proc setProcessCallback*(client: ClientP; processCallback: ProcessCallback; arg: pointer): cint {. +proc setProcessCallback*(client: ClientP; processCallback: ProcessCallback; arg: pointer = nil): cint {. importc: "jack_set_process_callback".} -proc setFreewheelCallback*(client: ClientP; freewheelCallback: FreewheelCallback; arg: pointer): cint {. +proc setFreewheelCallback*(client: ClientP; freewheelCallback: FreewheelCallback; arg: pointer = nil): cint {. importc: "jack_set_freewheel_callback".} -proc setBufferSizeCallback*(client: ClientP; bufsizeCallback: BufferSizeCallback; arg: pointer): cint {. +proc setBufferSizeCallback*(client: ClientP; bufsizeCallback: BufferSizeCallback; arg: pointer = nil): cint {. importc: "jack_set_buffer_size_callback".} -proc setSampleRateCallback*(client: ClientP; srateCallback: SampleRateCallback; arg: pointer): cint {. +proc setSampleRateCallback*(client: ClientP; srateCallback: SampleRateCallback; arg: pointer = nil): cint {. importc: "jack_set_sample_rate_callback".} proc setClientRegistrationCallback*(client: ClientP; registrationCallback: ClientRegistrationCallback; - arg: pointer): cint {. + arg: pointer = nil): cint {. importc: "jack_set_client_registration_callback".} proc setPortRegistrationCallback*(client: ClientP; registrationCallback: PortRegistrationCallback; - arg: pointer): cint {. + arg: pointer = nil): cint {. importc: "jack_set_port_registration_callback".} -proc setPortConnectCallback*(client: ClientP; connectCallback: PortConnectCallback; arg: pointer): cint {. +proc setPortConnectCallback*(client: ClientP; connectCallback: PortConnectCallback; arg: pointer = nil): cint {. importc: "jack_set_port_connect_callback".} -proc setPortRenameCallback*(client: ClientP; renameCallback: PortRenameCallback; arg: pointer): cint {. +proc setPortRenameCallback*(client: ClientP; renameCallback: PortRenameCallback; arg: pointer = nil): cint {. importc: "jack_set_port_rename_callback".} proc setGraphOrderCallback*(client: ClientP; graphCallback: GraphOrderCallback; a3: pointer): cint {. importc: "jack_set_graph_order_callback".} -proc setXrunCallback*(client: ClientP; xrunCallback: XRunCallback; arg: pointer): cint {. +proc setXrunCallback*(client: ClientP; xrunCallback: XRunCallback; arg: pointer = nil): cint {. importc: "jack_set_xrun_callback".} -proc setLatencyCallback*(client: ClientP; latencyCallback: LatencyCallback; arg: pointer): cint {. +proc setLatencyCallback*(client: ClientP; latencyCallback: LatencyCallback; arg: pointer = nil): cint {. importc: "jack_set_latency_callback".} @@ -617,7 +617,7 @@ proc getTime*(): Time {.importc: "jack_get_time".} proc releaseTimebase*(client: ClientP): cint {.importc: "jack_release_timebase".} # int jack_set_sync_callback (jack_client_t *client, JackSyncCallback sync_callback, void *arg) -proc setSyncCallback*(client: ClientP; syncCallback: SyncCallback; arg: pointer): cint {. +proc setSyncCallback*(client: ClientP; syncCallback: SyncCallback; arg: pointer = nil): cint {. importc: "jack_set_sync_callback".} # int jack_set_sync_timeout (jack_client_t *client, jack_time_t timeout) @@ -628,7 +628,7 @@ proc setSyncTimeout*(client: ClientP; timeout: Time): cint {.importc: "jack_set_ # JackTimebaseCallback timebase_callback, # void *arg) proc setTimebaseCallback*(client: ClientP; conditional: cint; timebaseCallback: TimebaseCallback; - arg: pointer): cint {. + arg: pointer = nil): cint {. importc: "jack_set_timebase_callback".} # int jack_transport_locate (jack_client_t *client, jack_nframes_t frame) @@ -722,7 +722,7 @@ proc removeProperties*(client: ClientP, subject: Uuid): cint {.importc: "jack_re proc removeAllProperties*(client: ClientP): cint {.importc: "jack_remove_all_properties".} # int jack_set_property_change_callback (jack_client_t* client, JackPropertyChangeCallback callback, void* arg) -proc setPropertyChangeCallback*(client: ClientP, callback: PropertyChangeCallback, arg: pointer): cint {. +proc setPropertyChangeCallback*(client: ClientP, callback: PropertyChangeCallback, arg: pointer = nil): cint {. importc: "jack_set_property_change_callback".}