mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-22 02:50:47 +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:
|
example:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# register the app self as an event observer
|
# register an app to receive updates
|
||||||
self.vm.subject.add(self)
|
class App():
|
||||||
|
def __init__(self, vm):
|
||||||
|
vm.subject.add(self)
|
||||||
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `vm.event`
|
#### `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:
|
example:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
vm.event.add("ldirty")
|
vm.event.ldirty = True
|
||||||
|
|
||||||
vm.event.remove("pdirty")
|
vm.event.pdirty = False
|
||||||
|
|
||||||
# get a list of currently subscribed
|
# get a list of currently subscribed
|
||||||
print(vm.event.get())
|
print(vm.event.get())
|
||||||
|
@ -56,7 +56,7 @@ class Parser:
|
|||||||
|
|
||||||
def main(cmds=None):
|
def main(cmds=None):
|
||||||
kind_id = "banana"
|
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:
|
with voicemeeterlib.api(kind_id, subs=subs) as vm:
|
||||||
parser = Parser(vm)
|
parser = Parser(vm)
|
||||||
|
@ -8,8 +8,8 @@ class Observer:
|
|||||||
self.vm = vm
|
self.vm = vm
|
||||||
# register your app as event observer
|
# register your app as event observer
|
||||||
self.vm.subject.add(self)
|
self.vm.subject.add(self)
|
||||||
# add level updates, since they are disabled by default.
|
# enable level updates, since they are disabled by default.
|
||||||
self.vm.event.add("ldirty")
|
self.vm.event.ldirty = True
|
||||||
|
|
||||||
# define an 'on_update' callback function to receive event updates
|
# define an 'on_update' callback function to receive event updates
|
||||||
def on_update(self, subject):
|
def on_update(self, subject):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "voicemeeter-api"
|
name = "voicemeeter-api"
|
||||||
version = "0.8.2"
|
version = "0.8.3"
|
||||||
description = "A Python wrapper for the Voiceemeter API"
|
description = "A Python wrapper for the Voiceemeter API"
|
||||||
authors = ["onyx-and-iris <code@onyxandiris.online>"]
|
authors = ["onyx-and-iris <code@onyxandiris.online>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -18,21 +18,41 @@ class Event:
|
|||||||
self.logger.info(", ".join(info))
|
self.logger.info(", ".join(info))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pdirty(self):
|
def pdirty(self) -> bool:
|
||||||
return self.subs["pdirty"]
|
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
|
@property
|
||||||
def mdirty(self):
|
def mdirty(self) -> bool:
|
||||||
return self.subs["mdirty"]
|
return self.subs["mdirty"]
|
||||||
|
|
||||||
@property
|
@mdirty.setter
|
||||||
def midi(self):
|
def mdirty(self, val: bool):
|
||||||
return self.subs["midi"]
|
self.subs["mdirty"] = val
|
||||||
|
self.info(f"mdirty {'added to' if val else {'removed from'}}")
|
||||||
|
|
||||||
@property
|
@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"]
|
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:
|
def get(self) -> list:
|
||||||
return [k for k, v in self.subs.items() if v]
|
return [k for k, v in self.subs.items() if v]
|
||||||
|
|
||||||
@ -40,9 +60,7 @@ class Event:
|
|||||||
return any(self.subs.values())
|
return any(self.subs.values())
|
||||||
|
|
||||||
def add(self, event):
|
def add(self, event):
|
||||||
self.subs[event] = True
|
setattr(self, event, True)
|
||||||
self.info(f"{event} added to")
|
|
||||||
|
|
||||||
def remove(self, event):
|
def remove(self, event):
|
||||||
self.subs[event] = False
|
setattr(self, event, False)
|
||||||
self.info(f"{event} removed from")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user