From 53f2c1847ff76f6b12e318c0a1ae808889680559 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Tue, 25 Jul 2023 10:20:31 +0100 Subject: [PATCH] pass convert as block to map --- lib/voicemeeter/bus.rb | 4 +++- lib/voicemeeter/strip.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/voicemeeter/bus.rb b/lib/voicemeeter/bus.rb index 72906bc..9adfb97 100644 --- a/lib/voicemeeter/bus.rb +++ b/lib/voicemeeter/bus.rb @@ -93,12 +93,14 @@ module Voicemeeter end def getter(mode) + convert = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 } + vals = if @remote.running && @remote.event.ldirty @remote.cache[:bus_level][@init, @offset] else (@init...@init + @offset).map { |i| @remote.get_level(mode, i) } end - vals.map { |x| (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 } + vals.map(&convert) end def all diff --git a/lib/voicemeeter/strip.rb b/lib/voicemeeter/strip.rb index a46e530..2451053 100644 --- a/lib/voicemeeter/strip.rb +++ b/lib/voicemeeter/strip.rb @@ -212,13 +212,15 @@ module Voicemeeter end def get_level(mode) + convert = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 } + @remote.cache[:strip_mode] = mode vals = if @remote.running && @remote.event.ldirty @remote.cache[:strip_level][@init, @offset] else (@init...@init + @offset).map { |i| @remote.get_level(mode, i) } end - vals.map { |x| (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 } + vals.map(&convert) end def prefader