|
1 | 1 | # jacket
|
2 | 2 |
|
3 |
| -A [Nim] wrapper for the [JACK] [C API] |
| 3 | +A [Nim] wrapper for the [JACK] client side [C API] aka *libjack*. |
4 | 4 |
|
5 | 5 |
|
6 | 6 | ## Project status
|
7 | 7 |
|
8 |
| -This software is in *alpha status* and has no official release yet. |
| 8 | +This software is in *beta status*. |
9 | 9 |
|
10 | 10 | The majority of JACK client APIs have been wrapped and are functional (see
|
11 | 11 | [examples]), but some APIs (e.g. threading) still need wrapping. Others, like
|
12 | 12 | the server control or the deprecated session API, will probably not be covered
|
13 |
| -by these bindings. While this project is in alpha or beta stage, symbol names |
14 |
| -may still be changed and things moved around before the first public release. |
15 |
| - |
16 |
| -Also, I plan to add a higher-level abstraction on top of the direct mapping |
17 |
| -from Nim procs and types to C functions and types, probably in the form of |
18 |
| -a JACK client object, which takes care of creating a JACK client instance, |
19 |
| -registering ports and setting up all the callbacks necessary for a well-behaved |
20 |
| -JACK application. |
| 13 | +by these bindings. While this project is in beta stage, symbol names may still |
| 14 | +be changed and things moved around before the first public release. |
21 | 15 |
|
22 | 16 |
|
23 | 17 | ## Installation
|
24 | 18 |
|
25 | 19 | * Clone this repository.
|
26 | 20 | * Change into the `jacket` directory.
|
27 | 21 | * Run [`nimble install`] (or `nimble develop`).
|
28 |
| -* Run the examples with `nim compile --run examples/<example>.nim` (some also |
29 |
| - need `--threads:on`). |
| 22 | +* Run the [examples] with `nim compile --run examples/<example>.nim`. |
| 23 | + |
| 24 | + (Some examples need `--threads:on` with Nim < 2.0). |
| 25 | + |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +Here is a very minimal JACK client application, which just passes audio through |
| 30 | +from its single input port to its output port. |
| 31 | + |
| 32 | +Any error checking and handling has been omitted for brevity's sake. See the |
| 33 | +files in the [examples] directory for more robust example code. |
| 34 | + |
| 35 | +```nim |
| 36 | +import std/os |
| 37 | +import system/ansi_c |
| 38 | +import jacket |
| 39 | +
|
| 40 | +var |
| 41 | + jackClient: ClientP |
| 42 | + status: cint |
| 43 | + exitSignalled: bool = false |
| 44 | + inpPort, outPort: PortP |
| 45 | +type JackBufferP = ptr UncheckedArray[DefaultAudioSample] |
| 46 | +
|
| 47 | +proc signalCb(sig: cint) {.noconv.} = |
| 48 | + exitSignalled = true |
| 49 | +
|
| 50 | +proc shutdownCb(arg: pointer = nil) {.cdecl.} = |
| 51 | + exitSignalled = true |
| 52 | +
|
| 53 | +proc processCb(nFrames: NFrames, arg: pointer): cint {.cdecl.} = |
| 54 | + var inpbuf = cast[JackBufferP](portGetBuffer(inpPort, nFrames)) |
| 55 | + var outbuf = cast[JackBufferP](portGetBuffer(outPort, nFrames)) |
| 56 | + # copy samples from input to output buffer |
| 57 | + for i in 0 ..< nFrames: |
| 58 | + outbuf[i] = inpbuf[i] |
| 59 | +
|
| 60 | +# Create JACK Client ptr |
| 61 | +jackClient = clientOpen("passthru", NullOption.ord, status.addr) |
| 62 | +# Register audio input and output ports |
| 63 | +inpPort = jackClient.portRegister("in_1", JACK_DEFAULT_AUDIO_TYPE, PortIsInput.ord, 0) |
| 64 | +outPort = jackClient.portRegister("out_1", JACK_DEFAULT_AUDIO_TYPE, PortIsOutput.ord, 0) |
| 65 | +# Set JACK callbacks |
| 66 | +jackClient.onShutdown(shutdownCb) |
| 67 | +discard jackClient.setProcessCallback(processCb, nil) |
| 68 | +# Handle POSIX signals |
| 69 | +c_signal(SIGINT, signalCb) |
| 70 | +c_signal(SIGTERM, signalCb) |
| 71 | +# Activate JACK client ... |
| 72 | +discard jackClient.activate() |
| 73 | +
|
| 74 | +while not exitSignalled: |
| 75 | + sleep(50) |
| 76 | +
|
| 77 | +discard jackClient.clientClose() |
| 78 | +``` |
30 | 79 |
|
31 | 80 |
|
32 | 81 | ## License
|
33 | 82 |
|
34 |
| -This software is released under the *MIT License*. See the [LICENSE](./LICENSE) |
35 |
| -file for more information. |
| 83 | +This software is released under the *MIT License*. See the file |
| 84 | +[LICENSE.md](./LICENSE.md) for more information. |
| 85 | + |
| 86 | +Please note that the JACK client library (libjack), which this project wraps, |
| 87 | +is licensed under the [LGPL-2.1]. This wrapper does not statically or |
| 88 | +dynamically link to libjack, but only loads it via the dynamic linker at |
| 89 | +run-time. |
| 90 | + |
| 91 | +Software using this wrapper is, in the opinion of its author, not considered a |
| 92 | +derivative work of libjack and not required to be released under the LGPL, but |
| 93 | +no guarantees are made in this regard and users are advised to employ |
| 94 | +professional legal counsel when in doubt. |
| 95 | + |
| 96 | + |
| 97 | +## Author |
| 98 | + |
| 99 | +*jacket* is written by [Christopher Arndt]. |
36 | 100 |
|
37 | 101 |
|
38 |
| -[`nimble install`]: https://github.com/nim-lang/nimble#nimble-usage |
39 | 102 | [C API]: https://jackaudio.org/api/
|
| 103 | +[Christopher Arndt]: mailto:[email protected] |
40 | 104 | [examples]: ./examples
|
41 | 105 | [JACK]: https://jackaudio.org/
|
| 106 | +[LGPL-2.1]: https://spdx.org/licenses/LGPL-2.1-or-later.html |
| 107 | +[`nimble install`]: https://github.com/nim-lang/nimble#nimble-usage |
42 | 108 | [Nim]: https://nim-lang.org/
|
0 commit comments