now using standard Ruby logger module

easy_logging removed from dependencies

@configs now raises error on invalid key
This commit is contained in:
onyx-and-iris 2023-07-16 11:08:24 +01:00
parent 35355fb31c
commit f14a549c03
11 changed files with 40 additions and 31 deletions

View File

@ -1,7 +1,4 @@
require_relative "../../lib/voicemeeter"
require "easy_logging"
EasyLogging.level = Logger::DEBUG
class Main
def initialize

View File

@ -4,11 +4,12 @@ require_relative "kinds"
require_relative "midi"
require_relative "event"
require_relative "worker"
require "easy_logging"
require_relative "errors"
require_relative "logger"
module Voicemeeter
class Base
# include EasyLogging
include Logging
include Worker
include Events::Callbacks
@ -36,7 +37,7 @@ module Voicemeeter
end
def login
runvm if CBindings.call(:bind_login, ok: [0, 1]) == 1
run_voicemeeter(kind.name) if CBindings.call(:bind_login, ok: [0, 1]) == 1
clear_dirty
logger.info "Successfully logged into #{self} version #{version}"
if event.any?
@ -68,25 +69,21 @@ module Voicemeeter
)
end
private
def clear_dirty
while pdirty? || mdirty?
end
end
def runvm
def run_voicemeeter(kind_id)
kinds = {
basic: Kinds::KindEnum::BASIC,
banana: Kinds::KindEnum::BANANA,
potato: (Install::OS_BITS == 64) ? 6 : Kinds::KindEnum::POTATO
}
CBindings.call(:bind_run_voicemeeter, kinds[kind.name])
CBindings.call(:bind_run_voicemeeter, kinds[kind_id])
sleep(1)
end
public
def type
ckind = FFI::MemoryPointer.new(:long, 1)
CBindings.call(:bind_get_voicemeeter_type, ckind)
@ -147,7 +144,7 @@ module Voicemeeter
cget.read_float
end
def _get_levels
private def _get_levels
[
(0...kind.num_strip_levels).map do |i|
get_level(cache[:strip_mode], i)
@ -158,7 +155,7 @@ module Voicemeeter
def get_num_devices(dir)
unless %i[in out].include? dir
raise VMError.new("dir got: #{dir}, expected in or out")
raise Errors::VMError.new("dir got: #{dir}, expected :in or :out")
end
if dir == :in
CBindings.call(:bind_input_get_device_number, exp: ->(x) { x >= 0 })
@ -169,7 +166,7 @@ module Voicemeeter
def get_device_description(index, dir)
unless %i[in out].include? dir
raise VMError.new("dir got: #{dir}, expected in or out")
raise Errors::VMError.new("dir got: #{dir}, expected :in or :out")
end
ctype = FFI::MemoryPointer.new(:long, 1)
cname = FFI::MemoryPointer.new(:string, 256, true)

View File

@ -15,7 +15,7 @@ module Voicemeeter
)
ffi_convention :stdcall
def self.attach_function(c_name, args, returns)
private_class_method def self.attach_function(c_name, args, returns)
ruby_name = "bind_#{c_name.to_s.delete_prefix("VBVMR_").snakecase}".to_sym
super(ruby_name, c_name, args, returns)
end

View File

@ -1,21 +1,24 @@
require "yaml"
require "easy_logging"
require "pathname"
require_relative "kinds"
require_relative "logger"
require_relative "errors"
module Voicemeeter
module Configs
private
class Loader
include EasyLogging
include Logging
attr_reader :configs
def initialize(kind)
@kind = kind
@configs = {}
@configs = Hash.new do |hash, key|
raise Errors::VMError.new("unknown config #{key}. known configs: #{hash.keys}")
end
@reader = FileReader.new(self, kind)
end
@ -77,7 +80,7 @@ module Voicemeeter
end
class FileReader
include EasyLogging
include Logging
def initialize(loader, kind)
@loader = loader

View File

@ -1,4 +1,4 @@
require "easy_logging"
require_relative "logger"
module Voicemeeter
module Events
@ -25,7 +25,7 @@ module Voicemeeter
end
class Tracker
# include EasyLogging
include Logging
attr_reader :pdirty, :mdirty, :midi, :ldirty

View File

@ -1,10 +1,10 @@
require_relative "errors"
require_relative "meta"
require "easy_logging"
require_relative "logger"
module Voicemeeter
class IRemote
include EasyLogging
include Logging
include MetaFunctions
def initialize(remote, i = nil)
@ -16,6 +16,8 @@ module Voicemeeter
"#{self.class.name.split("::").last}#{@index}#{@remote.kind}"
end
private
def getter(param, is_string = false)
logger.debug "getter: #{_cmd(param)}"
@remote.get(_cmd(param), is_string)
@ -34,6 +36,8 @@ module Voicemeeter
raise "Called abstract method: identifier"
end
public
def apply(params)
params.each do |key, val|
if val.is_a? Hash

View File

@ -31,14 +31,14 @@ module Voicemeeter
KIND_MAPS = [basic, banana, potato].to_h { |kind| [kind.name, kind] }
public
module KindEnum
BASIC = 1
BANANA = 2
POTATO = 3
end
public
def get(kind_id)
KIND_MAPS[kind_id]
end

11
lib/voicemeeter/logger.rb Normal file
View File

@ -0,0 +1,11 @@
require "logger"
module Voicemeeter
module Logging
def logger
@logger = Logger.new($stdout, level: ENV.fetch("LOG_LEVEL", "WARN"))
@logger.progname = self.class.name
@logger
end
end
end

View File

@ -4,7 +4,6 @@ require_relative "mixins"
require_relative "errors"
require "date"
require "easy_logging"
module Voicemeeter
module Recorder
@ -16,7 +15,6 @@ module Voicemeeter
end
class Recorder < IRemote
include EasyLogging
include Mixins::Outputs
attr_reader :mode, :armstrip, :armbus

View File

@ -1,8 +1,8 @@
require "easy_logging"
require_relative "logger"
module Voicemeeter
module Worker
include EasyLogging
include Logging
def init_producer(que)
Thread.new do

View File

@ -14,7 +14,6 @@ Gem::Specification.new do |spec|
spec.homepage = "https://rubygems.org/gems/voicemeeter"
spec.license = "MIT"
spec.add_runtime_dependency "ffi", "~> 1.9", ">= 1.9.10"
spec.add_runtime_dependency "easy_logging", "~> 0.4.0"
spec.add_development_dependency "rspec", "~> 3.4"
spec.add_development_dependency "standard", "~> 1.30"
spec.required_ruby_version = ">= 3.2"