aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2023-09-19 02:04:44 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2023-09-19 02:04:44 +0300
commit5011450c665009c0feb722016f381c087307ed0a (patch)
tree7d69283f284576e2ccc4ec866ee622a5ab7fd3bb
parent6b1b316687459dd07272e280fb6cfc5024111b4c (diff)
downloadapplause2-5011450c665009c0feb722016f381c087307ed0a.tar.gz
added Stream:print() for tracking control values streams
-rw-r--r--applause.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/applause.lua b/applause.lua
index c207cd0..d701330 100644
--- a/applause.lua
+++ b/applause.lua
@@ -914,6 +914,25 @@ function Stream:gnuplot()
hnd:close()
end
+--- Print values of stream when they change.
+-- This is useful to debug slowly or seldom changing streams like those
+-- produced by @{MIDIStream} or @{EvdevStream}.
+-- @string[opt='%s'] format
+-- A format string to format the samples.
+-- This can be used to prefix text or tweak the number formatting.
+-- @treturn Stream
+-- @see string.format
+function Stream:print(format)
+ format = format or "%s"
+
+ return self:scan(function(last, sample)
+ if sample ~= last then
+ print(string.format(format, sample))
+ end
+ return sample
+ end)
+end
+
--- Check whether stream is an instance of a particular class.
-- @function instanceof
-- @tparam Class other_class The other object or class to check against.