mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-22 01:40:49 +00:00
now using standard Ruby logger module
easy_logging removed from dependencies @configs now raises error on invalid key
This commit is contained in:
parent
35355fb31c
commit
f14a549c03
@ -1,7 +1,4 @@
|
|||||||
require_relative "../../lib/voicemeeter"
|
require_relative "../../lib/voicemeeter"
|
||||||
require "easy_logging"
|
|
||||||
|
|
||||||
EasyLogging.level = Logger::DEBUG
|
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -4,11 +4,12 @@ require_relative "kinds"
|
|||||||
require_relative "midi"
|
require_relative "midi"
|
||||||
require_relative "event"
|
require_relative "event"
|
||||||
require_relative "worker"
|
require_relative "worker"
|
||||||
require "easy_logging"
|
require_relative "errors"
|
||||||
|
require_relative "logger"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
class Base
|
class Base
|
||||||
# include EasyLogging
|
include Logging
|
||||||
include Worker
|
include Worker
|
||||||
include Events::Callbacks
|
include Events::Callbacks
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def login
|
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
|
clear_dirty
|
||||||
logger.info "Successfully logged into #{self} version #{version}"
|
logger.info "Successfully logged into #{self} version #{version}"
|
||||||
if event.any?
|
if event.any?
|
||||||
@ -68,25 +69,21 @@ module Voicemeeter
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def clear_dirty
|
def clear_dirty
|
||||||
while pdirty? || mdirty?
|
while pdirty? || mdirty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def runvm
|
def run_voicemeeter(kind_id)
|
||||||
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_id])
|
||||||
sleep(1)
|
sleep(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
public
|
|
||||||
|
|
||||||
def type
|
def type
|
||||||
ckind = FFI::MemoryPointer.new(:long, 1)
|
ckind = FFI::MemoryPointer.new(:long, 1)
|
||||||
CBindings.call(:bind_get_voicemeeter_type, ckind)
|
CBindings.call(:bind_get_voicemeeter_type, ckind)
|
||||||
@ -147,7 +144,7 @@ module Voicemeeter
|
|||||||
cget.read_float
|
cget.read_float
|
||||||
end
|
end
|
||||||
|
|
||||||
def _get_levels
|
private def _get_levels
|
||||||
[
|
[
|
||||||
(0...kind.num_strip_levels).map do |i|
|
(0...kind.num_strip_levels).map do |i|
|
||||||
get_level(cache[:strip_mode], i)
|
get_level(cache[:strip_mode], i)
|
||||||
@ -158,7 +155,7 @@ module Voicemeeter
|
|||||||
|
|
||||||
def get_num_devices(dir)
|
def get_num_devices(dir)
|
||||||
unless %i[in out].include? 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
|
end
|
||||||
if dir == :in
|
if dir == :in
|
||||||
CBindings.call(:bind_input_get_device_number, exp: ->(x) { x >= 0 })
|
CBindings.call(:bind_input_get_device_number, exp: ->(x) { x >= 0 })
|
||||||
@ -169,7 +166,7 @@ module Voicemeeter
|
|||||||
|
|
||||||
def get_device_description(index, dir)
|
def get_device_description(index, dir)
|
||||||
unless %i[in out].include? 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
|
end
|
||||||
ctype = FFI::MemoryPointer.new(:long, 1)
|
ctype = FFI::MemoryPointer.new(:long, 1)
|
||||||
cname = FFI::MemoryPointer.new(:string, 256, true)
|
cname = FFI::MemoryPointer.new(:string, 256, true)
|
||||||
|
@ -15,7 +15,7 @@ module Voicemeeter
|
|||||||
)
|
)
|
||||||
ffi_convention :stdcall
|
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
|
ruby_name = "bind_#{c_name.to_s.delete_prefix("VBVMR_").snakecase}".to_sym
|
||||||
super(ruby_name, c_name, args, returns)
|
super(ruby_name, c_name, args, returns)
|
||||||
end
|
end
|
||||||
|
@ -1,21 +1,24 @@
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
require "easy_logging"
|
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
|
||||||
require_relative "kinds"
|
require_relative "kinds"
|
||||||
|
require_relative "logger"
|
||||||
|
require_relative "errors"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module Configs
|
module Configs
|
||||||
private
|
private
|
||||||
|
|
||||||
class Loader
|
class Loader
|
||||||
include EasyLogging
|
include Logging
|
||||||
|
|
||||||
attr_reader :configs
|
attr_reader :configs
|
||||||
|
|
||||||
def initialize(kind)
|
def initialize(kind)
|
||||||
@kind = 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)
|
@reader = FileReader.new(self, kind)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -77,7 +80,7 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
class FileReader
|
class FileReader
|
||||||
include EasyLogging
|
include Logging
|
||||||
|
|
||||||
def initialize(loader, kind)
|
def initialize(loader, kind)
|
||||||
@loader = loader
|
@loader = loader
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require "easy_logging"
|
require_relative "logger"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module Events
|
module Events
|
||||||
@ -25,7 +25,7 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Tracker
|
class Tracker
|
||||||
# include EasyLogging
|
include Logging
|
||||||
|
|
||||||
attr_reader :pdirty, :mdirty, :midi, :ldirty
|
attr_reader :pdirty, :mdirty, :midi, :ldirty
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
require_relative "errors"
|
require_relative "errors"
|
||||||
require_relative "meta"
|
require_relative "meta"
|
||||||
require "easy_logging"
|
require_relative "logger"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
class IRemote
|
class IRemote
|
||||||
include EasyLogging
|
include Logging
|
||||||
include MetaFunctions
|
include MetaFunctions
|
||||||
|
|
||||||
def initialize(remote, i = nil)
|
def initialize(remote, i = nil)
|
||||||
@ -16,6 +16,8 @@ module Voicemeeter
|
|||||||
"#{self.class.name.split("::").last}#{@index}#{@remote.kind}"
|
"#{self.class.name.split("::").last}#{@index}#{@remote.kind}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def getter(param, is_string = false)
|
def getter(param, is_string = false)
|
||||||
logger.debug "getter: #{_cmd(param)}"
|
logger.debug "getter: #{_cmd(param)}"
|
||||||
@remote.get(_cmd(param), is_string)
|
@remote.get(_cmd(param), is_string)
|
||||||
@ -34,6 +36,8 @@ module Voicemeeter
|
|||||||
raise "Called abstract method: identifier"
|
raise "Called abstract method: identifier"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
public
|
||||||
|
|
||||||
def apply(params)
|
def apply(params)
|
||||||
params.each do |key, val|
|
params.each do |key, val|
|
||||||
if val.is_a? Hash
|
if val.is_a? Hash
|
||||||
|
@ -31,14 +31,14 @@ module Voicemeeter
|
|||||||
|
|
||||||
KIND_MAPS = [basic, banana, potato].to_h { |kind| [kind.name, kind] }
|
KIND_MAPS = [basic, banana, potato].to_h { |kind| [kind.name, kind] }
|
||||||
|
|
||||||
public
|
|
||||||
|
|
||||||
module KindEnum
|
module KindEnum
|
||||||
BASIC = 1
|
BASIC = 1
|
||||||
BANANA = 2
|
BANANA = 2
|
||||||
POTATO = 3
|
POTATO = 3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
public
|
||||||
|
|
||||||
def get(kind_id)
|
def get(kind_id)
|
||||||
KIND_MAPS[kind_id]
|
KIND_MAPS[kind_id]
|
||||||
end
|
end
|
||||||
|
11
lib/voicemeeter/logger.rb
Normal file
11
lib/voicemeeter/logger.rb
Normal 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
|
@ -4,7 +4,6 @@ require_relative "mixins"
|
|||||||
require_relative "errors"
|
require_relative "errors"
|
||||||
|
|
||||||
require "date"
|
require "date"
|
||||||
require "easy_logging"
|
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module Recorder
|
module Recorder
|
||||||
@ -16,7 +15,6 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Recorder < IRemote
|
class Recorder < IRemote
|
||||||
include EasyLogging
|
|
||||||
include Mixins::Outputs
|
include Mixins::Outputs
|
||||||
|
|
||||||
attr_reader :mode, :armstrip, :armbus
|
attr_reader :mode, :armstrip, :armbus
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
require "easy_logging"
|
require_relative "logger"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module Worker
|
module Worker
|
||||||
include EasyLogging
|
include Logging
|
||||||
|
|
||||||
def init_producer(que)
|
def init_producer(que)
|
||||||
Thread.new do
|
Thread.new do
|
||||||
|
@ -14,7 +14,6 @@ Gem::Specification.new do |spec|
|
|||||||
spec.homepage = "https://rubygems.org/gems/voicemeeter"
|
spec.homepage = "https://rubygems.org/gems/voicemeeter"
|
||||||
spec.license = "MIT"
|
spec.license = "MIT"
|
||||||
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_development_dependency "rspec", "~> 3.4"
|
spec.add_development_dependency "rspec", "~> 3.4"
|
||||||
spec.add_development_dependency "standard", "~> 1.30"
|
spec.add_development_dependency "standard", "~> 1.30"
|
||||||
spec.required_ruby_version = ">= 3.2"
|
spec.required_ruby_version = ">= 3.2"
|
||||||
|
Loading…
Reference in New Issue
Block a user