From 5c4af1a90a252471ef67f27fe5d0a187bf6179a2 Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Mon, 22 May 2023 07:09:35 +0200 Subject: [PATCH] feat: wrap MIDI API and add example MIDI client Signed-off-by: Christopher Arndt --- README.md | 2 +- examples/jacket_midi_print.nim | 89 ++++++++++++++++++++++++++++++++++ src/jacket.nim | 34 +++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 examples/jacket_midi_print.nim diff --git a/README.md b/README.md index 521a877..43417da 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A [Nim] wrapper for the [JACK] [C API] This software is in *alpha status* and has no official release yet. The basic JACK APIs (client lifecycle, ports, callbacks) have been wrapped and -are functional (see [examples]), but MIDI, transport and meta-data APIs still +are functional (see [examples]), but latency, transport and meta-data APIs still need wrapping. Also, symbol names may still be changed and things moved around before the first public release. diff --git a/examples/jacket_midi_print.nim b/examples/jacket_midi_print.nim new file mode 100644 index 0000000..f207ff5 --- /dev/null +++ b/examples/jacket_midi_print.nim @@ -0,0 +1,89 @@ +import std/[logging, os, strutils] +import signal +import jacket + +var jclient: ClientP +var event: MidiEvent +var midiPort: PortP +var status: cint +var exitSignalled: bool = false +var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug) + + +proc cleanup() = + debug "Cleaning up..." + if jclient != nil: + discard jclient.deactivate() + discard jclient.clientClose() + jclient = nil + +proc errorCb(msg: cstring) {.cdecl.} = + # Suppress verbose JACK error messages when server is not available by + # default. Pass ``lvlAll`` when creating the logger to enable them. + debug "JACK error: " & $msg + +proc signalCb(sig: cint) {.noconv.} = + info "Received signal: " & $sig + exitSignalled = true + +proc shutdownCb(arg: pointer = nil) {.cdecl.} = + info "JACK server has shut down." + exitSignalled = true + +proc printMidiEvent(event: var MidiEvent) = + if event.size <= 3: + for i in 0..