Compare commits

..

3 Commits

Author SHA1 Message Date
Christopher Arndt 4ccfad3911 refactor: getJackStatusErrorString helper function
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
2022-10-06 16:45:24 +02:00
Christopher Arndt b28d4fbfa6 fix: add missing cleanup to example
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
2022-10-06 16:45:24 +02:00
Christopher Arndt b8d5119d03 refactor: some style improvemnts in examples
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
2022-10-06 16:45:24 +02:00
2 changed files with 30 additions and 32 deletions

View File

@ -28,7 +28,7 @@ proc portConnected(portA: PortIdT; portB: PortIdT; connect: cint; arg: pointer)
else: else:
echo "Port B: <unknown>" echo "Port B: <unknown>"
echo "Action: " $ (if connect > 0: "connect" else: "disconnect") echo "Action: " & (if connect > 0: "connect" else: "disconnect")
jclient = clientOpen("jacket_port_register", NoStartServer.ord, addr status) jclient = clientOpen("jacket_port_register", NoStartServer.ord, addr status)
@ -39,6 +39,8 @@ if jclient == nil:
echo getJackStatusErrorString(status) echo getJackStatusErrorString(status)
quit 1 quit 1
setControlCHook(cleanup)
discard portRegister(jclient, "in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0) discard portRegister(jclient, "in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0)
discard portRegister(jclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0) discard portRegister(jclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0)

View File

@ -457,37 +457,33 @@ proc setInfoFunction*(infoCallback: JackInfoCallback) {.importc: "jack_set_info_
proc getJackStatusErrorString*(status: cint): string = proc getJackStatusErrorString*(status: cint): string =
# Get JACK error status as string. # Get JACK error status as string.
if status == ord(Success): if status == Success.ord:
return "" return ""
var errorString = "" if status == Failure.ord:
if status == ord(Failure):
# Only include this generic message if no other error status is set # Only include this generic message if no other error status is set
errorString = "Overall operation failed" result = "Overall operation failed"
if (status and ord(InvalidOption)) > 0: if (status and InvalidOption.ord) > 0:
errorString &= "\nThe operation contained an invalid and unsupported option" result.add("\nThe operation contained an invalid and unsupported option")
if (status and ord(NameNotUnique)) > 0: if (status and NameNotUnique.ord) > 0:
errorString &= "\nThe desired client name was not unique" result.add("\nThe desired client name was not unique")
if (status and ord(ServerStarted)) > 0: if (status and ServerStarted.ord) > 0:
errorString &= "\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 ord(ServerFailed)) > 0: if (status and ServerFailed.ord) > 0:
errorString &= "\nUnable to connect to the JACK server" result.add("\nUnable to connect to the JACK server")
if (status and ord(ServerError)) > 0: if (status and ServerError.ord) > 0:
errorString &= "\nCommunication error with the JACK server" result.add("\nCommunication error with the JACK server")
if (status and ord(NoSuchClient)) > 0: if (status and NoSuchClient.ord) > 0:
errorString &= "\nRequested client does not exist" result.add("\nRequested client does not exist")
if (status and ord(LoadFailure)) > 0: if (status and LoadFailure.ord) > 0:
errorString &= "\nUnable to load internal client" result.add("\nUnable to load internal client")
if (status and ord(InitFailure)) > 0: if (status and InitFailure.ord) > 0:
errorString &= "\nUnable to initialize client" result.add("\nUnable to initialize client")
if (status and ord(ShmFailure)) > 0: if (status and ShmFailure.ord) > 0:
errorString &= "\nUnable to access shared memory" result.add("\nUnable to access shared memory")
if (status and ord(VersionError)) > 0: if (status and VersionError.ord) > 0:
errorString &= "\nClient's protocol version does not match" result.add("\nClient's protocol version does not match")
if (status and ord(BackendError)) > 0: if (status and BackendError.ord) > 0:
errorString &= "\nBackend Error" result.add("\nBackend Error")
if (status and ord(ClientZombie)) > 0: if (status and ClientZombie.ord) > 0:
errorString &= "\nClient is being shutdown against its will" result.add("\nClient is being shutdown against its will")
return errorString