]> code.delx.au - pulseaudio/blob - src/tests/ladspa-dbus.py
channelmap: Add 2.1 surround
[pulseaudio] / src / tests / ladspa-dbus.py
1 #!/usr/bin/env python
2
3 USAGE = """
4 Usage:
5 python ladspa-dbus.py <sinkname> [values]
6
7 The "sinkname" parameter is the name of the ladspa sink. The "values"
8 parameter is a comma-separated list of ladspa sink parameter values. A
9 value in the list can be either string "default" or a float.
10
11 Example usage:
12
13 python ladspa-dbus.py ladspa_1 10.0,default,4.0,0.6,default
14
15 This command will configure sink "ladspa_1" by setting the first value
16 to 10.0, the second to the default value (specified in the ladspa
17 filter), the third to 4.0 and so on.
18 """
19
20 import dbus
21 import os
22 import sys
23
24 def get_ladspa_property_interface(sinkname):
25
26 # do some D-Bus stuff to get to the real ladspa property object
27 session = dbus.SessionBus()
28
29 # get the private D-Bus socket address from PulseAudio properties
30 session_property_iface = dbus.Interface(session.get_object("org.PulseAudio1", "/org/pulseaudio/server_lookup1"), "org.freedesktop.DBus.Properties")
31 socket = session_property_iface.Get("org.PulseAudio.ServerLookup1", "Address")
32
33 # connect to the private PulseAudio D-Bus socket
34 connection = dbus.connection.Connection(socket)
35
36 # core object for listing the sinks
37 core = connection.get_object(object_path="/org/pulseaudio/core1")
38
39 # object path to the ladspa sink
40 ladspa_sink_path = core.GetSinkByName(sinkname)
41
42 # property interface proxy for the sink
43 ladspa_sink_property_iface = dbus.Interface(connection.get_object(object_path=ladspa_sink_path), "org.freedesktop.DBus.Properties")
44
45 return ladspa_sink_property_iface
46
47 def parse_arguments(args):
48
49 sinkname = None
50 arguments = []
51 defaults = []
52
53 if len(args) >= 2:
54 sinkname = args[1]
55
56 if len(args) == 3:
57 tokens = args[2].split(",")
58
59 for token in tokens:
60 if token == "default":
61 arguments.append(0.0)
62 defaults.append(True)
63 else:
64 arguments.append(float(token))
65 defaults.append(False)
66
67 """
68 print("Input arguments:")
69 print(" sink: " + sink)
70 print(" arguments: " + str(arguments))
71 print(" defaults: " + str(defaults))
72 """
73
74 return sinkname, arguments, defaults
75
76 def print_arguments(arguments, defaults):
77 for i in range(len(arguments)):
78 default = ""
79 if defaults[i]:
80 default = "default"
81 print(str(i) + " : " + str(arguments[i]) + " \t" + default)
82
83
84 sinkname, arguments, defaults = parse_arguments(sys.argv)
85
86 if sinkname == None:
87 print USAGE
88 sys.exit(1)
89
90 # get the D-Bus property interface of the sink
91 ladspa = get_ladspa_property_interface(sinkname)
92
93 # read the current sink arguments from PulseAudio
94 oldarguments, olddefaults = ladspa.Get("org.PulseAudio.Ext.Ladspa1", "AlgorithmParameters")
95
96 print("Current LADSPA parameters for sink " + sinkname + ":")
97 print_arguments(oldarguments, olddefaults)
98
99 if len(arguments) != 0:
100 # set new arguments if they were provided on the command line
101
102 # Set the arguments ...
103 ladspa.Set("org.PulseAudio.Ext.Ladspa1", "AlgorithmParameters", (dbus.Array(arguments), dbus.Array(defaults)))
104
105 # ... and read them back.
106 newarguments, newdefaults = ladspa.Get("org.PulseAudio.Ext.Ladspa1", "AlgorithmParameters")
107
108 print("New LADSPA parameters for sink " + sinkname + ":")
109 print_arguments(newarguments, newdefaults)
110
111 # test the GetAll functionality
112 # print(str(ladspa.GetAll("org.PulseAudio.Ext.Ladspa1")))