mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-22 01:40:49 +00:00
add to_cname to call
fn_name now passed in cname form to VMCAPIError
This commit is contained in:
parent
fa2100f34b
commit
802bfdbc24
@ -1,11 +1,13 @@
|
|||||||
require_relative "install"
|
require_relative "install"
|
||||||
require_relative "errors"
|
require_relative "errors"
|
||||||
require_relative "util"
|
require_relative "util"
|
||||||
|
require_relative "logger"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module CBindings
|
module CBindings
|
||||||
private
|
private
|
||||||
|
|
||||||
|
extend Logging
|
||||||
extend FFI::Library
|
extend FFI::Library
|
||||||
|
|
||||||
VM_PATH = Install.get_vmpath
|
VM_PATH = Install.get_vmpath
|
||||||
@ -53,14 +55,21 @@ module Voicemeeter
|
|||||||
attach_function :VBVMR_GetMidiMessage, %i[pointer long], :long
|
attach_function :VBVMR_GetMidiMessage, %i[pointer long], :long
|
||||||
|
|
||||||
def call(fn, *args, ok: [0], exp: nil)
|
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)
|
res = send(fn, *args)
|
||||||
if exp.nil?
|
if exp.nil?
|
||||||
unless ok.include?(res)
|
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
|
end
|
||||||
else
|
else
|
||||||
unless exp.call(res) || ok.include?(res)
|
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
|
||||||
end
|
end
|
||||||
res
|
res
|
||||||
|
@ -6,10 +6,10 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
class VMCAPIError < VMError
|
class VMCAPIError < VMError
|
||||||
attr_reader :code
|
attr_reader :fn_name, :code
|
||||||
|
|
||||||
def initialize(ruby_name, code)
|
def initialize(fn_name, code)
|
||||||
@ruby_name = ruby_name
|
@fn_name = fn_name
|
||||||
@code = code
|
@code = code
|
||||||
super(message)
|
super(message)
|
||||||
end
|
end
|
||||||
@ -17,10 +17,6 @@ module Voicemeeter
|
|||||||
def message
|
def message
|
||||||
"#{fn_name} returned #{code}"
|
"#{fn_name} returned #{code}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def fn_name
|
|
||||||
"VBVMR_#{Util::String.camelcase(@ruby_name.to_s.delete_prefix("bind_")).sub("macro_button", "macrobutton")}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user