run through standard

This commit is contained in:
onyx-and-iris 2023-07-14 12:01:41 +01:00
parent d2160535a3
commit 6ccdfafc27
11 changed files with 68 additions and 94 deletions

View File

@ -8,17 +8,21 @@ 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
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
attach_function :VBVMR_Logout, [], :long

View File

@ -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),

View File

@ -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(

View File

@ -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)
send("#{key}=", val)
end
end
end
end
def method_missing(method, *args)
logger.debug "Unknown method #{method} for #{self}."
end
end
end

View File

@ -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)

View File

@ -1,5 +1,5 @@
module Voicemeeter
module Meta_Functions
module MetaFunctions
# Accessor methods
def make_accessor_bool(*params)
params.each do |param|

View File

@ -3,7 +3,7 @@ module Voicemeeter
attr_accessor :cache, :current, :channel
def initialize
@cache = Hash.new
@cache = {}
end
def get(key)

View File

@ -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

View File

@ -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

View File

@ -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)
@ -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) }
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

View File

@ -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