From c969b8b349290bb8adef0d248ac4d41b4130498b Mon Sep 17 00:00:00 2001 From: Brandon Taylor Date: Tue, 18 May 2021 13:48:54 -0400 Subject: [PATCH] actually, this might be nicer as a macro --- src/PortAudio.jl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/PortAudio.jl b/src/PortAudio.jl index fc7dc0c..ea5c52e 100644 --- a/src/PortAudio.jl +++ b/src/PortAudio.jl @@ -95,10 +95,8 @@ mutable struct PortAudioStream{T} # finalizer(close, this) this.sink = PortAudioSink{T}(outdev.name, this, outchans) this.source = PortAudioSource{T}(indev.name, this, inchans) - this.stream = suppress_err() do - Pa_OpenStream(inparams, outparams, sr, 0, paNoFlag, + this.stream = @stderr_as_debug Pa_OpenStream(inparams, outparams, sr, 0, paNoFlag, nothing, nothing) - end Pa_StartStream(this.stream) # pre-fill the output stream so we're less likely to underrun @@ -369,9 +367,11 @@ function discard_input(source::PortAudioSource) end end -function suppress_err(dofunc::Function) - debug_message = @suppress_err dofunc() - @debug debug_message +macro stderr_as_debug(expression) + quote + debug_message = @capture_err $(esc(expression)) + @debug debug_message + end end function __init__() @@ -407,9 +407,7 @@ function __init__() # junk to STDOUT on initialization, so we swallow it. # TODO: actually check the junk to make sure there's nothing in there we # don't expect - suppress_err() do - Pa_Initialize() - end + @stderr_as_debug Pa_Initialize() atexit() do Pa_Terminate()