add init_event_threads, end_event_threads

to Worker module.

run now handles init/end event threads
This commit is contained in:
onyx-and-iris 2023-07-21 14:37:17 +01:00
parent d8ee19e2f8
commit ce8c82a2ca
5 changed files with 14 additions and 12 deletions

View File

@ -14,8 +14,7 @@ module Voicemeeter
include Worker include Worker
include Util::Cache include Util::Cache
attr_reader :kind, :midi, :event, :running, :callback, :delay attr_reader :kind, :midi, :event, :callback, :running, :delay, :cache
attr_accessor :cache
alias_method :observer, :callback alias_method :observer, :callback
RATELIMIT = 0.033 RATELIMIT = 0.033
@ -44,14 +43,9 @@ module Voicemeeter
run_voicemeeter(kind.name) if CBindings.call(:bind_login, ok: [0, 1]) == 1 run_voicemeeter(kind.name) if CBindings.call(:bind_login, ok: [0, 1]) == 1
clear_dirty clear_dirty
logger.info "Successfully logged into #{self} version #{version}" logger.info "Successfully logged into #{self} version #{version}"
if event.any?
init_worker(@que)
init_producer(@que)
end
end end
def logout def logout
@running = false
sleep(0.1) sleep(0.1)
CBindings.call(:bind_logout) CBindings.call(:bind_logout)
logger.info "Sucessfully logged out of #{self}" logger.info "Sucessfully logged out of #{self}"

View File

@ -39,7 +39,6 @@ module Voicemeeter
eq = [:eq].to_h { |param| [param, {on: false}] } eq = [:eq].to_h { |param| [param, {on: false}] }
overrides = {B1: true} overrides = {B1: true}
# physical strip params # physical strip params
phys_strip = phys_strip =
(0...@kind.phys_in).to_h do |i| (0...@kind.phys_in).to_h do |i|

View File

@ -58,9 +58,13 @@ module Voicemeeter
def run def run
login login
if event.any?
init_event_threads
end
yield(self) if block_given? yield(self) if block_given?
ensure
end_event_threads
logout logout
end end
end end

View File

@ -45,10 +45,15 @@ module Voicemeeter
end end
end end
def end_worker def init_event_threads
init_worker(@que)
init_producer(@que)
end
def end_event_threads
@running = false @running = false
end end
module_function :init_worker, :end_worker module_function :init_event_threads, :end_event_threads
end end
end end

View File

@ -18,5 +18,5 @@ end
task :obs do task :obs do
targetdir = File.join(HERE, "examples", "obs") targetdir = File.join(HERE, "examples", "obs")
Dir.chdir(targetdir) Dir.chdir(targetdir)
bundle exec ruby File.join(targetdir, "main.rb") ruby File.join(targetdir, "main.rb")
end end