2022-10-06 04:12:22 +02:00
|
|
|
# jacket
|
|
|
|
|
2025-01-20 02:16:38 +01:00
|
|
|
A [Nim] wrapper for the JACK Audio Connection Kit ([JACK]) client side [C API]
|
|
|
|
aka **libjack**.
|
2022-10-06 15:16:57 +02:00
|
|
|
|
|
|
|
|
2022-10-10 20:35:36 +02:00
|
|
|
## Project status
|
|
|
|
|
2023-11-23 17:30:16 +01:00
|
|
|
This software is in *beta status*.
|
2022-10-10 20:35:36 +02:00
|
|
|
|
2025-01-20 02:16:38 +01:00
|
|
|
The majority of JACK client API functions have been wrapped and are functional
|
2025-01-20 02:23:45 +01:00
|
|
|
(see [examples]), but some API parts (e.g. threading) still need wrapping.
|
2025-01-20 02:16:38 +01:00
|
|
|
Others, like the server control or the deprecated session API, will probably
|
|
|
|
not be covered by these bindings. While this project is in beta stage, symbol
|
|
|
|
names may still be changed and things moved around before the first stable
|
|
|
|
release.
|
2022-10-10 20:35:36 +02:00
|
|
|
|
|
|
|
|
2022-10-11 00:15:42 +02:00
|
|
|
## Installation
|
2022-10-10 20:35:36 +02:00
|
|
|
|
|
|
|
* Clone this repository.
|
|
|
|
* Change into the `jacket` directory.
|
|
|
|
* Run [`nimble install`] (or `nimble develop`).
|
2025-01-20 02:16:38 +01:00
|
|
|
* Build the [examples] with `nimble examples`.
|
2023-11-23 17:30:16 +01:00
|
|
|
|
|
|
|
(Some examples need `--threads:on` with Nim < 2.0).
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Here is a very minimal JACK client application, which just passes audio through
|
2025-01-20 02:16:38 +01:00
|
|
|
from its single input port to its output port. Any error checking and handling
|
|
|
|
has been omitted for brevity's sake. See the files in the [examples] directory
|
|
|
|
for more robust example code.
|
2023-11-23 17:30:16 +01:00
|
|
|
|
|
|
|
```nim
|
|
|
|
import std/os
|
|
|
|
import system/ansi_c
|
|
|
|
import jacket
|
|
|
|
|
|
|
|
var
|
|
|
|
status: cint
|
2025-01-20 02:16:38 +01:00
|
|
|
exitSignalled = false
|
|
|
|
inpPort, outPort: Port
|
|
|
|
|
|
|
|
type SampleBuffer = ptr UncheckedArray[DefaultAudioSample]
|
2023-11-23 17:30:16 +01:00
|
|
|
|
|
|
|
proc signalCb(sig: cint) {.noconv.} =
|
|
|
|
exitSignalled = true
|
|
|
|
|
|
|
|
proc shutdownCb(arg: pointer = nil) {.cdecl.} =
|
|
|
|
exitSignalled = true
|
|
|
|
|
|
|
|
proc processCb(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
|
2025-01-20 02:16:38 +01:00
|
|
|
let inpbuf = cast[SampleBuffer](portGetBuffer(inpPort, nFrames))
|
|
|
|
let outbuf = cast[SampleBuffer](portGetBuffer(outPort, nFrames))
|
2023-11-23 17:30:16 +01:00
|
|
|
# copy samples from input to output buffer
|
|
|
|
for i in 0 ..< nFrames:
|
|
|
|
outbuf[i] = inpbuf[i]
|
|
|
|
|
|
|
|
# Create JACK Client ptr
|
2025-01-20 02:16:38 +01:00
|
|
|
var jackClient = clientOpen("passthru", NullOption, status.addr)
|
2023-11-23 17:30:16 +01:00
|
|
|
# Register audio input and output ports
|
2025-01-20 02:16:38 +01:00
|
|
|
inpPort = jackClient.portRegister("in_1", JackDefaultAudioType, PortIsInput, 0)
|
|
|
|
outPort = jackClient.portRegister("out_1", JackDefaultAudioType, PortIsOutput, 0)
|
2023-11-23 17:30:16 +01:00
|
|
|
# Set JACK callbacks
|
|
|
|
jackClient.onShutdown(shutdownCb)
|
2025-01-20 02:16:38 +01:00
|
|
|
jackClient.setProcessCallback(processCb, nil)
|
2023-11-23 17:30:16 +01:00
|
|
|
# Handle POSIX signals
|
|
|
|
c_signal(SIGINT, signalCb)
|
|
|
|
c_signal(SIGTERM, signalCb)
|
|
|
|
# Activate JACK client ...
|
2025-01-20 02:16:38 +01:00
|
|
|
jackClient.activate()
|
2023-11-23 17:30:16 +01:00
|
|
|
|
|
|
|
while not exitSignalled:
|
|
|
|
sleep(50)
|
|
|
|
|
2025-01-20 02:16:38 +01:00
|
|
|
jackClient.clientClose()
|
2023-11-23 17:30:16 +01:00
|
|
|
```
|
2022-10-10 20:35:36 +02:00
|
|
|
|
|
|
|
|
2022-10-06 15:16:57 +02:00
|
|
|
## License
|
|
|
|
|
2025-01-20 02:23:45 +01:00
|
|
|
This software is released under the **MIT License**. See the file
|
2023-11-23 17:30:16 +01:00
|
|
|
[LICENSE.md](./LICENSE.md) for more information.
|
|
|
|
|
|
|
|
Please note that the JACK client library (libjack), which this project wraps,
|
|
|
|
is licensed under the [LGPL-2.1]. This wrapper does not statically or
|
2025-01-20 02:23:45 +01:00
|
|
|
dynamically link to libjack at build time, but only loads it via [dynlib] at
|
2023-11-23 17:30:16 +01:00
|
|
|
run-time.
|
|
|
|
|
|
|
|
Software using this wrapper is, in the opinion of its author, not considered a
|
|
|
|
derivative work of libjack and not required to be released under the LGPL, but
|
|
|
|
no guarantees are made in this regard and users are advised to employ
|
|
|
|
professional legal counsel when in doubt.
|
|
|
|
|
|
|
|
|
|
|
|
## Author
|
|
|
|
|
2025-01-20 02:23:45 +01:00
|
|
|
**jacket** is written by [Christopher Arndt].
|
2022-10-06 15:16:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
[C API]: https://jackaudio.org/api/
|
2023-11-23 17:30:16 +01:00
|
|
|
[Christopher Arndt]: mailto:info@chrisarndt.de
|
2025-01-20 02:23:45 +01:00
|
|
|
[dynlib]: https://nim-lang.org/docs/manual.html#foreign-function-interface-dynlib-pragma-for-import
|
2022-10-10 20:35:36 +02:00
|
|
|
[examples]: ./examples
|
2022-10-06 15:16:57 +02:00
|
|
|
[JACK]: https://jackaudio.org/
|
2023-11-23 17:30:16 +01:00
|
|
|
[LGPL-2.1]: https://spdx.org/licenses/LGPL-2.1-or-later.html
|
|
|
|
[`nimble install`]: https://github.com/nim-lang/nimble#nimble-usage
|
2022-10-06 15:16:57 +02:00
|
|
|
[Nim]: https://nim-lang.org/
|