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

View File

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

View File

@ -27,11 +27,21 @@ module Voicemeeter
class Tracker class Tracker
include Logging 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_reader :pdirty, :mdirty, :midi, :ldirty
attr_events :pdirty, :mdirty, :midi, :ldirty
def initialize(**kwargs) def initialize(**kwargs)
make_writer_methods :pdirty, :mdirty, :midi, :ldirty
kwargs.each do |key, value| kwargs.each do |key, value|
instance_variable_set("@#{key}", value || false) instance_variable_set("@#{key}", value || false)
end end
@ -51,15 +61,6 @@ module Voicemeeter
logger.info info_msg.join(" ") logger.info info_msg.join(" ")
end 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 def get
%i[pdirty mdirty midi ldirty].reject { |ev| !send(ev) } %i[pdirty mdirty midi ldirty].reject { |ev| !send(ev) }
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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