diff --git a/examples/events/main.rb b/examples/events/main.rb index bbab054..98ab905 100644 --- a/examples/events/main.rb +++ b/examples/events/main.rb @@ -1,7 +1,4 @@ require_relative "../../lib/voicemeeter" -require "easy_logging" - -EasyLogging.level = Logger::DEBUG class Main def initialize diff --git a/lib/voicemeeter/base.rb b/lib/voicemeeter/base.rb index cf1cf44..ef42e52 100644 --- a/lib/voicemeeter/base.rb +++ b/lib/voicemeeter/base.rb @@ -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) diff --git a/lib/voicemeeter/cbindings.rb b/lib/voicemeeter/cbindings.rb index ca4a9c8..a05e558 100644 --- a/lib/voicemeeter/cbindings.rb +++ b/lib/voicemeeter/cbindings.rb @@ -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 diff --git a/lib/voicemeeter/configs.rb b/lib/voicemeeter/configs.rb index 7d4cd08..5f3f918 100644 --- a/lib/voicemeeter/configs.rb +++ b/lib/voicemeeter/configs.rb @@ -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 diff --git a/lib/voicemeeter/event.rb b/lib/voicemeeter/event.rb index bc08444..57184e0 100644 --- a/lib/voicemeeter/event.rb +++ b/lib/voicemeeter/event.rb @@ -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 diff --git a/lib/voicemeeter/iremote.rb b/lib/voicemeeter/iremote.rb index 3957be9..d6cac63 100644 --- a/lib/voicemeeter/iremote.rb +++ b/lib/voicemeeter/iremote.rb @@ -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 diff --git a/lib/voicemeeter/kinds.rb b/lib/voicemeeter/kinds.rb index 6e529bd..0b8fc28 100644 --- a/lib/voicemeeter/kinds.rb +++ b/lib/voicemeeter/kinds.rb @@ -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 diff --git a/lib/voicemeeter/logger.rb b/lib/voicemeeter/logger.rb new file mode 100644 index 0000000..ce9a66b --- /dev/null +++ b/lib/voicemeeter/logger.rb @@ -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 diff --git a/lib/voicemeeter/recorder.rb b/lib/voicemeeter/recorder.rb index 463db87..c7dc534 100644 --- a/lib/voicemeeter/recorder.rb +++ b/lib/voicemeeter/recorder.rb @@ -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 diff --git a/lib/voicemeeter/worker.rb b/lib/voicemeeter/worker.rb index 143db6b..08d33e4 100644 --- a/lib/voicemeeter/worker.rb +++ b/lib/voicemeeter/worker.rb @@ -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 diff --git a/voicemeeter.gemspec b/voicemeeter.gemspec index 040818d..e3c1bf7 100644 --- a/voicemeeter.gemspec +++ b/voicemeeter.gemspec @@ -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"