mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-24 19:00: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 "event"
|
||||||
require_relative "worker"
|
require_relative "worker"
|
||||||
require_relative "errors"
|
require_relative "errors"
|
||||||
|
require_relative "util"
|
||||||
require_relative "logger"
|
require_relative "logger"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
class Base
|
class Base
|
||||||
include Logging
|
include Logging
|
||||||
include Worker
|
include Worker
|
||||||
|
include Util::Cache
|
||||||
|
|
||||||
attr_reader :kind, :midi, :event, :running, :callback
|
attr_reader :kind, :midi, :event, :running, :callback
|
||||||
attr_accessor :cache
|
attr_accessor :cache
|
||||||
@ -106,15 +108,16 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get(name, is_string = false)
|
def get(name, is_string = false)
|
||||||
clear_dirty if @sync
|
polling(:get, name: name) do
|
||||||
if is_string
|
if is_string
|
||||||
c_get = FFI::MemoryPointer.new(:string, 512, true)
|
cget = FFI::MemoryPointer.new(:string, 512, true)
|
||||||
CBindings.call(:bind_get_parameter_string_a, name, c_get)
|
CBindings.call(:bind_get_parameter_string_a, name, cget)
|
||||||
c_get.read_string
|
cget.read_string
|
||||||
else
|
else
|
||||||
c_get = FFI::MemoryPointer.new(:float, 1)
|
cget = FFI::MemoryPointer.new(:float, 1)
|
||||||
CBindings.call(:bind_get_parameter_float, name, c_get)
|
CBindings.call(:bind_get_parameter_float, name, cget)
|
||||||
c_get.read_float.round(1)
|
cget.read_float.round(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -124,17 +127,20 @@ module Voicemeeter
|
|||||||
else
|
else
|
||||||
CBindings.call(:bind_set_parameter_float, name, value.to_f)
|
CBindings.call(:bind_set_parameter_float, name, value.to_f)
|
||||||
end
|
end
|
||||||
|
cache.store(name, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_buttonstatus(id, mode)
|
def get_buttonstatus(id, mode)
|
||||||
clear_dirty if @sync
|
polling(:get_buttonstatus, id: id, mode: mode) do
|
||||||
c_get = FFI::MemoryPointer.new(:float, 1)
|
cget = FFI::MemoryPointer.new(:float, 1)
|
||||||
CBindings.call(:bind_macro_button_get_status, id, c_get, mode)
|
CBindings.call(:bind_macro_button_get_status, id, cget, mode)
|
||||||
c_get.read_float.to_i
|
cget.read_float.to_i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_buttonstatus(id, state, mode)
|
def set_buttonstatus(id, mode, state)
|
||||||
CBindings.call(:bind_macro_button_set_status, id, state, mode)
|
CBindings.call(:bind_macro_button_set_status, id, state, mode)
|
||||||
|
cache.store("mb_#{id}_#{mode}", state)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_level(mode, index)
|
def get_level(mode, index)
|
||||||
|
@ -16,7 +16,7 @@ module Voicemeeter
|
|||||||
ffi_convention :stdcall
|
ffi_convention :stdcall
|
||||||
|
|
||||||
private_class_method def self.attach_function(c_name, args, returns)
|
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)
|
super(ruby_name, c_name, args, returns)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fn_name
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,19 +1,35 @@
|
|||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module Util
|
module Util
|
||||||
def snakecase(string)
|
module String
|
||||||
string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
def snakecase(string)
|
||||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||||
.tr("-", "_")
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||||
.gsub(/\s/, "_")
|
.tr("-", "_")
|
||||||
.gsub(/__+/, "_")
|
.gsub(/\s/, "_")
|
||||||
.downcase
|
.gsub(/__+/, "_")
|
||||||
|
.downcase
|
||||||
|
end
|
||||||
|
|
||||||
|
def camelcase(string)
|
||||||
|
string if string !~ /_/ && string =~ /[A-Z]+.*/
|
||||||
|
string.split("_").map { |e| e.capitalize }.join
|
||||||
|
end
|
||||||
|
|
||||||
|
module_function :snakecase, :camelcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def camelcase(string)
|
module Cache
|
||||||
string if string !~ /_/ && string =~ /[A-Z]+.*/
|
def polling(func, **kwargs)
|
||||||
string.split("_").map { |e| e.capitalize }.join
|
params = {
|
||||||
end
|
get: kwargs[:name],
|
||||||
|
get_buttonstatus: "mb_#{kwargs[:id]}_#{kwargs[:mode]}"
|
||||||
|
}
|
||||||
|
return cache.delete(params[func]) if cache.key? params[func]
|
||||||
|
|
||||||
module_function :snakecase, :camelcase
|
clear_dirty if @sync
|
||||||
|
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user