voicemeeter-rb/lib/voicemeeter/iremote.rb

51 lines
1.0 KiB
Ruby
Raw Normal View History

module Voicemeeter
2023-08-29 11:21:05 +01:00
# Common interface with the base Remote class.
2023-07-27 10:58:26 +01:00
module IRemote
include Logging
def initialize(remote, i = nil)
@remote = remote
@index = i
end
def to_s
"#{self.class.name.split("::").last}#{@index}#{@remote.kind}"
end
private
def getter(param, is_string = false)
logger.debug "getter: #{_cmd(param)}"
@remote.get(_cmd(param), is_string)
end
def setter(param, value)
logger.debug "setter: #{_cmd(param)}=#{value}"
@remote.set(_cmd(param), value)
end
def _cmd(param)
2023-07-14 01:47:36 +01:00
param.empty? ? identifier : "#{identifier}.#{param}"
end
def identifier
raise "Called abstract method: identifier"
end
public
def apply(params)
params.each do |key, val|
if val.is_a? Hash
2023-08-31 23:04:31 +01:00
target = public_send(key)
target.apply(val)
2023-07-14 12:01:41 +01:00
elsif key == :mode
2023-08-31 23:04:31 +01:00
mode.public_send("#{val}=", true)
else
2023-08-31 23:04:31 +01:00
public_send("#{key}=", val)
end
end
end
end
end