From a7d53dce74579ca9bb44bb83c68dd615220af9b6 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:08:53 +0100 Subject: [PATCH] levels example added --- examples/levels/__main__.py | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/levels/__main__.py diff --git a/examples/levels/__main__.py b/examples/levels/__main__.py new file mode 100644 index 0000000..701b1d9 --- /dev/null +++ b/examples/levels/__main__.py @@ -0,0 +1,43 @@ +from enum import IntEnum +from math import log + +import obsws_python as obs + +LEVELTYPE = IntEnum( + "LEVELTYPE", + "VU POSTFADER PREFADER", + start=0, +) + + +def on_input_mute_state_changed(data): + """The current program scene has changed.""" + print(f"{data.input_name} mute toggled") + + +def on_input_volume_meters(data): + def fget(x): + return round(20 * log(x, 10), 1) if x > 0 else -200.0 + + for device in data.inputs: + name = device["inputName"] + if name == INPUT_DEVICE and device["inputLevelsMul"]: + left, right = device["inputLevelsMul"] + print( + f"{name} [L: {fget(left[LEVELTYPE.POSTFADER])}, R: {fget(right[LEVELTYPE.POSTFADER])}]", + ) + + +def main(): + client = obs.EventClient(subs=(obs.Subs.LOW_VOLUME | obs.Subs.INPUTVOLUMEMETERS)) + client.callback.register([on_input_volume_meters, on_input_mute_state_changed]) + + while cmd := input(" to exit>\n"): + if not cmd: + break + + +if __name__ == "__main__": + INPUT_DEVICE = "Desktop Audio" + + main()