mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-21 17:30:49 +00:00
snakecase, camelcase functions moved into
Util::String module Cache added.
This commit is contained in:
parent
eb4920f4a5
commit
2efd07b3d5
@ -5,12 +5,14 @@ require_relative "midi"
|
||||
require_relative "event"
|
||||
require_relative "worker"
|
||||
require_relative "errors"
|
||||
require_relative "util"
|
||||
require_relative "logger"
|
||||
|
||||
module Voicemeeter
|
||||
class Base
|
||||
include Logging
|
||||
include Worker
|
||||
include Util::Cache
|
||||
|
||||
attr_reader :kind, :midi, :event, :running, :callback
|
||||
attr_accessor :cache
|
||||
@ -106,15 +108,16 @@ module Voicemeeter
|
||||
end
|
||||
|
||||
def get(name, is_string = false)
|
||||
clear_dirty if @sync
|
||||
polling(:get, name: name) do
|
||||
if is_string
|
||||
c_get = FFI::MemoryPointer.new(:string, 512, true)
|
||||
CBindings.call(:bind_get_parameter_string_a, name, c_get)
|
||||
c_get.read_string
|
||||
cget = FFI::MemoryPointer.new(:string, 512, true)
|
||||
CBindings.call(:bind_get_parameter_string_a, name, cget)
|
||||
cget.read_string
|
||||
else
|
||||
c_get = FFI::MemoryPointer.new(:float, 1)
|
||||
CBindings.call(:bind_get_parameter_float, name, c_get)
|
||||
c_get.read_float.round(1)
|
||||
cget = FFI::MemoryPointer.new(:float, 1)
|
||||
CBindings.call(:bind_get_parameter_float, name, cget)
|
||||
cget.read_float.round(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -124,17 +127,20 @@ module Voicemeeter
|
||||
else
|
||||
CBindings.call(:bind_set_parameter_float, name, value.to_f)
|
||||
end
|
||||
cache.store(name, value)
|
||||
end
|
||||
|
||||
def get_buttonstatus(id, mode)
|
||||
clear_dirty if @sync
|
||||
c_get = FFI::MemoryPointer.new(:float, 1)
|
||||
CBindings.call(:bind_macro_button_get_status, id, c_get, mode)
|
||||
c_get.read_float.to_i
|
||||
polling(:get_buttonstatus, id: id, mode: mode) do
|
||||
cget = FFI::MemoryPointer.new(:float, 1)
|
||||
CBindings.call(:bind_macro_button_get_status, id, cget, mode)
|
||||
cget.read_float.to_i
|
||||
end
|
||||
end
|
||||
|
||||
def set_buttonstatus(id, state, mode)
|
||||
def set_buttonstatus(id, mode, state)
|
||||
CBindings.call(:bind_macro_button_set_status, id, state, mode)
|
||||
cache.store("mb_#{id}_#{mode}", state)
|
||||
end
|
||||
|
||||
def get_level(mode, index)
|
||||
|
@ -16,7 +16,7 @@ module Voicemeeter
|
||||
ffi_convention :stdcall
|
||||
|
||||
private_class_method def self.attach_function(c_name, args, returns)
|
||||
ruby_name = "bind_#{Util.snakecase(c_name.to_s.delete_prefix("VBVMR_"))}".to_sym
|
||||
ruby_name = "bind_#{Util::String.snakecase(c_name.to_s.delete_prefix("VBVMR_"))}".to_sym
|
||||
super(ruby_name, c_name, args, returns)
|
||||
end
|
||||
|
||||
|
@ -19,7 +19,7 @@ module Voicemeeter
|
||||
end
|
||||
|
||||
def fn_name
|
||||
"VBVMR_#{Util.camelcase(@ruby_name.to_s.delete_prefix("bind_")).sub("macro_button", "macrobutton")}"
|
||||
"VBVMR_#{Util::String.camelcase(@ruby_name.to_s.delete_prefix("bind_")).sub("macro_button", "macrobutton")}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Voicemeeter
|
||||
module Util
|
||||
module String
|
||||
def snakecase(string)
|
||||
string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||
@ -16,4 +17,19 @@ module Voicemeeter
|
||||
|
||||
module_function :snakecase, :camelcase
|
||||
end
|
||||
|
||||
module Cache
|
||||
def polling(func, **kwargs)
|
||||
params = {
|
||||
get: kwargs[:name],
|
||||
get_buttonstatus: "mb_#{kwargs[:id]}_#{kwargs[:mode]}"
|
||||
}
|
||||
return cache.delete(params[func]) if cache.key? params[func]
|
||||
|
||||
clear_dirty if @sync
|
||||
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user