2023-07-07 02:35:34 +01:00
|
|
|
require_relative "errors"
|
2023-07-09 05:49:08 +01:00
|
|
|
require_relative "meta"
|
|
|
|
require "easy_logging"
|
2023-07-07 02:35:34 +01:00
|
|
|
|
|
|
|
module Voicemeeter
|
|
|
|
class IRemote
|
|
|
|
"
|
|
|
|
Common interface between base class and higher classes.
|
|
|
|
"
|
2023-07-09 05:49:08 +01:00
|
|
|
include EasyLogging
|
|
|
|
include Meta_Functions
|
|
|
|
|
2023-07-07 02:35:34 +01:00
|
|
|
def initialize(remote, i = nil)
|
|
|
|
@remote = remote
|
|
|
|
@index = i
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"#{self.class.name.split("::").last}#{@index}#{@remote.kind}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def getter(param, is_string = false)
|
2023-07-09 05:49:08 +01:00
|
|
|
logger.debug "getter: #{_cmd(param)}"
|
2023-07-07 02:35:34 +01:00
|
|
|
@remote.get(_cmd(param), is_string)
|
|
|
|
end
|
|
|
|
|
|
|
|
def setter(param, value)
|
2023-07-09 05:49:08 +01:00
|
|
|
logger.debug "setter: #{_cmd(param)}=#{value}"
|
2023-07-07 02:35:34 +01:00
|
|
|
@remote.set(_cmd(param), value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def _cmd(param)
|
2023-07-09 05:49:08 +01:00
|
|
|
param.empty? ? self.identifier : "#{self.identifier}.#{param}"
|
2023-07-07 02:35:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def identifier
|
|
|
|
raise "Called abstract method: identifier"
|
|
|
|
end
|
|
|
|
|
|
|
|
def apply(params)
|
2023-07-09 05:49:08 +01:00
|
|
|
params.each do |key, val|
|
|
|
|
if val.is_a? Hash
|
|
|
|
target = self.send(key)
|
|
|
|
target.apply(val)
|
|
|
|
else
|
|
|
|
self.send("#{key}=", val)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(method, *args)
|
|
|
|
logger.debug "Unknown method #{method} for #{self}."
|
2023-07-07 02:35:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|