mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-21 18:40:48 +00:00
add property setters in event class
use event property setters in examples update README patch bump
This commit is contained in:
parent
08fdad135d
commit
86612a65cb
20
README.md
20
README.md
@ -605,20 +605,30 @@ The following methods are available:
|
||||
example:
|
||||
|
||||
```python
|
||||
# register the app self as an event observer
|
||||
self.vm.subject.add(self)
|
||||
# register an app to receive updates
|
||||
class App():
|
||||
def __init__(self, vm):
|
||||
vm.subject.add(self)
|
||||
...
|
||||
```
|
||||
|
||||
#### `vm.event`
|
||||
|
||||
You may also add/remove event subscriptions as necessary with the Event class.
|
||||
Use the event class to toggle updates as necessary.
|
||||
|
||||
The following properties are available:
|
||||
|
||||
- `pdirty`: boolean
|
||||
- `mdirty`: boolean
|
||||
- `midi`: boolean
|
||||
- `ldirty`: boolean
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
vm.event.add("ldirty")
|
||||
vm.event.ldirty = True
|
||||
|
||||
vm.event.remove("pdirty")
|
||||
vm.event.pdirty = False
|
||||
|
||||
# get a list of currently subscribed
|
||||
print(vm.event.get())
|
||||
|
@ -56,7 +56,7 @@ class Parser:
|
||||
|
||||
def main(cmds=None):
|
||||
kind_id = "banana"
|
||||
subs = {ev: False for ev in ["pdirty", "mdirty", "ldirty", "midi"]}
|
||||
subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]}
|
||||
|
||||
with voicemeeterlib.api(kind_id, subs=subs) as vm:
|
||||
parser = Parser(vm)
|
||||
|
@ -8,8 +8,8 @@ class Observer:
|
||||
self.vm = vm
|
||||
# register your app as event observer
|
||||
self.vm.subject.add(self)
|
||||
# add level updates, since they are disabled by default.
|
||||
self.vm.event.add("ldirty")
|
||||
# enable level updates, since they are disabled by default.
|
||||
self.vm.event.ldirty = True
|
||||
|
||||
# define an 'on_update' callback function to receive event updates
|
||||
def on_update(self, subject):
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "voicemeeter-api"
|
||||
version = "0.8.2"
|
||||
version = "0.8.3"
|
||||
description = "A Python wrapper for the Voiceemeter API"
|
||||
authors = ["onyx-and-iris <code@onyxandiris.online>"]
|
||||
license = "MIT"
|
||||
|
@ -18,21 +18,41 @@ class Event:
|
||||
self.logger.info(", ".join(info))
|
||||
|
||||
@property
|
||||
def pdirty(self):
|
||||
def pdirty(self) -> bool:
|
||||
return self.subs["pdirty"]
|
||||
|
||||
@pdirty.setter
|
||||
def pdirty(self, val: bool):
|
||||
self.subs["pdirty"] = val
|
||||
self.info(f"pdirty {'added to' if val else {'removed from'}}")
|
||||
|
||||
@property
|
||||
def mdirty(self):
|
||||
def mdirty(self) -> bool:
|
||||
return self.subs["mdirty"]
|
||||
|
||||
@property
|
||||
def midi(self):
|
||||
return self.subs["midi"]
|
||||
@mdirty.setter
|
||||
def mdirty(self, val: bool):
|
||||
self.subs["mdirty"] = val
|
||||
self.info(f"mdirty {'added to' if val else {'removed from'}}")
|
||||
|
||||
@property
|
||||
def ldirty(self):
|
||||
def midi(self) -> bool:
|
||||
return self.subs["midi"]
|
||||
|
||||
@midi.setter
|
||||
def midi(self, val: bool):
|
||||
self.subs["midi"] = val
|
||||
self.info(f"midi {'added to' if val else {'removed from'}}")
|
||||
|
||||
@property
|
||||
def ldirty(self) -> bool:
|
||||
return self.subs["ldirty"]
|
||||
|
||||
@ldirty.setter
|
||||
def ldirty(self, val: bool):
|
||||
self.subs["ldirty"] = val
|
||||
self.info(f"ldirty {'added to' if val else {'removed from'}}")
|
||||
|
||||
def get(self) -> list:
|
||||
return [k for k, v in self.subs.items() if v]
|
||||
|
||||
@ -40,9 +60,7 @@ class Event:
|
||||
return any(self.subs.values())
|
||||
|
||||
def add(self, event):
|
||||
self.subs[event] = True
|
||||
self.info(f"{event} added to")
|
||||
setattr(self, event, True)
|
||||
|
||||
def remove(self, event):
|
||||
self.subs[event] = False
|
||||
self.info(f"{event} removed from")
|
||||
setattr(self, event, False)
|
||||
|
Loading…
Reference in New Issue
Block a user