2023-07-07 02:36:35 +01:00
|
|
|
module Voicemeeter
|
2023-08-29 11:21:05 +01:00
|
|
|
# Builder module for Remote factories.
|
2023-07-20 09:50:16 +01:00
|
|
|
module Builder
|
2023-07-07 02:36:35 +01:00
|
|
|
private
|
|
|
|
|
2023-07-25 08:17:51 +01:00
|
|
|
def steps(step)
|
|
|
|
case step
|
2023-07-27 10:58:26 +01:00
|
|
|
when :strip then -> { (0...kind.num_strip).map { Strip::Base.make(self, _1) } }
|
|
|
|
when :bus then -> { (0...kind.num_bus).map { Bus::Base.make(self, _1) } }
|
|
|
|
when :button then -> { (0...kind.num_buttons).map { Button::Base.new(self, _1) } }
|
|
|
|
when :vban then -> { Vban::Base.new(self) }
|
2023-07-25 09:53:00 +01:00
|
|
|
when :command then -> { Command.new(self) }
|
2023-07-27 10:58:26 +01:00
|
|
|
when :recorder then -> { Recorder::Base.new(self) }
|
2023-07-25 09:53:00 +01:00
|
|
|
when :device then -> { Device.new(self) }
|
|
|
|
when :fx then -> { Fx.new(self) }
|
2023-07-27 10:58:26 +01:00
|
|
|
when :patch then -> { Patch::Base.new(self) }
|
|
|
|
when :option then -> { Option::Base.new(self) }
|
2023-07-25 08:17:51 +01:00
|
|
|
end
|
2023-07-20 09:50:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def director
|
2023-07-25 08:17:51 +01:00
|
|
|
%i[strip bus button vban command device option]
|
2023-07-20 09:50:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Remote
|
2023-08-01 23:44:47 +01:00
|
|
|
extend Logging
|
|
|
|
|
2023-08-29 11:21:05 +01:00
|
|
|
# Concrete class for Remote types
|
2023-07-07 02:36:35 +01:00
|
|
|
class Remote < Base
|
2023-07-20 09:50:16 +01:00
|
|
|
include Builder
|
|
|
|
|
2023-07-22 10:08:18 +01:00
|
|
|
public attr_reader :strip, :bus, :button, :vban, :command, :device, :option
|
|
|
|
|
2023-07-25 10:03:43 +01:00
|
|
|
def initialize(...)
|
2023-07-07 02:36:35 +01:00
|
|
|
super
|
2023-07-25 14:54:16 +01:00
|
|
|
director.each { |step| instance_variable_set("@#{step}", steps(step).call) }
|
2023-07-07 02:36:35 +01:00
|
|
|
end
|
2023-07-09 05:50:57 +01:00
|
|
|
|
|
|
|
def configs
|
2023-07-14 01:46:46 +01:00
|
|
|
Configs.get(kind.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
login
|
2023-07-21 14:37:17 +01:00
|
|
|
if event.any?
|
|
|
|
init_event_threads
|
|
|
|
end
|
2023-07-14 01:46:46 +01:00
|
|
|
|
2023-07-14 17:07:56 +01:00
|
|
|
yield(self) if block_given?
|
2023-07-21 14:37:17 +01:00
|
|
|
ensure
|
|
|
|
end_event_threads
|
2023-07-14 01:46:46 +01:00
|
|
|
logout
|
2023-07-09 05:50:57 +01:00
|
|
|
end
|
2023-07-07 02:36:35 +01:00
|
|
|
end
|
|
|
|
|
2023-08-27 21:36:52 +01:00
|
|
|
# Represents a RemoteBasic type
|
2023-08-29 11:21:05 +01:00
|
|
|
class RemoteBasic < Remote; end
|
2023-07-16 22:33:02 +01:00
|
|
|
|
2023-08-29 11:21:05 +01:00
|
|
|
# Represents a RemoteBanana type
|
2023-07-16 22:33:02 +01:00
|
|
|
class RemoteBanana < Remote
|
2023-07-22 10:08:18 +01:00
|
|
|
public attr_reader :recorder, :patch
|
2023-07-20 09:50:16 +01:00
|
|
|
|
|
|
|
private def director
|
2023-07-29 21:36:13 +01:00
|
|
|
super | [:recorder, :patch]
|
2023-07-20 09:50:16 +01:00
|
|
|
end
|
2023-07-16 22:33:02 +01:00
|
|
|
end
|
|
|
|
|
2023-08-29 11:21:05 +01:00
|
|
|
# Represents a RemotePotato type
|
2023-07-16 22:33:02 +01:00
|
|
|
class RemotePotato < Remote
|
2023-07-22 10:08:18 +01:00
|
|
|
public attr_reader :recorder, :patch, :fx
|
2023-07-20 09:50:16 +01:00
|
|
|
|
|
|
|
private def director
|
2023-07-29 21:36:13 +01:00
|
|
|
super | [:recorder, :patch, :fx]
|
2023-07-20 09:50:16 +01:00
|
|
|
end
|
2023-07-16 22:33:02 +01:00
|
|
|
end
|
|
|
|
|
2023-08-29 11:21:05 +01:00
|
|
|
# Factory class for Remote types. Returns a Remote class of a kind.
|
2023-07-22 10:08:18 +01:00
|
|
|
class RequestRemote
|
2023-07-22 16:44:34 +01:00
|
|
|
def self.for(kind, **)
|
2023-07-22 10:08:18 +01:00
|
|
|
case kind.name
|
|
|
|
when :basic
|
2023-07-22 16:44:34 +01:00
|
|
|
RemoteBasic.new(kind, **)
|
2023-07-22 10:08:18 +01:00
|
|
|
when :banana
|
2023-07-22 16:44:34 +01:00
|
|
|
RemoteBanana.new(kind, **)
|
2023-07-22 10:08:18 +01:00
|
|
|
when :potato
|
2023-07-22 16:44:34 +01:00
|
|
|
RemotePotato.new(kind, **)
|
2023-07-22 10:08:18 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-29 11:21:05 +01:00
|
|
|
# Interface entry point. Wraps factory class and handles kind errors.
|
2023-07-22 16:44:34 +01:00
|
|
|
def self.new(kind_id, **)
|
2023-07-16 22:33:02 +01:00
|
|
|
kind = Kinds.get(kind_id)
|
2023-08-01 23:44:47 +01:00
|
|
|
rescue KeyError => e
|
|
|
|
logger.error "#{e.class.name}: #{e.message}"
|
2023-08-09 17:45:50 +01:00
|
|
|
raise Errors::VMError.new "unknown Voicemeeter kind '#{kind_id}'"
|
2023-07-16 22:33:02 +01:00
|
|
|
else
|
2023-07-22 16:44:34 +01:00
|
|
|
RequestRemote.for(kind, **)
|
2023-07-07 02:36:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|