-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixer.py
146 lines (118 loc) · 4.68 KB
/
mixer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
@copyright: 2013 Single D Software - All Rights Reserved
@summary: Provides a mixer API for Mix Maestro.
"""
# Standard library imports
import logging
# Named logger for this module
_logger = logging.getLogger(__name__)
def _getlist(nums):
if type(nums) is str:
return (int(n) for n in nums.split(','))
class Mixer:
"""Abstract class from which all other mixer classes inherit."""
def _updateinput(self, i, params):
self._inputs[i].update(params)
def _updateaux(self, a, params):
self._auxes[a].update(params)
def _updateauxinput(self, a, i, params):
self._inputs[i]['auxes'][a].update(params)
def getstatus(self):
"""
Provide status information for the connection to the mixer.
@return: Dictionary containing status information
"""
return {'condition': 'operational'}
def resetstatus(self):
"""Reset status information for the connection to the mixer."""
pass
def getmixer(self):
"""
Provide all mixer values.
@return: Dictionary containing the entire mixer structure
"""
mixer = {
'inputs': self._inputs,
'returns': self._returns,
'auxes': self._auxes,
'matrices': self._matrices,
'groups': self._groups,
'mains': self._mains,
'settings': self._settings
}
return mixer
def getsettings(self):
"""
Provide mixer settings.
@return: Dictionary containing the mixer settings
"""
return self._settings
def getinputs(self, inums):
"""
Provide information for a set of input channels.
@param inums: String containing a comma-separated list of input identifiers
@return: Dictionary containing the mixer settings
"""
ilist = _getlist(inums) or self._inputs.keys()
return {i: self._inputs[i] for i in ilist}
def getauxes(self, anums):
"""
Provide information for a set of aux channels.
@param anums: String containing a comma-separated list of aux identifiers
@return: Dictionary containing the mixer settings
"""
alist = _getlist(anums) or self._auxes.keys()
return {a: self._auxes[a] for a in alist}
def getauxinputs(self, anum, inums):
"""
Provide information for a set of inputs channels going to an aux channel.
@param anum: Identifies a particular aux channel
@param inums: String containing a comma-separated list of input identifiers
@return: Dictionary containing the mixer settings
"""
ilist = _getlist(inums) or self._inputs.keys()
a = int(anum)
auxinputs = {i: self._inputs[i]['auxes'][a].copy() for i in ilist}
for i, inp in auxinputs.items():
inp['name'] = self._inputs[i].get('name', '')
return {'name': self._auxes[a].get('name', ''), 'inputs': auxinputs}
def setinputs(self, inums, params):
"""
Update information on a set of input channels.
@param inums: String containing a comma-separated list of input identifiers
@param params: Dictionary of data to update
"""
ilist = _getlist(inums) or self._inputs.keys()
for i in ilist:
self._updateinput(i, params)
def setauxes(self, anums, params):
"""
Update information on a set of aux channels.
@param anums: String containing a comma-separated list of aux identifiers
@param params: Dictionary of data to update
"""
alist = _getlist(anums) or self._auxes.keys()
for a in alist:
self._updateaux(a, params)
def setauxinputs(self, anum, inums, params):
"""
Update information on a set of inputs channels for an aux channel.
@param anum: Identifies a particular aux channel
@param inums: String containing a comma-separated list of input identifiers
@param params: Dictionary of data to update
@return: Dictionary containing the mixer settings
"""
ilist = _getlist(inums) or self._inputs.keys()
a = int(anum)
for i in ilist:
self._updateauxinput(a, i, params)
def __init__(self, ids):
self._inputs = {i: {} for i in ids['inputs']}
for i in self._inputs:
self._inputs[i]['auxes'] = {a: {} for a in ids['auxes']}
self._returns = {r: {} for r in ids['returns']}
self._auxes = {a: {} for a in ids['auxes']}
self._matrices = {t: {} for t in ids['matrices']}
self._groups = {g: {} for g in ids['groups']}
self._mains = {m: {} for m in ids['mains']}
self._settings = {}