Revert "Import translations from Launchpad.", imported into the wrong branch
[laditools.git] / laditools / jack.py
blobccfad74b89b4dae48d09abdb4c0eeefb731870b6
1 #!/usr/bin/python
2 # LADITools - Linux Audio Desktop Integration Tools
3 # Copyright (C) 2011-2012 Alessio Treglia <quadrispro@ubuntu.com>
4 # Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
5 # Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 import sys
21 import dbus
22 from .controller import LadiController
24 name_base = 'org.jackaudio'
25 ctrl_iface_name = name_base + '.JackControl'
26 conf_iface_name = name_base + '.Configure'
27 service_name = name_base + '.service'
28 obj_path = '/org/jackaudio/Controller'
30 def _dbus_type_to_python_type (dbus_value):
31 if type (dbus_value) == dbus.Boolean:
32 return bool(dbus_value)
33 if type (dbus_value) == dbus.Int32 or type (dbus_value) == dbus.UInt32:
34 return int(dbus_value)
35 if type (dbus_value) == dbus.String:
36 return str(dbus_value)
37 if type (dbus_value) == dbus.Byte:
38 return str (dbus_value)
39 return dbus_value
41 class JackController(LadiController):
42 """Wrapper for controlling and monitoring JACK.
44 This class provides an (almost) complete control on configured JACK servers.
45 """
46 def __init__ (self):
47 LadiController.__init__(self,
48 dbus_type='SessionBus',
49 service_name=service_name,
50 obj_path=obj_path,
51 iface_name=ctrl_iface_name)
53 def is_started (self):
54 return self.controller_iface.IsStarted ()
56 def name_owner_changed (name = None, old_owner = None, new_owner = None):
57 sys.stderr.write("Name changed : %r\n" % name)
58 sys.stderr.flush()
60 def is_realtime (self):
61 return self.controller_iface.IsRealtime ()
63 def get_load (self):
64 return self.controller_iface.GetLoad ()
66 def get_xruns (self):
67 return self.controller_iface.GetXruns ()
69 def get_sample_rate (self):
70 return self.controller_iface.GetSampleRate ()
72 def get_latency (self):
73 return self.controller_iface.GetLatency ()
75 def reset_xruns (self):
76 return self.controller_iface.ResetXruns ()
78 def start (self):
79 self.controller_iface.StartServer ()
81 def stop (self):
82 self.controller_iface.StopServer ()
84 def kill (self):
85 self.controller_iface.Exit ()
87 class JackConfigParameter(object):
88 """Wrapper for JACK's parameters.
90 This class provides an (almost) complete control to JACK's configuration parameters.
91 """
92 def __init__(self, jack, path):
93 self._jack = jack
94 self.path = path
95 self.name = path[-1:]
97 def get_name(self):
98 return self.name
100 def get_type(self):
101 return self._jack.get_param_type(self.path)
103 def get_value(self):
104 return self._jack.get_param_value(self.path)
106 def set_value(self, value):
107 self._jack.set_param_value(self.path, value)
109 def reset_value(self):
110 self._jack.reset_param_value(self.path)
112 def get_short_description(self):
113 return self._jack.get_param_short_description(self.path)
115 def get_long_description(self):
116 descr = self._jack.get_param_long_description(self.path)
117 if not descr:
118 descr = self.get_short_description()
119 return descr
121 def has_range(self):
122 return self._jack.param_has_range(self.path)
124 def get_range(self):
125 return self._jack.param_get_range(self.path)
127 def has_enum(self):
128 return self._jack.param_has_enum(self.path)
130 def is_strict_enum(self):
131 return self._jack.param_is_strict_enum(self.path)
133 def is_fake_values_enum(self):
134 return self._jack.param_is_fake_value(self.path)
136 def get_enum_values(self):
137 return self._jack.param_get_enum_values(self.path)
139 class JackConfigProxy(LadiController):
140 """Wrapper for JACK's configuration.
142 This controller provides access to the JACK's whole configuration.
144 def __init__ (self):
145 LadiController.__init__(self,
146 dbus_type='SessionBus',
147 service_name=service_name,
148 obj_path=obj_path,
149 iface_name=conf_iface_name)
151 def name_owner_changed (name = None, old_owner = None, new_owner = None):
152 print "Name changed : %r" % name
154 def get_selected_driver (self):
155 isset, default, value = self.controller_iface.GetParameterValue (['engine', 'driver'])
156 return value
158 def read_container (self, path):
159 is_leaf, children = self.controller_iface.ReadContainer (path)
160 if is_leaf:
161 return []
162 return children
164 def get_param_names (self, path):
165 is_leaf, children = self.controller_iface.ReadContainer (path)
166 if not is_leaf:
167 return []
168 return children
170 def get_param_short_description (self, path):
171 type_char, name, short_descr, long_descr = self.controller_iface.GetParameterInfo (path)
172 return short_descr
174 def get_param_long_description (self, path):
175 type_char, name, short_descr, long_descr = self.controller_iface.GetParameterInfo (path)
176 return long_descr
178 def get_param_type (self, path):
179 type_char, name, short_descr, long_descr = self.controller_iface.GetParameterInfo (path)
180 return str (type_char)
182 def get_param_value (self, path):
183 isset, default, value = self.controller_iface.GetParameterValue (path)
184 isset = bool (isset)
185 default = _dbus_type_to_python_type (default)
186 value = _dbus_type_to_python_type (value)
187 return isset, default, value
189 def set_param_value (self, path, value):
190 typestr = self.get_param_type (path)
191 if typestr == "b":
192 value = dbus.Boolean (value)
193 elif typestr == "y":
194 value = dbus.Byte (value)
195 elif typestr == "i":
196 value = dbus.Int32 (value)
197 elif typestr == "u":
198 value = dbus.UInt32 (value)
199 self.controller_iface.SetParameterValue (path, value)
201 def reset_param_value (self, path):
202 self.controller_iface.ResetParameterValue (path)
204 def param_has_range (self, path):
205 is_range, is_strict, is_fake_value, values = self.controller_iface.GetParameterConstraint (path)
206 return bool (is_range)
208 def param_get_range (self, path):
209 is_range, is_strict, is_fake_value, values = self.controller_iface.GetParameterConstraint (path)
210 if not is_range or len (values) != 2:
211 return -1, -1
212 return _dbus_type_to_python_type (values[0][0]), _dbus_type_to_python_type (values[1][0])
214 def param_has_enum (self, path):
215 is_range, is_strict, is_fake_value, values = self.controller_iface.GetParameterConstraint (path)
216 return not is_range and len (values) != 0
218 def param_is_strict_enum (self, path):
219 is_range, is_strict, is_fake_value, values = self.controller_iface.GetParameterConstraint (path)
220 return is_strict
222 def param_is_fake_value (self, path):
223 is_range, is_strict, is_fake_value, values = self.controller_iface.GetParameterConstraint (path)
224 return is_fake_value
226 def param_get_enum_values (self, path):
227 is_range, is_strict, is_fake_value, dbus_values = self.controller_iface.GetParameterConstraint (path)
228 values = []
230 if not is_range and len (dbus_values) != 0:
231 for dbus_value in dbus_values:
232 values.append ([_dbus_type_to_python_type (dbus_value[0]), _dbus_type_to_python_type (dbus_value[1])])
233 return values