3 from __future__ import print_function
4 name_base = 'org.jackaudio'
5 control_interface_name = name_base + '.JackControl'
6 configure_interface_name = name_base + '.Configure'
7 service_name = name_base + '.service'
11 from traceback import print_exc
15 def bool_convert(str_value):
16 if str_value.lower() == "false":
19 if str_value.lower() == "off":
22 if str_value.lower() == "no":
28 if str_value.lower() == "(null)":
31 return bool(str_value)
33 def dbus_type_to_python_type(dbus_value):
34 if type(dbus_value) == dbus.Boolean:
35 return bool(dbus_value)
36 if type(dbus_value) == dbus.Int32 or type(dbus_value) == dbus.UInt32:
37 return int(dbus_value)
40 def python_type_to_jackdbus_type(value, type_char):
41 type_char = str(type_char)
44 return bool_convert(value);
45 elif type_char == "y":
46 return dbus.Byte(ord(value));
47 elif type_char == "i":
48 return dbus.Int32(value)
49 elif type_char == "u":
50 return dbus.UInt32(value)
54 def dbus_type_to_type_string(dbus_value):
55 if type(dbus_value) == dbus.Boolean:
57 if type(dbus_value) == dbus.Int32:
59 if type(dbus_value) == dbus.UInt32:
61 if type(dbus_value) == dbus.Byte:
63 if type(dbus_value) == dbus.String:
66 return None # throw exception here?
68 def dbus_typesig_to_type_string(type_char):
69 type_char = str(type_char)
82 return None # throw exception here?
84 def get_parameters(iface, path):
85 params = iface.GetParametersInfo(path)
89 typestr = dbus_typesig_to_type_string(param[0])
94 isset, default, value = iface.GetParameterValue(path + [name])
100 value = dbus_type_to_python_type(value)
101 default = dbus_type_to_python_type(default)
103 print("%20s: %s (%s:%s:%s:%s)" %(name, descr, typestr, isset, default, value))
106 print("Usage: %s [command] [command] ..." % os.path.basename(sys.argv[0]))
108 print(" exit - exit jack dbus service (stops jack server if currently running)")
109 print(" help - print this help text")
110 print(" status - check whether jack server is started, return value is 0 if running and 1 otherwise")
111 print(" start - start jack server if not currently started")
112 print(" stop - stop jack server if currently started")
113 print(" sm - switch master to currently selected driver")
114 print(" dl - get list of available drivers")
115 print(" dg - get currently selected driver")
116 print(" ds <driver> - select driver")
117 print(" dp - get parameters of currently selected driver")
118 print(" dpd <param> - get long description for driver parameter")
119 print(" dps <param> <value> - set driver parameter")
120 print(" dpr <param> - reset driver parameter to its default value")
121 print(" asd <driver> - add slave driver")
122 print(" rsd <driver> - remove slave driver")
123 print(" il - get list of available internals")
124 print(" ip <name> - get parameters of given internal")
125 print(" ipd <name> <param> - get long description for internal parameter")
126 print(" ips <name> <param> <value> - set internal parameter")
127 print(" ipr <name> <param> - reset internal parameter to its default value")
128 print(" iload <name> - load internal")
129 print(" iunload <name> - unload internal")
130 print(" ep - get engine parameters")
131 print(" epd <param> - get long description for engine parameter")
132 print(" eps <param> <value> - set engine parameter")
133 print(" epr <param> - reset engine parameter to its default value")
135 def maybe_print_param_constraint(iface, param):
136 is_range, is_strict, is_fake, values = iface.GetParameterConstraint(param)
139 print(("allowed range: %s to %s (inclusive)" % (values[0][0], values[1][0])))
143 print("allowed values:")
145 print("suggested values:")
149 if len(str(value[0])) > max_len:
150 max_len = len(str(value[0]))
152 print(("%*s'%s' - %s" % (1 + max_len - len(str(value[0])), "", str(value[0]), str(value[1]))))
155 if len(sys.argv) == 1 or sys.argv[1] in ["-h", "--help", "help"]:
159 bus = dbus.SessionBus()
161 controller = bus.get_object(service_name, "/org/jackaudio/Controller")
162 control_iface = dbus.Interface(controller, control_interface_name)
163 configure_iface = dbus.Interface(controller, configure_interface_name)
167 while index < len(sys.argv):
168 arg = sys.argv[index]
174 elif arg == "status":
176 if control_iface.IsStarted():
184 control_iface.StartServer()
187 control_iface.StopServer()
189 print("--- switch master driver")
190 control_iface.SwitchMaster()
192 if control_iface.IsManuallyActivated():
193 print("Manually activated")
195 print("Automatically activated")
197 print("--- drivers list")
198 is_range, is_strict, is_fake_values, values = configure_iface.GetParameterConstraint(['engine', 'driver'])
202 print("--- get selected driver")
203 isset, default, value = configure_iface.GetParameterValue(['engine', 'driver'])
206 if index >= len(sys.argv):
207 print("driver select command requires driver name argument")
210 arg = sys.argv[index]
213 print("--- driver select \"%s\"" % arg)
214 configure_iface.SetParameterValue(['engine', 'driver'], dbus.String(arg))
216 print("--- get driver parameters (type:isset:default:value)")
217 get_parameters(configure_iface, ['driver'])
219 if index >= len(sys.argv):
220 print("get driver parameter long description command requires parameter name argument")
223 param = sys.argv[index]
226 print("--- get driver parameter description (%s)" % param)
227 type_char, name, short_descr, long_descr = configure_iface.GetParameterInfo(['driver', param])
229 maybe_print_param_constraint(configure_iface, ['driver', param])
231 if index + 1 >= len(sys.argv):
232 print("driver parameter set command requires parameter name and value arguments")
235 param = sys.argv[index]
237 value = sys.argv[index]
240 print("--- driver param set \"%s\" -> \"%s\"" % (param, value))
242 type_char, name, short_descr, long_descr = configure_iface.GetParameterInfo(['driver', param])
243 configure_iface.SetParameterValue(['driver', param], python_type_to_jackdbus_type(value, type_char))
245 if index >= len(sys.argv):
246 print("driver parameter reset command requires parameter name argument")
249 param = sys.argv[index]
252 print("--- driver param reset \"%s\"" % param)
253 configure_iface.ResetParameterValue(['driver', param])
255 print("--- get engine parameters (type:isset:default:value)")
256 get_parameters(configure_iface, ['engine'])
258 if index >= len(sys.argv):
259 print("get engine parameter long description command requires parameter name argument")
262 param_name = sys.argv[index]
265 print("--- get engine parameter description (%s)" % param_name)
267 type_char, name, short_descr, long_descr = configure_iface.GetParameterInfo(['engine', param_name])
269 maybe_print_param_constraint(configure_iface, ['engine', param_name])
271 if index + 1 >= len(sys.argv):
272 print("engine parameter set command requires parameter name and value arguments")
275 param = sys.argv[index]
277 value = sys.argv[index]
280 print("--- engine param set \"%s\" -> \"%s\"" % (param, value))
282 type_char, name, short_descr, long_descr = configure_iface.GetParameterInfo(['engine', param])
283 configure_iface.SetParameterValue(['engine', param], python_type_to_jackdbus_type(value, type_char))
285 if index >= len(sys.argv):
286 print("engine parameter reset command requires parameter name")
289 param = sys.argv[index]
292 print("--- engine param reset \"%s\"" % param)
294 type_char, name, short_descr, long_descr = configure_iface.GetParameterInfo(['engine', param])
295 configure_iface.ResetParameterValue(['engine', param])
297 print("--- internals list")
298 is_leaf, internals = configure_iface.ReadContainer(['internals'])
299 for internal in internals:
302 print("--- get internal parameters (type:isset:default:value)")
304 if index >= len(sys.argv):
305 print("internal parameters command requires internal name argument")
308 internal_name = sys.argv[index]
311 get_parameters(configure_iface, ['internals', internal_name])
313 if index + 1 >= len(sys.argv):
314 print("get internal parameter long description command requires internal and parameter name arguments")
317 name = sys.argv[index]
319 param = sys.argv[index]
322 print("--- get internal parameter description (%s)" % param)
323 type_char, name, short_descr, long_descr = configure_iface.GetParameterInfo(['internals', name, param])
326 if index + 2 >= len(sys.argv):
327 print("internal parameter set command requires internal, parameter name and value arguments")
330 internal_name = sys.argv[index]
332 param = sys.argv[index]
334 value = sys.argv[index]
337 print("--- internal param set \"%s\" -> \"%s\"" % (param, value))
339 type_char, name, short_descr, long_descr = configure_iface.GetParameterInfo(['internals', internal_name, param])
340 configure_iface.SetParameterValue(['internals', internal_name, param], python_type_to_jackdbus_type(value, type_char))
342 if index + 1 >= len(sys.argv):
343 print("reset internal parameter command requires internal and parameter name arguments")
346 internal_name = sys.argv[index]
348 param = sys.argv[index]
351 print("--- internal param reset \"%s\"" % param)
353 configure_iface.ResetParameterValue(['internals', internal_name, param])
355 print("--- load internal")
357 if index >= len(sys.argv):
358 print("load internal command requires internal name argument")
361 name = sys.argv[index]
363 result = control_iface.LoadInternal(name)
364 elif arg == 'iunload':
365 print("--- unload internal")
367 if index >= len(sys.argv):
368 print("unload internal command requires internal name argument")
371 name = sys.argv[index]
373 result = control_iface.UnloadInternal(name)
375 print("--- add slave driver")
377 if index >= len(sys.argv):
378 print("add slave driver command requires driver name argument")
381 name = sys.argv[index]
383 result = control_iface.AddSlaveDriver(name)
385 print("--- remove slave driver")
387 if index >= len(sys.argv):
388 print("remove slave driver command requires driver name argument")
391 name = sys.argv[index]
393 result = control_iface.RemoveSlaveDriver(name)
395 print("Unknown command '%s'" % arg)
396 except dbus.DBusException as e:
397 print("DBus exception: %s" % str(e))
402 if __name__ == '__main__':