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

View File

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

View File

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

View File

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

View File

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