mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 12:50:53 +00:00
Merge pull request #12 from onyx-and-iris/dev
This commit is contained in:
commit
67fe16e97f
7
examples/hotkeys/setup.py
Normal file
7
examples/hotkeys/setup.py
Normal file
@ -0,0 +1,7 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="hotkeys",
|
||||
description="hotkeys example",
|
||||
install_requires=["obsws-python", "keyboard"],
|
||||
)
|
16
examples/levels/README.md
Normal file
16
examples/levels/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
## About
|
||||
|
||||
Prints POSTFADER level values for audio device `Desktop Audio`. If mute toggled prints mute state changed notification.
|
||||
|
||||
## Use
|
||||
|
||||
This example assumes the existence of a `config.toml`, placed next to `__main__.py`:
|
||||
|
||||
```toml
|
||||
[connection]
|
||||
host = "localhost"
|
||||
port = 4455
|
||||
password = "mystrongpass"
|
||||
```
|
||||
|
||||
Press `<Enter>` to exit from the script.
|
46
examples/levels/__main__.py
Normal file
46
examples/levels/__main__.py
Normal file
@ -0,0 +1,46 @@
|
||||
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):
|
||||
"""An input's mute state has changed."""
|
||||
if data.input_name == DEVICE:
|
||||
print(f"{DEVICE} mute toggled")
|
||||
|
||||
|
||||
def on_input_volume_meters(data):
|
||||
"""volume level update every 50 milliseconds"""
|
||||
|
||||
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 == 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("<Enter> to exit>\n"):
|
||||
if not cmd:
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
DEVICE = "Desktop Audio"
|
||||
|
||||
main()
|
@ -1,4 +1,5 @@
|
||||
from .enum import Subs
|
||||
from .events import EventClient
|
||||
from .reqs import ReqClient
|
||||
|
||||
__ALL__ = ["ReqClient", "EventClient"]
|
||||
__ALL__ = ["ReqClient", "EventClient", "Subs"]
|
||||
|
43
obsws_python/enum.py
Normal file
43
obsws_python/enum.py
Normal file
@ -0,0 +1,43 @@
|
||||
from enum import IntFlag
|
||||
|
||||
|
||||
class Subs(IntFlag):
|
||||
GENERAL = 1 << 0
|
||||
CONFIG = 1 << 1
|
||||
SCENES = 1 << 2
|
||||
INPUTS = 1 << 3
|
||||
TRANSITIONS = 1 << 4
|
||||
FILTERS = 1 << 5
|
||||
OUTPUTS = 1 << 6
|
||||
SCENEITEMS = 1 << 7
|
||||
MEDIAINPUTS = 1 << 8
|
||||
VENDORS = 1 << 9
|
||||
UI = 1 << 10
|
||||
|
||||
LOW_VOLUME = (
|
||||
GENERAL
|
||||
| CONFIG
|
||||
| SCENES
|
||||
| INPUTS
|
||||
| TRANSITIONS
|
||||
| FILTERS
|
||||
| OUTPUTS
|
||||
| SCENEITEMS
|
||||
| MEDIAINPUTS
|
||||
| VENDORS
|
||||
| UI
|
||||
)
|
||||
|
||||
INPUTVOLUMEMETERS = 1 << 16
|
||||
INPUTACTIVESTATECHANGED = 1 << 17
|
||||
INPUTSHOWSTATECHANGED = 1 << 18
|
||||
SCENEITEMTRANSFORMCHANGED = 1 << 19
|
||||
|
||||
HIGH_VOLUME = (
|
||||
INPUTVOLUMEMETERS
|
||||
| INPUTACTIVESTATECHANGED
|
||||
| INPUTSHOWSTATECHANGED
|
||||
| SCENEITEMTRANSFORMCHANGED
|
||||
)
|
||||
|
||||
ALL = LOW_VOLUME | HIGH_VOLUME
|
@ -1,11 +1,11 @@
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from enum import IntEnum
|
||||
from threading import Thread
|
||||
|
||||
from .baseclient import ObsClient
|
||||
from .callback import Callback
|
||||
from .enum import Subs
|
||||
|
||||
"""
|
||||
A class to interact with obs-websocket events
|
||||
@ -13,33 +13,13 @@ defined in official github repo
|
||||
https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#events
|
||||
"""
|
||||
|
||||
Subs = IntEnum(
|
||||
"Subs",
|
||||
"general config scenes inputs transitions filters outputs sceneitems mediainputs vendors ui",
|
||||
start=0,
|
||||
)
|
||||
|
||||
|
||||
class EventClient:
|
||||
logger = logging.getLogger("events.eventclient")
|
||||
DELAY = 0.001
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
defaultkwargs = {
|
||||
"subs": (
|
||||
(1 << Subs.general)
|
||||
| (1 << Subs.config)
|
||||
| (1 << Subs.scenes)
|
||||
| (1 << Subs.inputs)
|
||||
| (1 << Subs.transitions)
|
||||
| (1 << Subs.filters)
|
||||
| (1 << Subs.outputs)
|
||||
| (1 << Subs.sceneitems)
|
||||
| (1 << Subs.mediainputs)
|
||||
| (1 << Subs.vendors)
|
||||
| (1 << Subs.ui)
|
||||
)
|
||||
}
|
||||
defaultkwargs = {"subs": Subs.LOW_VOLUME}
|
||||
kwargs = defaultkwargs | kwargs
|
||||
self.base_client = ObsClient(**kwargs)
|
||||
if self.base_client.authenticate():
|
||||
|
Loading…
Reference in New Issue
Block a user