2023-07-21 06:37:14 +01:00
|
|
|
require_relative "../../lib/obsws"
|
2023-07-19 15:13:26 +01:00
|
|
|
require "yaml"
|
2022-10-27 06:45:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
module LevelTypes
|
|
|
|
VU = 0
|
|
|
|
POSTFADER = 1
|
|
|
|
PREFADER = 2
|
|
|
|
end
|
|
|
|
|
2023-07-19 15:13:26 +01:00
|
|
|
class Main
|
2023-07-21 07:55:50 +01:00
|
|
|
DEVICE = "Desktop Audio"
|
|
|
|
|
2022-10-27 06:45:52 +01:00
|
|
|
def initialize(**kwargs)
|
2023-07-19 15:13:26 +01:00
|
|
|
subs = OBSWS::Events::SUBS::LOW_VOLUME | OBSWS::Events::SUBS::INPUTVOLUMEMETERS
|
|
|
|
@e_client = OBSWS::Events::Client.new(subs:, **kwargs)
|
2022-10-27 06:45:52 +01:00
|
|
|
@e_client.add_observer(self)
|
|
|
|
end
|
2023-07-19 15:13:26 +01:00
|
|
|
|
|
|
|
def run
|
|
|
|
puts "press <Enter> to quit"
|
2023-07-21 07:55:50 +01:00
|
|
|
loop { break if gets.chomp.empty? }
|
2023-07-19 15:13:26 +01:00
|
|
|
end
|
|
|
|
|
2022-10-27 06:45:52 +01:00
|
|
|
def on_input_mute_state_changed(data)
|
|
|
|
if data.input_name == DEVICE
|
|
|
|
puts "#{DEVICE} mute toggled"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_input_volume_meters(data)
|
2023-07-19 15:13:26 +01:00
|
|
|
fget = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 }
|
2022-10-27 06:45:52 +01:00
|
|
|
|
|
|
|
data.inputs.each do |d|
|
|
|
|
name = d[:inputName]
|
|
|
|
if name == DEVICE && !d[:inputLevelsMul].empty?
|
|
|
|
left, right = d[:inputLevelsMul]
|
2023-07-19 15:13:26 +01:00
|
|
|
puts "#{name} [L: #{fget.call(left[LevelTypes::POSTFADER])}, R: #{fget.call(right[LevelTypes::POSTFADER])}]"
|
2022-10-27 06:45:52 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-19 15:13:26 +01:00
|
|
|
def conn_from_yaml
|
|
|
|
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
|
2022-10-27 06:45:52 +01:00
|
|
|
end
|
|
|
|
|
2023-07-21 06:37:14 +01:00
|
|
|
Main.new(**conn_from_yaml).run if $PROGRAM_NAME == __FILE__
|