From 781d9530d29cde97317e42b43633f0b24c6cefb6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 2 Jan 2021 21:08:26 +0100 Subject: Print backtraces for MIDI receive thread --- guile/starlet/midi-control/base.scm | 49 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/guile/starlet/midi-control/base.scm b/guile/starlet/midi-control/base.scm index fe626c7..70da1d9 100644 --- a/guile/starlet/midi-control/base.scm +++ b/guile/starlet/midi-control/base.scm @@ -171,28 +171,33 @@ ;; Read thread (begin-thread - (let again () - - (let* ((status-byte (get-u8 midi-port)) - (channel (bit-extract status-byte 0 4)) - (command (bit-extract status-byte 4 8))) - - (case command - - ;; Note on - ((9) (let* ((note (get-u8 midi-port)) - (vel (get-u8 midi-port))) - (check-note-callbacks channel note))) - - ;; Control value - ((11) (let* ((cc-number (get-u8 midi-port)) - (value (get-u8 midi-port))) - (handle-cc-change! channel - cc-number - value)))) - - (yield) - (again)))) + (with-exception-handler + (lambda (exn) + (backtrace) + (raise-exception exn)) + (lambda () + (let again () + + (let* ((status-byte (get-u8 midi-port)) + (channel (bit-extract status-byte 0 4)) + (command (bit-extract status-byte 4 8))) + + (case command + + ;; Note on + ((9) (let* ((note (get-u8 midi-port)) + (vel (get-u8 midi-port))) + (check-note-callbacks channel note))) + + ;; Control value + ((11) (let* ((cc-number (get-u8 midi-port)) + (value (get-u8 midi-port))) + (handle-cc-change! channel + cc-number + value)))) + + (yield) + (again)))))) ;; Write thread (begin-thread -- cgit v1.2.3