From eaf92197dcdbe61078b410f99c3a4d13119ddc64 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 17 Jul 2023 20:00:34 +0100 Subject: [PATCH] obs example added --- examples/obs/Gemfile | 9 ++++++ examples/obs/README.md | 23 +++++++++++++++ examples/obs/main.rb | 66 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 examples/obs/Gemfile create mode 100644 examples/obs/README.md create mode 100644 examples/obs/main.rb diff --git a/examples/obs/Gemfile b/examples/obs/Gemfile new file mode 100644 index 0000000..37e5a6d --- /dev/null +++ b/examples/obs/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "voicemeeter", path: "../.." + +gem "obsws", "~> 0.1.3" + +gem "pathname", "~> 0.2.1" diff --git a/examples/obs/README.md b/examples/obs/README.md new file mode 100644 index 0000000..85d8488 --- /dev/null +++ b/examples/obs/README.md @@ -0,0 +1,23 @@ +## Requirements + +- [OBS Studio v28+](https://obsproject.com/) +- [OBSWS Ruby wrapper for Websocket v5](https://github.com/onyx-and-iris/obsws-ruby) + +## About + +A simple demonstration showing how to sync OBS scene switches to Voicemeeter states. + +## Use + +The script assumes you have connection info saved in a config yaml file named `config.yaml` placed next to `obs.rb`. It also assumes you have scenes named `START` `BRB` `END` and `LIVE`. + +A valid `config.yaml` file might look like this: + +```yaml +connection: + host: localhost + port: 4455 + password: strongpassword +``` + +Closing OBS will end the script and logout of Voicemeeter. diff --git a/examples/obs/main.rb b/examples/obs/main.rb new file mode 100644 index 0000000..927e329 --- /dev/null +++ b/examples/obs/main.rb @@ -0,0 +1,66 @@ +require "voicemeeter" +require "obsws" +require "yaml" +require "pathname" + +class Observer + attr_reader :running + + def initialize(vm, **kwargs) + @vm = vm + @obsws = OBSWS::Events::Client.new(**kwargs) + @obsws.add_observer(self) + @running = true + end + + def run + sleep(0.1) while running + end + + def on_start + @vm.strip[0].mute = true + @vm.strip[1].B1 = true + @vm.strip[2].B2 = true + end + + def on_live + @vm.strip[0].mute = false + @vm.strip[7].A3 = true + @vm.strip[7].fadeto(-6, 500) + @vm.vban.instream[0].on = true + end + + def on_brb + @vm.strip[0].mute = false + @vm.strip[5].A1 = true + @vm.strip[5].A2 = true + @vm.strip[7].fadeto(0, 500) + end + + 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}" + send("on_#{scene.downcase}") + 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 $0 == __FILE__ + Voicemeeter::Remote.new(:potato).run do |vm| + Observer.new(vm, **conn_from_yml).run + end +end