add to_cname to call

fn_name now passed in cname form to VMCAPIError
This commit is contained in:
onyx-and-iris 2023-07-25 12:58:17 +01:00
parent fa2100f34b
commit 802bfdbc24
2 changed files with 14 additions and 9 deletions

View File

@ -1,11 +1,13 @@
require_relative "install"
require_relative "errors"
require_relative "util"
require_relative "logger"
module Voicemeeter
module CBindings
private
extend Logging
extend FFI::Library
VM_PATH = Install.get_vmpath
@ -53,14 +55,21 @@ module Voicemeeter
attach_function :VBVMR_GetMidiMessage, %i[pointer long], :long
def call(fn, *args, ok: [0], exp: nil)
to_cname = -> {
"VBVMR_#{Util::String.camelcase(fn.to_s.delete_prefix("bind_"))
.gsub(/(Button|Input|Output)/, '\1_')}"
}
res = send(fn, *args)
if exp.nil?
unless ok.include?(res)
raise Errors::VMCAPIError.new fn, res
logger.error "#{to_cname.call} returned #{res}"
raise Errors::VMCAPIError.new to_cname.call, res
end
else
unless exp.call(res) || ok.include?(res)
raise Errors::VMCAPIError.new fn, res
logger.error "#{to_cname.call} returned #{res}"
raise Errors::VMCAPIError.new to_cname.call, res
end
end
res

View File

@ -6,10 +6,10 @@ module Voicemeeter
end
class VMCAPIError < VMError
attr_reader :code
attr_reader :fn_name, :code
def initialize(ruby_name, code)
@ruby_name = ruby_name
def initialize(fn_name, code)
@fn_name = fn_name
@code = code
super(message)
end
@ -17,10 +17,6 @@ module Voicemeeter
def message
"#{fn_name} returned #{code}"
end
def fn_name
"VBVMR_#{Util::String.camelcase(@ruby_name.to_s.delete_prefix("bind_")).sub("macro_button", "macrobutton")}"
end
end
end
end