run files through standard

This commit is contained in:
onyx-and-iris 2023-07-14 11:44:49 +01:00
parent 91253385e6
commit e3b72b9c45
6 changed files with 38 additions and 34 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"standardRuby.commandPath": "C:\\Ruby32-x64\\bin\\standardrb.bat"
}

View File

@ -8,6 +8,7 @@ require "easy_logging"
module Voicemeeter module Voicemeeter
class Base class Base
include EasyLogging
include Worker include Worker
include Events::Callbacks include Events::Callbacks
@ -25,8 +26,7 @@ module Voicemeeter
Events::Tracker.new( Events::Tracker.new(
**(kwargs.select { |k, _| %i[pdirty mdirty ldirty midi].include? k }) **(kwargs.select { |k, _| %i[pdirty mdirty ldirty midi].include? k })
) )
@callbacks = Array.new @callbacks = []
@running = false
@que = Queue.new @que = Queue.new
@cache = {strip_mode: 0} @cache = {strip_mode: 0}
end end
@ -36,7 +36,7 @@ module Voicemeeter
end end
def login def login
self.runvm if CBindings.call(:bind_login, ok: [0, 1]) == 1 runvm if CBindings.call(:bind_login, ok: [0, 1]) == 1
clear_dirty clear_dirty
logger.info "Successfully logged into #{self} version #{version}" logger.info "Successfully logged into #{self} version #{version}"
if event.any? if event.any?
@ -79,7 +79,7 @@ module Voicemeeter
kinds = { kinds = {
basic: Kinds::KindEnum::BASIC, basic: Kinds::KindEnum::BASIC,
banana: Kinds::KindEnum::BANANA, banana: Kinds::KindEnum::BANANA,
potato: Install::OS_BITS == 64 ? 6 : Kinds::KindEnum::POTATO potato: (Install::OS_BITS == 64) ? 6 : Kinds::KindEnum::POTATO
} }
CBindings.call(:bind_run_voicemeeter, kinds[kind.name]) CBindings.call(:bind_run_voicemeeter, kinds[kind.name])
sleep(1) sleep(1)

View File

@ -11,13 +11,8 @@ module Voicemeeter
attr_reader :eq, :mode, :levels attr_reader :eq, :mode, :levels
def self.make(remote, i) def self.make(remote, i)
"
Factory function for Bus classes.
Returns a PhysicalBus or VirtualBus class
"
p_out = remote.kind.phys_out p_out = remote.kind.phys_out
i < p_out ? PhysicalBus.new(remote, i) : VirtualBus.new(remote, i) (i < p_out) ? PhysicalBus.new(remote, i) : VirtualBus.new(remote, i)
end end
def initialize(remote, i) def initialize(remote, i)
@ -88,12 +83,12 @@ module Voicemeeter
end end
def getter(mode) def getter(mode)
if @remote.running && @remote.event.ldirty vals = if @remote.running && @remote.event.ldirty
vals = @remote.cache[:bus_level][@init, @offset] @remote.cache[:bus_level][@init, @offset]
else else
vals = (@init...@init + @offset).map { |i| @remote.get_level(mode, i) } (@init...@init + @offset).map { |i| @remote.get_level(mode, i) }
end end
vals.map { |x| x > 0 ? (20 * Math.log(x, 10)).round(1) : -200.0 } vals.map { |x| (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 }
end end
def all def all

View File

@ -1,3 +1,5 @@
require "easy_logging"
module Voicemeeter module Voicemeeter
module Events module Events
module Callbacks module Callbacks
@ -16,13 +18,15 @@ module Voicemeeter
if callback.respond_to? :on_update if callback.respond_to? :on_update
callback.on_update { event.to_s[3..] } callback.on_update { event.to_s[3..] }
else else
callback.call if callback.name == event callback.call # if callback == event
end end
end end
end end
end end
class Tracker class Tracker
include EasyLogging
attr_reader :pdirty, :mdirty, :midi, :ldirty attr_reader :pdirty, :mdirty, :midi, :ldirty
def initialize(pdirty: false, mdirty: false, midi: false, ldirty: false) def initialize(pdirty: false, mdirty: false, midi: false, ldirty: false)
@ -33,15 +37,15 @@ module Voicemeeter
end end
def to_s def to_s
"#{self.class.name.split("::").last}" self.class.name.split("::").last.to_s
end end
def info(msg = nil) def info(msg = nil)
info_msg = msg ? ["#{msg} events."] : [] info_msg = msg ? ["#{msg} events."] : []
if any? info_msg += if any?
info_msg += ["Now listening for #{get.join(", ")} events"] ["Now listening for #{get.join(", ")} events"]
else else
info_msg += ["Not listening for any events"] ["Not listening for any events"]
end end
logger.info(info_msg.join(" ")) logger.info(info_msg.join(" "))
end end
@ -67,7 +71,7 @@ module Voicemeeter
end end
def get def get
%w[pdirty mdirty midi ldirty].reject { |ev| !send("#{ev}") } %w[pdirty mdirty midi ldirty].reject { |ev| !send(ev.to_s) }
end end
def any? def any?

View File

@ -13,6 +13,7 @@ module Voicemeeter
que << :ldirty if event.ldirty que << :ldirty if event.ldirty
sleep(@ratelimit) sleep(@ratelimit)
end end
logger.debug("closing producer thread")
que << :stop que << :stop
end end
end end
@ -25,8 +26,8 @@ module Voicemeeter
loop do loop do
e_from_que = @que.pop e_from_que = @que.pop
if e_from_que == :stop if e_from_que == :stop
logger.debug("closing worker thread")
break break
logger.debug("closing #{self} thread")
end end
on_event :on_pdirty if e_from_que == :pdirty && pdirty? on_event :on_pdirty if e_from_que == :pdirty && pdirty?
on_event :on_mdirty if e_from_que == :mdirty && mdirty? on_event :on_mdirty if e_from_que == :mdirty && mdirty?

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require File.expand_path("lib/voicemeeter/version", __dir__) require File.expand_path("lib/voicemeeter/version", __dir__)
lib = File.expand_path("./lib")
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = "voicemeeter" spec.name = "voicemeeter"
@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "ffi", "~> 1.9", ">= 1.9.10" spec.add_runtime_dependency "ffi", "~> 1.9", ">= 1.9.10"
spec.add_runtime_dependency "easy_logging", "~> 0.4.0" spec.add_runtime_dependency "easy_logging", "~> 0.4.0"
spec.add_development_dependency "rspec", "~> 3.4" spec.add_development_dependency "rspec", "~> 3.4"
spec.add_development_dependency "standard", "~> 1.30"
spec.required_ruby_version = ">= 3.0" spec.required_ruby_version = ">= 3.0"
spec.metadata = { spec.metadata = {
"source_code_uri" => "https://github.com/onyx-and-iris/voicemeeter-rb.git" "source_code_uri" => "https://github.com/onyx-and-iris/voicemeeter-rb.git"