2023-07-09 05:47:37 +01:00
|
|
|
require "yaml"
|
2023-07-09 19:44:43 +01:00
|
|
|
require "pathname"
|
|
|
|
|
|
|
|
require_relative "kinds"
|
2023-07-16 11:08:24 +01:00
|
|
|
require_relative "logger"
|
|
|
|
require_relative "errors"
|
2023-07-09 05:47:37 +01:00
|
|
|
|
|
|
|
module Voicemeeter
|
|
|
|
module Configs
|
|
|
|
private
|
|
|
|
|
|
|
|
class Loader
|
2023-07-16 11:08:24 +01:00
|
|
|
include Logging
|
2023-07-09 05:47:37 +01:00
|
|
|
|
|
|
|
attr_reader :configs
|
|
|
|
|
|
|
|
def initialize(kind)
|
|
|
|
@kind = kind
|
2023-07-16 11:08:24 +01:00
|
|
|
@configs = Hash.new do |hash, key|
|
|
|
|
raise Errors::VMError.new("unknown config #{key}. known configs: #{hash.keys}")
|
|
|
|
end
|
2023-07-14 14:37:49 +01:00
|
|
|
@reader = FileReader.new(self, kind)
|
2023-07-09 21:05:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"Loader #{@kind}"
|
2023-07-09 05:47:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2023-07-09 21:05:47 +01:00
|
|
|
def build_reset_profile
|
2023-07-14 14:37:49 +01:00
|
|
|
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] }
|
2023-07-14 01:48:11 +01:00
|
|
|
gain = [:gain].to_h { |param| [param, 0.0] }
|
2023-07-09 05:47:37 +01:00
|
|
|
|
|
|
|
phys_float =
|
2023-07-14 14:37:49 +01:00
|
|
|
%i[comp gate denoiser].to_h { |param| [param, {knob: 0.0}] }
|
2023-07-14 12:01:41 +01:00
|
|
|
eq = [:eq].to_h { |param| [param, {on: false}] }
|
2023-07-09 19:44:43 +01:00
|
|
|
|
2023-07-14 12:01:41 +01:00
|
|
|
overrides = {B1: true}
|
2023-07-09 05:47:37 +01:00
|
|
|
|
|
|
|
# physical strip params
|
|
|
|
phys_strip =
|
|
|
|
(0...@kind.phys_in).to_h do |i|
|
|
|
|
[
|
|
|
|
"strip-#{i}",
|
2023-07-14 01:48:11 +01:00
|
|
|
{**aouts, **bouts, **strip_bools, **gain, **phys_float, **eq, **overrides}
|
2023-07-09 05:47:37 +01:00
|
|
|
]
|
|
|
|
end
|
2023-07-09 19:44:43 +01:00
|
|
|
|
2023-07-14 12:01:41 +01:00
|
|
|
overrides = {A1: true}
|
2023-07-09 05:47:37 +01:00
|
|
|
# virtual strip params
|
|
|
|
virt_strip =
|
|
|
|
(@kind.phys_in...@kind.phys_in + @kind.virt_in).to_h do |i|
|
2023-07-09 19:44:43 +01:00
|
|
|
[
|
|
|
|
"strip-#{i}",
|
2023-07-14 12:01:41 +01:00
|
|
|
{**aouts, **bouts, **strip_bools, **gain, **overrides}
|
2023-07-09 19:44:43 +01:00
|
|
|
]
|
2023-07-09 05:47:37 +01:00
|
|
|
end
|
2023-07-09 19:44:43 +01:00
|
|
|
|
2023-07-14 01:48:11 +01:00
|
|
|
bus_bools = %i[mute mono].to_h { |param| [param, false] }
|
2023-07-09 19:44:43 +01:00
|
|
|
bus =
|
|
|
|
(0...@kind.num_bus).to_h do |i|
|
2023-07-14 12:01:41 +01:00
|
|
|
["bus-#{i}", {**bus_bools, **gain, **eq}]
|
2023-07-09 19:44:43 +01:00
|
|
|
end
|
2023-07-14 14:37:49 +01:00
|
|
|
|
2023-07-14 12:01:41 +01:00
|
|
|
{**phys_strip, **virt_strip, **bus}
|
2023-07-09 19:44:43 +01:00
|
|
|
end
|
|
|
|
|
2023-07-14 14:37:49 +01:00
|
|
|
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
|
2023-07-16 11:08:24 +01:00
|
|
|
include Logging
|
2023-07-14 14:37:49 +01:00
|
|
|
|
|
|
|
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)
|
2023-07-09 19:44:43 +01:00
|
|
|
]
|
2023-07-14 14:37:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def read
|
|
|
|
@configpaths.each do |configpath|
|
2023-07-14 01:48:11 +01:00
|
|
|
if configpath.exist?
|
|
|
|
logger.debug "checking #{configpath} for configs"
|
|
|
|
filepaths = configpath.glob("*.yml")
|
|
|
|
filepaths.each do |filepath|
|
2023-07-14 14:37:49 +01:00
|
|
|
register(filepath)
|
2023-07-09 21:05:47 +01:00
|
|
|
end
|
2023-07-09 19:44:43 +01:00
|
|
|
end
|
|
|
|
end
|
2023-07-09 05:47:37 +01:00
|
|
|
end
|
|
|
|
|
2023-07-14 14:37:49 +01:00
|
|
|
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
|
2023-07-09 05:47:37 +01:00
|
|
|
|
2023-07-14 14:37:49 +01:00
|
|
|
@loader.configs[filename] = YAML.load_file(
|
|
|
|
filepath,
|
|
|
|
symbolize_names: true
|
|
|
|
)
|
|
|
|
logger.info "#{@kind.name}/#{filename} loaded into memory"
|
2023-07-09 05:47:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
public
|
|
|
|
|
2023-07-09 19:44:43 +01:00
|
|
|
def get(kind_id)
|
2023-07-09 05:47:37 +01:00
|
|
|
if @loaders.nil?
|
|
|
|
@loaders = Kinds::ALL.to_h { |kind| [kind.name, Loader.new(kind)] }
|
2023-07-14 14:37:49 +01:00
|
|
|
@loaders.each { |name, loader| loader.run }
|
2023-07-09 05:47:37 +01:00
|
|
|
end
|
|
|
|
@loaders[kind_id].configs
|
|
|
|
end
|
|
|
|
|
2023-07-09 19:44:43 +01:00
|
|
|
module_function :get
|
2023-07-09 05:47:37 +01:00
|
|
|
end
|
|
|
|
end
|