use array

This commit is contained in:
onyx-and-iris 2023-08-10 20:37:47 +01:00
parent 6769013ee3
commit 10a4eade93

View File

@ -88,11 +88,7 @@ module Voicemeeter
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)
kinds = { kinds = [nil, :basic, :banana, :potato]
Kinds::KindEnum::BASIC => :basic,
Kinds::KindEnum::BANANA => :banana,
Kinds::KindEnum::POTATO => :potato
}
kinds[ckind.read_long] kinds[ckind.read_long]
end end
@ -218,19 +214,16 @@ module Voicemeeter
end end
def apply(data) def apply(data)
data.each do |key, val| data.each do |key, hash|
kls, index, *rem = key.to_s.split("-") case key.to_s.split("-")
case kls in [/strip|bus|button/ => kls, /^[0-9]+$/ => index]
when "strip", "bus", "button"
target = send(kls) target = send(kls)
when "vban" in ["vban", String => dir, /^[0-9]+$/ => index]
dir = "#{index.chomp("stream")}stream" target = vban.send("#{dir.chomp("stream")}stream")
index = rem[0]
target = vban.send(dir)
else else
raise KeyError, "invalid config key '#{kls}'" raise KeyError, "invalid config key '#{key}'"
end end
target[index.to_i].apply(val) target[index.to_i].apply(hash)
end end
end end