callbacks now public method

register,deregister handle single callbacks
or arrays of callbacks
This commit is contained in:
onyx-and-iris 2023-08-03 15:07:18 +01:00
parent 2dab83ec31
commit 1ba1247b7f
2 changed files with 6 additions and 4 deletions

View File

@ -3,7 +3,7 @@ require_relative "../../lib/voicemeeter"
class Main
def initialize(vm)
@vm = vm
@vm.register(method(:on_pdirty), method(:on_mdirty), method(:on_midi), method(:on_ldirty))
@vm.register([method(:on_pdirty), method(:on_mdirty), method(:on_midi), method(:on_ldirty)])
end
def run

View File

@ -3,15 +3,17 @@ require_relative "logger"
module Voicemeeter
module Events
module Callback
private def callbacks
def callbacks
@callbacks ||= []
end
def register(*cbs)
def register(cbs)
cbs = [cbs] unless cbs.respond_to? :each
cbs.each { |cb| callbacks << cb unless callbacks.include? cb }
end
def deregister(*cbs)
def deregister(cbs)
cbs = [cbs] unless cbs.respond_to? :each
callbacks.reject! { |cb| cbs.include? cb }
end