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..