2023-07-07 02:29:43 +01:00
|
|
|
require_relative "install"
|
|
|
|
require_relative "errors"
|
2023-07-17 06:03:37 +01:00
|
|
|
require_relative "util"
|
2023-07-25 12:58:17 +01:00
|
|
|
require_relative "logger"
|
2023-07-07 02:29:43 +01:00
|
|
|
|
|
|
|
module Voicemeeter
|
|
|
|
module CBindings
|
|
|
|
private
|
|
|
|
|
2023-07-25 12:58:17 +01:00
|
|
|
extend Logging
|
2023-07-07 02:29:43 +01:00
|
|
|
extend FFI::Library
|
|
|
|
|
2023-07-14 12:01:41 +01:00
|
|
|
VM_PATH = Install.get_vmpath
|
2023-07-07 02:29:43 +01:00
|
|
|
|
|
|
|
ffi_lib VM_PATH.join(
|
2023-07-14 12:01:41 +01:00
|
|
|
"VoicemeeterRemote#{(Install::OS_BITS == 64) ? "64" : "32"}.dll"
|
|
|
|
)
|
2023-07-07 02:29:43 +01:00
|
|
|
ffi_convention :stdcall
|
|
|
|
|
2023-07-16 11:08:24 +01:00
|
|
|
private_class_method def self.attach_function(c_name, args, returns)
|
2023-07-17 14:13:08 +01:00
|
|
|
ruby_name = "bind_#{Util::String.snakecase(c_name.to_s.delete_prefix("VBVMR_"))}".to_sym
|
2023-07-14 12:32:12 +01:00
|
|
|
super(ruby_name, c_name, args, returns)
|
2023-07-09 23:48:35 +01:00
|
|
|
end
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_Login, [], :long
|
|
|
|
attach_function :VBVMR_Logout, [], :long
|
|
|
|
attach_function :VBVMR_RunVoicemeeter, [:long], :long
|
|
|
|
attach_function :VBVMR_GetVoicemeeterType, [:pointer], :long
|
|
|
|
attach_function :VBVMR_GetVoicemeeterVersion, [:pointer], :long
|
|
|
|
attach_function :VBVMR_MacroButton_IsDirty, [], :long
|
|
|
|
attach_function :VBVMR_MacroButton_GetStatus, %i[long pointer long], :long
|
|
|
|
attach_function :VBVMR_MacroButton_SetStatus, %i[long float long], :long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_IsParametersDirty, [], :long
|
|
|
|
attach_function :VBVMR_GetParameterFloat, %i[string pointer], :long
|
|
|
|
attach_function :VBVMR_SetParameterFloat, %i[string float], :long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_GetParameterStringA, %i[string pointer], :long
|
|
|
|
attach_function :VBVMR_SetParameterStringA, %i[string string], :long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_SetParameters, [:string], :long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_GetLevel, %i[long long pointer], :long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_Input_GetDeviceNumber, [], :long
|
|
|
|
attach_function :VBVMR_Input_GetDeviceDescA,
|
2023-07-14 12:01:41 +01:00
|
|
|
%i[long pointer pointer pointer],
|
|
|
|
:long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_Output_GetDeviceNumber, [], :long
|
|
|
|
attach_function :VBVMR_Output_GetDeviceDescA,
|
2023-07-14 12:01:41 +01:00
|
|
|
%i[long pointer pointer pointer],
|
|
|
|
:long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
2023-07-09 23:48:35 +01:00
|
|
|
attach_function :VBVMR_GetMidiMessage, %i[pointer long], :long
|
2023-07-07 02:29:43 +01:00
|
|
|
|
|
|
|
def call(fn, *args, ok: [0], exp: nil)
|
2023-07-25 12:58:17 +01:00
|
|
|
to_cname = -> {
|
|
|
|
"VBVMR_#{Util::String.camelcase(fn.to_s.delete_prefix("bind_"))
|
|
|
|
.gsub(/(Button|Input|Output)/, '\1_')}"
|
|
|
|
}
|
|
|
|
|
2023-07-07 02:29:43 +01:00
|
|
|
res = send(fn, *args)
|
2023-07-26 08:45:20 +01:00
|
|
|
if exp
|
|
|
|
unless exp.call(res) || ok.include?(res)
|
2023-07-25 12:58:17 +01:00
|
|
|
logger.error "#{to_cname.call} returned #{res}"
|
|
|
|
raise Errors::VMCAPIError.new to_cname.call, res
|
2023-07-07 02:29:43 +01:00
|
|
|
end
|
|
|
|
else
|
2023-07-26 08:45:20 +01:00
|
|
|
unless ok.include?(res)
|
2023-07-25 12:58:17 +01:00
|
|
|
logger.error "#{to_cname.call} returned #{res}"
|
|
|
|
raise Errors::VMCAPIError.new to_cname.call, res
|
2023-07-07 02:29:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
module_function :call
|
|
|
|
end
|
|
|
|
end
|