RequestRemote factory class added

This commit is contained in:
onyx-and-iris 2023-07-22 10:08:18 +01:00
parent ce8c82a2ca
commit fefcbe6661

View File

@ -32,12 +32,6 @@ module Voicemeeter
} }
end end
def build
steps.select { |k, v| director.include? k }.each do |k, v|
send("#{k}=", v.call)
end
end
def director def director
[:strip, :bus, :button, :vban, :command, :device, :option] [:strip, :bus, :button, :vban, :command, :device, :option]
end end
@ -47,9 +41,14 @@ module Voicemeeter
class Remote < Base class Remote < Base
include Builder include Builder
public attr_reader :strip, :bus, :button, :vban, :command, :device, :option
private attr_writer :strip, :bus, :button, :vban, :command, :device, :option
def initialize(kind, **kwargs) def initialize(kind, **kwargs)
super super
build steps.select { |k, v| director.include? k }.each do |k, v|
send("#{k}=", v.call)
end
end end
def configs def configs
@ -70,13 +69,11 @@ module Voicemeeter
end end
class RemoteBasic < Remote class RemoteBasic < Remote
public attr_reader :strip, :bus, :button, :vban, :command, :device, :option
private attr_writer :strip, :bus, :button, :vban, :command, :device, :option
end end
class RemoteBanana < Remote class RemoteBanana < Remote
public attr_reader :strip, :bus, :button, :vban, :command, :device, :option, :recorder, :patch public attr_reader :recorder, :patch
private attr_writer :strip, :bus, :button, :vban, :command, :device, :option, :recorder, :patch private attr_writer :recorder, :patch
private def director private def director
super.append(:recorder, :patch) super.append(:recorder, :patch)
@ -84,14 +81,27 @@ module Voicemeeter
end end
class RemotePotato < Remote class RemotePotato < Remote
public attr_reader :strip, :bus, :button, :vban, :command, :device, :option, :recorder, :patch, :fx public attr_reader :recorder, :patch, :fx
private attr_writer :strip, :bus, :button, :vban, :command, :device, :option, :recorder, :patch, :fx private attr_writer :recorder, :patch, :fx
private def director private def director
super.append(:recorder, :patch, :fx) super.append(:recorder, :patch, :fx)
end end
end end
class RequestRemote
def self.for(kind, **kwargs)
case kind.name
when :basic
RemoteBasic.new(kind, **kwargs)
when :banana
RemoteBanana.new(kind, **kwargs)
when :potato
RemotePotato.new(kind, **kwargs)
end
end
end
public public
def self.new(kind_id, **kwargs) def self.new(kind_id, **kwargs)
@ -99,13 +109,7 @@ module Voicemeeter
rescue KeyError rescue KeyError
raise Errors::VMError.new "unknown Voicemeeter kind #{kind_id}" raise Errors::VMError.new "unknown Voicemeeter kind #{kind_id}"
else else
if kind_id == :basic RequestRemote.for(kind, **kwargs)
RemoteBasic.new(kind, **kwargs)
elsif kind_id == :banana
RemoteBanana.new(kind, **kwargs)
elsif kind_id == :potato
RemotePotato.new(kind, **kwargs)
end
end end
end end
end end