From ce27f46a472d9173ef2ecfce192c8caecd519825 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 27 Jul 2023 10:58:26 +0100 Subject: [PATCH] Mixin IRemote methods added docstrings --- lib/voicemeeter/base.rb | 1 + lib/voicemeeter/bus.rb | 26 +++++++++++++++++------- lib/voicemeeter/button.rb | 4 +++- lib/voicemeeter/cbindings.rb | 2 ++ lib/voicemeeter/command.rb | 4 +++- lib/voicemeeter/fx.rb | 11 ++++++++--- lib/voicemeeter/install.rb | 1 - lib/voicemeeter/iremote.rb | 4 +++- lib/voicemeeter/kinds.rb | 2 ++ lib/voicemeeter/option.rb | 15 ++++++++++---- lib/voicemeeter/patch.rb | 16 +++++++++++---- lib/voicemeeter/recorder.rb | 12 +++++++++--- lib/voicemeeter/remote.rb | 24 ++++++++++++++++------- lib/voicemeeter/strip.rb | 38 ++++++++++++++++++++++++++---------- lib/voicemeeter/util.rb | 12 +++++++----- lib/voicemeeter/vban.rb | 9 +++++---- lib/voicemeeter/worker.rb | 2 ++ 17 files changed, 132 insertions(+), 51 deletions(-) diff --git a/lib/voicemeeter/base.rb b/lib/voicemeeter/base.rb index 9d6381c..c4f4b3a 100644 --- a/lib/voicemeeter/base.rb +++ b/lib/voicemeeter/base.rb @@ -10,6 +10,7 @@ require_relative "logger" module Voicemeeter class Base + # Base class for Remote types include Logging include Worker prepend Util::Cache diff --git a/lib/voicemeeter/bus.rb b/lib/voicemeeter/bus.rb index 9adfb97..5c32c06 100644 --- a/lib/voicemeeter/bus.rb +++ b/lib/voicemeeter/bus.rb @@ -4,7 +4,9 @@ require_relative "mixins" module Voicemeeter module Bus - class Bus < IRemote + class Base + # Base class for Bus types + include IRemote include Mixins::Fades include Mixins::Return @@ -31,13 +33,17 @@ module Voicemeeter end end - class PhysicalBus < Bus + class PhysicalBus < Base + # Represents a Physical Bus end - class VirtualBus < Bus + class VirtualBus < Base + # Represents a Virtual Bus end - class BusEq < IRemote + class BusEq + include IRemote + def initialize(remote, i) super make_accessor_bool :on, :ab @@ -48,7 +54,9 @@ module Voicemeeter end end - class BusModes < IRemote + class BusModes + include IRemote + def initialize(remote, i) super make_accessor_bool :normal, @@ -81,7 +89,9 @@ module Voicemeeter end end - class BusLevels < IRemote + class BusLevels + include IRemote + def initialize(remote, i) super @init = i * 8 @@ -110,7 +120,9 @@ module Voicemeeter def isdirty? = @remote.cache[:bus_comp][@init, @offset].any? end - class BusDevice < IRemote + class BusDevice + include IRemote + def initialize(remote, i) super make_reader_only :name, :sr diff --git a/lib/voicemeeter/button.rb b/lib/voicemeeter/button.rb index 4728f8e..aea10f9 100644 --- a/lib/voicemeeter/button.rb +++ b/lib/voicemeeter/button.rb @@ -23,7 +23,9 @@ module Voicemeeter end end - class Button < IRemote + class Base + # Base class for Button types + include IRemote include ButtonColorMixin def getter(mode) diff --git a/lib/voicemeeter/cbindings.rb b/lib/voicemeeter/cbindings.rb index 4b32ddb..cdc538f 100644 --- a/lib/voicemeeter/cbindings.rb +++ b/lib/voicemeeter/cbindings.rb @@ -5,6 +5,8 @@ require_relative "logger" module Voicemeeter module CBindings + # Ruby bindings for the C-API functions + private extend Logging diff --git a/lib/voicemeeter/command.rb b/lib/voicemeeter/command.rb index adee6db..17783df 100644 --- a/lib/voicemeeter/command.rb +++ b/lib/voicemeeter/command.rb @@ -2,7 +2,9 @@ require_relative "iremote" require_relative "meta" module Voicemeeter - class Command < IRemote + class Command + include IRemote + def initialize(remote) super make_action_method :show, :restart, :shutdown diff --git a/lib/voicemeeter/fx.rb b/lib/voicemeeter/fx.rb index 471cc57..e15ab5e 100644 --- a/lib/voicemeeter/fx.rb +++ b/lib/voicemeeter/fx.rb @@ -1,7 +1,8 @@ require_relative "iremote" module Voicemeeter - class Fx < IRemote + class Fx + include IRemote attr_reader :reverb, :delay def initialize(remote) @@ -15,7 +16,9 @@ module Voicemeeter end end - class FxReverb < IRemote + class FxReverb + include IRemote + def initialize(remote) super make_accessor_bool :on, :ab @@ -26,7 +29,9 @@ module Voicemeeter end end - class FxDelay < IRemote + class FxDelay + include IRemote + def initialize(remote) super make_accessor_bool :on, :ab diff --git a/lib/voicemeeter/install.rb b/lib/voicemeeter/install.rb index ebabe03..18d2b86 100644 --- a/lib/voicemeeter/install.rb +++ b/lib/voicemeeter/install.rb @@ -5,7 +5,6 @@ require "ffi" module Voicemeeter private - # stree-ignore module Install OS_BITS = (FFI::Platform::CPU.downcase == "x64") ? 64 : 32 diff --git a/lib/voicemeeter/iremote.rb b/lib/voicemeeter/iremote.rb index d6cac63..152b599 100644 --- a/lib/voicemeeter/iremote.rb +++ b/lib/voicemeeter/iremote.rb @@ -3,7 +3,9 @@ require_relative "meta" require_relative "logger" module Voicemeeter - class IRemote + module IRemote + # A commmon interface between the base Remote class and extended classes. + include Logging include MetaFunctions diff --git a/lib/voicemeeter/kinds.rb b/lib/voicemeeter/kinds.rb index d0a3044..3326c85 100644 --- a/lib/voicemeeter/kinds.rb +++ b/lib/voicemeeter/kinds.rb @@ -1,5 +1,7 @@ module Voicemeeter module Kinds + # KindMaps that describe the layout for each kind + private KindMap = diff --git a/lib/voicemeeter/option.rb b/lib/voicemeeter/option.rb index aa5343e..68a6e35 100644 --- a/lib/voicemeeter/option.rb +++ b/lib/voicemeeter/option.rb @@ -2,7 +2,8 @@ require_relative "iremote" module Voicemeeter module Option - class Option < IRemote + class Base + include IRemote attr_reader :delay, :buffer, :mode def initialize(remote) @@ -20,7 +21,9 @@ module Voicemeeter end end - class OptionDelay < IRemote + class OptionDelay + include IRemote + def initialize(remote, i) super make_accessor_bool :on, :ab @@ -39,7 +42,9 @@ module Voicemeeter end end - class OptionBuffer < IRemote + class OptionBuffer + include IRemote + def initialize(remote) super make_accessor_int :mme, :wdm, :ks, :asio @@ -50,7 +55,9 @@ module Voicemeeter end end - class OptionMode < IRemote + class OptionMode + include IRemote + def initialize(remote) super make_accessor_bool :exclusif, :swift diff --git a/lib/voicemeeter/patch.rb b/lib/voicemeeter/patch.rb index dabfa41..d32b0e2 100644 --- a/lib/voicemeeter/patch.rb +++ b/lib/voicemeeter/patch.rb @@ -2,7 +2,9 @@ require_relative "iremote" module Voicemeeter module Patch - class Patch < IRemote + class Base + # Base class for Patch types + include IRemote attr_reader :asio, :A2, :A3, :A4, :A5, :composite, :insert def initialize(remote) @@ -19,7 +21,9 @@ module Voicemeeter end end - class PatchAsio < IRemote + class PatchAsio + include IRemote + def identifier :patch end @@ -50,7 +54,9 @@ module Voicemeeter end end - class PatchComposite < IRemote + class PatchComposite + include IRemote + def get getter("composite[#{@index}]").to_i end @@ -60,7 +66,9 @@ module Voicemeeter end end - class PatchInsert < IRemote + class PatchInsert + include IRemote + def get getter("insert[#{@index}]").to_i == 1 end diff --git a/lib/voicemeeter/recorder.rb b/lib/voicemeeter/recorder.rb index 316687f..62518be 100644 --- a/lib/voicemeeter/recorder.rb +++ b/lib/voicemeeter/recorder.rb @@ -14,7 +14,9 @@ module Voicemeeter MP3 = 100 end - class Recorder < IRemote + class Base + # Base class for Recorder types + include IRemote include Mixins::Outputs attr_reader :mode, :armstrip, :armbus @@ -54,7 +56,9 @@ module Voicemeeter end end - class RecorderMode < IRemote + class RecorderMode + include IRemote + def initialize(remote) super make_accessor_bool :recbus, :playonload, :loop, :multitrack @@ -65,7 +69,9 @@ module Voicemeeter end end - class RecorderArmChannel < IRemote + class RecorderArmChannel + include IRemote + def initialize(remote, j) super(remote) @j = j diff --git a/lib/voicemeeter/remote.rb b/lib/voicemeeter/remote.rb index 6ba07e9..b1d572e 100644 --- a/lib/voicemeeter/remote.rb +++ b/lib/voicemeeter/remote.rb @@ -15,20 +15,24 @@ require_relative "configs" module Voicemeeter module Builder + # Builder module for Remote factories. + # Defines steps for building a Remote type of a kind. + # Defines the base director + private def steps(step) case step - when :strip then -> { (0...kind.num_strip).map { Strip::Strip.make(self, _1) } } - when :bus then -> { (0...kind.num_bus).map { Bus::Bus.make(self, _1) } } - when :button then -> { (0...kind.num_buttons).map { Button::Button.new(self, _1) } } - when :vban then -> { Vban::Vban.new(self) } + 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) } when :command then -> { Command.new(self) } - when :recorder then -> { Recorder::Recorder.new(self) } + when :recorder then -> { Recorder::Base.new(self) } when :device then -> { Device.new(self) } when :fx then -> { Fx.new(self) } - when :patch then -> { Patch::Patch.new(self) } - when :option then -> { Option::Option.new(self) } + when :patch then -> { Patch::Base.new(self) } + when :option then -> { Option::Base.new(self) } end end @@ -39,6 +43,7 @@ module Voicemeeter module Remote class Remote < Base + # Concrete class for Remote types include Builder public attr_reader :strip, :bus, :button, :vban, :command, :device, :option @@ -66,9 +71,11 @@ module Voicemeeter end class RemoteBasic < Remote + # Concrete class for RemoteBasic types end class RemoteBanana < Remote + # Concrete class for RemoteBanana types public attr_reader :recorder, :patch private def director @@ -77,6 +84,7 @@ module Voicemeeter end class RemotePotato < Remote + # Concrete class for RemotePotato types public attr_reader :recorder, :patch, :fx private def director @@ -85,6 +93,7 @@ module Voicemeeter end class RequestRemote + # Factory class for Remote types. Returns a Remote class for a kind. def self.for(kind, **) case kind.name when :basic @@ -100,6 +109,7 @@ module Voicemeeter public def self.new(kind_id, **) + # Interface entry point. Wraps factory class and handles kind errors. kind = Kinds.get(kind_id) rescue KeyError raise Errors::VMError.new "unknown Voicemeeter kind #{kind_id}" diff --git a/lib/voicemeeter/strip.rb b/lib/voicemeeter/strip.rb index 2451053..fed083a 100644 --- a/lib/voicemeeter/strip.rb +++ b/lib/voicemeeter/strip.rb @@ -4,7 +4,9 @@ require_relative "mixins" module Voicemeeter module Strip - class Strip < IRemote + class Base + # Base class for Strip types + include IRemote include Mixins::Outputs include Mixins::Fades @@ -31,7 +33,8 @@ module Voicemeeter end end - class PhysicalStrip < Strip + class PhysicalStrip < Base + # Represents a Physical Strip include Mixins::Xy::Pan include Mixins::Xy::Color include Mixins::Xy::Fx @@ -51,7 +54,9 @@ module Voicemeeter end end - class StripComp < IRemote + class StripComp + include IRemote + def initialize(remote, i) super make_accessor_float :gainin, @@ -77,7 +82,9 @@ module Voicemeeter end end - class StripGate < IRemote + class StripGate + include IRemote + def initialize(remote, i) super make_accessor_float :threshold, :damping, :attack, :hold, :release @@ -97,7 +104,9 @@ module Voicemeeter end end - class StripDenoiser < IRemote + class StripDenoiser + include IRemote + def identifier "strip[#{@index}].denoiser" end @@ -111,7 +120,9 @@ module Voicemeeter end end - class StripEq < IRemote + class StripEq + include IRemote + def initialize(remote, i) super make_accessor_bool :on, :ab @@ -122,7 +133,9 @@ module Voicemeeter end end - class StripDevice < IRemote + class StripDevice + include IRemote + def initialize(remote, i) super make_reader_int :sr @@ -135,7 +148,8 @@ module Voicemeeter end end - class VirtualStrip < Strip + class VirtualStrip < Base + # Represents a Virtual Strip include Mixins::Xy::Pan include Mixins::Apps @@ -175,7 +189,9 @@ module Voicemeeter alias_method :high=, :treble= end - class GainLayer < IRemote + class GainLayer + include IRemote + def initialize(remote, i, j) super(remote, i) @j = j @@ -194,7 +210,9 @@ module Voicemeeter end end - class StripLevels < IRemote + class StripLevels + include IRemote + def initialize(remote, i) super p_in = remote.kind.phys_in diff --git a/lib/voicemeeter/util.rb b/lib/voicemeeter/util.rb index 4499d2d..5b4f5fd 100644 --- a/lib/voicemeeter/util.rb +++ b/lib/voicemeeter/util.rb @@ -1,8 +1,8 @@ module Voicemeeter module Util module String - def snakecase(string) - string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + def snakecase(s) + s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("-", "_") .gsub(/\s/, "_") @@ -10,15 +10,17 @@ module Voicemeeter .downcase end - def camelcase(string) - string if string !~ /_/ && string =~ /[A-Z]+.*/ - string.split("_").map { |e| e.capitalize }.join + def camelcase(s) + s if s !~ /_/ && s =~ /[A-Z]+.*/ + s.split("_").map { |e| e.capitalize }.join end module_function :snakecase, :camelcase end module Cache + # Prepended methods, provides wrap-like functionality + def get(name, is_string = false) return cache.delete(name) if cache.key? name clear_dirty if @sync diff --git a/lib/voicemeeter/vban.rb b/lib/voicemeeter/vban.rb index 171e49b..6bf16dd 100644 --- a/lib/voicemeeter/vban.rb +++ b/lib/voicemeeter/vban.rb @@ -4,7 +4,9 @@ require_relative "errors" module Voicemeeter module Vban - class VbanStream < IRemote + class VbanStream + include IRemote + def initialize(remote, i) super make_accessor_bool :on @@ -43,7 +45,8 @@ module Voicemeeter end end - class Vban + class Base + # Base class for Vban type attr_reader :instream, :outstream def initialize(remote) @@ -54,12 +57,10 @@ module Voicemeeter @remote = remote end - # stree-ignore def enable @remote.set("vban.enable", 1) end - # stree-ignore def disable @remote.set("vban.enable", 0) end diff --git a/lib/voicemeeter/worker.rb b/lib/voicemeeter/worker.rb index 107584d..5e0a741 100644 --- a/lib/voicemeeter/worker.rb +++ b/lib/voicemeeter/worker.rb @@ -2,6 +2,8 @@ require_relative "logger" module Voicemeeter module Worker + # Event threads, provides updates to observers + include Logging def init_producer(que)