now extending MetaFunctions into classes

macro methods renamed
This commit is contained in:
onyx-and-iris 2023-08-30 12:27:50 +01:00
parent 9cfc409049
commit cfeb3a7263
12 changed files with 137 additions and 171 deletions

View File

@ -5,8 +5,12 @@ module Voicemeeter
include IRemote
include Mixins::Fades
include Mixins::Return
extend MetaFunctions
attr_reader :eq, :mode, :levels
attr_accessor_bool :mute, :mono, :sel, :monitor
attr_accessor_float :gain
attr_accessor_string :label
def self.make(remote, i)
(i < remote.kind.phys_out) ? PhysicalBus.new(remote, i) : VirtualBus.new(remote, i)
@ -14,9 +18,6 @@ module Voicemeeter
def initialize(remote, i)
super
make_accessor_bool :mute, :mono, :sel, :monitor
make_accessor_float :gain
make_accessor_string :label
@eq = BusEq.new(remote, i)
@mode = BusModes.new(remote, i)
@ -36,11 +37,9 @@ module Voicemeeter
class BusEq
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_bool :on, :ab
end
attr_accessor_bool :on, :ab
def identifier
"bus[#{@index}].eq"
@ -49,22 +48,20 @@ module Voicemeeter
class BusModes
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_bool :normal,
:amix,
:bmix,
:repeat,
:composite,
:tvmix,
:upmix21,
:upmix41,
:upmix61,
:centeronly,
:lfeonly,
:rearonly
end
attr_accessor_bool :normal,
:amix,
:bmix,
:repeat,
:composite,
:tvmix,
:upmix21,
:upmix41,
:upmix61,
:centeronly,
:lfeonly,
:rearonly
def identifier
"bus[#{@index}].mode"

View File

@ -1,12 +1,10 @@
module Voicemeeter
class Command
include IRemote
extend MetaFunctions
def initialize(remote)
super
make_action_method :show, :restart, :shutdown
make_writer_bool :showvbanchat, :lock
end
attr_action_method :show, :restart, :shutdown
attr_writer_bool :showvbanchat, :lock
def identifier
:command

View File

@ -27,11 +27,21 @@ module Voicemeeter
class Tracker
include Logging
class << self
private def attr_events(*params)
params.each do |param|
define_method("#{param}=") do |value|
instance_variable_set("@#{param}", value)
info("#{param} #{value ? "added to" : "removed from"}")
end
end
end
end
attr_reader :pdirty, :mdirty, :midi, :ldirty
attr_events :pdirty, :mdirty, :midi, :ldirty
def initialize(**kwargs)
make_writer_methods :pdirty, :mdirty, :midi, :ldirty
kwargs.each do |key, value|
instance_variable_set("@#{key}", value || false)
end
@ -51,15 +61,6 @@ module Voicemeeter
logger.info info_msg.join(" ")
end
private def make_writer_methods(*params)
params.each do |param|
define_singleton_method("#{param}=") do |value|
instance_variable_set("@#{param}", value)
info("#{param} #{value ? "added to" : "removed from"}")
end
end
end
def get
%i[pdirty mdirty midi ldirty].reject { |ev| !send(ev) }
end

View File

@ -1,6 +1,8 @@
module Voicemeeter
class Fx
include IRemote
extend MetaFunctions
attr_reader :reverb, :delay
def initialize(remote)
@ -16,11 +18,9 @@ module Voicemeeter
class FxReverb
include IRemote
extend MetaFunctions
def initialize(remote)
super
make_accessor_bool :on, :ab
end
attr_accessor_bool :on, :ab
def identifier
"fx.reverb"
@ -29,11 +29,9 @@ module Voicemeeter
class FxDelay
include IRemote
extend MetaFunctions
def initialize(remote)
super
make_accessor_bool :on, :ab
end
attr_accessor_bool :on, :ab
def identifier
"fx.delay"

View File

@ -2,7 +2,6 @@ module Voicemeeter
# Common interface with the base Remote class.
module IRemote
include Logging
include MetaFunctions
def initialize(remote, i = nil)
@remote = remote

View File

