A Nim wrapper for the JACK C API
Go to file
Christopher Arndt ca918769ec
[ci] feat: add GitHub actions workflows for building/testing/docs (#2)
* disable windows runner for now (chocolatey jack package is broken)
* install jack and pcre from homebrew for macOS workflow
* install libjack-jackd2-dev libpcre3-dev for linux workflow
* add additional libjack location candidate for macOS / homebrew
* make library name patterns const strings

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
2025-01-23 03:10:43 +01:00
.github/workflows [ci] feat: add GitHub actions workflows for building/testing/docs (#2) 2025-01-23 03:10:43 +01:00
examples fix: define SIGTERM on windows, since it is not exported by system/ansi_c there 2025-01-22 23:13:01 +01:00
src [ci] feat: add GitHub actions workflows for building/testing/docs (#2) 2025-01-23 03:10:43 +01:00
tests test: ignore compiled tests 2023-06-06 02:47:27 +02:00
.gitignore Add README, LICENSE and .gitignore 2022-10-06 04:19:20 +02:00
LICENSE.md docs: clean up & improve readme 2023-11-23 17:30:16 +01:00
README.md docs: minor readme tweaks and fixes 2025-01-20 02:23:45 +01:00
TODO.md docs: clean up & improve readme 2023-11-23 17:30:16 +01:00
jacket.nimble fix: examples require threading package 2025-01-23 02:58:11 +01:00

README.md

jacket

A Nim wrapper for the JACK Audio Connection Kit (JACK) client side C API aka libjack.

Project status

This software is in beta status.

The majority of JACK client API functions have been wrapped and are functional (see examples), but some API parts (e.g. threading) still need wrapping. 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.

Installation

  • Clone this repository.

  • Change into the jacket directory.

  • Run nimble install (or nimble develop).

  • Build the examples with nimble examples.

    (Some examples need --threads:on with Nim < 2.0).

Usage

Here is a very minimal JACK client application, which just passes audio through 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.

import std/os
import system/ansi_c
import jacket

var
    status: cint
    exitSignalled = false
    inpPort, outPort: Port

type SampleBuffer = ptr UncheckedArray[DefaultAudioSample]

proc signalCb(sig: cint) {.noconv.} =
    exitSignalled = true

proc shutdownCb(arg: pointer = nil) {.cdecl.} =
    exitSignalled = true

proc processCb(nFrames: NFrames, arg: pointer): cint {.cdecl.} =
    let inpbuf = cast[SampleBuffer](portGetBuffer(inpPort, nFrames))
    let outbuf = cast[SampleBuffer](portGetBuffer(outPort, nFrames))
    # copy samples from input to output buffer
    for i in 0 ..< nFrames:
        outbuf[i] = inpbuf[i]

# Create JACK Client ptr
var jackClient = clientOpen("passthru", NullOption, status.addr)
# Register audio input and output ports
inpPort = jackClient.portRegister("in_1", JackDefaultAudioType, PortIsInput, 0)
outPort = jackClient.portRegister("out_1", JackDefaultAudioType, PortIsOutput, 0)
# Set JACK callbacks
jackClient.onShutdown(shutdownCb)
jackClient.setProcessCallback(processCb, nil)
# Handle POSIX signals
c_signal(SIGINT, signalCb)
c_signal(SIGTERM, signalCb)
# Activate JACK client ...
jackClient.activate()

while not exitSignalled:
    sleep(50)

jackClient.clientClose()

License

This software is released under the MIT License. See the file 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 dynamically link to libjack at build time, but only loads it via dynlib at 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

jacket is written by Christopher Arndt.