2023-07-14 11:44:49 +01:00
|
|
|
require "easy_logging"
|
|
|
|
|
2023-07-14 00:54:12 +01:00
|
|
|
module Voicemeeter
|
|
|
|
module Events
|
|
|
|
module Callbacks
|
|
|
|
attr_reader :callbacks
|
|
|
|
|
|
|
|
def register(*args)
|
|
|
|
args.each { |callback| @callbacks.append callback }
|
|
|
|
end
|
|
|
|
|
|
|
|
def deregister(*args)
|
|
|
|
@callbacks.reject! { |c| args.include? c }
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_event(event)
|
|
|
|
@callbacks.each do |callback|
|
|
|
|
if callback.respond_to? :on_update
|
|
|
|
callback.on_update { event.to_s[3..] }
|
|
|
|
else
|
2023-07-14 11:44:49 +01:00
|
|
|
callback.call # if callback == event
|
2023-07-14 00:54:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Tracker
|
2023-07-14 14:37:49 +01:00
|
|
|
# include EasyLogging
|
2023-07-14 11:44:49 +01:00
|
|
|
|
2023-07-14 00:54:12 +01:00
|
|
|
attr_reader :pdirty, :mdirty, :midi, :ldirty
|
|
|
|
|
|
|
|
def initialize(pdirty: false, mdirty: false, midi: false, ldirty: false)
|
|
|
|
@pdirty = pdirty
|
|
|
|
@mdirty = mdirty
|
|
|
|
@midi = midi
|
|
|
|
@ldirty = ldirty
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2023-07-14 11:44:49 +01:00
|
|
|
self.class.name.split("::").last.to_s
|
2023-07-14 00:54:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def info(msg = nil)
|
|
|
|
info_msg = msg ? ["#{msg} events."] : []
|
2023-07-14 11:44:49 +01:00
|
|
|
info_msg += if any?
|
|
|
|
["Now listening for #{get.join(", ")} events"]
|
2023-07-14 00:54:12 +01:00
|
|
|
else
|
2023-07-14 11:44:49 +01:00
|
|
|
["Not listening for any events"]
|
2023-07-14 00:54:12 +01:00
|
|
|
end
|
|
|
|
logger.info(info_msg.join(" "))
|
|
|
|
end
|
|
|
|
|
|
|
|
def pdirty=(val)
|
|
|
|
@pdirty = val
|
|
|
|
info("pdirty #{val ? "added to" : "removed from"}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def mdirty=(val)
|
|
|
|
@mdirty = val
|
|
|
|
info("mdirty #{val ? "added to" : "removed from"}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def ldirty=(val)
|
|
|
|
@ldirty = val
|
|
|
|
info("ldirty #{val ? "added to" : "removed from"}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def midi=(val)
|
|
|
|
@midi = val
|
|
|
|
info("midi #{val ? "added to" : "removed from"}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def get
|
2023-07-14 11:44:49 +01:00
|
|
|
%w[pdirty mdirty midi ldirty].reject { |ev| !send(ev.to_s) }
|
2023-07-14 00:54:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def any?
|
|
|
|
[pdirty, mdirty, midi, ldirty].any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(events)
|
|
|
|
events = [events] if !events.respond_to? :each
|
|
|
|
events.each { |e| send("#{e}=", true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove(events)
|
|
|
|
events = [events] if !events.respond_to? :each
|
|
|
|
events.each { |e| send("#{e}=", false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|