@ -3,72 +3,72 @@ module Voicemeeter
private
# Accessor methods
def make_accessor_bool(*params)
def attr_accessor_bool(*params)
params.each do |param|
define_singleton_method(param) { getter(param).to_i == 1 }
define_method(param) { getter(param).to_i == 1 }
define_singleton_method("#{param}=") do |value|
define_method("#{param}=") do |value|
setter(param, value && 1 || 0)
end
end
end
def make_accessor_string(*params)
def attr_accessor_string(*params)
params.each do |param|
define_singleton_method(param) { getter(param, true) }
define_method(param) { getter(param, true) }
define_singleton_method("#{param}=") { |value| setter(param, value) }
define_method("#{param}=") { |value| setter(param, value) }
end
end
def make_accessor_int(*params)
def attr_accessor_int(*params)
params.each do |param|
define_singleton_method(param) { getter(param).to_i }
define_method(param) { getter(param).to_i }
define_singleton_method("#{param}=") { |value| setter(param, value) }
define_method("#{param}=") { |value| setter(param, value) }
end
end
def make_accessor_float(*params)
def attr_accessor_float(*params)
params.each do |param|
define_singleton_method(param) { getter(param) }
define_method(param) { getter(param) }
define_singleton_method("#{param}=") { |value| setter(param, value) }
define_method("#{param}=") { |value| setter(param, value) }
end
end
# reader methods
def make_reader_string(*params)
def attr_reader_string(*params)
params.each do |param|
define_singleton_method(param) { getter(param, true) }
define_method(param) { getter(param, true) }
end
end
def make_reader_int(*params)
def attr_reader_int(*params)
params.each do |param|
define_singleton_method(param) { getter(param).to_i }
define_method(param) { getter(param).to_i }
end
end
# writer methods
def make_writer_bool(*params)
def attr_writer_bool(*params)
params.each do |param|
define_singleton_method("#{param}=") do |value|
define_method("#{param}=") do |value|
setter(param, value && 1 || 0)
end
end
end
def make_writer_string(*params)
def attr_writer_string(*params)
params.each do |param|
define_singleton_method("#{param}=") { |value| setter(param, value) }
define_method("#{param}=") { |value| setter(param, value) }
end
end
# methods for performing certain actions as opposed to setting values
def make_action_method(*params)
def attr_action_method(*params)
params.each do |param|
define_singleton_method(param) { setter(param, 1) }
define_method(param) { setter(param, 1) }
end
end
end

View File

@ -13,10 +13,8 @@ module Voicemeeter
end
module Return
def initialize(remote, i)
super
make_accessor_float :returnreverb, :returndelay, :returnfx1, :returnfx2
end
extend MetaFunctions
attr_accessor_float :returnreverb, :returndelay, :returnfx1, :returnfx2
end
module Apps
@ -30,47 +28,40 @@ module Voicemeeter
end
module Outputs
def initialize(*args)
super
remote, *_ = args
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}"
def make_attr_outputs(num_a, num_b)
(1..(num_a + num_b)).each do |i|
param = (i <= num_a) ? :"A#{i}" : :"B#{i - num_a}"
define_singleton_method(param) do
getter(param).to_i == 1
end
make_accessor_bool(*channels)
define_singleton_method("#{param}=") do |value|
setter(param, value && 1 || 0)
end
end
end
end
module Xy
module Pan
def initialize(remote, i)
super
make_accessor_float :pan_x, :pan_y
end
extend MetaFunctions
attr_accessor_float :pan_x, :pan_y
end
module Color
def initialize(remote, i)
super
make_accessor_float :color_x, :color_y
end
extend MetaFunctions
attr_accessor_float :color_x, :color_y
end
module Fx
def initialize(remote, i)
super
make_accessor_float :fx_x, :fx_y
end
extend MetaFunctions
attr_accessor_float :fx_x, :fx_y
end
end
module Fx
def initialize(remote, i)
super
make_accessor_float :reverb, :delay, :fx1, :fx2
make_accessor_bool :postreverb, :postdelay, :postfx1, :postfx2
end
extend MetaFunctions
attr_accessor_float :reverb, :delay, :fx1, :fx2
attr_accessor_bool :postreverb, :postdelay, :postfx1, :postfx2
end
module LevelEnum

View File

@ -2,12 +2,14 @@ module Voicemeeter
module Option
class Base
include IRemote
extend MetaFunctions
attr_reader :delay, :buffer, :mode
attr_accessor_int :sr
attr_accessor_bool :asiosr, :monitoronsel, :slidermode
def initialize(remote)
super
make_accessor_int :sr
make_accessor_bool :asiosr, :monitoronsel, :slidermode
@delay = (0...remote.kind.phys_out).map { OptionDelay.new(remote, _1) }
@buffer = OptionBuffer.new(remote)
@ -21,11 +23,9 @@ module Voicemeeter
class OptionDelay
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_bool :on, :ab
end
attr_accessor_bool :on, :ab
def identifier
"option.delay"
@ -42,11 +42,9 @@ module Voicemeeter
class OptionBuffer
include IRemote
extend MetaFunctions
def initialize(remote)
super
make_accessor_int :mme, :wdm, :ks, :asio
end
attr_accessor_int :mme, :wdm, :ks, :asio
def identifier
"option.buffer"
@ -55,11 +53,9 @@ module Voicemeeter
class OptionMode
include IRemote
extend MetaFunctions
def initialize(remote)
super
make_accessor_bool :exclusif, :swift
end
attr_accessor_bool :exclusif, :swift
def identifier
"option.mode"

View File

@ -3,11 +3,13 @@ module Voicemeeter
# Base class for Patch
class Base
include IRemote
extend MetaFunctions
attr_reader :asio, :A2, :A3, :A4, :A5, :composite, :insert
attr_accessor_bool :postfadercomposite, :postfxinsert
def initialize(remote)
super
make_accessor_bool :postfadercomposite, :postfxinsert
asio_in, asio_out = remote.kind.asio
@asio = (0...asio_in).map { PatchAsioIn.new(remote, _1) }

View File

