mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-15 23:00:48 +00:00
use callback methods in obs example
This commit is contained in:
parent
9700610eef
commit
a942ce6745
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem "obsws", "~> 0.3.0"
|
gem "obsws", "~> 0.4.0"
|
||||||
|
@ -9,7 +9,10 @@ class Main
|
|||||||
def initialize(vm, **kwargs)
|
def initialize(vm, **kwargs)
|
||||||
@vm = vm
|
@vm = vm
|
||||||
@obsws = OBSWS::Events::Client.new(**kwargs)
|
@obsws = OBSWS::Events::Client.new(**kwargs)
|
||||||
@obsws.add_observer(self)
|
@obsws.register([
|
||||||
|
method(:on_current_program_scene_changed),
|
||||||
|
method(:on_exit_started)
|
||||||
|
])
|
||||||
@running = true
|
@running = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -17,6 +20,20 @@ class Main
|
|||||||
sleep(0.1) while running
|
sleep(0.1) while running
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_current_program_scene_changed(data)
|
||||||
|
scene = data.scene_name
|
||||||
|
puts "Switched to scene #{scene}"
|
||||||
|
if respond_to?("on_#{scene.downcase}")
|
||||||
|
send("on_#{scene.downcase}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_exit_started
|
||||||
|
puts "OBS closing!"
|
||||||
|
@obsws.close
|
||||||
|
@running = false
|
||||||
|
end
|
||||||
|
|
||||||
def on_start
|
def on_start
|
||||||
@vm.strip[0].mute = true
|
@vm.strip[0].mute = true
|
||||||
@vm.strip[1].B1 = true
|
@vm.strip[1].B1 = true
|
||||||
@ -40,27 +57,12 @@ class Main
|
|||||||
def on_end
|
def on_end
|
||||||
@vm.apply({"strip-0" => {mute: true}, "vban-instream-0" => {on: false}})
|
@vm.apply({"strip-0" => {mute: true}, "vban-instream-0" => {on: false}})
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_current_program_scene_changed(data)
|
|
||||||
scene = data.scene_name
|
|
||||||
puts "Switched to scene #{scene}"
|
|
||||||
if respond_to?("on_#{scene.downcase}")
|
|
||||||
send("on_#{scene.downcase}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def on_exit_started
|
|
||||||
puts "OBS closing!"
|
|
||||||
@obsws.close
|
|
||||||
@running = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def conn_from_yml
|
def conn_from_yml
|
||||||
YAML.load_file("config.yaml", symbolize_names: true)[:connection]
|
YAML.load_file("config.yaml", symbolize_names: true)[:connection]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if $PROGRAM_NAME == __FILE__
|
if $PROGRAM_NAME == __FILE__
|
||||||
Voicemeeter::Remote.new(:potato).run do |vm|
|
Voicemeeter::Remote.new(:potato).run do |vm|
|
||||||
Main.new(vm, **conn_from_yml).run
|
Main.new(vm, **conn_from_yml).run
|
||||||
|
Loading…
Reference in New Issue
Block a user