xair-api 2.4.1__py3-none-any.whl → 2.4.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
xair_api/strip.py CHANGED
@@ -1,73 +1,73 @@
1
- import abc
2
- import logging
3
-
4
- from .meta import mute_prop
5
- from .shared import EQ, Automix, Config, Dyn, Gate, Group, Insert, Mix, Preamp, Send
6
-
7
- logger = logging.getLogger(__name__)
8
-
9
-
10
- class IStrip(abc.ABC):
11
- """Abstract Base Class for strips"""
12
-
13
- def __init__(self, remote, index: int):
14
- self._remote = remote
15
- self.index = index + 1
16
- self.logger = logger.getChild(self.__class__.__name__)
17
-
18
- def getter(self, param: str) -> tuple:
19
- return self._remote.query(f'{self.address}/{param}')
20
-
21
- def setter(self, param: str, val: int):
22
- self._remote.send(f'{self.address}/{param}', val)
23
-
24
- @abc.abstractmethod
25
- def address(self):
26
- pass
27
-
28
-
29
- class Strip(IStrip):
30
- """Concrete class for strips"""
31
-
32
- @classmethod
33
- def make(cls, remote, index):
34
- """
35
- Factory function for strips
36
-
37
- Creates a mixin of shared subclasses, sets them as class attributes.
38
-
39
- Returns a Strip class of a kind.
40
- """
41
-
42
- STRIP_cls = type(
43
- f'Strip{remote.kind}',
44
- (cls,),
45
- {
46
- **{
47
- _cls.__name__.lower(): type(
48
- f'{_cls.__name__}{remote.kind}', (_cls, cls), {}
49
- )(remote, index)
50
- for _cls in (
51
- Config,
52
- Preamp,
53
- Gate,
54
- Dyn,
55
- Insert,
56
- EQ.make_fourband(cls, remote, index),
57
- Mix,
58
- Group,
59
- Automix,
60
- )
61
- },
62
- 'send': tuple(
63
- Send.make(cls, i, remote, index)
64
- for i in range(remote.kind.num_bus + remote.kind.num_fx)
65
- ),
66
- 'mute': mute_prop(),
67
- },
68
- )
69
- return STRIP_cls(remote, index)
70
-
71
- @property
72
- def address(self) -> str:
73
- return f'/ch/{str(self.index).zfill(2)}'
1
+ import abc
2
+ import logging
3
+
4
+ from .meta import mute_prop
5
+ from .shared import EQ, Automix, Config, Dyn, Gate, Group, Insert, Mix, Preamp, Send
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ class IStrip(abc.ABC):
11
+ """Abstract Base Class for strips"""
12
+
13
+ def __init__(self, remote, index: int):
14
+ self._remote = remote
15
+ self.index = index + 1
16
+ self.logger = logger.getChild(self.__class__.__name__)
17
+
18
+ def getter(self, param: str) -> tuple:
19
+ return self._remote.query(f'{self.address}/{param}')
20
+
21
+ def setter(self, param: str, val: int):
22
+ self._remote.send(f'{self.address}/{param}', val)
23
+
24
+ @abc.abstractmethod
25
+ def address(self):
26
+ pass
27
+
28
+
29
+ class Strip(IStrip):
30
+ """Concrete class for strips"""
31
+
32
+ @classmethod
33
+ def make(cls, remote, index):
34
+ """
35
+ Factory function for strips
36
+
37
+ Creates a mixin of shared subclasses, sets them as class attributes.
38
+
39
+ Returns a Strip class of a kind.
40
+ """
41
+
42
+ STRIP_cls = type(
43
+ f'Strip{remote.kind}',
44
+ (cls,),
45
+ {
46
+ **{
47
+ _cls.__name__.lower(): type(
48
+ f'{_cls.__name__}{remote.kind}', (_cls, cls), {}
49
+ )(remote, index)
50
+ for _cls in (
51
+ Config,
52
+ Preamp,
53
+ Gate,
54
+ Dyn,
55
+ Insert,
56
+ EQ.make_fourband(cls, remote, index),
57
+ Mix,
58
+ Group,
59
+ Automix,
60
+ )
61
+ },
62
+ 'send': tuple(
63
+ Send.make(cls, i, remote, index)
64
+ for i in range(remote.kind.num_bus + remote.kind.num_fx)
65
+ ),
66
+ 'mute': mute_prop(),
67
+ },
68
+ )
69
+ return STRIP_cls(remote, index)
70
+
71
+ @property
72
+ def address(self) -> str:
73
+ return f'/ch/{str(self.index).zfill(2)}'
xair_api/util.py CHANGED
@@ -1,94 +1,94 @@
1
- import functools
2
- import time
3
- from math import exp, log
4
-
5
- from .errors import XAirRemoteConnectionTimeoutError
6
-
7
-
8
- def timeout(func):
9
- """
10
- Times out the validate_connection function once time elapsed exceeds remote.connect_timeout.
11
- """
12
-
13
- @functools.wraps(func)
14
- def wrapper(*args, **kwargs):
15
- remote, *_ = args
16
-
17
- err = None
18
- start = time.time()
19
- while time.time() < start + remote.connect_timeout:
20
- try:
21
- func(*args, **kwargs)
22
- remote.logger.debug(f'login time: {round(time.time() - start, 2)}')
23
- err = None
24
- break
25
- except XAirRemoteConnectionTimeoutError as e:
26
- err = e
27
- continue
28
- if err:
29
- raise err
30
-
31
- return wrapper
32
-
33
-
34
- def lin_get(min, max, val):
35
- return min + (max - min) * val
36
-
37
-
38
- def lin_set(min, max, val):
39
- return (val - min) / (max - min)
40
-
41
-
42
- def log_get(min, max, val):
43
- return min * exp(log(max / min) * val)
44
-
45
-
46
- def log_set(min, max, val):
47
- return log(val / min) / log(max / min)
48
-
49
-
50
- def db_from(func):
51
- """fader|level converter for getters"""
52
-
53
- @functools.wraps(func)
54
- def wrapper(*args, **kwargs):
55
- retval = func(*args, **kwargs)
56
-
57
- if retval >= 1:
58
- return 10
59
- elif retval >= 0.5:
60
- return round((40 * retval) - 30, 1)
61
- elif retval >= 0.25:
62
- return round((80 * retval) - 50, 1)
63
- elif retval >= 0.0625:
64
- return round((160 * retval) - 70, 1)
65
- elif retval >= 0:
66
- return round((480 * retval) - 90, 1)
67
- else:
68
- return -90
69
-
70
- return wrapper
71
-
72
-
73
- def db_to(func):
74
- """fader|level converter for setters"""
75
-
76
- @functools.wraps(func)
77
- def wrapper(*args, **kwargs):
78
- param, val = args
79
- if val >= 10:
80
- val = 1
81
- elif val >= -10:
82
- val = (val + 30) / 40
83
- elif val >= -30:
84
- val = (val + 50) / 80
85
- elif val >= -60:
86
- val = (val + 70) / 160
87
- elif val >= -90:
88
- val = (val + 90) / 480
89
- else:
90
- val = 0
91
-
92
- func(param, val, **kwargs)
93
-
94
- return wrapper
1
+ import functools
2
+ import time
3
+ from math import exp, log
4
+
5
+ from .errors import XAirRemoteConnectionTimeoutError
6
+
7
+
8
+ def timeout(func):
9
+ """
10
+ Times out the validate_connection function once time elapsed exceeds remote.connect_timeout.
11
+ """
12
+
13
+ @functools.wraps(func)
14
+ def wrapper(*args, **kwargs):
15
+ remote, *_ = args
16
+
17
+ err = None
18
+ start = time.time()
19
+ while time.time() < start + remote.connect_timeout:
20
+ try:
21
+ func(*args, **kwargs)
22
+ remote.logger.debug(f'login time: {round(time.time() - start, 2)}')
23
+ err = None
24
+ break
25
+ except XAirRemoteConnectionTimeoutError as e:
26
+ err = e
27
+ continue
28
+ if err:
29
+ raise err
30
+
31
+ return wrapper
32
+
33
+
34
+ def lin_get(min, max, val):
35
+ return min + (max - min) * val
36
+
37
+
38
+ def lin_set(min, max, val):
39
+ return (val - min) / (max - min)
40
+
41
+
42
+ def log_get(min, max, val):
43
+ return min * exp(log(max / min) * val)
44
+
45
+
46
+ def log_set(min, max, val):
47
+ return log(val / min) / log(max / min)
48
+
49
+
50
+ def db_from(func):
51
+ """fader|level converter for getters"""
52
+
53
+ @functools.wraps(func)
54
+ def wrapper(*args, **kwargs):
55
+ retval = func(*args, **kwargs)
56
+
57
+ if retval >= 1:
58
+ return 10
59
+ elif retval >= 0.5:
60
+ return round((40 * retval) - 30, 1)
61
+ elif retval >= 0.25:
62
+ return round((80 * retval) - 50, 1)
63
+ elif retval >= 0.0625:
64
+ return round((160 * retval) - 70, 1)
65
+ elif retval >= 0:
66
+ return round((480 * retval) - 90, 1)
67
+ else:
68
+ return -90
69
+
70
+ return wrapper
71
+
72
+
73
+ def db_to(func):
74
+ """fader|level converter for setters"""
75
+
76
+ @functools.wraps(func)
77
+ def wrapper(*args, **kwargs):
78
+ param, val = args
79
+ if val >= 10:
80
+ val = 1
81
+ elif val >= -10:
82
+ val = (val + 30) / 40
83
+ elif val >= -30:
84
+ val = (val + 50) / 80
85
+ elif val >= -60:
86
+ val = (val + 70) / 160
87
+ elif val >= -90:
88
+ val = (val + 90) / 480
89
+ else:
90
+ val = 0
91
+
92
+ func(param, val, **kwargs)
93
+
94
+ return wrapper