@ -11,14 +11,16 @@ module Voicemeeter
class Base
include IRemote
include Mixins::Outputs
extend MetaFunctions
attr_reader :mode, :armstrip, :armbus
attr_action_method :play, :stop, :pause, :replay, :record, :ff, :rew
attr_accessor_int :bitresolution, :channel, :kbps
attr_accessor_float :gain
def initialize(remote)
super
make_action_method :play, :stop, :pause, :replay, :record, :ff, :rew
make_accessor_int :bitresolution, :channel, :kbps
make_accessor_float :gain
make_attr_outputs(*remote.kind.outs)
@mode = RecorderMode.new(remote)
@armstrip = (0...remote.kind.num_strip).map { RecorderArmStrip.new(remote, _1) }
@ -51,11 +53,9 @@ module Voicemeeter
class RecorderMode
include IRemote
extend MetaFunctions
def initialize(remote)
super
make_accessor_bool :recbus, :playonload, :loop, :multitrack
end
attr_accessor_bool :recbus, :playonload, :loop, :multitrack
def identifier
"recorder.mode"

View File

@ -5,8 +5,13 @@ module Voicemeeter
include IRemote
include Mixins::Outputs
include Mixins::Fades
extend MetaFunctions
attr_reader :gainlayer, :levels
attr_accessor_bool :solo, :mute, :mono
attr_accessor_float :gain
attr_accessor_int :limit
attr_accessor_string :label
def self.make(remote, i)
(i < remote.kind.phys_in) ? PhysicalStrip.new(remote, i) : VirtualStrip.new(remote, i)
@ -14,10 +19,7 @@ module Voicemeeter
def initialize(remote, i)
super
make_accessor_bool :solo, :mute, :mono
make_accessor_float :gain
make_accessor_int :limit
make_accessor_string :label
make_attr_outputs(*remote.kind.outs)
@gainlayer = (0...8).map { GainLayer.new(remote, i, _1) }
@levels = StripLevels.new(remote, i)
@ -34,13 +36,13 @@ module Voicemeeter
include Mixins::Xy::Color
include Mixins::Xy::Fx
include Mixins::Fx
extend MetaFunctions
attr_reader :comp, :gate, :denoiser, :eq, :device
attr_accessor_float :audibility
def initialize(remote, i)
super
make_accessor_float :audibility
@comp = StripComp.new(remote, i)
@gate = StripGate.new(remote, i)
@denoiser = StripDenoiser.new(remote, i)
@ -51,18 +53,16 @@ module Voicemeeter
class StripComp
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_float :gainin,
:ratio,
:threshold,
:attack,
:release,
:knee,
:gainout
make_accessor_bool :makeup
end
attr_accessor_float :gainin,
:ratio,
:threshold,
:attack,
:release,
:knee,
:gainout
attr_accessor_bool :makeup
def identifier
"strip[#{@index}].comp"
@ -79,12 +79,10 @@ module Voicemeeter
class StripGate
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_float :threshold, :damping, :attack, :hold, :release
make_accessor_int :bpsidechain
end
attr_accessor_float :threshold, :damping, :attack, :hold, :release
attr_accessor_int :bpsidechain
def identifier
"strip[#{@index}].gate"
@ -117,11 +115,9 @@ module Voicemeeter
class StripEq
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_bool :on, :ab
end
attr_accessor_bool :on, :ab
def identifier
"strip[#{@index}].eq"
@ -130,13 +126,11 @@ module Voicemeeter
class StripDevice
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_reader_int :sr
make_reader_string :name
make_writer_string :wdm, :ks, :mme, :asio
end
attr_reader_int :sr
attr_reader_string :name
attr_writer_string :wdm, :ks, :mme, :asio
def identifier
"strip[#{@index}].device"
@ -147,12 +141,10 @@ module Voicemeeter
class VirtualStrip < Base
include Mixins::Xy::Pan
include Mixins::Apps
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_bool :mc
make_accessor_int :karaoke
end
attr_accessor_bool :mc
attr_accessor_int :karaoke
def bass
round(getter("EQGain1"), 1)

View File

@ -3,13 +3,11 @@ module Voicemeeter
# Base class for Vban In/Out Streams
class VbanStream
include IRemote
extend MetaFunctions
def initialize(remote, i)
super
make_accessor_bool :on
make_accessor_string :name, :ip
make_accessor_int :quality, :route
end
attr_accessor_bool :on
attr_accessor_string :name, :ip
attr_accessor_int :quality, :route
def identifier
"vban.#{direction}stream[#{@index}]"
@ -22,10 +20,7 @@ module Voicemeeter
# Represents a Vban InStream
class VbanInstream < VbanStream
def initialize(remote, i)
super
make_reader_int :sr, :channel, :bit
end
attr_reader_int :sr, :channel, :bit
def direction
:in
@ -43,10 +38,7 @@ module Voicemeeter
# Represents a Vban OutStream
class VbanOutstream < VbanStream
def initialize(remote, i)
super
make_accessor_int :sr, :channel, :bit
end
attr_accessor_int :sr, :channel, :bit
def direction
:out