diff --git a/lib/voicemeeter/cbindings.rb b/lib/voicemeeter/cbindings.rb index ed7cacf..aef1ed6 100644 --- a/lib/voicemeeter/cbindings.rb +++ b/lib/voicemeeter/cbindings.rb @@ -8,16 +8,20 @@ module Voicemeeter extend FFI::Library - VM_PATH = Install.get_vmpath() + VM_PATH = Install.get_vmpath ffi_lib VM_PATH.join( - "VoicemeeterRemote#{Install::OS_BITS == 64 ? "64" : "32"}.dll" - ) + "VoicemeeterRemote#{(Install::OS_BITS == 64) ? "64" : "32"}.dll" + ) ffi_convention :stdcall - def self.attach_function(c_name, args, returns) - ruby_name = "bind_#{c_name.to_s.delete_prefix("VBVMR_").snakecase}".to_sym - super(ruby_name, c_name, args, returns) + class << self + private + + def self.attach_function(c_name, args, returns) + ruby_name = "bind_#{c_name.to_s.delete_prefix("VBVMR_").snakecase}".to_sym + super(ruby_name, c_name, args, returns) + end end attach_function :VBVMR_Login, [], :long @@ -42,13 +46,13 @@ module Voicemeeter attach_function :VBVMR_Input_GetDeviceNumber, [], :long attach_function :VBVMR_Input_GetDeviceDescA, - %i[long pointer pointer pointer], - :long + %i[long pointer pointer pointer], + :long attach_function :VBVMR_Output_GetDeviceNumber, [], :long attach_function :VBVMR_Output_GetDeviceDescA, - %i[long pointer pointer pointer], - :long + %i[long pointer pointer pointer], + :long attach_function :VBVMR_GetMidiMessage, %i[pointer long], :long diff --git a/lib/voicemeeter/configs.rb b/lib/voicemeeter/configs.rb index 06c25e2..bfdc4cc 100644 --- a/lib/voicemeeter/configs.rb +++ b/lib/voicemeeter/configs.rb @@ -15,7 +15,7 @@ module Voicemeeter def initialize(kind) @kind = kind - @configs = Hash.new + @configs = {} end def to_s @@ -24,7 +24,7 @@ module Voicemeeter protected - #stree-ignore + # stree-ignore def build_reset_profile aouts = (0...@kind.phys_out).to_h { |i| ["A#{i + 1}", false] } bouts = (0...@kind.virt_out).to_h { |i| ["B#{i + 1}", false] } @@ -32,10 +32,10 @@ module Voicemeeter gain = [:gain].to_h { |param| [param, 0.0] } phys_float = - %w[comp gate denoiser].to_h { |param| [param, { knob: 0.0 }] } - eq = [:eq].to_h { |param| [param, { on: false }] } + %w[comp gate denoiser].to_h { |param| [param, {knob: 0.0}] } + eq = [:eq].to_h { |param| [param, {on: false}] } - overrides = { B1: true } + overrides = {B1: true} # physical strip params phys_strip = @@ -46,26 +46,26 @@ module Voicemeeter ] end - overrides = { A1: true } + overrides = {A1: true} # virtual strip params virt_strip = (@kind.phys_in...@kind.phys_in + @kind.virt_in).to_h do |i| [ "strip-#{i}", - { **aouts, **bouts, **strip_bools, **gain, **overrides } + {**aouts, **bouts, **strip_bools, **gain, **overrides} ] end bus_bools = %i[mute mono].to_h { |param| [param, false] } bus = (0...@kind.num_bus).to_h do |i| - ["bus-#{i}", { **bus_bools, **gain, **eq }] + ["bus-#{i}", {**bus_bools, **gain, **eq}] end - { **phys_strip, **virt_strip, **bus } + {**phys_strip, **virt_strip, **bus} end def read_from_yml - #stree-ignore + # stree-ignore configpaths = [ Pathname.getwd.join("configs", @kind.name.to_s), Pathname.new(Dir.home).join(".config", "voicemeeter-rb", @kind.name.to_s), diff --git a/lib/voicemeeter/install.rb b/lib/voicemeeter/install.rb index 69d4b96..ebabe03 100644 --- a/lib/voicemeeter/install.rb +++ b/lib/voicemeeter/install.rb @@ -5,19 +5,19 @@ require "ffi" module Voicemeeter private - #stree-ignore + # stree-ignore module Install - OS_BITS = FFI::Platform::CPU.downcase == "x64" ? 64 : 32 + OS_BITS = (FFI::Platform::CPU.downcase == "x64") ? 64 : 32 - def get_vmpath() + def get_vmpath reg_key = [ :Software, - (OS_BITS == 64 ? :WOW6432Node : nil), + ((OS_BITS == 64) ? :WOW6432Node : nil), :Microsoft, :Windows, :CurrentVersion, :Uninstall, - :'VB:Voicemeeter {17359A74-1236-5467}' + :"VB:Voicemeeter {17359A74-1236-5467}" ] Win32::Registry::HKEY_LOCAL_MACHINE.open( diff --git a/lib/voicemeeter/iremote.rb b/lib/voicemeeter/iremote.rb index 30423c4..3957be9 100644 --- a/lib/voicemeeter/iremote.rb +++ b/lib/voicemeeter/iremote.rb @@ -4,11 +4,8 @@ require "easy_logging" module Voicemeeter class IRemote - " - Common interface between base class and higher classes. - " include EasyLogging - include Meta_Functions + include MetaFunctions def initialize(remote, i = nil) @remote = remote @@ -40,20 +37,14 @@ module Voicemeeter def apply(params) params.each do |key, val| if val.is_a? Hash - target = self.send(key) + target = send(key) target.apply(val) + elsif key == :mode + mode.send("#{val}=", true) else - if key == :mode - self.mode.send("#{val}=", true) - else - self.send("#{key}=", val) - end + send("#{key}=", val) end end end - - def method_missing(method, *args) - logger.debug "Unknown method #{method} for #{self}." - end end end diff --git a/lib/voicemeeter/kinds.rb b/lib/voicemeeter/kinds.rb index 55094cf..6e529bd 100644 --- a/lib/voicemeeter/kinds.rb +++ b/lib/voicemeeter/kinds.rb @@ -5,14 +5,22 @@ module Voicemeeter KindMap = Data.define(:name, :ins, :outs, :vban, :asio, :insert, :num_buttons) do def phys_in = ins[0] + def virt_in = ins[1] + def phys_out = outs[0] + def virt_out = outs[1] + def num_strip = ins.sum + def num_bus = outs.sum + def num_strip_levels = 2 * phys_in + 8 * virt_in + def num_bus_levels = 8 * (phys_out + virt_out) - def to_s = "#{name}".capitalize + + def to_s = name.to_s.capitalize end basic = KindMap.new(:basic, [2, 1], [1, 1], [4, 4], [0, 0], 0, 80) diff --git a/lib/voicemeeter/meta.rb b/lib/voicemeeter/meta.rb index 55e840e..360890a 100644 --- a/lib/voicemeeter/meta.rb +++ b/lib/voicemeeter/meta.rb @@ -1,5 +1,5 @@ module Voicemeeter - module Meta_Functions + module MetaFunctions # Accessor methods def make_accessor_bool(*params) params.each do |param| diff --git a/lib/voicemeeter/midi.rb b/lib/voicemeeter/midi.rb index 7b9d74b..30c64ea 100644 --- a/lib/voicemeeter/midi.rb +++ b/lib/voicemeeter/midi.rb @@ -3,7 +3,7 @@ module Voicemeeter attr_accessor :cache, :current, :channel def initialize - @cache = Hash.new + @cache = {} end def get(key) diff --git a/lib/voicemeeter/mixins.rb b/lib/voicemeeter/mixins.rb index 8e00d2c..d46c151 100644 --- a/lib/voicemeeter/mixins.rb +++ b/lib/voicemeeter/mixins.rb @@ -2,12 +2,12 @@ module Voicemeeter module Mixins module Fades def fadeto(target, time) - self.setter("FadeTo", "(#{target}, #{time})") + setter("FadeTo", "(#{target}, #{time})") sleep(@remote.delay) end def fadeby(change, time) - self.setter("FadeBy", "(#{change}, #{time})") + setter("FadeBy", "(#{change}, #{time})") sleep(@remote.delay) end end @@ -21,11 +21,11 @@ module Voicemeeter module Apps def appgain(name, gain) - self.setter("AppGain", "(\"#{name}\", #{gain})") + setter("AppGain", "(\"#{name}\", #{gain})") end def appmute(name, mute) - self.setter("AppMute", "(\"#{name}\", #{mute ? 1 : 0})") + setter("AppMute", "(\"#{name}\", #{mute ? 1 : 0})") end end @@ -33,12 +33,12 @@ module Voicemeeter def initialize(*args) super remote, *rem = args - num_A, num_B = remote.kind.outs + num_a, num_b = remote.kind.outs channels = - (1..(num_A + num_B)).map do |i| - i <= num_A ? "A#{i}" : "B#{i - num_A}" + (1..(num_a + num_b)).map do |i| + (i <= num_a) ? "A#{i}" : "B#{i - num_a}" end - make_accessor_bool *channels + make_accessor_bool(*channels) end end diff --git a/lib/voicemeeter/remote.rb b/lib/voicemeeter/remote.rb index 378b54f..1a3c24a 100644 --- a/lib/voicemeeter/remote.rb +++ b/lib/voicemeeter/remote.rb @@ -38,13 +38,6 @@ module Voicemeeter public def self.new(kind_id, **kwargs) - " - Factory method for remotes - - Wraps factory expression and handles errors - - Returns a Remote class of a Kind - " remotes = Kinds::ALL.to_h { |kind| [kind.name, Remote.new(kind, **kwargs)] } unless remotes.key? kind_id diff --git a/lib/voicemeeter/strip.rb b/lib/voicemeeter/strip.rb index b246d3f..074408c 100644 --- a/lib/voicemeeter/strip.rb +++ b/lib/voicemeeter/strip.rb @@ -11,13 +11,8 @@ module Voicemeeter attr_reader :gainlayer, :levels def self.make(remote, i) - " - Factory function for Strip classes. - - Returns a PhysicalStrip or VirtualStrip class - " p_in = remote.kind.phys_in - i < p_in ? PhysicalStrip.new(remote, i) : VirtualStrip.new(remote, i) + (i < p_in) ? PhysicalStrip.new(remote, i) : VirtualStrip.new(remote, i) end def initialize(remote, i) @@ -60,12 +55,12 @@ module Voicemeeter def initialize(remote, i) super make_accessor_float :gainin, - :ratio, - :threshold, - :attack, - :release, - :knee, - :gainout + :ratio, + :threshold, + :attack, + :release, + :knee, + :gainout make_accessor_bool :makeup end @@ -190,17 +185,15 @@ module Voicemeeter end def gain - self.getter("gainlayer[#{@j}]") + getter("gainlayer[#{@j}]") end def gain=(value) - self.setter("gainlayer[#{@j}]", value) + setter("gainlayer[#{@j}]", value) end end class StripLevels < IRemote - attr_reader :prefader, :postfader, :postmute - def initialize(remote, i) super p_in = remote.kind.phys_in @@ -219,13 +212,12 @@ module Voicemeeter def get_level(mode) @remote.cache[:strip_mode] = mode - if @remote.running && @remote.event.ldirty - vals = @remote.cache[:strip_level][@init, @offset] + vals = if @remote.running && @remote.event.ldirty + @remote.cache[:strip_level][@init, @offset] else - vals = - (@init...@init + @offset).map { |i| @remote.get_level(mode, i) } + (@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 { |x| (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 } end def prefader diff --git a/lib/voicemeeter/vban.rb b/lib/voicemeeter/vban.rb index 6c6f722..153ab87 100644 --- a/lib/voicemeeter/vban.rb +++ b/lib/voicemeeter/vban.rb @@ -5,9 +5,6 @@ require_relative "errors" module Voicemeeter module Vban class VbanStream < IRemote - " - A class representing a VBAN stream - " def initialize(remote, i) super make_accessor_bool :on @@ -25,9 +22,6 @@ module Voicemeeter end class VbanInstream < VbanStream - " - A subclass representing a VBAN Instream - " def initialize(remote, i) super make_reader_int :sr, :channel, :bit @@ -39,9 +33,6 @@ module Voicemeeter end class VbanOutstream < VbanStream - " - A subclass representing a VBAN Outstream - " def initialize(remote, i) super make_accessor_int :sr, :channel, :bit @@ -56,11 +47,6 @@ module Voicemeeter attr_reader :instream, :outstream def initialize(remote) - " - Initializes a Vban class - - Creates an array for each in/out stream and sets as class attributes - " vban_in, vban_out = remote.kind.vban @instream = [] vban_in.times { |i| @instream << VbanInstream.new(remote, i) } @@ -70,12 +56,12 @@ module Voicemeeter @remote = remote end - #stree-ignore + # stree-ignore def enable @remote.set("vban.enable", 1) end - #stree-ignore + # stree-ignore def disable @remote.set("vban.enable", 0) end