mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2025-04-01 19:33:48 +01:00
Compare commits
33 Commits
e6ea1e5f4f
...
b3febbe831
Author | SHA1 | Date | |
---|---|---|---|
b3febbe831 | |||
cf18ae6fcc | |||
01178082d2 | |||
3d98b2accd | |||
cc26720ae2 | |||
2f9864cf60 | |||
f57475daa0 | |||
8fc052d093 | |||
8831277160 | |||
d428694fcf | |||
0548d82295 | |||
27d7f1fcd5 | |||
40d984c44f | |||
9ef89852de | |||
b81c4c4b97 | |||
1ee0fc5f06 | |||
772a3344ca | |||
b2f57a9e60 | |||
c23a6aff6d | |||
342a49804f | |||
064cfeb23d | |||
6c4259d6de | |||
9cf048185d | |||
435a9e2085 | |||
b10a90418e | |||
7d4d09ff29 | |||
6ddfe3044e | |||
36fe77f0f0 | |||
155e597db5 | |||
92e04f1419 | |||
b5c8641c11 | |||
c6b203a1df | |||
9f27968c5c |
2
.gitignore
vendored
2
.gitignore
vendored
@ -131,5 +131,7 @@ dmypy.json
|
||||
# test/config
|
||||
quick.py
|
||||
config.toml
|
||||
vm-api.log
|
||||
logging.json
|
||||
|
||||
.vscode/
|
65
CHANGELOG.md
65
CHANGELOG.md
@ -11,6 +11,69 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
||||
|
||||
- [x]
|
||||
|
||||
## [2.0.0] - 2023-06-25
|
||||
|
||||
Where possible I've attempted to make the changes backwards compatible. The breaking changes affect two higher classes, Strip and Bus, as well as the behaviour of events. All other changes are additive or QOL aimed at giving more options to the developer. For example, every low-level CAPI call is now logged and error raised on Exception, you can now register callback functions as well as observer classes, extra examples to demonstrate different use cases etc.
|
||||
|
||||
The breaking changes are as follows:
|
||||
|
||||
### Changed
|
||||
|
||||
- `strip[i].comp` now references StripComp class
|
||||
- To change the comp knob you should now use the property `strip[i].comp.knob`
|
||||
- `strip[i].gate` now references StripGate class
|
||||
|
||||
- To change the gate knob you should now use the property `strip[i].gate.knob`
|
||||
|
||||
- `bus[i].eq` now references BusEQ class
|
||||
|
||||
- To set bus[i].{eq,eq_ab} as before you should now use bus[i].eq.on and bus[i].eq.ab
|
||||
|
||||
- by default, <strong>NO</strong> events are checked for. This is reflected in factory.FactoryBase defaultkwargs.
|
||||
- This is a fundamental behaviour change from version 1.0 of the wrapper. It means the following:
|
||||
- Unless any events are explicitly requested with an event kwarg the event emitter thread will not run automatically.
|
||||
- Whether using a context manager or not, you can still initiate the event thread manually and request events with the event object.<br>
|
||||
see `events` example.
|
||||
|
||||
There are other non-breaking changes:
|
||||
|
||||
### Added
|
||||
|
||||
- `strip[i].eq` added to PhysicalStrip
|
||||
- `strip[i].denoiser` added to PhysicalStrip
|
||||
- `Strip.Comp`, `Strip.Gate`, `Strip.Denoiser` sections added to README.
|
||||
- `Events` section in readme updated to reflect changes to events kwargs.
|
||||
- new comp, gate, denoiser and eq tests added to higher tests.
|
||||
- `levels` example to demonstrate use of the interface without a context manager.
|
||||
- `events` example to demonstrate how to interact with event thread/event object.
|
||||
- `gui` example to demonstrate GUI controls.
|
||||
- `{Remote}.observer` can be used in place of `{Remote}.subject` although subject will still work. Check examples.
|
||||
- Subject class extended to allow registering/de-registering callback functions (as well as observer classes). See `events` example.
|
||||
|
||||
### Changed
|
||||
|
||||
- `comp.knob`, `gate.knob`, `denoiser.knob`, `eq.on` added to phys_strip_params in config.TOMLStrBuilder
|
||||
|
||||
- The `example.toml` config files have been updated to demonstrate setting new comp, gate and eq settings.
|
||||
|
||||
- event kwargs can now be set directly. no need for `subs`. example: `voicemeeterlib.api('banana', midi=True})`
|
||||
|
||||
- factorybuilder steps now logged in DEBUG mode.
|
||||
|
||||
- now using a producer thread to send events to the updater thread.
|
||||
|
||||
- module level loggers implemented (with class loggers as child loggers)
|
||||
|
||||
- config.loader now checks `Path.home() / ".config" / "voicemeeter" / kind.name` for configs.
|
||||
- note. `Path(__file__).parent / "configs" / kind.name,` was removed as a path to check.
|
||||
|
||||
### Fixed
|
||||
|
||||
- All low level CAPI calls are now wrapped by CBindings.call() which logs any errors raised.
|
||||
- Dynamic binding of Macrobutton functions from the CAPI.
|
||||
Should add backwards compatibility with very old versions of the api. See [Issue #4][issue 4].
|
||||
- factory.request_remote_obj now raises a `VMError` if passed an incorrect kind.
|
||||
|
||||
## [1.0.0] - 2023-06-19
|
||||
|
||||
No changes to the codebase but it has been stable for several months and should already have been bumped to major version 1.0
|
||||
@ -298,3 +361,5 @@ I will move this commit to a separate branch in preparation for version 2.0.
|
||||
- inst module implemented (fetch vm path from registry)
|
||||
- kind maps implemented as dataclasses
|
||||
- project packaged with poetry and added to pypi.
|
||||
|
||||
[issue 4]: https://github.com/onyx-and-iris/voicemeeter-api-python/issues/4
|
||||
|
136
README.md
136
README.md
@ -52,16 +52,18 @@ class ManyThings:
|
||||
|
||||
def other_things(self):
|
||||
self.vm.bus[3].gain = -6.3
|
||||
self.vm.bus[4].eq = True
|
||||
self.vm.bus[4].eq.on = True
|
||||
info = (
|
||||
f"bus 3 gain has been set to {self.vm.bus[3].gain}",
|
||||
f"bus 4 eq has been set to {self.vm.bus[4].eq}",
|
||||
f"bus 4 eq has been set to {self.vm.bus[4].eq.on}",
|
||||
)
|
||||
print("\n".join(info))
|
||||
|
||||
|
||||
def main():
|
||||
with voicemeeterlib.api(kind_id) as vm:
|
||||
KIND_ID = "banana"
|
||||
|
||||
with voicemeeterlib.api(KIND_ID) as vm:
|
||||
do = ManyThings(vm)
|
||||
do.things()
|
||||
do.other_things()
|
||||
@ -70,7 +72,7 @@ def main():
|
||||
vm.apply(
|
||||
{
|
||||
"strip-2": {"A1": True, "B1": True, "gain": -6.0},
|
||||
"bus-2": {"mute": True},
|
||||
"bus-2": {"mute": True, "eq": {"on": True}},
|
||||
"button-0": {"state": True},
|
||||
"vban-in-0": {"on": True},
|
||||
"vban-out-1": {"name": "streamname"},
|
||||
@ -79,16 +81,15 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
kind_id = "banana"
|
||||
|
||||
main()
|
||||
|
||||
```
|
||||
|
||||
Otherwise you must remember to call `vm.login()`, `vm.logout()` at the start/end of your code.
|
||||
|
||||
## `kind_id`
|
||||
## `KIND_ID`
|
||||
|
||||
Pass the kind of Voicemeeter as an argument. kind_id may be:
|
||||
Pass the kind of Voicemeeter as an argument. KIND_ID may be:
|
||||
|
||||
- `basic`
|
||||
- `banana`
|
||||
@ -104,8 +105,6 @@ The following properties are available.
|
||||
- `solo`: boolean
|
||||
- `mute`: boolean
|
||||
- `gain`: float, from -60.0 to 12.0
|
||||
- `comp`: float, from 0.0 to 10.0
|
||||
- `gate`: float, from 0.0 to 10.0
|
||||
- `audibility`: float, from 0.0 to 10.0
|
||||
- `limit`: int, from -40 to 12
|
||||
- `A1 - A5`, `B1 - B3`: boolean
|
||||
@ -154,7 +153,72 @@ vm.strip[5].appmute("Spotify", True)
|
||||
vm.strip[5].appgain("Spotify", 0.5)
|
||||
```
|
||||
|
||||
##### Gainlayers
|
||||
#### Strip.Comp
|
||||
|
||||
- `knob`: float, from 0.0 to 10.0
|
||||
- `gainin`: float, from -24.0 to 24.0
|
||||
- `ratio`: float, from 1.0 to 8.0
|
||||
- `threshold`: float, from -40.0 to -3.0
|
||||
- `attack`: float, from 0.0 to 200.0
|
||||
- `release`: float, from 0.0 to 5000.0
|
||||
- `knee`: float, from 0.0 to 1.0
|
||||
- `gainout`: float, from -24.0 to 24.0
|
||||
- `makeup`: boolean
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
print(vm.strip[4].comp.knob)
|
||||
```
|
||||
|
||||
Strip Comp parameters are defined for PhysicalStrips, potato version only.
|
||||
|
||||
#### Strip.Gate
|
||||
|
||||
- `knob`: float, from 0.0 to 10.0
|
||||
- `threshold`: float, from -60.0 to -10.0
|
||||
- `damping`: float, from -60.0 to -10.0
|
||||
- `bpsidechain`: int, from 100 to 4000
|
||||
- `attack`: float, from 0.0 to 1000.0
|
||||
- `hold`: float, from 0.0 to 5000.0
|
||||
- `release`: float, from 0.0 to 5000.0
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
vm.strip[2].gate.attack = 300.8
|
||||
```
|
||||
|
||||
Strip Gate parameters are defined for PhysicalStrips, potato version only.
|
||||
|
||||
#### Strip.Denoiser
|
||||
|
||||
- `knob`: float, from 0.0 to 10.0
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
vm.strip[0].denoiser.knob = 0.5
|
||||
```
|
||||
|
||||
Strip Denoiser parameters are defined for PhysicalStrips, potato version only.
|
||||
|
||||
#### Strip.EQ
|
||||
|
||||
The following properties are available.
|
||||
|
||||
- `on`: boolean
|
||||
- `ab`: boolean
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
vm.strip[0].eq.ab = True
|
||||
```
|
||||
|
||||
Strip EQ parameters are defined for PhysicalStrips, potato version only.
|
||||
|
||||
##### Strip.Gainlayers
|
||||
|
||||
- `gain`: float, from -60.0 to 12.0
|
||||
|
||||
@ -166,7 +230,7 @@ vm.strip[3].gainlayer[3].gain = 3.7
|
||||
|
||||
Gainlayers are defined for potato version only.
|
||||
|
||||
##### Levels
|
||||
##### Strip.Levels
|
||||
|
||||
The following properties are available.
|
||||
|
||||
@ -187,8 +251,6 @@ Level properties will return -200.0 if no audio detected.
|
||||
The following properties are available.
|
||||
|
||||
- `mono`: boolean
|
||||
- `eq`: boolean
|
||||
- `eq_ab`: boolean
|
||||
- `mute`: boolean
|
||||
- `sel`: boolean
|
||||
- `gain`: float, from -60.0 to 12.0
|
||||
@ -208,7 +270,20 @@ print(vm.bus[0].label)
|
||||
vm.bus[4].mono = True
|
||||
```
|
||||
|
||||
##### Modes
|
||||
##### Bus.EQ
|
||||
|
||||
The following properties are available.
|
||||
|
||||
- `on`: boolean
|
||||
- `ab`: boolean
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
vm.bus[3].eq.on = True
|
||||
```
|
||||
|
||||
##### Bus.Modes
|
||||
|
||||
The following properties are available.
|
||||
|
||||
@ -236,7 +311,7 @@ vm.bus[4].mode.amix = True
|
||||
print(vm.bus[2].mode.get())
|
||||
```
|
||||
|
||||
##### Levels
|
||||
##### Bus.Levels
|
||||
|
||||
The following properties are available.
|
||||
|
||||
@ -409,7 +484,7 @@ example:
|
||||
|
||||
```python
|
||||
import voicemeeterlib
|
||||
with voicemeeterlib.api(kind_id) as vm:
|
||||
with voicemeeterlib.api(KIND_ID) as vm:
|
||||
for i in range(vm.device.ins):
|
||||
print(vm.device.input(i))
|
||||
```
|
||||
@ -562,7 +637,7 @@ get() may return None if no value for requested key in midi cache
|
||||
vm.apply(
|
||||
{
|
||||
"strip-2": {"A1": True, "B1": True, "gain": -6.0},
|
||||
"bus-2": {"mute": True},
|
||||
"bus-2": {"mute": True, "eq": {"on": True}},
|
||||
"button-0": {"state": True},
|
||||
"vban-in-0": {"on": True},
|
||||
"vban-out-1": {"name": "streamname"},
|
||||
@ -595,19 +670,19 @@ will load a user config file at configs/banana/example.toml for Voicemeeter Bana
|
||||
|
||||
## Events
|
||||
|
||||
Level updates are considered high volume, by default they are NOT listened for. Use subs keyword arg to initialize event updates.
|
||||
By default, NO events are listened for. Use events kwargs to enable specific event types.
|
||||
|
||||
example:
|
||||
|
||||
```python
|
||||
import voicemeeterlib
|
||||
# Set updates to occur every 50ms
|
||||
# Listen for level updates but disable midi updates
|
||||
with voicemeeterlib.api('banana', ratelimit=0.05, subs={"ldirty": True, "midi": False}) as vm:
|
||||
# Set event updates to occur every 50ms
|
||||
# Listen for level updates only
|
||||
with voicemeeterlib.api('banana', ratelimit=0.05, ldirty=True}) as vm:
|
||||
...
|
||||
```
|
||||
|
||||
#### `vm.subject`
|
||||
#### `vm.observer`
|
||||
|
||||
Use the Subject class to register an app as event observer.
|
||||
|
||||
@ -622,7 +697,7 @@ example:
|
||||
# register an app to receive updates
|
||||
class App():
|
||||
def __init__(self, vm):
|
||||
vm.subject.add(self)
|
||||
vm.observer.add(self)
|
||||
...
|
||||
```
|
||||
|
||||
@ -664,17 +739,16 @@ print(vm.event.get())
|
||||
|
||||
## Remote class
|
||||
|
||||
`voicemeeterlib.api(kind_id: str)`
|
||||
`voicemeeterlib.api(KIND_ID: str)`
|
||||
|
||||
You may pass the following optional keyword arguments:
|
||||
|
||||
- `sync`: boolean=False, force the getters to wait for dirty parameters to clear. For most cases leave this as False.
|
||||
- `ratelimit`: float=0.033, how often to check for updates in ms.
|
||||
- `subs`: dict={"pdirty": True, "mdirty": True, "midi": True, "ldirty": False}, initialize which event updates to listen for.
|
||||
- `pdirty`: parameter updates
|
||||
- `mdirty`: macrobutton updates
|
||||
- `midi`: midi updates
|
||||
- `ldirty`: level updates
|
||||
- `pdirty`: boolean=False, parameter updates
|
||||
- `mdirty`: boolean=False, macrobutton updates
|
||||
- `midi`: boolean=False, midi updates
|
||||
- `ldirty`: boolean=False, level updates
|
||||
|
||||
Access to lower level Getters and Setters are provided with these functions:
|
||||
|
||||
@ -705,4 +779,4 @@ pytest -v
|
||||
|
||||
### Official Documentation
|
||||
|
||||
- [Voicemeeter Remote C API](https://github.com/onyx-and-iris/Voicemeeter-SDK/blob/main/VoicemeeterRemoteAPI.pdf)
|
||||
- [Voicemeeter Remote C API](https://github.com/onyx-and-iris/Voicemeeter-SDK/blob/update-docs/VoicemeeterRemoteAPI.pdf)
|
||||
|
12
__main__.py
12
__main__.py
@ -14,16 +14,18 @@ class ManyThings:
|
||||
|
||||
def other_things(self):
|
||||
self.vm.bus[3].gain = -6.3
|
||||
self.vm.bus[4].eq = True
|
||||
self.vm.bus[4].eq.on = True
|
||||
info = (
|
||||
f"bus 3 gain has been set to {self.vm.bus[3].gain}",
|
||||
f"bus 4 eq has been set to {self.vm.bus[4].eq}",
|
||||
f"bus 4 eq has been set to {self.vm.bus[4].eq.on}",
|
||||
)
|
||||
print("\n".join(info))
|
||||
|
||||
|
||||
def main():
|
||||
with voicemeeterlib.api(kind_id) as vm:
|
||||
KIND_ID = "banana"
|
||||
|
||||
with voicemeeterlib.api(KIND_ID) as vm:
|
||||
do = ManyThings(vm)
|
||||
do.things()
|
||||
do.other_things()
|
||||
@ -32,7 +34,7 @@ def main():
|
||||
vm.apply(
|
||||
{
|
||||
"strip-2": {"A1": True, "B1": True, "gain": -6.0},
|
||||
"bus-2": {"mute": True},
|
||||
"bus-2": {"mute": True, "eq": {"on": True}},
|
||||
"button-0": {"state": True},
|
||||
"vban-in-0": {"on": True},
|
||||
"vban-out-1": {"name": "streamname"},
|
||||
@ -41,6 +43,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
kind_id = "banana"
|
||||
|
||||
main()
|
||||
|
@ -2,12 +2,12 @@
|
||||
label = "PhysStrip0"
|
||||
A1 = true
|
||||
gain = -8.8
|
||||
comp = 3.2
|
||||
comp.knob = 3.2
|
||||
|
||||
[strip-1]
|
||||
label = "PhysStrip1"
|
||||
B1 = true
|
||||
gate = 4.1
|
||||
gate.knob = 4.1
|
||||
|
||||
[strip-2]
|
||||
label = "PhysStrip2"
|
||||
@ -34,12 +34,12 @@ mono = true
|
||||
|
||||
[bus-2]
|
||||
label = "PhysBus2"
|
||||
eq = true
|
||||
eq.ab = true
|
||||
mode = "composite"
|
||||
|
||||
[bus-3]
|
||||
label = "VirtBus0"
|
||||
eq_ab = true
|
||||
eq.on = true
|
||||
mode = "upmix61"
|
||||
|
||||
[bus-4]
|
||||
|
@ -2,26 +2,29 @@
|
||||
label = "PhysStrip0"
|
||||
A1 = true
|
||||
gain = -8.8
|
||||
comp = 3.2
|
||||
comp.knob = 3.2
|
||||
|
||||
[strip-1]
|
||||
label = "PhysStrip1"
|
||||
B1 = true
|
||||
gate = 4.1
|
||||
gate.knob = 4.1
|
||||
|
||||
[strip-2]
|
||||
label = "PhysStrip2"
|
||||
gain = 1.1
|
||||
limit = -15
|
||||
comp.threshold = -35.8
|
||||
|
||||
[strip-3]
|
||||
label = "PhysStrip3"
|
||||
B2 = false
|
||||
eq.on = true
|
||||
|
||||
[strip-4]
|
||||
label = "PhysStrip4"
|
||||
B3 = true
|
||||
gain = -8.8
|
||||
eq.on = true
|
||||
|
||||
[strip-5]
|
||||
label = "VirtStrip0"
|
||||
@ -50,7 +53,7 @@ mono = true
|
||||
|
||||
[bus-2]
|
||||
label = "PhysBus2"
|
||||
eq = true
|
||||
eq.on = true
|
||||
|
||||
[bus-3]
|
||||
label = "PhysBus3"
|
||||
@ -62,7 +65,7 @@ mode = "composite"
|
||||
|
||||
[bus-5]
|
||||
label = "VirtBus0"
|
||||
eq_ab = true
|
||||
eq.ab = true
|
||||
|
||||
[bus-6]
|
||||
label = "VirtBus1"
|
||||
|
@ -2,7 +2,6 @@ import argparse
|
||||
import logging
|
||||
import time
|
||||
|
||||
import voicemeeterlib
|
||||
from pyparsing import (
|
||||
Combine,
|
||||
Group,
|
||||
@ -15,6 +14,8 @@ from pyparsing import (
|
||||
nums,
|
||||
)
|
||||
|
||||
import voicemeeterlib
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
argparser = argparse.ArgumentParser(description="creates a basic dsl")
|
||||
argparser.add_argument("-i", action="store_true")
|
||||
@ -81,10 +82,9 @@ def main():
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
kind_id = "banana"
|
||||
subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]}
|
||||
KIND_ID = "banana"
|
||||
|
||||
with voicemeeterlib.api(kind_id, subs=subs) as vm:
|
||||
with voicemeeterlib.api(KIND_ID) as vm:
|
||||
parser = Parser(vm)
|
||||
if args.i:
|
||||
interactive_mode(parser)
|
||||
|
7
examples/dsl/setup.py
Normal file
7
examples/dsl/setup.py
Normal file
@ -0,0 +1,7 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="dsl",
|
||||
description="dsl example",
|
||||
install_requires=["pyparsing"],
|
||||
)
|
33
examples/events/README.md
Normal file
33
examples/events/README.md
Normal file
@ -0,0 +1,33 @@
|
||||
## About
|
||||
|
||||
This script demonstrates how to interact with the event thread/event object. It also demonstrates how to register event specific callbacks.
|
||||
|
||||
By default the interface does not broadcast any events. So even though our callbacks are registered, and the event thread has been initiated, we won't receive updates.
|
||||
|
||||
After five seconds the event object is used to subscribe to all events for a total of thirty seconds.
|
||||
|
||||
Remember that events can also be unsubscribed to with `vm.event.remove()`. Callbacks can also be deregistered using vm.observer.remove().
|
||||
|
||||
The same can be done without a context manager:
|
||||
|
||||
```python
|
||||
vm = voicemeeterlib.api(KIND_ID)
|
||||
vm.login()
|
||||
vm.observer.add(on_midi) # register an `on_midi` callback function
|
||||
vm.init_thread()
|
||||
vm.event.add("midi") # in this case we only subscribe to midi events.
|
||||
...
|
||||
vm.end_thread()
|
||||
vm.logout()
|
||||
```
|
||||
|
||||
Once initialized, the event thread will continously run until end_thread() is called. Even if all events are unsubscribed to.
|
||||
|
||||
## Use
|
||||
|
||||
Simply run the script and trigger events and you should see the output after 5 seconds. To trigger events do the following:
|
||||
|
||||
- change GUI parameters to trigger pdirty
|
||||
- press any macrobutton to trigger mdirty
|
||||
- play audio through any bus to trigger ldirty
|
||||
- any midi input to trigger midi
|
54
examples/events/__main__.py
Normal file
54
examples/events/__main__.py
Normal file
@ -0,0 +1,54 @@
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from logging import config
|
||||
|
||||
import voicemeeterlib
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
class App:
|
||||
def __init__(self, vm):
|
||||
self.vm = vm
|
||||
# register the callbacks for each event
|
||||
self.vm.observer.add(
|
||||
[self.on_pdirty, self.on_mdirty, self.on_ldirty, self.on_midi]
|
||||
)
|
||||
|
||||
def __enter__(self):
|
||||
self.vm.init_thread()
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.vm.end_thread()
|
||||
|
||||
def on_pdirty(self):
|
||||
print("pdirty!")
|
||||
|
||||
def on_mdirty(self):
|
||||
print("mdirty!")
|
||||
|
||||
def on_ldirty(self):
|
||||
for bus in self.vm.bus:
|
||||
if bus.levels.isdirty:
|
||||
print(bus, bus.levels.all)
|
||||
|
||||
def on_midi(self):
|
||||
current = self.vm.midi.current
|
||||
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
||||
|
||||
|
||||
def main():
|
||||
KIND_ID = "banana"
|
||||
|
||||
with voicemeeterlib.api(KIND_ID) as vm:
|
||||
with App(vm) as app:
|
||||
for i in range(5, 0, -1):
|
||||
print(f"events start in {i} seconds")
|
||||
time.sleep(1)
|
||||
vm.event.add(["pdirty", "ldirty", "midi", "mdirty"])
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
13
examples/gui/README.md
Normal file
13
examples/gui/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
## About
|
||||
|
||||
A single channel GUI demonstrating controls for the first virtual strip if Voicemeeter Banana.
|
||||
|
||||
This example demonstrates (to an extent) two way communication.
|
||||
- Sending parameters values to the Voicemeeter driver.
|
||||
- Receiving level updates
|
||||
|
||||
Parameter updates (pdirty) events are not being received so changing a UI element on the main Voicemeeter app will not be reflected in the example GUI.
|
||||
|
||||
## Use
|
||||
|
||||
Simply run the script and try the controls.
|
100
examples/gui/__main__.py
Normal file
100
examples/gui/__main__.py
Normal file
@ -0,0 +1,100 @@
|
||||
import logging
|
||||
|
||||
import voicemeeterlib
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
|
||||
class App(tk.Tk):
|
||||
def __init__(self, vm):
|
||||
super().__init__()
|
||||
self.vm = vm
|
||||
self.title(f"{vm} - version {vm.version}")
|
||||
self.vm.observer.add(self.on_ldirty)
|
||||
|
||||
# create widget variables
|
||||
self.button_var = tk.BooleanVar(value=vm.strip[3].mute)
|
||||
self.slider_var = tk.DoubleVar(value=vm.strip[3].gain)
|
||||
self.meter_var = tk.DoubleVar(value=self._get_level())
|
||||
self.gainlabel_var = tk.StringVar(value=self.slider_var.get())
|
||||
|
||||
# initialize style table
|
||||
self.style = ttk.Style()
|
||||
self.style.theme_use("clam")
|
||||
self.style.configure(
|
||||
"Mute.TButton", foreground="#cd5c5c" if vm.strip[3].mute else "#5a5a5a"
|
||||
)
|
||||
|
||||
# create labelframe and grid it onto the mainframe
|
||||
self.labelframe = tk.LabelFrame(text=self.vm.strip[3].label)
|
||||
self.labelframe.grid(padx=1)
|
||||
|
||||
# create slider and grid it
|
||||
slider = ttk.Scale(
|
||||
self.labelframe,
|
||||
from_=12,
|
||||
to_=-60,
|
||||
orient="vertical",
|
||||
variable=self.slider_var,
|
||||
command=lambda arg: self.on_slider_move(arg),
|
||||
)
|
||||
slider.grid(
|
||||
column=0,
|
||||
row=0,
|
||||
)
|
||||
|
||||
# create level meter and grid it onto the labelframe
|
||||
level_meter = ttk.Progressbar(
|
||||
self.labelframe,
|
||||
orient="vertical",
|
||||
variable=self.meter_var,
|
||||
maximum=72,
|
||||
mode="determinate",
|
||||
)
|
||||
level_meter.grid(column=1, row=0)
|
||||
|
||||
# create gainlabel and grid it onto the labelframe
|
||||
gainlabel = ttk.Label(self.labelframe, textvariable=self.gainlabel_var)
|
||||
gainlabel.grid(column=0, row=1, columnspan=2)
|
||||
|
||||
# create button and grid it onto the labelframe
|
||||
button = ttk.Button(
|
||||
self.labelframe,
|
||||
text="Mute",
|
||||
style="Mute.TButton",
|
||||
command=lambda: self.on_button_press(),
|
||||
)
|
||||
button.grid(column=0, row=2, columnspan=2, padx=1, pady=2)
|
||||
|
||||
# define callbacks
|
||||
|
||||
def on_slider_move(self, *args):
|
||||
val = round(self.slider_var.get(), 1)
|
||||
self.vm.strip[3].gain = val
|
||||
self.gainlabel_var.set(val)
|
||||
|
||||
def on_button_press(self):
|
||||
self.button_var.set(not self.button_var.get())
|
||||
self.vm.strip[3].mute = self.button_var.get()
|
||||
self.style.configure(
|
||||
"Mute.TButton", foreground="#cd5c5c" if self.button_var.get() else "#5a5a5a"
|
||||
)
|
||||
|
||||
def _get_level(self):
|
||||
val = max(self.vm.strip[3].levels.postfader)
|
||||
return 0 if self.button_var.get() else 72 + val - 12
|
||||
|
||||
def on_ldirty(self):
|
||||
self.meter_var.set(self._get_level())
|
||||
|
||||
|
||||
def main():
|
||||
with voicemeeterlib.api("banana", ldirty=True) as vm:
|
||||
app = App(vm)
|
||||
app.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
13
examples/levels/README.md
Normal file
13
examples/levels/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
## About
|
||||
|
||||
The purpose of this script is to demonstrate:
|
||||
|
||||
- use of the interface without a context manager.
|
||||
- retrieving level values for channels by polling (instead of receiving data as event)
|
||||
- use of the interface without the events thread running.
|
||||
|
||||
## Use
|
||||
|
||||
Configured for potato version.
|
||||
|
||||
Make sure you are playing audio into the first virtual strip and out of the first physical bus, both channels are unmuted and that you aren't monitoring another mixbus. Then run the script.
|
28
examples/levels/__main__.py
Normal file
28
examples/levels/__main__.py
Normal file
@ -0,0 +1,28 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
import voicemeeterlib
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
KIND_ID = "potato"
|
||||
|
||||
vm = voicemeeterlib.api(KIND_ID)
|
||||
vm.login()
|
||||
for _ in range(500):
|
||||
print(
|
||||
"\n".join(
|
||||
[
|
||||
f"{vm.strip[5]}: {vm.strip[5].levels.postmute}",
|
||||
f"{vm.bus[1]}: {vm.bus[0].levels.all}",
|
||||
]
|
||||
)
|
||||
)
|
||||
time.sleep(0.033)
|
||||
vm.logout()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -2,62 +2,48 @@ import logging
|
||||
|
||||
import voicemeeterlib
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
class Observer:
|
||||
# leftmost M on korg nanokontrol2 in CC mode
|
||||
MIDI_BUTTON = 48
|
||||
class App:
|
||||
MIDI_BUTTON = 48 # leftmost M on korg nanokontrol2 in CC mode
|
||||
MACROBUTTON = 0
|
||||
|
||||
def __init__(self, vm):
|
||||
self.vm = vm
|
||||
self.vm.subject.add(self)
|
||||
self.vm.observer.add(self.on_midi)
|
||||
|
||||
def on_update(self, subject):
|
||||
"""
|
||||
We expect to only receive midi updates.
|
||||
|
||||
We could skip subject check but check anyway, in case an event is added later.
|
||||
"""
|
||||
if subject == "midi":
|
||||
self.get_info()
|
||||
self.on_midi_press()
|
||||
def on_midi(self):
|
||||
self.get_info()
|
||||
self.on_midi_press()
|
||||
|
||||
def get_info(self):
|
||||
current = self.vm.midi.current
|
||||
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
||||
|
||||
def on_midi_press(self):
|
||||
"""
|
||||
checks if strip 3 level postfader mode is greater than -40
|
||||
"""if strip 3 level max > -40 and midi button 48 is pressed, then set trigger for macrobutton 0"""
|
||||
|
||||
checks if midi button 48 velocity is 127 (full velocity for button press).
|
||||
"""
|
||||
if (
|
||||
max(self.vm.strip[3].levels.postfader) > -40
|
||||
and self.vm.midi.get(self.MIDI_BUTTON) == 127
|
||||
):
|
||||
print(
|
||||
f"Strip 3 level is greater than -40 and midi button {self.MIDI_BUTTON} is pressed"
|
||||
f"Strip 3 level max is greater than -40 and midi button {self.MIDI_BUTTON} is pressed"
|
||||
)
|
||||
self.vm.button[self.MACROBUTTON].trigger = True
|
||||
else:
|
||||
self.vm.button[self.MACROBUTTON].trigger = False
|
||||
self.vm.button[self.MACROBUTTON].state = False
|
||||
|
||||
|
||||
def main():
|
||||
kind_id = "banana"
|
||||
KIND_ID = "banana"
|
||||
|
||||
# we only care about midi events here.
|
||||
subs = {ev: False for ev in ["pdirty", "mdirty"]}
|
||||
with voicemeeterlib.api(kind_id, subs=subs) as vm:
|
||||
obs = Observer(vm)
|
||||
with voicemeeterlib.api(KIND_ID, midi=True) as vm:
|
||||
App(vm)
|
||||
|
||||
while cmd := input("Press <Enter> to exit\n"):
|
||||
if not cmd:
|
||||
break
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -17,8 +17,12 @@ port = 4455
|
||||
password = "mystrongpass"
|
||||
```
|
||||
|
||||
Closing OBS will end the script.
|
||||
|
||||
## Notes
|
||||
|
||||
In this example all but `voicemeeterlib.iremote` logs are filtered out. Log level set at DEBUG.
|
||||
|
||||
For a similar Streamlabs Desktop example:
|
||||
|
||||
[Streamlabs example](https://gist.github.com/onyx-and-iris/c864f07126eeae389b011dc49520a19b)
|
||||
|
@ -1,16 +1,43 @@
|
||||
import logging
|
||||
import time
|
||||
from logging import config
|
||||
|
||||
import obsws_python as obsws
|
||||
|
||||
import obsws_python as obs
|
||||
import voicemeeterlib
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
config.dictConfig(
|
||||
{
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
"standard": {
|
||||
"format": "%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s"
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
"stream": {
|
||||
"level": "DEBUG",
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "standard",
|
||||
}
|
||||
},
|
||||
"loggers": {
|
||||
"voicemeeterlib.iremote": {"handlers": ["stream"], "level": "DEBUG"}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class Observer:
|
||||
class MyClient:
|
||||
def __init__(self, vm):
|
||||
self.vm = vm
|
||||
self.client = obs.EventClient()
|
||||
self.client.callback.register(self.on_current_program_scene_changed)
|
||||
self.client = obsws.EventClient()
|
||||
self.client.callback.register(
|
||||
(
|
||||
self.on_current_program_scene_changed,
|
||||
self.on_exit_started,
|
||||
)
|
||||
)
|
||||
self.is_running = True
|
||||
|
||||
def on_start(self):
|
||||
self.vm.strip[0].mute = True
|
||||
@ -24,8 +51,8 @@ class Observer:
|
||||
def on_end(self):
|
||||
self.vm.apply(
|
||||
{
|
||||
"strip-0": {"mute": True},
|
||||
"strip-1": {"mute": True, "B1": False},
|
||||
"strip-0": {"mute": True, "comp": {"ratio": 4.3}},
|
||||
"strip-1": {"mute": True, "B1": False, "gate": {"attack": 2.3}},
|
||||
"strip-2": {"mute": True, "B1": False},
|
||||
"vban-in-0": {"on": False},
|
||||
}
|
||||
@ -52,14 +79,18 @@ class Observer:
|
||||
if fn := fget(scene):
|
||||
fn()
|
||||
|
||||
def on_exit_started(self, _):
|
||||
self.client.unsubscribe()
|
||||
self.is_running = False
|
||||
|
||||
|
||||
def main():
|
||||
subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]}
|
||||
with voicemeeterlib.api("potato", subs=subs) as vm:
|
||||
obs = Observer(vm)
|
||||
while cmd := input("<Enter> to exit\n"):
|
||||
if not cmd:
|
||||
break
|
||||
KIND_ID = "potato"
|
||||
|
||||
with voicemeeterlib.api(KIND_ID) as vm:
|
||||
client = MyClient(vm)
|
||||
while client.is_running:
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -3,5 +3,5 @@ from setuptools import setup
|
||||
setup(
|
||||
name="obs",
|
||||
description="OBS Example",
|
||||
install_requires=["voicemeeter-api", "obsws-python"],
|
||||
install_requires=["obsws-python"],
|
||||
)
|
||||
|
@ -5,38 +5,40 @@ import voicemeeterlib
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
class Observer:
|
||||
class App:
|
||||
def __init__(self, vm):
|
||||
self.vm = vm
|
||||
# register your app as event observer
|
||||
self.vm.subject.add(self)
|
||||
# enable level updates, since they are disabled by default.
|
||||
self.vm.event.ldirty = True
|
||||
self.vm.observer.add(self)
|
||||
|
||||
def __str__(self):
|
||||
return type(self).__name__
|
||||
|
||||
# define an 'on_update' callback function to receive event updates
|
||||
def on_update(self, subject):
|
||||
if subject == "pdirty":
|
||||
def on_update(self, event):
|
||||
if event == "pdirty":
|
||||
print("pdirty!")
|
||||
elif subject == "mdirty":
|
||||
elif event == "mdirty":
|
||||
print("mdirty!")
|
||||
elif subject == "ldirty":
|
||||
elif event == "ldirty":
|
||||
for bus in self.vm.bus:
|
||||
if bus.levels.isdirty:
|
||||
print(bus, bus.levels.all)
|
||||
elif subject == "midi":
|
||||
elif event == "midi":
|
||||
current = self.vm.midi.current
|
||||
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
||||
|
||||
|
||||
def main():
|
||||
kind_id = "banana"
|
||||
KIND_ID = "banana"
|
||||
|
||||
with voicemeeterlib.api(kind_id) as vm:
|
||||
Observer(vm)
|
||||
with voicemeeterlib.api(
|
||||
KIND_ID, **{k: True for k in ("pdirty", "mdirty", "ldirty", "midi")}
|
||||
) as vm:
|
||||
App(vm)
|
||||
|
||||
while cmd := input("Press <Enter> to exit\n"):
|
||||
if not cmd:
|
||||
break
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
200
poetry.lock
generated
200
poetry.lock
generated
@ -1,24 +1,10 @@
|
||||
[[package]]
|
||||
name = "attrs"
|
||||
version = "22.1.0"
|
||||
description = "Classes Without Boilerplate"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.5"
|
||||
|
||||
[package.extras]
|
||||
dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"]
|
||||
docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"]
|
||||
tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "cloudpickle"]
|
||||
tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "cloudpickle"]
|
||||
|
||||
[[package]]
|
||||
name = "black"
|
||||
version = "22.8.0"
|
||||
version = "22.12.0"
|
||||
description = "The uncompromising code formatter."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.6.2"
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.dependencies]
|
||||
click = ">=8.0.0"
|
||||
@ -33,6 +19,22 @@ d = ["aiohttp (>=3.7.4)"]
|
||||
jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
|
||||
uvloop = ["uvloop (>=0.15.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "cachetools"
|
||||
version = "5.3.1"
|
||||
description = "Extensible memoizing collections and decorators"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "chardet"
|
||||
version = "5.1.0"
|
||||
description = "Universal encoding detector for Python 3"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "8.1.3"
|
||||
@ -46,56 +48,84 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.5"
|
||||
version = "0.4.6"
|
||||
description = "Cross-platform colored terminal text."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||
|
||||
[[package]]
|
||||
name = "iniconfig"
|
||||
version = "1.1.1"
|
||||
description = "iniconfig: brain-dead simple config-ini parsing"
|
||||
name = "distlib"
|
||||
version = "0.3.6"
|
||||
description = "Distribution utilities"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[[package]]
|
||||
name = "exceptiongroup"
|
||||
version = "1.1.1"
|
||||
description = "Backport of PEP 654 (exception groups)"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.extras]
|
||||
test = ["pytest (>=6)"]
|
||||
|
||||
[[package]]
|
||||
name = "filelock"
|
||||
version = "3.12.2"
|
||||
description = "A platform independent file lock."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo (>=2023.5.20)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)", "sphinx (>=7.0.1)"]
|
||||
testing = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "diff-cover (>=7.5)", "pytest-cov (>=4.1)", "pytest-mock (>=3.10)", "pytest-timeout (>=2.1)", "pytest (>=7.3.1)"]
|
||||
|
||||
[[package]]
|
||||
name = "iniconfig"
|
||||
version = "2.0.0"
|
||||
description = "brain-dead simple config-ini parsing"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "isort"
|
||||
version = "5.10.1"
|
||||
version = "5.12.0"
|
||||
description = "A Python utility / library to sort Python imports."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.6.1,<4.0"
|
||||
python-versions = ">=3.8.0"
|
||||
|
||||
[package.extras]
|
||||
pipfile_deprecated_finder = ["pipreqs", "requirementslib"]
|
||||
requirements_deprecated_finder = ["pipreqs", "pip-api"]
|
||||
colors = ["colorama (>=0.4.3,<0.5.0)"]
|
||||
colors = ["colorama (>=0.4.3)"]
|
||||
requirements-deprecated-finder = ["pip-api", "pipreqs"]
|
||||
pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"]
|
||||
plugins = ["setuptools"]
|
||||
|
||||
[[package]]
|
||||
name = "mypy-extensions"
|
||||
version = "0.4.3"
|
||||
description = "Experimental type system extensions for programs checked with the mypy typechecker."
|
||||
version = "1.0.0"
|
||||
description = "Type system extensions for programs checked with the mypy type checker."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
python-versions = ">=3.5"
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "21.3"
|
||||
version = "23.1"
|
||||
description = "Core utilities for Python packages"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
[package.dependencies]
|
||||
pyparsing = ">=2.0.2,<3.0.5 || >3.0.5"
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "pathspec"
|
||||
version = "0.10.1"
|
||||
version = "0.11.1"
|
||||
description = "Utility library for gitignore style pattern matching of file paths."
|
||||
category = "dev"
|
||||
optional = false
|
||||
@ -103,66 +133,62 @@ python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "platformdirs"
|
||||
version = "2.5.2"
|
||||
description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
|
||||
version = "3.6.0"
|
||||
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)", "sphinx (>=4)"]
|
||||
test = ["appdirs (==1.4.4)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)", "pytest (>=6)"]
|
||||
docs = ["furo (>=2023.5.20)", "proselint (>=0.13)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)", "sphinx (>=7.0.1)"]
|
||||
test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.10)", "pytest (>=7.3.1)"]
|
||||
|
||||
[[package]]
|
||||
name = "pluggy"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
description = "plugin and hook calling mechanisms for python"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.extras]
|
||||
testing = ["pytest-benchmark", "pytest"]
|
||||
dev = ["tox", "pre-commit"]
|
||||
dev = ["pre-commit", "tox"]
|
||||
testing = ["pytest", "pytest-benchmark"]
|
||||
|
||||
[[package]]
|
||||
name = "py"
|
||||
version = "1.11.0"
|
||||
description = "library with cross-python path, ini-parsing, io, code, log facilities"
|
||||
name = "pyproject-api"
|
||||
version = "1.5.2"
|
||||
description = "API to interact with the python pyproject.toml based projects"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "pyparsing"
|
||||
version = "3.0.9"
|
||||
description = "pyparsing module - Classes and methods to define and execute parsing grammars"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.6.8"
|
||||
[package.dependencies]
|
||||
packaging = ">=23.1"
|
||||
tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""}
|
||||
|
||||
[package.extras]
|
||||
diagrams = ["railroad-diagrams", "jinja2"]
|
||||
docs = ["furo (>=2023.5.20)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)", "sphinx (>=7.0.1)"]
|
||||
testing = ["covdefaults (>=2.3)", "importlib-metadata (>=6.6)", "pytest-cov (>=4.1)", "pytest-mock (>=3.10)", "pytest (>=7.3.1)", "setuptools (>=67.8)", "wheel (>=0.40)"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest"
|
||||
version = "7.1.3"
|
||||
version = "7.3.2"
|
||||
description = "pytest: simple powerful testing with Python"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.dependencies]
|
||||
attrs = ">=19.2.0"
|
||||
colorama = {version = "*", markers = "sys_platform == \"win32\""}
|
||||
exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""}
|
||||
iniconfig = "*"
|
||||
packaging = "*"
|
||||
pluggy = ">=0.12,<2.0"
|
||||
py = ">=1.8.2"
|
||||
tomli = ">=1.0.0"
|
||||
tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""}
|
||||
|
||||
[package.extras]
|
||||
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"]
|
||||
testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-randomly"
|
||||
@ -194,16 +220,61 @@ category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "tox"
|
||||
version = "4.6.3"
|
||||
description = "tox is a generic virtualenv management and test command line tool"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.dependencies]
|
||||
cachetools = ">=5.3.1"
|
||||
chardet = ">=5.1"
|
||||
colorama = ">=0.4.6"
|
||||
filelock = ">=3.12.2"
|
||||
packaging = ">=23.1"
|
||||
platformdirs = ">=3.5.3"
|
||||
pluggy = ">=1"
|
||||
pyproject-api = ">=1.5.2"
|
||||
tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""}
|
||||
virtualenv = ">=20.23.1"
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo (>=2023.5.20)", "sphinx-argparse-cli (>=1.11.1)", "sphinx-autodoc-typehints (>=1.23.2,!=1.23.4)", "sphinx-copybutton (>=0.5.2)", "sphinx-inline-tabs (>=2023.4.21)", "sphinx (>=7.0.1)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"]
|
||||
testing = ["build[virtualenv] (>=0.10)", "covdefaults (>=2.3)", "detect-test-pollution (>=1.1.1)", "devpi-process (>=0.3.1)", "diff-cover (>=7.6)", "distlib (>=0.3.6)", "flaky (>=3.7)", "hatch-vcs (>=0.3)", "hatchling (>=1.17.1)", "psutil (>=5.9.5)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "pytest-xdist (>=3.3.1)", "pytest (>=7.3.2)", "re-assert (>=1.1)", "time-machine (>=2.10)", "wheel (>=0.40)"]
|
||||
|
||||
[[package]]
|
||||
name = "virtualenv"
|
||||
version = "20.23.1"
|
||||
description = "Virtual Python Environment builder"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.dependencies]
|
||||
distlib = ">=0.3.6,<1"
|
||||
filelock = ">=3.12,<4"
|
||||
platformdirs = ">=3.5.1,<4"
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo (>=2023.5.20)", "proselint (>=0.13)", "sphinx-argparse (>=0.4)", "sphinx (>=7.0.1)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"]
|
||||
test = ["covdefaults (>=2.3)", "coverage-enable-subprocess (>=1)", "coverage (>=7.2.7)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest-env (>=0.8.1)", "pytest-freezer (>=0.4.6)", "pytest-mock (>=3.10)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "pytest (>=7.3.1)", "setuptools (>=67.8)", "time-machine (>=2.9)"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "9f887ae517ade09119bf1f2cf77261d2445ae95857b69470ce1707f9791ce080"
|
||||
content-hash = "5d0edd070ea010edb4e2ade88dc37324b8b4b04f22db78e49db161185365849b"
|
||||
|
||||
[metadata.files]
|
||||
attrs = []
|
||||
black = []
|
||||
cachetools = []
|
||||
chardet = []
|
||||
click = []
|
||||
colorama = []
|
||||
distlib = []
|
||||
exceptiongroup = []
|
||||
filelock = []
|
||||
iniconfig = []
|
||||
isort = []
|
||||
mypy-extensions = []
|
||||
@ -211,9 +282,10 @@ packaging = []
|
||||
pathspec = []
|
||||
platformdirs = []
|
||||
pluggy = []
|
||||
py = []
|
||||
pyparsing = []
|
||||
pyproject-api = []
|
||||
pytest = []
|
||||
pytest-randomly = []
|
||||
pytest-repeat = []
|
||||
tomli = []
|
||||
tox = []
|
||||
virtualenv = []
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "voicemeeter-api"
|
||||
version = "1.0.0"
|
||||
version = "2.0.0"
|
||||
description = "A Python wrapper for the Voiceemeter API"
|
||||
authors = ["onyx-and-iris <code@onyxandiris.online>"]
|
||||
license = "MIT"
|
||||
@ -21,6 +21,7 @@ pytest-randomly = "^3.12.0"
|
||||
pytest-repeat = "^0.9.1"
|
||||
black = "^22.3.0"
|
||||
isort = "^5.10.1"
|
||||
tox = "^4.6.3"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
@ -28,7 +29,22 @@ build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
dsl = "scripts:ex_dsl"
|
||||
events = "scripts:ex_events"
|
||||
gui = "scripts:ex_gui"
|
||||
levels = "scripts:ex_levels"
|
||||
midi = "scripts:ex_midi"
|
||||
obs = "scripts:ex_obs"
|
||||
observer = "scripts:ex_observer"
|
||||
test ="scripts:test"
|
||||
test = "scripts:test"
|
||||
|
||||
[tool.tox]
|
||||
legacy_tox_ini = """
|
||||
[tox]
|
||||
envlist = py310,py311
|
||||
|
||||
[testenv]
|
||||
allowlist_externals = poetry
|
||||
commands =
|
||||
poetry install -v
|
||||
poetry run pytest tests/
|
||||
"""
|
||||
|
17
scripts.py
17
scripts.py
@ -7,6 +7,21 @@ def ex_dsl():
|
||||
subprocess.run(["py", str(path)])
|
||||
|
||||
|
||||
def ex_events():
|
||||
path = Path.cwd() / "examples" / "events" / "."
|
||||
subprocess.run(["py", str(path)])
|
||||
|
||||
|
||||
def ex_gui():
|
||||
path = Path.cwd() / "examples" / "gui" / "."
|
||||
subprocess.run(["py", str(path)])
|
||||
|
||||
|
||||
def ex_levels():
|
||||
path = Path.cwd() / "examples" / "levels" / "."
|
||||
subprocess.run(["py", str(path)])
|
||||
|
||||
|
||||
def ex_midi():
|
||||
path = Path.cwd() / "examples" / "midi" / "."
|
||||
subprocess.run(["py", str(path)])
|
||||
@ -23,4 +38,4 @@ def ex_observer():
|
||||
|
||||
|
||||
def test():
|
||||
subprocess.run(["pytest", "-v"])
|
||||
subprocess.run(["tox"])
|
||||
|
@ -3,15 +3,13 @@ import sys
|
||||
from dataclasses import dataclass
|
||||
|
||||
import voicemeeterlib
|
||||
from voicemeeterlib.kinds import KindId, kinds_all
|
||||
from voicemeeterlib.kinds import KindId
|
||||
from voicemeeterlib.kinds import request_kind_map as kindmap
|
||||
|
||||
# let's keep things random
|
||||
kind_id = random.choice(tuple(kind_id.name.lower() for kind_id in KindId))
|
||||
|
||||
vmrs = {kind.name: voicemeeterlib.api(kind.name) for kind in kinds_all}
|
||||
tests = vmrs[kind_id]
|
||||
kind = kindmap(kind_id)
|
||||
KIND_ID = random.choice(tuple(kind_id.name.lower() for kind_id in KindId))
|
||||
vm = voicemeeterlib.api(KIND_ID)
|
||||
kind = kindmap(KIND_ID)
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -42,9 +40,9 @@ data = Data()
|
||||
|
||||
def setup_module():
|
||||
print(f"\nRunning tests for kind [{data.name}]\n", file=sys.stdout)
|
||||
tests.login()
|
||||
tests.command.reset()
|
||||
vm.login()
|
||||
vm.command.reset()
|
||||
|
||||
|
||||
def teardown_module():
|
||||
tests.logout()
|
||||
vm.logout()
|
||||
|
@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="68" height="20" role="img" aria-label="tests: 140"><title>tests: 140</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="68" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="37" height="20" fill="#555"/><rect x="37" width="31" height="20" fill="#4c1"/><rect width="68" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="195" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">tests</text><text x="195" y="140" transform="scale(.1)" fill="#fff" textLength="270">tests</text><text aria-hidden="true" x="515" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">140</text><text x="515" y="140" transform="scale(.1)" fill="#fff" textLength="210">140</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="68" height="20" role="img" aria-label="tests: 139"><title>tests: 139</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="68" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="37" height="20" fill="#555"/><rect x="37" width="31" height="20" fill="#4c1"/><rect width="68" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="195" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">tests</text><text x="195" y="140" transform="scale(.1)" fill="#fff" textLength="270">tests</text><text aria-hidden="true" x="515" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">139</text><text x="515" y="140" transform="scale(.1)" fill="#fff" textLength="210">139</text></g></svg>
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="68" height="20" role="img" aria-label="tests: 116"><title>tests: 116</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="68" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="37" height="20" fill="#555"/><rect x="37" width="31" height="20" fill="#4c1"/><rect width="68" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="195" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">tests</text><text x="195" y="140" transform="scale(.1)" fill="#fff" textLength="270">tests</text><text aria-hidden="true" x="515" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">116</text><text x="515" y="140" transform="scale(.1)" fill="#fff" textLength="210">116</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="68" height="20" role="img" aria-label="tests: 112"><title>tests: 112</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="68" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="37" height="20" fill="#555"/><rect x="37" width="31" height="20" fill="#4c1"/><rect width="68" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="195" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">tests</text><text x="195" y="140" transform="scale(.1)" fill="#fff" textLength="270">tests</text><text aria-hidden="true" x="515" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">112</text><text x="515" y="140" transform="scale(.1)" fill="#fff" textLength="210">112</text></g></svg>
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="68" height="20" role="img" aria-label="tests: 158"><title>tests: 158</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="68" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="37" height="20" fill="#555"/><rect x="37" width="31" height="20" fill="#4c1"/><rect width="68" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="195" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">tests</text><text x="195" y="140" transform="scale(.1)" fill="#fff" textLength="270">tests</text><text aria-hidden="true" x="515" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">158</text><text x="515" y="140" transform="scale(.1)" fill="#fff" textLength="210">158</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="68" height="20" role="img" aria-label="tests: 164"><title>tests: 164</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="68" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="37" height="20" fill="#555"/><rect x="37" width="31" height="20" fill="#4c1"/><rect width="68" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="195" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="270">tests</text><text x="195" y="140" transform="scale(.1)" fill="#fff" textLength="270">tests</text><text aria-hidden="true" x="515" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">164</text><text x="515" y="140" transform="scale(.1)" fill="#fff" textLength="210">164</text></g></svg>
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@ -1,36 +1,48 @@
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from tests import data, tests
|
||||
from tests import data, vm
|
||||
|
||||
|
||||
class TestUserConfigs:
|
||||
__test__ = True
|
||||
|
||||
"""example config tests"""
|
||||
"""example config vm"""
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
tests.apply_config("example")
|
||||
vm.apply_config("example")
|
||||
|
||||
def test_it_tests_config_string(self):
|
||||
assert "PhysStrip" in tests.strip[data.phys_in].label
|
||||
assert "VirtStrip" in tests.strip[data.virt_in].label
|
||||
assert "PhysBus" in tests.bus[data.phys_out].label
|
||||
assert "VirtBus" in tests.bus[data.virt_out].label
|
||||
def test_it_vm_config_string(self):
|
||||
assert "PhysStrip" in vm.strip[data.phys_in].label
|
||||
assert "VirtStrip" in vm.strip[data.virt_in].label
|
||||
assert "PhysBus" in vm.bus[data.phys_out].label
|
||||
assert "VirtBus" in vm.bus[data.virt_out].label
|
||||
|
||||
def test_it_tests_config_bool(self):
|
||||
assert tests.strip[0].A1 == True
|
||||
def test_it_vm_config_bool(self):
|
||||
assert vm.strip[0].A1 == True
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
reason="Skip test if kind is not potato",
|
||||
)
|
||||
def test_it_vm_config_bool_strip_eq_on(self):
|
||||
assert vm.strip[data.phys_in].eq.on == True
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "banana",
|
||||
reason="Skip test if kind is not banana",
|
||||
)
|
||||
def test_it_vm_config_bool_bus_eq_ab(self):
|
||||
assert vm.bus[data.phys_out].eq.ab == True
|
||||
|
||||
@pytest.mark.skipif(
|
||||
"not config.getoption('--run-slow')",
|
||||
reason="Only run when --run-slow is given",
|
||||
)
|
||||
def test_it_tests_config_busmode(self):
|
||||
assert tests.bus[data.phys_out].mode.get() == "composite"
|
||||
def test_it_vm_config_busmode(self):
|
||||
assert vm.bus[data.phys_out].mode.get() == "composite"
|
||||
|
||||
def test_it_tests_config_bass_med_high(self):
|
||||
assert tests.strip[data.virt_in].bass == -3.2
|
||||
assert tests.strip[data.virt_in].mid == 1.5
|
||||
assert tests.strip[data.virt_in].high == 2.1
|
||||
def test_it_vm_config_bass_med_high(self):
|
||||
assert vm.strip[data.virt_in].bass == -3.2
|
||||
assert vm.strip[data.virt_in].mid == 1.5
|
||||
assert vm.strip[data.virt_in].high == 2.1
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from tests import data, tests
|
||||
from tests import data, vm
|
||||
|
||||
|
||||
class TestRemoteFactories:
|
||||
@ -10,57 +10,57 @@ class TestRemoteFactories:
|
||||
data.name != "basic",
|
||||
reason="Skip test if kind is not basic",
|
||||
)
|
||||
def test_it_tests_remote_attrs_for_basic(self):
|
||||
assert hasattr(tests, "strip")
|
||||
assert hasattr(tests, "bus")
|
||||
assert hasattr(tests, "command")
|
||||
assert hasattr(tests, "button")
|
||||
assert hasattr(tests, "vban")
|
||||
assert hasattr(tests, "device")
|
||||
assert hasattr(tests, "option")
|
||||
def test_it_vm_remote_attrs_for_basic(self):
|
||||
assert hasattr(vm, "strip")
|
||||
assert hasattr(vm, "bus")
|
||||
assert hasattr(vm, "command")
|
||||
assert hasattr(vm, "button")
|
||||
assert hasattr(vm, "vban")
|
||||
assert hasattr(vm, "device")
|
||||
assert hasattr(vm, "option")
|
||||
|
||||
assert len(tests.strip) == 3
|
||||
assert len(tests.bus) == 2
|
||||
assert len(tests.button) == 80
|
||||
assert len(tests.vban.instream) == 4 and len(tests.vban.outstream) == 4
|
||||
assert len(vm.strip) == 3
|
||||
assert len(vm.bus) == 2
|
||||
assert len(vm.button) == 80
|
||||
assert len(vm.vban.instream) == 4 and len(vm.vban.outstream) == 4
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "banana",
|
||||
reason="Skip test if kind is not banana",
|
||||
)
|
||||
def test_it_tests_remote_attrs_for_banana(self):
|
||||
assert hasattr(tests, "strip")
|
||||
assert hasattr(tests, "bus")
|
||||
assert hasattr(tests, "command")
|
||||
assert hasattr(tests, "button")
|
||||
assert hasattr(tests, "vban")
|
||||
assert hasattr(tests, "device")
|
||||
assert hasattr(tests, "option")
|
||||
assert hasattr(tests, "recorder")
|
||||
assert hasattr(tests, "patch")
|
||||
def test_it_vm_remote_attrs_for_banana(self):
|
||||
assert hasattr(vm, "strip")
|
||||
assert hasattr(vm, "bus")
|
||||
assert hasattr(vm, "command")
|
||||
assert hasattr(vm, "button")
|
||||
assert hasattr(vm, "vban")
|
||||
assert hasattr(vm, "device")
|
||||
assert hasattr(vm, "option")
|
||||
assert hasattr(vm, "recorder")
|
||||
assert hasattr(vm, "patch")
|
||||
|
||||
assert len(tests.strip) == 5
|
||||
assert len(tests.bus) == 5
|
||||
assert len(tests.button) == 80
|
||||
assert len(tests.vban.instream) == 8 and len(tests.vban.outstream) == 8
|
||||
assert len(vm.strip) == 5
|
||||
assert len(vm.bus) == 5
|
||||
assert len(vm.button) == 80
|
||||
assert len(vm.vban.instream) == 8 and len(vm.vban.outstream) == 8
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
reason="Skip test if kind is not potato",
|
||||
)
|
||||
def test_it_tests_remote_attrs_for_potato(self):
|
||||
assert hasattr(tests, "strip")
|
||||
assert hasattr(tests, "bus")
|
||||
assert hasattr(tests, "command")
|
||||
assert hasattr(tests, "button")
|
||||
assert hasattr(tests, "vban")
|
||||
assert hasattr(tests, "device")
|
||||
assert hasattr(tests, "option")
|
||||
assert hasattr(tests, "recorder")
|
||||
assert hasattr(tests, "patch")
|
||||
assert hasattr(tests, "fx")
|
||||
def test_it_vm_remote_attrs_for_potato(self):
|
||||
assert hasattr(vm, "strip")
|
||||
assert hasattr(vm, "bus")
|
||||
assert hasattr(vm, "command")
|
||||
assert hasattr(vm, "button")
|
||||
assert hasattr(vm, "vban")
|
||||
assert hasattr(vm, "device")
|
||||
assert hasattr(vm, "option")
|
||||
assert hasattr(vm, "recorder")
|
||||
assert hasattr(vm, "patch")
|
||||
assert hasattr(vm, "fx")
|
||||
|
||||
assert len(tests.strip) == 8
|
||||
assert len(tests.bus) == 8
|
||||
assert len(tests.button) == 80
|
||||
assert len(tests.vban.instream) == 8 and len(tests.vban.outstream) == 8
|
||||
assert len(vm.strip) == 8
|
||||
assert len(vm.bus) == 8
|
||||
assert len(vm.button) == 80
|
||||
assert len(vm.vban.instream) == 8 and len(vm.vban.outstream) == 8
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from tests import data, tests
|
||||
from tests import data, vm
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [False, True])
|
||||
@ -19,23 +19,54 @@ class TestSetAndGetBoolHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_bool_params(self, index, param, value):
|
||||
setattr(tests.strip[index], param, value)
|
||||
assert getattr(tests.strip[index], param) == value
|
||||
setattr(vm.strip[index], param, value)
|
||||
assert getattr(vm.strip[index], param) == value
|
||||
|
||||
""" strip EQ tests, physical """
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
reason="Skip test if kind is not potato",
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"index,param",
|
||||
[
|
||||
(data.phys_in, "on"),
|
||||
(data.phys_in, "ab"),
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_eq_bool_params(self, index, param, value):
|
||||
assert hasattr(vm.strip[index].eq, param)
|
||||
setattr(vm.strip[index].eq, param, value)
|
||||
assert getattr(vm.strip[index].eq, param) == value
|
||||
|
||||
""" bus tests, physical and virtual """
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index,param",
|
||||
[
|
||||
(data.phys_out, "eq"),
|
||||
(data.phys_out, "mute"),
|
||||
(data.virt_out, "eq_ab"),
|
||||
(data.virt_out, "sel"),
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_bus_bool_params(self, index, param, value):
|
||||
setattr(tests.bus[index], param, value)
|
||||
assert getattr(tests.bus[index], param) == value
|
||||
assert hasattr(vm.bus[index], param)
|
||||
setattr(vm.bus[index], param, value)
|
||||
assert getattr(vm.bus[index], param) == value
|
||||
|
||||
""" bus EQ tests, physical and virtual """
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index,param",
|
||||
[
|
||||
(data.phys_out, "on"),
|
||||
(data.virt_out, "ab"),
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_bus_eq_bool_params(self, index, param, value):
|
||||
assert hasattr(vm.bus[index].eq, param)
|
||||
setattr(vm.bus[index].eq, param, value)
|
||||
assert getattr(vm.bus[index].eq, param) == value
|
||||
|
||||
""" bus modes tests, physical and virtual """
|
||||
|
||||
@ -53,8 +84,8 @@ class TestSetAndGetBoolHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_busmode_basic_bool_params(self, index, param, value):
|
||||
setattr(tests.bus[index].mode, param, value)
|
||||
assert getattr(tests.bus[index].mode, param) == value
|
||||
setattr(vm.bus[index].mode, param, value)
|
||||
assert getattr(vm.bus[index].mode, param) == value
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name == "basic",
|
||||
@ -72,8 +103,8 @@ class TestSetAndGetBoolHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_busmode_bool_params(self, index, param, value):
|
||||
setattr(tests.bus[index].mode, param, value)
|
||||
assert getattr(tests.bus[index].mode, param) == value
|
||||
setattr(vm.bus[index].mode, param, value)
|
||||
assert getattr(vm.bus[index].mode, param) == value
|
||||
|
||||
""" macrobutton tests """
|
||||
|
||||
@ -82,8 +113,8 @@ class TestSetAndGetBoolHigher:
|
||||
[(data.button_lower, "state"), (data.button_upper, "trigger")],
|
||||
)
|
||||
def test_it_sets_and_gets_macrobutton_bool_params(self, index, param, value):
|
||||
setattr(tests.button[index], param, value)
|
||||
assert getattr(tests.button[index], param) == value
|
||||
setattr(vm.button[index], param, value)
|
||||
assert getattr(vm.button[index], param) == value
|
||||
|
||||
""" vban instream tests """
|
||||
|
||||
@ -92,8 +123,8 @@ class TestSetAndGetBoolHigher:
|
||||
[(data.vban_in, "on")],
|
||||
)
|
||||
def test_it_sets_and_gets_vban_instream_bool_params(self, index, param, value):
|
||||
setattr(tests.vban.instream[index], param, value)
|
||||
assert getattr(tests.vban.instream[index], param) == value
|
||||
setattr(vm.vban.instream[index], param, value)
|
||||
assert getattr(vm.vban.instream[index], param) == value
|
||||
|
||||
""" vban outstream tests """
|
||||
|
||||
@ -102,8 +133,8 @@ class TestSetAndGetBoolHigher:
|
||||
[(data.vban_out, "on")],
|
||||
)
|
||||
def test_it_sets_and_gets_vban_outstream_bool_params(self, index, param, value):
|
||||
setattr(tests.vban.outstream[index], param, value)
|
||||
assert getattr(tests.vban.outstream[index], param) == value
|
||||
setattr(vm.vban.outstream[index], param, value)
|
||||
assert getattr(vm.vban.outstream[index], param) == value
|
||||
|
||||
""" command tests """
|
||||
|
||||
@ -112,7 +143,7 @@ class TestSetAndGetBoolHigher:
|
||||
[("lock")],
|
||||
)
|
||||
def test_it_sets_command_bool_params(self, param, value):
|
||||
setattr(tests.command, param, value)
|
||||
setattr(vm.command, param, value)
|
||||
|
||||
""" recorder tests """
|
||||
|
||||
@ -125,8 +156,8 @@ class TestSetAndGetBoolHigher:
|
||||
[("A1"), ("B2")],
|
||||
)
|
||||
def test_it_sets_and_gets_recorder_bool_params(self, param, value):
|
||||
setattr(tests.recorder, param, value)
|
||||
assert getattr(tests.recorder, param) == value
|
||||
setattr(vm.recorder, param, value)
|
||||
assert getattr(vm.recorder, param) == value
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name == "basic",
|
||||
@ -137,7 +168,7 @@ class TestSetAndGetBoolHigher:
|
||||
[("loop")],
|
||||
)
|
||||
def test_it_sets_recorder_bool_params(self, param, value):
|
||||
setattr(tests.recorder, param, value)
|
||||
setattr(vm.recorder, param, value)
|
||||
|
||||
""" fx tests """
|
||||
|
||||
@ -150,8 +181,8 @@ class TestSetAndGetBoolHigher:
|
||||
[("reverb"), ("reverb_ab"), ("delay"), ("delay_ab")],
|
||||
)
|
||||
def test_it_sets_and_gets_fx_bool_params(self, param, value):
|
||||
setattr(tests.fx, param, value)
|
||||
assert getattr(tests.fx, param) == value
|
||||
setattr(vm.fx, param, value)
|
||||
assert getattr(vm.fx, param) == value
|
||||
|
||||
""" patch tests """
|
||||
|
||||
@ -164,8 +195,8 @@ class TestSetAndGetBoolHigher:
|
||||
[("postfadercomposite")],
|
||||
)
|
||||
def test_it_sets_and_gets_patch_bool_params(self, param, value):
|
||||
setattr(tests.patch, param, value)
|
||||
assert getattr(tests.patch, param) == value
|
||||
setattr(vm.patch, param, value)
|
||||
assert getattr(vm.patch, param) == value
|
||||
|
||||
""" patch.insert tests """
|
||||
|
||||
@ -178,8 +209,8 @@ class TestSetAndGetBoolHigher:
|
||||
[(data.insert_lower, "on"), (data.insert_higher, "on")],
|
||||
)
|
||||
def test_it_sets_and_gets_patch_insert_bool_params(self, index, param, value):
|
||||
setattr(tests.patch.insert[index], param, value)
|
||||
assert getattr(tests.patch.insert[index], param) == value
|
||||
setattr(vm.patch.insert[index], param, value)
|
||||
assert getattr(vm.patch.insert[index], param) == value
|
||||
|
||||
""" option tests """
|
||||
|
||||
@ -188,8 +219,8 @@ class TestSetAndGetBoolHigher:
|
||||
[("monitoronsel")],
|
||||
)
|
||||
def test_it_sets_and_gets_option_bool_params(self, param, value):
|
||||
setattr(tests.option, param, value)
|
||||
assert getattr(tests.option, param) == value
|
||||
setattr(vm.option, param, value)
|
||||
assert getattr(vm.option, param) == value
|
||||
|
||||
|
||||
class TestSetAndGetIntHigher:
|
||||
@ -207,8 +238,8 @@ class TestSetAndGetIntHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_bool_params(self, index, param, value):
|
||||
setattr(tests.strip[index], param, value)
|
||||
assert getattr(tests.strip[index], param) == value
|
||||
setattr(vm.strip[index], param, value)
|
||||
assert getattr(vm.strip[index], param) == value
|
||||
|
||||
""" vban outstream tests """
|
||||
|
||||
@ -217,8 +248,8 @@ class TestSetAndGetIntHigher:
|
||||
[(data.vban_out, "sr", 48000)],
|
||||
)
|
||||
def test_it_sets_and_gets_vban_outstream_bool_params(self, index, param, value):
|
||||
setattr(tests.vban.outstream[index], param, value)
|
||||
assert getattr(tests.vban.outstream[index], param) == value
|
||||
setattr(vm.vban.outstream[index], param, value)
|
||||
assert getattr(vm.vban.outstream[index], param) == value
|
||||
|
||||
""" patch.asio tests """
|
||||
|
||||
@ -234,8 +265,8 @@ class TestSetAndGetIntHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_patch_asio_in_int_params(self, index, value):
|
||||
tests.patch.asio[index].set(value)
|
||||
assert tests.patch.asio[index].get() == value
|
||||
vm.patch.asio[index].set(value)
|
||||
assert vm.patch.asio[index].get() == value
|
||||
|
||||
""" patch.A2[i]-A5[i] tests """
|
||||
|
||||
@ -251,10 +282,10 @@ class TestSetAndGetIntHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_patch_asio_out_int_params(self, index, value):
|
||||
tests.patch.A2[index].set(value)
|
||||
assert tests.patch.A2[index].get() == value
|
||||
tests.patch.A5[index].set(value)
|
||||
assert tests.patch.A5[index].get() == value
|
||||
vm.patch.A2[index].set(value)
|
||||
assert vm.patch.A2[index].get() == value
|
||||
vm.patch.A5[index].set(value)
|
||||
assert vm.patch.A5[index].get() == value
|
||||
|
||||
""" patch.composite tests """
|
||||
|
||||
@ -272,8 +303,8 @@ class TestSetAndGetIntHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_patch_composite_int_params(self, index, value):
|
||||
tests.patch.composite[index].set(value)
|
||||
assert tests.patch.composite[index].get() == value
|
||||
vm.patch.composite[index].set(value)
|
||||
assert vm.patch.composite[index].get() == value
|
||||
|
||||
""" option tests """
|
||||
|
||||
@ -289,8 +320,8 @@ class TestSetAndGetIntHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_patch_delay_int_params(self, index, value):
|
||||
tests.option.delay[index].set(value)
|
||||
assert tests.option.delay[index].get() == value
|
||||
vm.option.delay[index].set(value)
|
||||
assert vm.option.delay[index].get() == value
|
||||
|
||||
|
||||
class TestSetAndGetFloatHigher:
|
||||
@ -303,29 +334,25 @@ class TestSetAndGetFloatHigher:
|
||||
[
|
||||
(data.phys_in, "gain", -3.6),
|
||||
(data.virt_in, "gain", 5.8),
|
||||
(data.phys_in, "comp", 0.0),
|
||||
(data.virt_in, "comp", 8.2),
|
||||
(data.phys_in, "gate", 2.3),
|
||||
(data.virt_in, "gate", 6.7),
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_float_params(self, index, param, value):
|
||||
setattr(tests.strip[index], param, value)
|
||||
assert getattr(tests.strip[index], param) == value
|
||||
setattr(vm.strip[index], param, value)
|
||||
assert getattr(vm.strip[index], param) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index,value",
|
||||
[(data.phys_in, 2), (data.phys_in, 2), (data.virt_in, 8), (data.virt_in, 8)],
|
||||
)
|
||||
def test_it_gets_prefader_levels_and_compares_length_of_array(self, index, value):
|
||||
assert len(tests.strip[index].levels.prefader) == value
|
||||
assert len(vm.strip[index].levels.prefader) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index,value",
|
||||
[(data.phys_in, 2), (data.phys_in, 2), (data.virt_in, 8), (data.virt_in, 8)],
|
||||
)
|
||||
def test_it_gets_postmute_levels_and_compares_length_of_array(self, index, value):
|
||||
assert len(tests.strip[index].levels.postmute) == value
|
||||
assert len(vm.strip[index].levels.postmute) == value
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
@ -341,8 +368,8 @@ class TestSetAndGetFloatHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_gainlayer_values(self, index, j, value):
|
||||
tests.strip[index].gainlayer[j].gain = value
|
||||
assert tests.strip[index].gainlayer[j].gain == value
|
||||
vm.strip[index].gainlayer[j].gain = value
|
||||
assert vm.strip[index].gainlayer[j].gain == value
|
||||
|
||||
""" strip tests, physical """
|
||||
|
||||
@ -356,9 +383,9 @@ class TestSetAndGetFloatHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_xy_params(self, index, param, value):
|
||||
assert hasattr(tests.strip[index], param)
|
||||
setattr(tests.strip[index], param, value)
|
||||
assert getattr(tests.strip[index], param) == value
|
||||
assert hasattr(vm.strip[index], param)
|
||||
setattr(vm.strip[index], param, value)
|
||||
assert getattr(vm.strip[index], param) == value
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
@ -372,9 +399,55 @@ class TestSetAndGetFloatHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_effects_params(self, index, param, value):
|
||||
assert hasattr(tests.strip[index], param)
|
||||
setattr(tests.strip[index], param, value)
|
||||
assert getattr(tests.strip[index], param) == value
|
||||
assert hasattr(vm.strip[index], param)
|
||||
setattr(vm.strip[index], param, value)
|
||||
assert getattr(vm.strip[index], param) == value
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
reason="Only test if logged into Potato version",
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"index, param, value",
|
||||
[
|
||||
(data.phys_in, "gainin", -8.6),
|
||||
(data.phys_in, "knee", 0.5),
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_comp_params(self, index, param, value):
|
||||
assert hasattr(vm.strip[index].comp, param)
|
||||
setattr(vm.strip[index].comp, param, value)
|
||||
assert getattr(vm.strip[index].comp, param) == value
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
reason="Only test if logged into Potato version",
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"index, param, value",
|
||||
[
|
||||
(data.phys_in, "bpsidechain", 120),
|
||||
(data.phys_in, "hold", 3000),
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_gate_params(self, index, param, value):
|
||||
assert hasattr(vm.strip[index].gate, param)
|
||||
setattr(vm.strip[index].gate, param, value)
|
||||
assert getattr(vm.strip[index].gate, param) == value
|
||||
|
||||
@pytest.mark.skipif(
|
||||
data.name != "potato",
|
||||
reason="Only test if logged into Potato version",
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"index, param, value",
|
||||
[
|
||||
(data.phys_in, "knob", -8.6),
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_denoiser_params(self, index, param, value):
|
||||
setattr(vm.strip[index].denoiser, param, value)
|
||||
assert getattr(vm.strip[index].denoiser, param) == value
|
||||
|
||||
""" strip tests, virtual """
|
||||
|
||||
@ -389,8 +462,8 @@ class TestSetAndGetFloatHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_eq_params(self, index, param, value):
|
||||
setattr(tests.strip[index], param, value)
|
||||
assert getattr(tests.strip[index], param) == value
|
||||
setattr(vm.strip[index], param, value)
|
||||
assert getattr(vm.strip[index], param) == value
|
||||
|
||||
""" bus tests, physical and virtual """
|
||||
|
||||
@ -403,24 +476,24 @@ class TestSetAndGetFloatHigher:
|
||||
[(data.phys_out, "returnreverb", 3.6), (data.virt_out, "returnfx1", 5.8)],
|
||||
)
|
||||
def test_it_sets_and_gets_bus_effects_float_params(self, index, param, value):
|
||||
assert hasattr(tests.bus[index], param)
|
||||
setattr(tests.bus[index], param, value)
|
||||
assert getattr(tests.bus[index], param) == value
|
||||
assert hasattr(vm.bus[index], param)
|
||||
setattr(vm.bus[index], param, value)
|
||||
assert getattr(vm.bus[index], param) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index, param, value",
|
||||
[(data.phys_out, "gain", -3.6), (data.virt_out, "gain", 5.8)],
|
||||
)
|
||||
def test_it_sets_and_gets_bus_float_params(self, index, param, value):
|
||||
setattr(tests.bus[index], param, value)
|
||||
assert getattr(tests.bus[index], param) == value
|
||||
setattr(vm.bus[index], param, value)
|
||||
assert getattr(vm.bus[index], param) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index,value",
|
||||
[(data.phys_out, 8), (data.virt_out, 8)],
|
||||
)
|
||||
def test_it_gets_prefader_levels_and_compares_length_of_array(self, index, value):
|
||||
assert len(tests.bus[index].levels.all) == value
|
||||
assert len(vm.bus[index].levels.all) == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["test0", "test1"])
|
||||
@ -434,8 +507,8 @@ class TestSetAndGetStringHigher:
|
||||
[(data.phys_in, "label"), (data.virt_in, "label")],
|
||||
)
|
||||
def test_it_sets_and_gets_strip_string_params(self, index, param, value):
|
||||
setattr(tests.strip[index], param, value)
|
||||
assert getattr(tests.strip[index], param) == value
|
||||
setattr(vm.strip[index], param, value)
|
||||
assert getattr(vm.strip[index], param) == value
|
||||
|
||||
""" bus tests, physical and virtual """
|
||||
|
||||
@ -444,8 +517,8 @@ class TestSetAndGetStringHigher:
|
||||
[(data.phys_out, "label"), (data.virt_out, "label")],
|
||||
)
|
||||
def test_it_sets_and_gets_bus_string_params(self, index, param, value):
|
||||
setattr(tests.bus[index], param, value)
|
||||
assert getattr(tests.bus[index], param) == value
|
||||
setattr(vm.bus[index], param, value)
|
||||
assert getattr(vm.bus[index], param) == value
|
||||
|
||||
""" vban instream tests """
|
||||
|
||||
@ -454,8 +527,8 @@ class TestSetAndGetStringHigher:
|
||||
[(data.vban_in, "name")],
|
||||
)
|
||||
def test_it_sets_and_gets_vban_instream_string_params(self, index, param, value):
|
||||
setattr(tests.vban.instream[index], param, value)
|
||||
assert getattr(tests.vban.instream[index], param) == value
|
||||
setattr(vm.vban.instream[index], param, value)
|
||||
assert getattr(vm.vban.instream[index], param) == value
|
||||
|
||||
""" vban outstream tests """
|
||||
|
||||
@ -464,8 +537,8 @@ class TestSetAndGetStringHigher:
|
||||
[(data.vban_out, "name")],
|
||||
)
|
||||
def test_it_sets_and_gets_vban_outstream_string_params(self, index, param, value):
|
||||
setattr(tests.vban.outstream[index], param, value)
|
||||
assert getattr(tests.vban.outstream[index], param) == value
|
||||
setattr(vm.vban.outstream[index], param, value)
|
||||
assert getattr(vm.vban.outstream[index], param) == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [False, True])
|
||||
@ -486,5 +559,5 @@ class TestSetAndGetMacroButtonHigher:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_macrobutton_params(self, index, param, value):
|
||||
setattr(tests.button[index], param, value)
|
||||
assert getattr(tests.button[index], param) == value
|
||||
setattr(vm.button[index], param, value)
|
||||
assert getattr(vm.button[index], param) == value
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from tests import data, tests
|
||||
from tests import data, vm
|
||||
|
||||
|
||||
class TestSetAndGetFloatLower:
|
||||
@ -18,8 +18,8 @@ class TestSetAndGetFloatLower:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_mute_eq_float_params(self, param, value):
|
||||
tests.set(param, value)
|
||||
assert (round(tests.get(param))) == value
|
||||
vm.set(param, value)
|
||||
assert (round(vm.get(param))) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"param,value",
|
||||
@ -30,8 +30,8 @@ class TestSetAndGetFloatLower:
|
||||
],
|
||||
)
|
||||
def test_it_sets_and_gets_comp_gain_float_params(self, param, value):
|
||||
tests.set(param, value)
|
||||
assert (round(tests.get(param), 1)) == value
|
||||
vm.set(param, value)
|
||||
assert (round(vm.get(param), 1)) == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["test0", "test1"])
|
||||
@ -45,12 +45,14 @@ class TestSetAndGetStringLower:
|
||||
[(f"Strip[{data.phys_out}].label"), (f"Bus[{data.virt_out}].label")],
|
||||
)
|
||||
def test_it_sets_and_gets_string_params(self, param, value):
|
||||
tests.set(param, value)
|
||||
assert tests.get(param, string=True) == value
|
||||
vm.set(param, value)
|
||||
assert vm.get(param, string=True) == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [0, 1])
|
||||
class TestMacroButtonsLower:
|
||||
__test__ = True
|
||||
|
||||
"""VBVMR_MacroButton_SetStatus, VBVMR_MacroButton_GetStatus"""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -58,21 +60,21 @@ class TestMacroButtonsLower:
|
||||
[(33, 1), (49, 1)],
|
||||
)
|
||||
def test_it_sets_and_gets_macrobuttons_state(self, index, mode, value):
|
||||
tests.set_buttonstatus(index, value, mode)
|
||||
assert tests.get_buttonstatus(index, mode) == value
|
||||
vm.set_buttonstatus(index, value, mode)
|
||||
assert vm.get_buttonstatus(index, mode) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index, mode",
|
||||
[(14, 2), (12, 2)],
|
||||
)
|
||||
def test_it_sets_and_gets_macrobuttons_stateonly(self, index, mode, value):
|
||||
tests.set_buttonstatus(index, value, mode)
|
||||
assert tests.get_buttonstatus(index, mode) == value
|
||||
vm.set_buttonstatus(index, value, mode)
|
||||
assert vm.get_buttonstatus(index, mode) == value
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index, mode",
|
||||
[(50, 3), (65, 3)],
|
||||
)
|
||||
def test_it_sets_and_gets_macrobuttons_trigger(self, index, mode, value):
|
||||
tests.set_buttonstatus(index, value, mode)
|
||||
assert tests.get_buttonstatus(index, mode) == value
|
||||
vm.set_buttonstatus(index, value, mode)
|
||||
assert vm.get_buttonstatus(index, mode) == value
|
||||
|
@ -46,22 +46,6 @@ class Bus(IRemote):
|
||||
def mono(self, val: bool):
|
||||
self.setter("mono", 1 if val else 0)
|
||||
|
||||
@property
|
||||
def eq(self) -> bool:
|
||||
return self.getter("eq.On") == 1
|
||||
|
||||
@eq.setter
|
||||
def eq(self, val: bool):
|
||||
self.setter("eq.On", 1 if val else 0)
|
||||
|
||||
@property
|
||||
def eq_ab(self) -> bool:
|
||||
return self.getter("eq.ab") == 1
|
||||
|
||||
@eq_ab.setter
|
||||
def eq_ab(self, val: bool):
|
||||
self.setter("eq.ab", 1 if val else 0)
|
||||
|
||||
@property
|
||||
def sel(self) -> bool:
|
||||
return self.getter("sel") == 1
|
||||
@ -103,6 +87,28 @@ class Bus(IRemote):
|
||||
time.sleep(self._remote.DELAY)
|
||||
|
||||
|
||||
class BusEQ(IRemote):
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return f"Bus[{self.index}].eq"
|
||||
|
||||
@property
|
||||
def on(self) -> bool:
|
||||
return self.getter("on") == 1
|
||||
|
||||
@on.setter
|
||||
def on(self, val: bool):
|
||||
self.setter("on", 1 if val else 0)
|
||||
|
||||
@property
|
||||
def ab(self) -> bool:
|
||||
return self.getter("ab") == 1
|
||||
|
||||
@ab.setter
|
||||
def ab(self, val: bool):
|
||||
self.setter("ab", 1 if val else 0)
|
||||
|
||||
|
||||
class PhysicalBus(Bus):
|
||||
@classmethod
|
||||
def make(cls, remote, i, kind):
|
||||
@ -309,6 +315,7 @@ def bus_factory(is_phys_bus, remote, i) -> Union[PhysicalBus, VirtualBus]:
|
||||
{
|
||||
"levels": BusLevel(remote, i),
|
||||
"mode": BUSMODEMIXIN_cls(remote, i),
|
||||
"eq": BusEQ(remote, i),
|
||||
},
|
||||
)(remote, i)
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
import ctypes as ct
|
||||
import logging
|
||||
from abc import ABCMeta
|
||||
from ctypes.wintypes import CHAR, FLOAT, LONG, WCHAR
|
||||
|
||||
from .error import CAPIError
|
||||
from .inst import libc
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CBindings(metaclass=ABCMeta):
|
||||
"""
|
||||
@ -13,6 +16,8 @@ class CBindings(metaclass=ABCMeta):
|
||||
Maps expected ctype argument and res types for each binding.
|
||||
"""
|
||||
|
||||
logger_cbindings = logger.getChild("Cbindings")
|
||||
|
||||
vm_login = libc.VBVMR_Login
|
||||
vm_login.restype = LONG
|
||||
vm_login.argtypes = None
|
||||
@ -33,17 +38,20 @@ class CBindings(metaclass=ABCMeta):
|
||||
vm_get_version.restype = LONG
|
||||
vm_get_version.argtypes = [ct.POINTER(LONG)]
|
||||
|
||||
vm_mdirty = libc.VBVMR_MacroButton_IsDirty
|
||||
vm_mdirty.restype = LONG
|
||||
vm_mdirty.argtypes = None
|
||||
if hasattr(libc, "VBVMR_MacroButton_IsDirty"):
|
||||
vm_mdirty = libc.VBVMR_MacroButton_IsDirty
|
||||
vm_mdirty.restype = LONG
|
||||
vm_mdirty.argtypes = None
|
||||
|
||||
vm_get_buttonstatus = libc.VBVMR_MacroButton_GetStatus
|
||||
vm_get_buttonstatus.restype = LONG
|
||||
vm_get_buttonstatus.argtypes = [LONG, ct.POINTER(FLOAT), LONG]
|
||||
if hasattr(libc, "VBVMR_MacroButton_GetStatus"):
|
||||
vm_get_buttonstatus = libc.VBVMR_MacroButton_GetStatus
|
||||
vm_get_buttonstatus.restype = LONG
|
||||
vm_get_buttonstatus.argtypes = [LONG, ct.POINTER(FLOAT), LONG]
|
||||
|
||||
vm_set_buttonstatus = libc.VBVMR_MacroButton_SetStatus
|
||||
vm_set_buttonstatus.restype = LONG
|
||||
vm_set_buttonstatus.argtypes = [LONG, FLOAT, LONG]
|
||||
if hasattr(libc, "VBVMR_MacroButton_SetStatus"):
|
||||
vm_set_buttonstatus = libc.VBVMR_MacroButton_SetStatus
|
||||
vm_set_buttonstatus.restype = LONG
|
||||
vm_set_buttonstatus.argtypes = [LONG, FLOAT, LONG]
|
||||
|
||||
vm_pdirty = libc.VBVMR_IsParametersDirty
|
||||
vm_pdirty.restype = LONG
|
||||
@ -103,7 +111,15 @@ class CBindings(metaclass=ABCMeta):
|
||||
vm_get_midi_message.restype = LONG
|
||||
vm_get_midi_message.argtypes = [ct.POINTER(CHAR * 1024), LONG]
|
||||
|
||||
def call(self, func):
|
||||
res = func()
|
||||
if res != 0:
|
||||
raise CAPIError(f"Function {func.func.__name__} returned {res}")
|
||||
def call(self, func, *args, ok=(0,), ok_exp=None):
|
||||
try:
|
||||
res = func(*args)
|
||||
if ok_exp is None:
|
||||
if res not in ok:
|
||||
raise CAPIError(f"{func.__name__} returned {res}")
|
||||
elif not ok_exp(res):
|
||||
raise CAPIError(f"{func.__name__} returned {res}")
|
||||
return res
|
||||
except CAPIError as e:
|
||||
self.logger_cbindings.exception(f"{type(e).__name__}: {e}")
|
||||
raise
|
||||
|
@ -1,6 +1,5 @@
|
||||
from .error import VMError
|
||||
from .iremote import IRemote
|
||||
from .meta import action_prop
|
||||
from .meta import action_fn
|
||||
|
||||
|
||||
class Command(IRemote):
|
||||
@ -22,10 +21,9 @@ class Command(IRemote):
|
||||
(cls,),
|
||||
{
|
||||
**{
|
||||
param: action_prop(param)
|
||||
for param in ["show", "shutdown", "restart"]
|
||||
param: action_fn(param) for param in ["show", "shutdown", "restart"]
|
||||
},
|
||||
"hide": action_prop("show", val=0),
|
||||
"hide": action_fn("show", val=0),
|
||||
},
|
||||
)
|
||||
return CMD_cls(remote)
|
||||
|
@ -2,6 +2,8 @@ import itertools
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from .error import VMError
|
||||
|
||||
try:
|
||||
import tomllib
|
||||
except ModuleNotFoundError:
|
||||
@ -9,6 +11,8 @@ except ModuleNotFoundError:
|
||||
|
||||
from .kinds import request_kind_map as kindmap
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TOMLStrBuilder:
|
||||
"""builds a config profile, as a string, for the toml parser"""
|
||||
@ -32,10 +36,17 @@ class TOMLStrBuilder:
|
||||
+ [f"B{i} = false" for i in range(1, self.kind.virt_out + 1)]
|
||||
)
|
||||
self.phys_strip_params = self.virt_strip_params + [
|
||||
"comp = 0.0",
|
||||
"gate = 0.0",
|
||||
"comp.knob = 0.0",
|
||||
"gate.knob = 0.0",
|
||||
"denoiser.knob = 0.0",
|
||||
"eq.on = false",
|
||||
]
|
||||
self.bus_params = [
|
||||
"mono = false",
|
||||
"eq.on = false",
|
||||
"mute = false",
|
||||
"gain = 0.0",
|
||||
]
|
||||
self.bus_bool = ["mono = false", "eq = false", "mute = false"]
|
||||
|
||||
if profile == "reset":
|
||||
self.reset_config()
|
||||
@ -66,7 +77,7 @@ class TOMLStrBuilder:
|
||||
else self.virt_strip_params
|
||||
)
|
||||
case "bus":
|
||||
toml_str += ("\n").join(self.bus_bool)
|
||||
toml_str += ("\n").join(self.bus_params)
|
||||
case _:
|
||||
pass
|
||||
return toml_str + "\n"
|
||||
@ -119,10 +130,9 @@ class Loader(metaclass=SingletonType):
|
||||
loads data into memory if not found
|
||||
"""
|
||||
|
||||
logger = logging.getLogger("config.Loader")
|
||||
|
||||
def __init__(self, kind):
|
||||
self._kind = kind
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
self._configs = dict()
|
||||
self.defaults(kind)
|
||||
self.parser = None
|
||||
@ -166,16 +176,16 @@ def loader(kind):
|
||||
|
||||
returns configs loaded into memory
|
||||
"""
|
||||
logger = logging.getLogger("config.loader")
|
||||
logger_loader = logger.getChild("loader")
|
||||
loader = Loader(kind)
|
||||
|
||||
for path in (
|
||||
Path.cwd() / "configs" / kind.name,
|
||||
Path(__file__).parent / "configs" / kind.name,
|
||||
Path.home() / "Documents/Voicemeeter" / "configs" / kind.name,
|
||||
Path.home() / ".config" / "voicemeeter" / kind.name,
|
||||
Path.home() / "Documents" / "Voicemeeter" / "configs" / kind.name,
|
||||
):
|
||||
if path.is_dir():
|
||||
logger.info(f"Checking [{path}] for TOML config files:")
|
||||
logger_loader.info(f"Checking [{path}] for TOML config files:")
|
||||
for file in path.glob("*.toml"):
|
||||
identifier = file.with_suffix("").stem
|
||||
if loader.parse(identifier, file):
|
||||
@ -192,5 +202,5 @@ def request_config(kind_id: str):
|
||||
try:
|
||||
configs = loader(kindmap(kind_id))
|
||||
except KeyError as e:
|
||||
print(f"Unknown Voicemeeter kind '{kind_id}'")
|
||||
raise VMError(f"Unknown Voicemeeter kind {kind_id}") from e
|
||||
return configs
|
||||
|
@ -1,16 +1,10 @@
|
||||
class InstallError(Exception):
|
||||
"""errors related to installation"""
|
||||
|
||||
pass
|
||||
"""Exception raised when installation errors occur"""
|
||||
|
||||
|
||||
class CAPIError(Exception):
|
||||
"""errors related to low-level C API calls"""
|
||||
|
||||
pass
|
||||
"""Exception raised when the C-API returns error values"""
|
||||
|
||||
|
||||
class VMError(Exception):
|
||||
"""general errors"""
|
||||
|
||||
pass
|
||||
"""Exception raised when general errors occur"""
|
||||
|
@ -1,14 +1,15 @@
|
||||
import logging
|
||||
from typing import Iterable, Union
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Event:
|
||||
"""Keeps track of event subscriptions"""
|
||||
|
||||
logger = logging.getLogger("event.event")
|
||||
|
||||
def __init__(self, subs: dict):
|
||||
self.subs = subs
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
def info(self, msg=None):
|
||||
info = (f"{msg} events",) if msg else ()
|
||||
|
@ -9,6 +9,7 @@ from .bus import request_bus_obj as bus
|
||||
from .command import Command
|
||||
from .config import request_config as configs
|
||||
from .device import Device
|
||||
from .error import VMError
|
||||
from .kinds import KindMapClass
|
||||
from .kinds import request_kind_map as kindmap
|
||||
from .macrobutton import MacroButton
|
||||
@ -17,6 +18,8 @@ from .remote import Remote
|
||||
from .strip import request_strip_obj as strip
|
||||
from .vban import request_vban_obj as vban
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FactoryBuilder:
|
||||
"""
|
||||
@ -25,7 +28,6 @@ class FactoryBuilder:
|
||||
Separates construction from representation.
|
||||
"""
|
||||
|
||||
logger = logging.getLogger("remote.factorybuilder")
|
||||
BuilderProgress = IntEnum(
|
||||
"BuilderProgress",
|
||||
"strip bus command macrobutton vban device option recorder patch fx",
|
||||
@ -47,11 +49,12 @@ class FactoryBuilder:
|
||||
f"Finished building patch for {self._factory}",
|
||||
f"Finished building fx for {self._factory}",
|
||||
)
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
def _pinfo(self, name: str) -> NoReturn:
|
||||
"""prints progress status for each step"""
|
||||
name = name.split("_")[1]
|
||||
self.logger.info(self._info[int(getattr(self.BuilderProgress, name))])
|
||||
self.logger.debug(self._info[int(getattr(self.BuilderProgress, name))])
|
||||
|
||||
def make_strip(self):
|
||||
self._factory.strip = tuple(
|
||||
@ -104,10 +107,16 @@ class FactoryBase(Remote):
|
||||
"""Base class for factories, subclasses Remote."""
|
||||
|
||||
def __init__(self, kind_id: str, **kwargs):
|
||||
defaultevents = {"pdirty": True, "mdirty": True, "midi": True, "ldirty": False}
|
||||
defaultkwargs = {
|
||||
"sync": False,
|
||||
"ratelimit": 0.033,
|
||||
"pdirty": False,
|
||||
"mdirty": False,
|
||||
"midi": False,
|
||||
"ldirty": False,
|
||||
}
|
||||
if "subs" in kwargs:
|
||||
defaultevents = defaultevents | kwargs.pop("subs")
|
||||
defaultkwargs = {"sync": False, "ratelimit": 0.033, "subs": defaultevents}
|
||||
defaultkwargs |= kwargs.pop("subs") # for backwards compatibility
|
||||
kwargs = defaultkwargs | kwargs
|
||||
self.kind = kindmap(kind_id)
|
||||
super().__init__(**kwargs)
|
||||
@ -231,9 +240,13 @@ def request_remote_obj(kind_id: str, **kwargs) -> Remote:
|
||||
|
||||
Returns a reference to a Remote class of a kind
|
||||
"""
|
||||
|
||||
logger_entry = logger.getChild("request_remote_obj")
|
||||
|
||||
REMOTE_obj = None
|
||||
try:
|
||||
REMOTE_obj = remote_factory(kind_id, **kwargs)
|
||||
except (ValueError, TypeError) as e:
|
||||
raise SystemExit(e)
|
||||
logger_entry.exception(f"{type(e).__name__}: {e}")
|
||||
raise VMError(str(e)) from e
|
||||
return REMOTE_obj
|
||||
|
@ -25,17 +25,19 @@ def get_vmpath():
|
||||
with winreg.OpenKey(
|
||||
winreg.HKEY_LOCAL_MACHINE, r"{}".format(REG_KEY + "\\" + VM_KEY)
|
||||
) as vm_key:
|
||||
path = winreg.QueryValueEx(vm_key, r"UninstallString")[0]
|
||||
return path
|
||||
return winreg.QueryValueEx(vm_key, r"UninstallString")[0]
|
||||
|
||||
|
||||
vm_path = Path(get_vmpath())
|
||||
try:
|
||||
vm_path = Path(get_vmpath())
|
||||
except FileNotFoundError as e:
|
||||
raise InstallError(f"Unable to fetch DLL path from the registry") from e
|
||||
vm_parent = vm_path.parent
|
||||
|
||||
DLL_NAME = f'VoicemeeterRemote{"64" if bits == 64 else ""}.dll'
|
||||
|
||||
dll_path = vm_parent.joinpath(DLL_NAME)
|
||||
if not dll_path.is_file():
|
||||
raise InstallError(f"Could not find {DLL_NAME}")
|
||||
raise InstallError(f"Could not find {dll_path}")
|
||||
|
||||
libc = ct.CDLL(str(dll_path))
|
||||
|
@ -1,6 +1,9 @@
|
||||
import logging
|
||||
import time
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IRemote(metaclass=ABCMeta):
|
||||
"""
|
||||
@ -12,14 +15,23 @@ class IRemote(metaclass=ABCMeta):
|
||||
def __init__(self, remote, index=None):
|
||||
self._remote = remote
|
||||
self.index = index
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
def getter(self, param, **kwargs):
|
||||
"""Gets a parameter value"""
|
||||
return self._remote.get(f"{self.identifier}.{param}", **kwargs)
|
||||
self.logger.debug(f"getter: {self._cmd(param)}")
|
||||
return self._remote.get(self._cmd(param), **kwargs)
|
||||
|
||||
def setter(self, param, val):
|
||||
"""Sets a parameter value"""
|
||||
self._remote.set(f"{self.identifier}.{param}", val)
|
||||
self.logger.debug(f"setter: {self._cmd(param)}={val}")
|
||||
self._remote.set(self._cmd(param), val)
|
||||
|
||||
def _cmd(self, param):
|
||||
cmd = (self.identifier,)
|
||||
if param:
|
||||
cmd += (f".{param}",)
|
||||
return "".join(cmd)
|
||||
|
||||
@abstractmethod
|
||||
def identifier(self):
|
||||
@ -32,9 +44,15 @@ class IRemote(metaclass=ABCMeta):
|
||||
return (self, attr, val)
|
||||
|
||||
for attr, val in data.items():
|
||||
if hasattr(self, attr):
|
||||
target, attr, val = fget(attr, val)
|
||||
setattr(target, attr, val)
|
||||
if not isinstance(val, dict):
|
||||
if attr in dir(self): # avoid calling getattr (with hasattr)
|
||||
target, attr, val = fget(attr, val)
|
||||
setattr(target, attr, val)
|
||||
else:
|
||||
self.logger.error(f"invalid attribute {attr} for {self}")
|
||||
else:
|
||||
target = getattr(self, attr)
|
||||
target.apply(val)
|
||||
return self
|
||||
|
||||
def then_wait(self):
|
||||
|
@ -1,6 +1,8 @@
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum, unique
|
||||
|
||||
from .error import VMError
|
||||
|
||||
|
||||
@unique
|
||||
class KindId(Enum):
|
||||
@ -105,7 +107,7 @@ def request_kind_map(kind_id):
|
||||
try:
|
||||
KIND_obj = kind_factory(kind_id)
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
raise VMError(str(e)) from e
|
||||
return KIND_obj
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
from .error import VMError
|
||||
from .iremote import IRemote
|
||||
|
||||
|
||||
|
@ -22,8 +22,8 @@ def float_prop(param):
|
||||
return property(fget, fset)
|
||||
|
||||
|
||||
def action_prop(param, val: int = 1):
|
||||
"""A param that performs an action"""
|
||||
def action_fn(param, val: int = 1):
|
||||
"""meta function that performs an action"""
|
||||
|
||||
def fdo(self):
|
||||
self.setter(param, val)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from .error import VMError
|
||||
from .iremote import IRemote
|
||||
from .kinds import kinds_all
|
||||
from .meta import action_prop, bool_prop
|
||||
from .meta import action_fn, bool_prop
|
||||
|
||||
|
||||
class Recorder(IRemote):
|
||||
@ -24,7 +24,7 @@ class Recorder(IRemote):
|
||||
(cls, CHANNELOUTMIXIN_cls),
|
||||
{
|
||||
**{
|
||||
param: action_prop(param)
|
||||
param: action_fn(param)
|
||||
for param in [
|
||||
"play",
|
||||
"stop",
|
||||
|
@ -2,7 +2,7 @@ import ctypes as ct
|
||||
import logging
|
||||
import time
|
||||
from abc import abstractmethod
|
||||
from functools import partial
|
||||
from queue import Queue
|
||||
from typing import Iterable, NoReturn, Optional, Union
|
||||
|
||||
from .cbindings import CBindings
|
||||
@ -12,33 +12,36 @@ from .inst import bits
|
||||
from .kinds import KindId
|
||||
from .misc import Midi
|
||||
from .subject import Subject
|
||||
from .updater import Updater
|
||||
from .updater import Producer, Updater
|
||||
from .util import grouper, polling, script
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Remote(CBindings):
|
||||
"""Base class responsible for wrapping the C Remote API"""
|
||||
|
||||
logger = logging.getLogger("remote.remote")
|
||||
DELAY = 0.001
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.strip_mode = 0
|
||||
self.cache = {}
|
||||
self.cache["strip_level"], self.cache["bus_level"] = self._get_levels()
|
||||
self.midi = Midi()
|
||||
self.subject = Subject()
|
||||
self.running = None
|
||||
self.subject = self.observer = Subject()
|
||||
self.running = False
|
||||
self.event = Event(
|
||||
{k: kwargs.pop(k) for k in ("pdirty", "mdirty", "midi", "ldirty")}
|
||||
)
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
for attr, val in kwargs.items():
|
||||
setattr(self, attr, val)
|
||||
|
||||
self.event = Event(self.subs)
|
||||
|
||||
def __enter__(self):
|
||||
"""setup procedures"""
|
||||
self.login()
|
||||
self.init_thread()
|
||||
if self.event.any():
|
||||
self.init_thread()
|
||||
return self
|
||||
|
||||
@abstractmethod
|
||||
@ -51,16 +54,21 @@ class Remote(CBindings):
|
||||
self.running = True
|
||||
self.event.info()
|
||||
|
||||
self.updater = Updater(self)
|
||||
self.logger.debug("initiating events thread")
|
||||
queue = Queue()
|
||||
self.updater = Updater(self, queue)
|
||||
self.updater.start()
|
||||
self.producer = Producer(self, queue)
|
||||
self.producer.start()
|
||||
|
||||
def login(self) -> NoReturn:
|
||||
"""Login to the API, initialize dirty parameters"""
|
||||
res = self.vm_login()
|
||||
res = self.call(self.vm_login, ok=(0, 1))
|
||||
if res == 1:
|
||||
self.logger.info(
|
||||
"Voicemeeter engine running but GUI not launched. Launching the GUI now."
|
||||
)
|
||||
self.run_voicemeeter(self.kind.name)
|
||||
elif res != 0:
|
||||
raise CAPIError(f"VBVMR_Login returned {res}")
|
||||
self.logger.info(f"{type(self).__name__}: Successfully logged into {self}")
|
||||
self.clear_dirty()
|
||||
|
||||
@ -71,21 +79,21 @@ class Remote(CBindings):
|
||||
value = KindId[kind_id.upper()].value + 3
|
||||
else:
|
||||
value = KindId[kind_id.upper()].value
|
||||
self.vm_runvm(value)
|
||||
self.call(self.vm_runvm, value)
|
||||
time.sleep(1)
|
||||
|
||||
@property
|
||||
def type(self) -> str:
|
||||
"""Returns the type of Voicemeeter installation (basic, banana, potato)."""
|
||||
type_ = ct.c_long()
|
||||
self.vm_get_type(ct.byref(type_))
|
||||
self.call(self.vm_get_type, ct.byref(type_))
|
||||
return KindId(type_.value).name.lower()
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
"""Returns Voicemeeter's version as a string"""
|
||||
ver = ct.c_long()
|
||||
self.vm_get_version(ct.byref(ver))
|
||||
self.call(self.vm_get_version, ct.byref(ver))
|
||||
return "{}.{}.{}.{}".format(
|
||||
(ver.value & 0xFF000000) >> 24,
|
||||
(ver.value & 0x00FF0000) >> 16,
|
||||
@ -96,12 +104,18 @@ class Remote(CBindings):
|
||||
@property
|
||||
def pdirty(self) -> bool:
|
||||
"""True iff UI parameters have been updated."""
|
||||
return self.vm_pdirty() == 1
|
||||
return self.call(self.vm_pdirty, ok=(0, 1)) == 1
|
||||
|
||||
@property
|
||||
def mdirty(self) -> bool:
|
||||
"""True iff MB parameters have been updated."""
|
||||
return self.vm_mdirty() == 1
|
||||
try:
|
||||
return self.call(self.vm_mdirty, ok=(0, 1)) == 1
|
||||
except AttributeError as e:
|
||||
self.logger.exception(f"{type(e).__name__}: {e}")
|
||||
raise CAPIError(
|
||||
"no bind for VBVMR_MacroButton_IsDirty. are you using an old version of the API?"
|
||||
) from e
|
||||
|
||||
@property
|
||||
def ldirty(self) -> bool:
|
||||
@ -112,23 +126,24 @@ class Remote(CBindings):
|
||||
and self.cache.get("bus_level") == self._bus_buf
|
||||
)
|
||||
|
||||
def clear_dirty(self):
|
||||
while self.pdirty or self.mdirty:
|
||||
pass
|
||||
def clear_dirty(self) -> NoReturn:
|
||||
try:
|
||||
while self.pdirty or self.mdirty:
|
||||
pass
|
||||
except CAPIError:
|
||||
self.logger.error("no bind for mdirty, clearing pdirty only")
|
||||
while self.pdirty:
|
||||
pass
|
||||
|
||||
@polling
|
||||
def get(self, param: str, is_string: Optional[bool] = False) -> Union[str, float]:
|
||||
"""Gets a string or float parameter"""
|
||||
if is_string:
|
||||
buf = ct.create_unicode_buffer(512)
|
||||
self.call(
|
||||
partial(self.vm_get_parameter_string, param.encode(), ct.byref(buf))
|
||||
)
|
||||
self.call(self.vm_get_parameter_string, param.encode(), ct.byref(buf))
|
||||
else:
|
||||
buf = ct.c_float()
|
||||
self.call(
|
||||
partial(self.vm_get_parameter_float, param.encode(), ct.byref(buf))
|
||||
)
|
||||
self.call(self.vm_get_parameter_float, param.encode(), ct.byref(buf))
|
||||
return buf.value
|
||||
|
||||
def set(self, param: str, val: Union[str, float]) -> NoReturn:
|
||||
@ -136,14 +151,10 @@ class Remote(CBindings):
|
||||
if isinstance(val, str):
|
||||
if len(val) >= 512:
|
||||
raise VMError("String is too long")
|
||||
self.call(
|
||||
partial(self.vm_set_parameter_string, param.encode(), ct.c_wchar_p(val))
|
||||
)
|
||||
self.call(self.vm_set_parameter_string, param.encode(), ct.c_wchar_p(val))
|
||||
else:
|
||||
self.call(
|
||||
partial(
|
||||
self.vm_set_parameter_float, param.encode(), ct.c_float(float(val))
|
||||
)
|
||||
self.vm_set_parameter_float, param.encode(), ct.c_float(float(val))
|
||||
)
|
||||
self.cache[param] = val
|
||||
|
||||
@ -151,22 +162,30 @@ class Remote(CBindings):
|
||||
def get_buttonstatus(self, id: int, mode: int) -> int:
|
||||
"""Gets a macrobutton parameter"""
|
||||
state = ct.c_float()
|
||||
self.call(
|
||||
partial(
|
||||
try:
|
||||
self.call(
|
||||
self.vm_get_buttonstatus,
|
||||
ct.c_long(id),
|
||||
ct.byref(state),
|
||||
ct.c_long(mode),
|
||||
)
|
||||
)
|
||||
except AttributeError as e:
|
||||
self.logger.exception(f"{type(e).__name__}: {e}")
|
||||
raise CAPIError(
|
||||
"no bind for VBVMR_MacroButton_GetStatus. are you using an old version of the API?"
|
||||
) from e
|
||||
return int(state.value)
|
||||
|
||||
def set_buttonstatus(self, id: int, state: int, mode: int) -> NoReturn:
|
||||
"""Sets a macrobutton parameter. Caches value"""
|
||||
c_state = ct.c_float(float(state))
|
||||
self.call(
|
||||
partial(self.vm_set_buttonstatus, ct.c_long(id), c_state, ct.c_long(mode))
|
||||
)
|
||||
try:
|
||||
self.call(self.vm_set_buttonstatus, ct.c_long(id), c_state, ct.c_long(mode))
|
||||
except AttributeError as e:
|
||||
self.logger.exception(f"{type(e).__name__}: {e}")
|
||||
raise CAPIError(
|
||||
"no bind for VBVMR_MacroButton_SetStatus. are you using an old version of the API?"
|
||||
) from e
|
||||
self.cache[f"mb_{id}_{mode}"] = int(c_state.value)
|
||||
|
||||
def get_num_devices(self, direction: str = None) -> int:
|
||||
@ -174,7 +193,8 @@ class Remote(CBindings):
|
||||
if direction not in ("in", "out"):
|
||||
raise VMError("Expected a direction: in or out")
|
||||
func = getattr(self, f"vm_get_num_{direction}devices")
|
||||
return func()
|
||||
res = self.call(func, ok_exp=lambda r: r >= 0)
|
||||
return res
|
||||
|
||||
def get_device_description(self, index: int, direction: str = None) -> tuple:
|
||||
"""Returns a tuple of device parameters"""
|
||||
@ -184,7 +204,8 @@ class Remote(CBindings):
|
||||
name = ct.create_unicode_buffer(256)
|
||||
hwid = ct.create_unicode_buffer(256)
|
||||
func = getattr(self, f"vm_get_desc_{direction}devices")
|
||||
func(
|
||||
self.call(
|
||||
func,
|
||||
ct.c_long(index),
|
||||
ct.byref(type_),
|
||||
ct.byref(name),
|
||||
@ -195,7 +216,7 @@ class Remote(CBindings):
|
||||
def get_level(self, type_: int, index: int) -> float:
|
||||
"""Retrieves a single level value"""
|
||||
val = ct.c_float()
|
||||
self.vm_get_level(ct.c_long(type_), ct.c_long(index), ct.byref(val))
|
||||
self.call(self.vm_get_level, ct.c_long(type_), ct.c_long(index), ct.byref(val))
|
||||
return val.value
|
||||
|
||||
def _get_levels(self) -> Iterable:
|
||||
@ -216,7 +237,7 @@ class Remote(CBindings):
|
||||
def get_midi_message(self):
|
||||
n = ct.c_long(1024)
|
||||
buf = ct.create_string_buffer(1024)
|
||||
res = self.vm_get_midi_message(ct.byref(buf), n)
|
||||
res = self.vm_get_midi_message(ct.byref(buf), n, ok_exp=lambda r: r >= 0)
|
||||
if res > 0:
|
||||
vals = tuple(
|
||||
grouper(3, (int.from_bytes(buf[i], "little") for i in range(res)))
|
||||
@ -228,15 +249,13 @@ class Remote(CBindings):
|
||||
self.midi._most_recent = pitch
|
||||
self.midi._set(pitch, vel)
|
||||
return True
|
||||
elif res == -1 or res == -2:
|
||||
raise CAPIError(f"VBVMR_GetMidiMessage returned {res}")
|
||||
|
||||
@script
|
||||
def sendtext(self, script: str):
|
||||
"""Sets many parameters from a script"""
|
||||
if len(script) > 48000:
|
||||
raise ValueError("Script too large, max size 48kB")
|
||||
self.call(partial(self.vm_set_parameter_multi, script.encode()))
|
||||
self.call(self.vm_set_parameter_multi, script.encode())
|
||||
time.sleep(self.DELAY * 5)
|
||||
|
||||
def apply(self, data: dict):
|
||||
@ -266,19 +285,18 @@ class Remote(CBindings):
|
||||
try:
|
||||
self.apply(self.configs[name])
|
||||
self.logger.info(f"Profile '{name}' applied!")
|
||||
except KeyError as e:
|
||||
except KeyError:
|
||||
self.logger.error(("\n").join(error_msg))
|
||||
|
||||
def logout(self) -> NoReturn:
|
||||
"""Wait for dirty parameters to clear, then logout of the API"""
|
||||
self.clear_dirty()
|
||||
time.sleep(0.1)
|
||||
res = self.vm_logout()
|
||||
if res != 0:
|
||||
raise CAPIError(f"VBVMR_Logout returned {res}")
|
||||
self.call(self.vm_logout)
|
||||
self.logger.info(f"{type(self).__name__}: Successfully logged out of {self}")
|
||||
|
||||
def end_thread(self):
|
||||
self.logger.debug("events thread shutdown started")
|
||||
self.running = False
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_traceback) -> NoReturn:
|
||||
|
@ -93,6 +93,10 @@ class PhysicalStrip(Strip):
|
||||
f"PhysicalStrip",
|
||||
(cls, EFFECTS_cls),
|
||||
{
|
||||
"comp": StripComp(remote, i),
|
||||
"gate": StripGate(remote, i),
|
||||
"denoiser": StripDenoiser(remote, i),
|
||||
"eq": StripEQ(remote, i),
|
||||
"device": StripDevice.make(remote, i),
|
||||
},
|
||||
)
|
||||
@ -100,22 +104,6 @@ class PhysicalStrip(Strip):
|
||||
def __str__(self):
|
||||
return f"{type(self).__name__}{self.index}"
|
||||
|
||||
@property
|
||||
def comp(self) -> float:
|
||||
return round(self.getter("Comp"), 1)
|
||||
|
||||
@comp.setter
|
||||
def comp(self, val: float):
|
||||
self.setter("Comp", val)
|
||||
|
||||
@property
|
||||
def gate(self) -> float:
|
||||
return round(self.getter("Gate"), 1)
|
||||
|
||||
@gate.setter
|
||||
def gate(self, val: float):
|
||||
self.setter("Gate", val)
|
||||
|
||||
@property
|
||||
def audibility(self) -> float:
|
||||
return round(self.getter("audibility"), 1)
|
||||
@ -125,6 +113,182 @@ class PhysicalStrip(Strip):
|
||||
self.setter("audibility", val)
|
||||
|
||||
|
||||
class StripComp(IRemote):
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return f"Strip[{self.index}].comp"
|
||||
|
||||
@property
|
||||
def knob(self) -> float:
|
||||
return round(self.getter(""), 1)
|
||||
|
||||
@knob.setter
|
||||
def knob(self, val: float):
|
||||
self.setter("", val)
|
||||
|
||||
@property
|
||||
def gainin(self) -> float:
|
||||
return round(self.getter("GainIn"), 1)
|
||||
|
||||
@gainin.setter
|
||||
def gainin(self, val: float):
|
||||
self.setter("GainIn", val)
|
||||
|
||||
@property
|
||||
def ratio(self) -> float:
|
||||
return round(self.getter("Ratio"), 1)
|
||||
|
||||
@ratio.setter
|
||||
def ratio(self, val: float):
|
||||
self.setter("Ratio", val)
|
||||
|
||||
@property
|
||||
def threshold(self) -> float:
|
||||
return round(self.getter("Threshold"), 1)
|
||||
|
||||
@threshold.setter
|
||||
def threshold(self, val: float):
|
||||
self.setter("Threshold", val)
|
||||
|
||||
@property
|
||||
def attack(self) -> float:
|
||||
return round(self.getter("Attack"), 1)
|
||||
|
||||
@attack.setter
|
||||
def attack(self, val: float):
|
||||
self.setter("Attack", val)
|
||||
|
||||
@property
|
||||
def release(self) -> float:
|
||||
return round(self.getter("Release"), 1)
|
||||
|
||||
@release.setter
|
||||
def release(self, val: float):
|
||||
self.setter("Release", val)
|
||||
|
||||
@property
|
||||
def knee(self) -> float:
|
||||
return round(self.getter("Knee"), 1)
|
||||
|
||||
@knee.setter
|
||||
def knee(self, val: float):
|
||||
self.setter("Knee", val)
|
||||
|
||||
@property
|
||||
def gainout(self) -> float:
|
||||
return round(self.getter("GainOut"), 1)
|
||||
|
||||
@gainout.setter
|
||||
def gainout(self, val: float):
|
||||
self.setter("GainOut", val)
|
||||
|
||||
@property
|
||||
def makeup(self) -> bool:
|
||||
return self.getter("makeup") == 1
|
||||
|
||||
@makeup.setter
|
||||
def makeup(self, val: bool):
|
||||
self.setter("makeup", 1 if val else 0)
|
||||
|
||||
|
||||
class StripGate(IRemote):
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return f"Strip[{self.index}].gate"
|
||||
|
||||
@property
|
||||
def knob(self) -> float:
|
||||
return round(self.getter(""), 1)
|
||||
|
||||
@knob.setter
|
||||
def knob(self, val: float):
|
||||
self.setter("", val)
|
||||
|
||||
@property
|
||||
def threshold(self) -> float:
|
||||
return round(self.getter("Threshold"), 1)
|
||||
|
||||
@threshold.setter
|
||||
def threshold(self, val: float):
|
||||
self.setter("Threshold", val)
|
||||
|
||||
@property
|
||||
def damping(self) -> float:
|
||||
return round(self.getter("Damping"), 1)
|
||||
|
||||
@damping.setter
|
||||
def damping(self, val: float):
|
||||
self.setter("Damping", val)
|
||||
|
||||
@property
|
||||
def bpsidechain(self) -> int:
|
||||
return int(self.getter("BPSidechain"))
|
||||
|
||||
@bpsidechain.setter
|
||||
def bpsidechain(self, val: int):
|
||||
self.setter("BPSidechain", val)
|
||||
|
||||
@property
|
||||
def attack(self) -> float:
|
||||
return round(self.getter("Attack"), 1)
|
||||
|
||||
@attack.setter
|
||||
def attack(self, val: float):
|
||||
self.setter("Attack", val)
|
||||
|
||||
@property
|
||||
def hold(self) -> float:
|
||||
return round(self.getter("Hold"), 1)
|
||||
|
||||
@hold.setter
|
||||
def hold(self, val: float):
|
||||
self.setter("Hold", val)
|
||||
|
||||
@property
|
||||
def release(self) -> float:
|
||||
return round(self.getter("Release"), 1)
|
||||
|
||||
@release.setter
|
||||
def release(self, val: float):
|
||||
self.setter("Release", val)
|
||||
|
||||
|
||||
class StripDenoiser(IRemote):
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return f"Strip[{self.index}].denoiser"
|
||||
|
||||
@property
|
||||
def knob(self) -> float:
|
||||
return round(self.getter(""), 1)
|
||||
|
||||
@knob.setter
|
||||
def knob(self, val: float):
|
||||
self.setter("", val)
|
||||
|
||||
|
||||
class StripEQ(IRemote):
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return f"Strip[{self.index}].eq"
|
||||
|
||||
@property
|
||||
def on(self) -> bool:
|
||||
return self.getter("on") == 1
|
||||
|
||||
@on.setter
|
||||
def on(self, val: bool):
|
||||
self.setter("on", 1 if val else 0)
|
||||
|
||||
@property
|
||||
def ab(self) -> bool:
|
||||
return self.getter("ab") == 1
|
||||
|
||||
@ab.setter
|
||||
def ab(self, val: bool):
|
||||
self.setter("ab", 1 if val else 0)
|
||||
|
||||
|
||||
class StripDevice(IRemote):
|
||||
@classmethod
|
||||
def make(cls, remote, i):
|
||||
|
@ -1,15 +1,14 @@
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Subject:
|
||||
"""Adds support for observers"""
|
||||
|
||||
logger = logging.getLogger("subject.subject")
|
||||
|
||||
def __init__(self):
|
||||
"""list of current observers"""
|
||||
"""Adds support for observers and callbacks"""
|
||||
|
||||
self._observers = list()
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
@property
|
||||
def observers(self) -> list:
|
||||
@ -17,34 +16,57 @@ class Subject:
|
||||
|
||||
return self._observers
|
||||
|
||||
def notify(self, modifier):
|
||||
def notify(self, event):
|
||||
"""run callbacks on update"""
|
||||
|
||||
[o.on_update(modifier) for o in self._observers]
|
||||
for o in self._observers:
|
||||
if hasattr(o, "on_update"):
|
||||
o.on_update(event)
|
||||
else:
|
||||
if o.__name__ == f"on_{event}":
|
||||
o()
|
||||
|
||||
def add(self, observer):
|
||||
"""adds an observer to _observers"""
|
||||
|
||||
if observer not in self._observers:
|
||||
self._observers.append(observer)
|
||||
self.logger.info(f"{type(observer).__name__} added to event observers")
|
||||
else:
|
||||
self.logger.error(
|
||||
f"Failed to add {type(observer).__name__} to event observers"
|
||||
)
|
||||
|
||||
def remove(self, observer):
|
||||
"""removes an observer from _observers"""
|
||||
"""adds an observer to observers"""
|
||||
|
||||
try:
|
||||
self._observers.remove(observer)
|
||||
self.logger.info(f"{type(observer).__name__} removed from event observers")
|
||||
except ValueError:
|
||||
self.logger.error(
|
||||
f"Failed to remove {type(observer).__name__} from event observers"
|
||||
)
|
||||
iterator = iter(observer)
|
||||
for o in iterator:
|
||||
if o not in self._observers:
|
||||
self._observers.append(o)
|
||||
self.logger.info(f"{o} added to event observers")
|
||||
else:
|
||||
self.logger.error(f"Failed to add {o} to event observers")
|
||||
except TypeError:
|
||||
if observer not in self._observers:
|
||||
self._observers.append(observer)
|
||||
self.logger.info(f"{observer} added to event observers")
|
||||
else:
|
||||
self.logger.error(f"Failed to add {observer} to event observers")
|
||||
|
||||
register = add
|
||||
|
||||
def remove(self, observer):
|
||||
"""removes an observer from observers"""
|
||||
|
||||
try:
|
||||
iterator = iter(observer)
|
||||
for o in iterator:
|
||||
try:
|
||||
self._observers.remove(o)
|
||||
self.logger.info(f"{o} removed from event observers")
|
||||
except ValueError:
|
||||
self.logger.error(f"Failed to remove {o} from event observers")
|
||||
except TypeError:
|
||||
try:
|
||||
self._observers.remove(observer)
|
||||
self.logger.info(f"{observer} removed from event observers")
|
||||
except ValueError:
|
||||
self.logger.error(f"Failed to remove {observer} from event observers")
|
||||
|
||||
deregister = remove
|
||||
|
||||
def clear(self):
|
||||
"""clears the _observers list"""
|
||||
"""clears the observers list"""
|
||||
|
||||
self._observers.clear()
|
||||
|
@ -1,17 +1,50 @@
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
from .util import comp
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Producer(threading.Thread):
|
||||
"""Continously send job queue to the Updater thread at a rate of self._remote.ratelimit."""
|
||||
|
||||
def __init__(self, remote, queue):
|
||||
super().__init__(name="producer", daemon=True)
|
||||
self._remote = remote
|
||||
self.queue = queue
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
def run(self):
|
||||
while self._remote.running:
|
||||
if self._remote.event.pdirty:
|
||||
self.queue.put("pdirty")
|
||||
if self._remote.event.mdirty:
|
||||
self.queue.put("mdirty")
|
||||
if self._remote.event.midi:
|
||||
self.queue.put("midi")
|
||||
if self._remote.event.ldirty:
|
||||
self.queue.put("ldirty")
|
||||
time.sleep(self._remote.ratelimit)
|
||||
self.logger.debug(f"terminating {self.getName()} thread")
|
||||
self.queue.put(None)
|
||||
|
||||
|
||||
class Updater(threading.Thread):
|
||||
def __init__(self, remote):
|
||||
super().__init__(name="updater", target=self.update, daemon=True)
|
||||
def __init__(self, remote, queue):
|
||||
super().__init__(name="updater", daemon=True)
|
||||
self._remote = remote
|
||||
self.queue = queue
|
||||
self._remote._strip_comp = [False] * (
|
||||
2 * self._remote.kind.phys_in + 8 * self._remote.kind.virt_in
|
||||
)
|
||||
self._remote._bus_comp = [False] * (self._remote.kind.num_bus * 8)
|
||||
(
|
||||
self._remote.cache["strip_level"],
|
||||
self._remote.cache["bus_level"],
|
||||
) = self._remote._get_levels()
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
def _update_comps(self, strip_level, bus_level):
|
||||
self._remote._strip_comp, self._remote._bus_comp = (
|
||||
@ -19,30 +52,26 @@ class Updater(threading.Thread):
|
||||
tuple(not x for x in comp(self._remote.cache["bus_level"], bus_level)),
|
||||
)
|
||||
|
||||
def update(self):
|
||||
def run(self):
|
||||
"""
|
||||
Continously update observers of dirty states.
|
||||
|
||||
Generate _strip_comp, _bus_comp and update level cache if ldirty.
|
||||
|
||||
Runs updates at a rate of self.ratelimit.
|
||||
"""
|
||||
while self._remote.running:
|
||||
start = time.time()
|
||||
if self._remote.event.pdirty and self._remote.pdirty:
|
||||
self._remote.subject.notify("pdirty")
|
||||
if self._remote.event.mdirty and self._remote.mdirty:
|
||||
self._remote.subject.notify("mdirty")
|
||||
if self._remote.event.midi and self._remote.get_midi_message():
|
||||
self._remote.subject.notify("midi")
|
||||
if self._remote.event.ldirty and self._remote.ldirty:
|
||||
while True:
|
||||
event = self.queue.get()
|
||||
if event is None:
|
||||
self.logger.debug(f"terminating {self.getName()} thread")
|
||||
break
|
||||
|
||||
if event == "pdirty" and self._remote.pdirty:
|
||||
self._remote.subject.notify(event)
|
||||
elif event == "mdirty" and self._remote.mdirty:
|
||||
self._remote.subject.notify(event)
|
||||
elif event == "midi" and self._remote.get_midi_message():
|
||||
self._remote.subject.notify(event)
|
||||
elif event == "ldirty" and self._remote.ldirty:
|
||||
self._update_comps(self._remote._strip_buf, self._remote._bus_buf)
|
||||
self._remote.cache["strip_level"] = self._remote._strip_buf
|
||||
self._remote.cache["bus_level"] = self._remote._bus_buf
|
||||
self._remote.subject.notify("ldirty")
|
||||
|
||||
elapsed = time.time() - start
|
||||
if self._remote.event.any() and self._remote.ratelimit - elapsed > 0:
|
||||
time.sleep(self._remote.ratelimit - elapsed)
|
||||
else:
|
||||
time.sleep(0.1)
|
||||
self._remote.subject.notify(event)
|
||||
|
Loading…
x
Reference in New Issue
Block a user