mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-22 09:50:49 +00:00
add FileReader class to configs.rb
handles reading from yml and storing into configs hash
This commit is contained in:
parent
9c02586cef
commit
4b311520d4
@ -8,7 +8,7 @@ require "easy_logging"
|
||||
|
||||
module Voicemeeter
|
||||
class Base
|
||||
include EasyLogging
|
||||
# include EasyLogging
|
||||
include Worker
|
||||
include Events::Callbacks
|
||||
|
||||
|
@ -16,6 +16,7 @@ module Voicemeeter
|
||||
def initialize(kind)
|
||||
@kind = kind
|
||||
@configs = {}
|
||||
@reader = FileReader.new(self, kind)
|
||||
end
|
||||
|
||||
def to_s
|
||||
@ -24,15 +25,14 @@ module Voicemeeter
|
||||
|
||||
protected
|
||||
|
||||
# stree-ignore
|
||||
def build_reset_profile
|
||||
aouts = (0...@kind.phys_out).to_h { |i| ["A#{i + 1}", false] }
|
||||
bouts = (0...@kind.virt_out).to_h { |i| ["B#{i + 1}", false] }
|
||||
strip_bools = %w[mute mono solo].to_h { |param| [param, false] }
|
||||
aouts = (0...@kind.phys_out).to_h { |i| ["A#{i + 1}".to_sym, false] }
|
||||
bouts = (0...@kind.virt_out).to_h { |i| ["B#{i + 1}".to_sym, false] }
|
||||
strip_bools = %i[mute mono solo].to_h { |param| [param, false] }
|
||||
gain = [:gain].to_h { |param| [param, 0.0] }
|
||||
|
||||
phys_float =
|
||||
%w[comp gate denoiser].to_h { |param| [param, {knob: 0.0}] }
|
||||
%i[comp gate denoiser].to_h { |param| [param, {knob: 0.0}] }
|
||||
eq = [:eq].to_h { |param| [param, {on: false}] }
|
||||
|
||||
overrides = {B1: true}
|
||||
@ -61,52 +61,67 @@ module Voicemeeter
|
||||
(0...@kind.num_bus).to_h do |i|
|
||||
["bus-#{i}", {**bus_bools, **gain, **eq}]
|
||||
end
|
||||
|
||||
{**phys_strip, **virt_strip, **bus}
|
||||
end
|
||||
|
||||
def read_from_yml
|
||||
# stree-ignore
|
||||
configpaths = [
|
||||
Pathname.getwd.join("configs", @kind.name.to_s),
|
||||
Pathname.new(Dir.home).join(".config", "voicemeeter-rb", @kind.name.to_s),
|
||||
Pathname.new(Dir.home).join("Documents", "Voicemeeter", "configs", @kind.name.to_s)
|
||||
def read_from_yml = @reader.read
|
||||
|
||||
public
|
||||
|
||||
def run
|
||||
logger.debug "Running #{self}"
|
||||
configs[:reset] = build_reset_profile
|
||||
read_from_yml
|
||||
end
|
||||
end
|
||||
|
||||
class FileReader
|
||||
include EasyLogging
|
||||
|
||||
def initialize(loader, kind)
|
||||
@loader = loader
|
||||
@kind = kind
|
||||
@configpaths = [
|
||||
Pathname.getwd.join("configs", kind.name.to_s),
|
||||
Pathname.new(Dir.home).join(".config", "voicemeeter-rb", kind.name.to_s),
|
||||
Pathname.new(Dir.home).join("Documents", "Voicemeeter", "configs", kind.name.to_s)
|
||||
]
|
||||
configpaths.each do |configpath|
|
||||
end
|
||||
|
||||
def read
|
||||
@configpaths.each do |configpath|
|
||||
if configpath.exist?
|
||||
logger.debug "checking #{configpath} for configs"
|
||||
filepaths = configpath.glob("*.yml")
|
||||
filepaths.each do |filepath|
|
||||
filename = (filepath.basename.sub_ext "").to_s.to_sym
|
||||
if configs.key? filename
|
||||
logger.debug "config with name '#{filename}' already in memory, skipping..."
|
||||
next
|
||||
register(filepath)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
configs[filename] = YAML.load_file(
|
||||
def register(filepath)
|
||||
filename = (filepath.basename.sub_ext "").to_s.to_sym
|
||||
if @loader.configs.key? filename
|
||||
logger.debug "config with name '#{filename}' already in memory, skipping..."
|
||||
return
|
||||
end
|
||||
|
||||
@loader.configs[filename] = YAML.load_file(
|
||||
filepath,
|
||||
symbolize_names: true
|
||||
)
|
||||
logger.info "#{@kind.name}/#{filename} loaded into memory"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
def build
|
||||
logger.debug "Running #{self}"
|
||||
configs[:reset] = build_reset_profile
|
||||
read_from_yml
|
||||
end
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
def get(kind_id)
|
||||
if @loaders.nil?
|
||||
@loaders = Kinds::ALL.to_h { |kind| [kind.name, Loader.new(kind)] }
|
||||
@loaders.each { |name, loader| loader.build }
|
||||
@loaders.each { |name, loader| loader.run }
|
||||
end
|
||||
@loaders[kind_id].configs
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ module Voicemeeter
|
||||
end
|
||||
|
||||
class Tracker
|
||||
include EasyLogging
|
||||
# include EasyLogging
|
||||
|
||||
attr_reader :pdirty, :mdirty, :midi, :ldirty
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user