mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-15 15:00:46 +00:00
Events::Callback now a class
on_event method renamed to trigger events example updated to reflect changes to Events module
This commit is contained in:
parent
6d080af041
commit
ac7d9c0d03
@ -1,13 +1,13 @@
|
||||
require_relative "../../lib/voicemeeter"
|
||||
|
||||
class Main
|
||||
def initialize
|
||||
@vm = Voicemeeter::Remote.new(:potato, pdirty: true, ldirty: true)
|
||||
@vm.register(method(:on_pdirty), method(:on_ldirty))
|
||||
def initialize(vm)
|
||||
@vm = vm
|
||||
@vm.callback.register(method(:on_pdirty), method(:on_mdirty), method(:on_midi), method(:on_ldirty))
|
||||
end
|
||||
|
||||
def run
|
||||
@vm.run { exit if gets.chomp.empty? }
|
||||
exit if gets.chomp.empty?
|
||||
end
|
||||
|
||||
def on_pdirty
|
||||
@ -30,4 +30,8 @@ class Main
|
||||
end
|
||||
end
|
||||
|
||||
Main.new.run if $0 == __FILE__
|
||||
if $0 == __FILE__
|
||||
Voicemeeter::Remote.new(:potato, pdirty: true, mdirty: true, midi: true, ldirty: true).run do |vm|
|
||||
Main.new(vm).run
|
||||
end
|
||||
end
|
||||
|
@ -11,9 +11,8 @@ module Voicemeeter
|
||||
class Base
|
||||
include Logging
|
||||
include Worker
|
||||
include Events::Callbacks
|
||||
|
||||
attr_reader :kind, :midi, :event, :running
|
||||
attr_reader :kind, :midi, :event, :running, :callback
|
||||
attr_accessor :cache
|
||||
|
||||
RATELIMIT = 0.033
|
||||
@ -27,7 +26,7 @@ module Voicemeeter
|
||||
Events::Tracker.new(
|
||||
**(kwargs.select { |k, _| %i[pdirty mdirty ldirty midi].include? k })
|
||||
)
|
||||
@callbacks = []
|
||||
@callback = Events::Callback.new
|
||||
@que = Queue.new
|
||||
@cache = {strip_mode: 0}
|
||||
end
|
||||
|
@ -2,8 +2,10 @@ require_relative "logger"
|
||||
|
||||
module Voicemeeter
|
||||
module Events
|
||||
module Callbacks
|
||||
attr_reader :callbacks
|
||||
class Callback
|
||||
def initialize
|
||||
@callbacks = []
|
||||
end
|
||||
|
||||
def register(*args)
|
||||
args.each { |callback| @callbacks.append callback }
|
||||
@ -13,7 +15,7 @@ module Voicemeeter
|
||||
@callbacks.reject! { |c| args.include? c }
|
||||
end
|
||||
|
||||
def on_event(event)
|
||||
def trigger(event)
|
||||
@callbacks.each do |callback|
|
||||
if callback.respond_to? :on_update
|
||||
callback.on_update { event.to_s[3..] }
|
||||
|
@ -31,15 +31,15 @@ module Voicemeeter
|
||||
logger.debug("closing worker thread")
|
||||
break
|
||||
end
|
||||
on_event :on_pdirty if e_from_que == :pdirty && pdirty?
|
||||
on_event :on_mdirty if e_from_que == :mdirty && mdirty?
|
||||
on_event :on_midi if e_from_que == :midi && get_midi_message
|
||||
callback.trigger :on_pdirty if e_from_que == :pdirty && pdirty?
|
||||
callback.trigger :on_mdirty if e_from_que == :mdirty && mdirty?
|
||||
callback.trigger :on_midi if e_from_que == :midi && get_midi_message
|
||||
if e_from_que == :ldirty && ldirty?
|
||||
cache[:strip_comp] = cache[:strip_level].zip(cache[:strip_buf]).map { |a, b| a != b }
|
||||
cache[:bus_comp] = cache[:bus_level].zip(cache[:bus_buf]).map { |a, b| a != b }
|
||||
cache[:strip_level] = cache[:strip_buf]
|
||||
cache[:bus_level] = cache[:bus_buf]
|
||||
on_event :on_ldirty
|
||||
callback.trigger :on_ldirty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user