diff --git a/examples/obs/Gemfile b/examples/obs/Gemfile index 4c31b12..ce79feb 100644 --- a/examples/obs/Gemfile +++ b/examples/obs/Gemfile @@ -2,4 +2,4 @@ source "https://rubygems.org" -gem "obsws", "~> 0.3.0" +gem "obsws", "~> 0.4.0" diff --git a/examples/obs/main.rb b/examples/obs/main.rb index 29acbd1..3fd72f2 100644 --- a/examples/obs/main.rb +++ b/examples/obs/main.rb @@ -9,7 +9,10 @@ class Main def initialize(vm, **kwargs) @vm = vm @obsws = OBSWS::Events::Client.new(**kwargs) - @obsws.add_observer(self) + @obsws.register([ + method(:on_current_program_scene_changed), + method(:on_exit_started) + ]) @running = true end @@ -17,6 +20,20 @@ class Main sleep(0.1) while running 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 @vm.strip[0].mute = true @vm.strip[1].B1 = true @@ -40,27 +57,12 @@ class Main def on_end @vm.apply({"strip-0" => {mute: true}, "vban-instream-0" => {on: false}}) 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 def conn_from_yml YAML.load_file("config.yaml", symbolize_names: true)[:connection] end - if $PROGRAM_NAME == __FILE__ Voicemeeter::Remote.new(:potato).run do |vm| Main.new(vm, **conn_from_yml).run