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
|
module Voicemeeter
|
||||||
class Base
|
class Base
|
||||||
include EasyLogging
|
# include EasyLogging
|
||||||
include Worker
|
include Worker
|
||||||
include Events::Callbacks
|
include Events::Callbacks
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ module Voicemeeter
|
|||||||
def initialize(kind)
|
def initialize(kind)
|
||||||
@kind = kind
|
@kind = kind
|
||||||
@configs = {}
|
@configs = {}
|
||||||
|
@reader = FileReader.new(self, kind)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@ -24,15 +25,14 @@ module Voicemeeter
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# stree-ignore
|
|
||||||
def build_reset_profile
|
def build_reset_profile
|
||||||
aouts = (0...@kind.phys_out).to_h { |i| ["A#{i + 1}", 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}", false] }
|
bouts = (0...@kind.virt_out).to_h { |i| ["B#{i + 1}".to_sym, false] }
|
||||||
strip_bools = %w[mute mono solo].to_h { |param| [param, false] }
|
strip_bools = %i[mute mono solo].to_h { |param| [param, false] }
|
||||||
gain = [:gain].to_h { |param| [param, 0.0] }
|
gain = [:gain].to_h { |param| [param, 0.0] }
|
||||||
|
|
||||||
phys_float =
|
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}] }
|
eq = [:eq].to_h { |param| [param, {on: false}] }
|
||||||
|
|
||||||
overrides = {B1: true}
|
overrides = {B1: true}
|
||||||
@ -61,52 +61,67 @@ module Voicemeeter
|
|||||||
(0...@kind.num_bus).to_h do |i|
|
(0...@kind.num_bus).to_h do |i|
|
||||||
["bus-#{i}", {**bus_bools, **gain, **eq}]
|
["bus-#{i}", {**bus_bools, **gain, **eq}]
|
||||||
end
|
end
|
||||||
|
|
||||||
{**phys_strip, **virt_strip, **bus}
|
{**phys_strip, **virt_strip, **bus}
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_from_yml
|
def read_from_yml = @reader.read
|
||||||
# stree-ignore
|
|
||||||
configpaths = [
|
public
|
||||||
Pathname.getwd.join("configs", @kind.name.to_s),
|
|
||||||
Pathname.new(Dir.home).join(".config", "voicemeeter-rb", @kind.name.to_s),
|
def run
|
||||||
Pathname.new(Dir.home).join("Documents", "Voicemeeter", "configs", @kind.name.to_s)
|
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?
|
if configpath.exist?
|
||||||
logger.debug "checking #{configpath} for configs"
|
logger.debug "checking #{configpath} for configs"
|
||||||
filepaths = configpath.glob("*.yml")
|
filepaths = configpath.glob("*.yml")
|
||||||
filepaths.each do |filepath|
|
filepaths.each do |filepath|
|
||||||
filename = (filepath.basename.sub_ext "").to_s.to_sym
|
register(filepath)
|
||||||
if configs.key? filename
|
end
|
||||||
logger.debug "config with name '#{filename}' already in memory, skipping..."
|
end
|
||||||
next
|
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,
|
filepath,
|
||||||
symbolize_names: true
|
symbolize_names: true
|
||||||
)
|
)
|
||||||
logger.info "#{@kind.name}/#{filename} loaded into memory"
|
logger.info "#{@kind.name}/#{filename} loaded into memory"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
public
|
|
||||||
|
|
||||||
def build
|
|
||||||
logger.debug "Running #{self}"
|
|
||||||
configs[:reset] = build_reset_profile
|
|
||||||
read_from_yml
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|
||||||
def get(kind_id)
|
def get(kind_id)
|
||||||
if @loaders.nil?
|
if @loaders.nil?
|
||||||
@loaders = Kinds::ALL.to_h { |kind| [kind.name, Loader.new(kind)] }
|
@loaders = Kinds::ALL.to_h { |kind| [kind.name, Loader.new(kind)] }
|
||||||
@loaders.each { |name, loader| loader.build }
|
@loaders.each { |name, loader| loader.run }
|
||||||
end
|
end
|
||||||
@loaders[kind_id].configs
|
@loaders[kind_id].configs
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Tracker
|
class Tracker
|
||||||
include EasyLogging
|
# include EasyLogging
|
||||||
|
|
||||||
attr_reader :pdirty, :mdirty, :midi, :ldirty
|
attr_reader :pdirty, :mdirty, :midi, :ldirty
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user