mirror of
https://github.com/onyx-and-iris/obsws-ruby.git
synced 2024-11-15 18:50:47 +00:00
examples refactored
This commit is contained in:
parent
153f35e742
commit
73ae24eb4b
@ -5,5 +5,3 @@ source "https://rubygems.org"
|
|||||||
# gem "rails"
|
# gem "rails"
|
||||||
|
|
||||||
gem "obsws", path: "../.."
|
gem "obsws", path: "../.."
|
||||||
|
|
||||||
gem "perfect_toml", "~> 0.9.0"
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: ../..
|
remote: ../..
|
||||||
specs:
|
specs:
|
||||||
obsws (0.1.0)
|
obsws (0.1.3)
|
||||||
observer (~> 0.1.1)
|
observer (~> 0.1.1)
|
||||||
waitutil (~> 0.2.1)
|
waitutil (~> 0.2.1)
|
||||||
websocket-driver (~> 0.7.5)
|
websocket-driver (~> 0.7.5)
|
||||||
@ -10,7 +10,6 @@ GEM
|
|||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
observer (0.1.1)
|
observer (0.1.1)
|
||||||
perfect_toml (0.9.0)
|
|
||||||
waitutil (0.2.1)
|
waitutil (0.2.1)
|
||||||
websocket-driver (0.7.5)
|
websocket-driver (0.7.5)
|
||||||
websocket-extensions (>= 0.1.0)
|
websocket-extensions (>= 0.1.0)
|
||||||
@ -21,7 +20,6 @@ PLATFORMS
|
|||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
obsws!
|
obsws!
|
||||||
perfect_toml (~> 0.9.0)
|
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.3.22
|
2.3.22
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
require "obsws"
|
require "obsws"
|
||||||
require "perfect_toml"
|
require "yaml"
|
||||||
|
|
||||||
OBSWS::LOGGER.info!
|
OBSWS::LOGGER.info!
|
||||||
|
|
||||||
class Observer
|
class Main
|
||||||
attr_reader :running
|
attr_reader :running
|
||||||
|
|
||||||
def initialize(**kwargs)
|
def initialize(**kwargs)
|
||||||
@ -15,6 +15,10 @@ class Observer
|
|||||||
@running = true
|
@running = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
sleep(0.1) while running
|
||||||
|
end
|
||||||
|
|
||||||
def info
|
def info
|
||||||
resp = @r_client.get_version
|
resp = @r_client.get_version
|
||||||
[
|
[
|
||||||
@ -45,14 +49,8 @@ class Observer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def conn_from_toml
|
def conn_from_yaml
|
||||||
PerfectTOML.load_file("obs.toml", symbolize_names: true)[:connection]
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
||||||
end
|
end
|
||||||
|
|
||||||
def main
|
Main.new(**conn_from_yaml).run if $0 == __FILE__
|
||||||
o = Observer.new(**conn_from_toml)
|
|
||||||
|
|
||||||
sleep(0.1) while o.running
|
|
||||||
end
|
|
||||||
|
|
||||||
main if $0 == __FILE__
|
|
||||||
|
7
examples/levels/Gemfile
Normal file
7
examples/levels/Gemfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
# gem "rails"
|
||||||
|
|
||||||
|
gem "obsws", path: "../.."
|
25
examples/levels/Gemfile.lock
Normal file
25
examples/levels/Gemfile.lock
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
PATH
|
||||||
|
remote: ../..
|
||||||
|
specs:
|
||||||
|
obsws (0.1.3)
|
||||||
|
observer (~> 0.1.1)
|
||||||
|
waitutil (~> 0.2.1)
|
||||||
|
websocket-driver (~> 0.7.5)
|
||||||
|
|
||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
observer (0.1.1)
|
||||||
|
waitutil (0.2.1)
|
||||||
|
websocket-driver (0.7.5)
|
||||||
|
websocket-extensions (>= 0.1.0)
|
||||||
|
websocket-extensions (0.1.5)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
x64-mingw-ucrt
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
obsws!
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.4.15
|
@ -1,5 +1,5 @@
|
|||||||
require "obsws"
|
require "obsws"
|
||||||
require "perfect_toml"
|
require "yaml"
|
||||||
|
|
||||||
OBSWS::LOGGER.info!
|
OBSWS::LOGGER.info!
|
||||||
DEVICE = "Desktop Audio"
|
DEVICE = "Desktop Audio"
|
||||||
@ -10,44 +10,39 @@ module LevelTypes
|
|||||||
PREFADER = 2
|
PREFADER = 2
|
||||||
end
|
end
|
||||||
|
|
||||||
class Observer
|
class Main
|
||||||
attr_reader :running
|
|
||||||
|
|
||||||
def initialize(**kwargs)
|
def initialize(**kwargs)
|
||||||
kwargs[:subs] = OBSWS::Events::SUBS::LOW_VOLUME | OBSWS::Events::SUBS::INPUTVOLUMEMETERS
|
subs = OBSWS::Events::SUBS::LOW_VOLUME | OBSWS::Events::SUBS::INPUTVOLUMEMETERS
|
||||||
@e_client = OBSWS::Events::Client.new(**kwargs)
|
@e_client = OBSWS::Events::Client.new(subs:, **kwargs)
|
||||||
@e_client.add_observer(self)
|
@e_client.add_observer(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
puts "press <Enter> to quit"
|
||||||
|
exit if gets.chomp.empty?
|
||||||
|
end
|
||||||
|
|
||||||
def on_input_mute_state_changed(data)
|
def on_input_mute_state_changed(data)
|
||||||
"""An input's mute state has changed."""
|
|
||||||
if data.input_name == DEVICE
|
if data.input_name == DEVICE
|
||||||
puts "#{DEVICE} mute toggled"
|
puts "#{DEVICE} mute toggled"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_input_volume_meters(data)
|
def on_input_volume_meters(data)
|
||||||
def fget(x) = x > 0 ? (20 * Math.log(x, 10)).round(1) : -200.0
|
fget = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 }
|
||||||
|
|
||||||
data.inputs.each do |d|
|
data.inputs.each do |d|
|
||||||
name = d[:inputName]
|
name = d[:inputName]
|
||||||
if name == DEVICE && !d[:inputLevelsMul].empty?
|
if name == DEVICE && !d[:inputLevelsMul].empty?
|
||||||
left, right = d[:inputLevelsMul]
|
left, right = d[:inputLevelsMul]
|
||||||
puts "#{name} [L: #{fget(left[LevelTypes::POSTFADER])}, R: #{fget(right[LevelTypes::POSTFADER])}]"
|
puts "#{name} [L: #{fget.call(left[LevelTypes::POSTFADER])}, R: #{fget.call(right[LevelTypes::POSTFADER])}]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def conn_from_toml
|
def conn_from_yaml
|
||||||
PerfectTOML.load_file("obs.toml", symbolize_names: true)[:connection]
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
||||||
end
|
end
|
||||||
|
|
||||||
def main
|
Main.new(**conn_from_yaml).run if $0 == __FILE__
|
||||||
o = Observer.new(**conn_from_toml)
|
|
||||||
|
|
||||||
puts "press <Enter> to quit"
|
|
||||||
loop { exit if gets.chomp.empty? }
|
|
||||||
end
|
|
||||||
|
|
||||||
main if $0 == __FILE__
|
|
||||||
|
@ -5,5 +5,3 @@ source "https://rubygems.org"
|
|||||||
# gem "rails"
|
# gem "rails"
|
||||||
|
|
||||||
gem "obsws", path: "../.."
|
gem "obsws", path: "../.."
|
||||||
|
|
||||||
gem "perfect_toml", "~> 0.9.0"
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: ../..
|
remote: ../..
|
||||||
specs:
|
specs:
|
||||||
obsws (0.1.0)
|
obsws (0.1.3)
|
||||||
observer (~> 0.1.1)
|
observer (~> 0.1.1)
|
||||||
waitutil (~> 0.2.1)
|
waitutil (~> 0.2.1)
|
||||||
websocket-driver (~> 0.7.5)
|
websocket-driver (~> 0.7.5)
|
||||||
@ -10,7 +10,6 @@ GEM
|
|||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
observer (0.1.1)
|
observer (0.1.1)
|
||||||
perfect_toml (0.9.0)
|
|
||||||
waitutil (0.2.1)
|
waitutil (0.2.1)
|
||||||
websocket-driver (0.7.5)
|
websocket-driver (0.7.5)
|
||||||
websocket-extensions (>= 0.1.0)
|
websocket-extensions (>= 0.1.0)
|
||||||
@ -21,7 +20,6 @@ PLATFORMS
|
|||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
obsws!
|
obsws!
|
||||||
perfect_toml (~> 0.9.0)
|
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.3.22
|
2.3.22
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
require "obsws"
|
require "obsws"
|
||||||
require "perfect_toml"
|
require "yaml"
|
||||||
|
|
||||||
OBSWS::LOGGER.info!
|
OBSWS::LOGGER.info!
|
||||||
|
|
||||||
def conn_from_toml
|
def conn_from_yaml
|
||||||
PerfectTOML.load_file("obs.toml", symbolize_names: true)[:connection]
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
||||||
end
|
end
|
||||||
|
|
||||||
def main
|
def main
|
||||||
r_client = OBSWS::Requests::Client.new(**conn_from_toml)
|
OBSWS::Requests::Client.new(**conn_from_yaml).run do |client|
|
||||||
r_client.run do
|
resp = client.get_scene_list
|
||||||
resp = r_client.get_scene_list
|
resp.scenes.reverse_each do |scene|
|
||||||
resp.scenes.reverse.each do |s|
|
puts "Switching to scene #{scene[:sceneName]}"
|
||||||
puts "Switching to scene #{s[:sceneName]}"
|
client.set_current_program_scene(scene[:sceneName])
|
||||||
r_client.set_current_program_scene(s[:sceneName])
|
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user