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/>.
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
)
41 class JackController(LadiController
):
42 """Wrapper for controlling and monitoring JACK.
44 This class provides an (almost) complete control on configured JACK servers.
47 LadiController
.__init
__(self
,
48 dbus_type
='SessionBus',
49 service_name
=service_name
,
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
)
60 def is_realtime (self
):
61 return self
.controller_iface
.IsRealtime ()
64 return self
.controller_iface
.GetLoad ()
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 ()
79 self
.controller_iface
.StartServer ()
82 self
.controller_iface
.StopServer ()
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.
92 def __init__(self
, jack
, path
):
101 return self
._jack
.get_param_type(self
.path
)
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
)
118 descr
= self
.get_short_description()
122 return self
._jack
.param_has_range(self
.path
)
125 return self
._jack
.param_get_range(self
.path
)
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.
145 LadiController
.__init
__(self
,
146 dbus_type
='SessionBus',
147 service_name
=service_name
,
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'])
158 def read_container (self
, path
):
159 is_leaf
, children
= self
.controller_iface
.ReadContainer (path
)
164 def get_param_names (self
, path
):
165 is_leaf
, children
= self
.controller_iface
.ReadContainer (path
)
170 def get_param_short_description (self
, path
):
171 type_char
, name
, short_descr
, long_descr
= self
.controller_iface
.GetParameterInfo (path
)
174 def get_param_long_description (self
, path
):
175 type_char
, name
, short_descr
, long_descr
= self
.controller_iface
.GetParameterInfo (path
)
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
)
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
)
192 value
= dbus
.Boolean (value
)
194 value
= dbus
.Byte (value
)
196 value
= dbus
.Int32 (value
)
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:
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
)
222 def param_is_fake_value (self
, path
):
223 is_range
, is_strict
, is_fake_value
, values
= self
.controller_iface
.GetParameterConstraint (path
)
226 def param_get_enum_values (self
, path
):
227 is_range
, is_strict
, is_fake_value
, dbus_values
= self
.controller_iface
.GetParameterConstraint (path
)
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])])