voicemeeter-rb/lib/voicemeeter/iremote.rb
2023-07-27 10:58:26 +01:00

57 lines
1.1 KiB
Ruby

require_relative "errors"
require_relative "meta"
require_relative "logger"
module Voicemeeter
module IRemote
# A commmon interface between the base Remote class and extended classes.
include Logging
include MetaFunctions
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)
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
target = send(key)
target.apply(val)
elsif key == :mode
mode.send("#{val}=", true)
else
send("#{key}=", val)
end
end
end
end
end