command class implemented

This commit is contained in:
onyx-and-iris 2023-07-14 17:07:56 +01:00
parent ecdf9fa4cc
commit 2f93fc14f9
3 changed files with 48 additions and 2 deletions

View File

@ -0,0 +1,36 @@
require_relative "iremote"
require_relative "meta"
module Voicemeeter
class Command < IRemote
def initialize(remote)
super
make_action_method :show, :restart, :shutdown
make_writer_bool :showvbanchat, :lock
end
def identifier
:command
end
def hide
setter("show", 0)
end
def load(value)
raise VMError.new("load got: #{value}, but expected a string") unless value.is_a? String
setter("load", value)
sleep(0.2)
end
def save(value)
raise VMError.new("save got: #{value}, but expected a string") unless value.is_a? String
setter("save", value)
sleep(0.2)
end
def reset
@remote.apply_config(:reset)
end
end
end

View File

@ -49,6 +49,14 @@ module Voicemeeter
end
# writer methods
def make_writer_bool(*params)
params.each do |param|
define_singleton_method("#{param}=") do |value|
setter(param, value && 1 || 0)
end
end
end
def make_writer_string(*params)
params.each do |param|
define_singleton_method("#{param}=") { |value| setter(param, value) }

View File

@ -5,6 +5,7 @@ require_relative "strip"
require_relative "bus"
require_relative "button"
require_relative "vban"
require_relative "command"
require_relative "recorder"
require_relative "configs"
@ -13,7 +14,7 @@ module Voicemeeter
private
class Remote < Base
attr_reader :strip, :bus, :button, :vban, :recorder
attr_reader :strip, :bus, :button, :vban, :command, :recorder
def initialize(kind, **kwargs)
super
@ -21,6 +22,7 @@ module Voicemeeter
@bus = (0...kind.num_bus).map { |i| Bus::Bus.make(self, i) }
@button = (0...kind.num_buttons).map { |i| Button::Button.new(self, i) }
@vban = Vban::Vban.new(self)
@command = Command.new(self)
@recorder = Recorder::Recorder.new(self)
end
@ -31,7 +33,7 @@ module Voicemeeter
def run
login
yield if block_given?
yield(self) if block_given?
logout
end