2 # -*- coding: utf-8 -*-
4 # -------------------------------------------------------------------------------
12 LADSPA_Property
= c_int
13 LADSPA_PluginType
= c_ulonglong
17 LADSPA_UNIT_COEF
= 0x02
21 LADSPA_UNIT_MIN
= 0x20
23 LADSPA_UNIT_CLASS_AMPLITUDE
= LADSPA_UNIT_DB|LADSPA_UNIT_COEF
24 LADSPA_UNIT_CLASS_FREQUENCY
= LADSPA_UNIT_HZ
25 LADSPA_UNIT_CLASS_TIME
= LADSPA_UNIT_S|LADSPA_UNIT_MS|LADSPA_UNIT_MIN
27 # Port Types (Official API)
28 LADSPA_PORT_INPUT
= 0x1
29 LADSPA_PORT_OUTPUT
= 0x2
30 LADSPA_PORT_CONTROL
= 0x4
31 LADSPA_PORT_AUDIO
= 0x8
34 LADSPA_PORT_UNIT
= 0x1
35 LADSPA_PORT_DEFAULT
= 0x2
36 LADSPA_PORT_LABEL
= 0x4
39 LADSPA_CLASS_UTILITY
= 0x000000001
40 LADSPA_CLASS_GENERATOR
= 0x000000002
41 LADSPA_CLASS_SIMULATOR
= 0x000000004
42 LADSPA_CLASS_OSCILLATOR
= 0x000000008
43 LADSPA_CLASS_TIME
= 0x000000010
44 LADSPA_CLASS_DELAY
= 0x000000020
45 LADSPA_CLASS_PHASER
= 0x000000040
46 LADSPA_CLASS_FLANGER
= 0x000000080
47 LADSPA_CLASS_CHORUS
= 0x000000100
48 LADSPA_CLASS_REVERB
= 0x000000200
49 LADSPA_CLASS_FREQUENCY
= 0x000000400
50 LADSPA_CLASS_FREQUENCY_METER
= 0x000000800
51 LADSPA_CLASS_FILTER
= 0x000001000
52 LADSPA_CLASS_LOWPASS
= 0x000002000
53 LADSPA_CLASS_HIGHPASS
= 0x000004000
54 LADSPA_CLASS_BANDPASS
= 0x000008000
55 LADSPA_CLASS_COMB
= 0x000010000
56 LADSPA_CLASS_ALLPASS
= 0x000020000
57 LADSPA_CLASS_EQ
= 0x000040000
58 LADSPA_CLASS_PARAEQ
= 0x000080000
59 LADSPA_CLASS_MULTIEQ
= 0x000100000
60 LADSPA_CLASS_AMPLITUDE
= 0x000200000
61 LADSPA_CLASS_PITCH
= 0x000400000
62 LADSPA_CLASS_AMPLIFIER
= 0x000800000
63 LADSPA_CLASS_WAVESHAPER
= 0x001000000
64 LADSPA_CLASS_MODULATOR
= 0x002000000
65 LADSPA_CLASS_DISTORTION
= 0x004000000
66 LADSPA_CLASS_DYNAMICS
= 0x008000000
67 LADSPA_CLASS_COMPRESSOR
= 0x010000000
68 LADSPA_CLASS_EXPANDER
= 0x020000000
69 LADSPA_CLASS_LIMITER
= 0x040000000
70 LADSPA_CLASS_GATE
= 0x080000000
71 LADSPA_CLASS_SPECTRAL
= 0x100000000
72 LADSPA_CLASS_NOTCH
= 0x200000000
74 LADSPA_GROUP_DYNAMICS
= LADSPA_CLASS_DYNAMICS|LADSPA_CLASS_COMPRESSOR|LADSPA_CLASS_EXPANDER|LADSPA_CLASS_LIMITER|LADSPA_CLASS_GATE
75 LADSPA_GROUP_AMPLITUDE
= LADSPA_CLASS_AMPLITUDE|LADSPA_CLASS_AMPLIFIER|LADSPA_CLASS_WAVESHAPER|LADSPA_CLASS_MODULATOR|LADSPA_CLASS_DISTORTION|LADSPA_GROUP_DYNAMICS
76 LADSPA_GROUP_EQ
= LADSPA_CLASS_EQ|LADSPA_CLASS_PARAEQ|LADSPA_CLASS_MULTIEQ
77 LADSPA_GROUP_FILTER
= LADSPA_CLASS_FILTER|LADSPA_CLASS_LOWPASS|LADSPA_CLASS_HIGHPASS|LADSPA_CLASS_BANDPASS|LADSPA_CLASS_COMB|LADSPA_CLASS_ALLPASS|LADSPA_CLASS_NOTCH
78 LADSPA_GROUP_FREQUENCY
= LADSPA_CLASS_FREQUENCY|LADSPA_CLASS_FREQUENCY_METER|LADSPA_GROUP_FILTER|LADSPA_GROUP_EQ|LADSPA_CLASS_PITCH
79 LADSPA_GROUP_SIMULATOR
= LADSPA_CLASS_SIMULATOR|LADSPA_CLASS_REVERB
80 LADSPA_GROUP_TIME
= LADSPA_CLASS_TIME|LADSPA_CLASS_DELAY|LADSPA_CLASS_PHASER|LADSPA_CLASS_FLANGER|LADSPA_CLASS_CHORUS|LADSPA_CLASS_REVERB
81 LADSPA_GROUP_GENERATOR
= LADSPA_CLASS_GENERATOR|LADSPA_CLASS_OSCILLATOR
84 LADSPA_PLUGIN_CREATOR
= 0x1
85 LADSPA_PLUGIN_TITLE
= 0x2
86 LADSPA_PLUGIN_RIGHTS
= 0x4
89 class LADSPA_RDF_ScalePoint(Structure
):
91 ("Value", LADSPA_Data
),
96 class LADSPA_RDF_Port(Structure
):
98 ("Type", LADSPA_Property
),
99 ("Hints", LADSPA_Property
),
100 ("Unit", LADSPA_Property
),
101 ("Default", LADSPA_Data
),
104 ("ScalePointCount", c_ulong
),
105 ("ScalePoints", POINTER(LADSPA_RDF_ScalePoint
))
108 # The actual plugin descriptor
109 class LADSPA_RDF_Descriptor(Structure
):
111 ("Type", LADSPA_PluginType
),
112 ("Hints", LADSPA_Property
),
113 ("UniqueID", c_ulong
),
114 ("Creator", c_char_p
),
116 ("Rights", c_char_p
),
118 ("PortCount", c_ulong
),
119 ("Ports", POINTER(LADSPA_RDF_Port
))
122 # -------------------------------------------------------------------------------
123 # Python compatible C types
125 PyLADSPA_RDF_ScalePoint
= {
130 PyLADSPA_RDF_Port
= {
137 'ScalePointCount': 0,
140 # Only here to help, NOT in the API:
144 PyLADSPA_RDF_Descriptor
= {
156 # -------------------------------------------------------------------------------
157 # RDF data and conversions
159 # Prefixes (sorted alphabetically and by type)
162 'dc': "http://purl.org/dc/elements/1.1/",
163 'rdf': "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
164 'rdfs': "http://www.w3.org/2000/01/rdf-schema#",
167 'dc:creator': "http://purl.org/dc/elements/1.1/creator",
168 'dc:rights': "http://purl.org/dc/elements/1.1/rights",
169 'dc:title': "http://purl.org/dc/elements/1.1/title",
170 'rdf:value': "http://www.w3.org/1999/02/22-rdf-syntax-ns#value",
171 'rdf:type': "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
174 'ladspa': "http://ladspa.org/ontology#",
175 'ladspa:forPort': "http://ladspa.org/ontology#forPort",
176 'ladspa:hasLabel': "http://ladspa.org/ontology#hasLabel",
177 'ladspa:hasPoint': "http://ladspa.org/ontology#hasPoint",
178 'ladspa:hasPort': "http://ladspa.org/ontology#hasPort",
179 'ladspa:hasPortValue': "http://ladspa.org/ontology#hasPortValue",
180 'ladspa:hasScale': "http://ladspa.org/ontology#hasScale",
181 'ladspa:hasSetting': "http://ladspa.org/ontology#hasSetting",
182 'ladspa:hasUnit': "http://ladspa.org/ontology#hasUnit",
183 'ladspa:hasUnits': "http://ladspa.org/ontology#hasUnits",
185 # LADSPA "Extensions"
186 'ladspa:NotchPlugin': "http://ladspa.org/ontology#NotchPlugin",
187 'ladspa:SpectralPlugin': "http://ladspa.org/ontology#SpectralPlugin"
190 def get_c_plugin_class(value
):
191 value_str
= value
.replace(rdf_prefix
['ladspa'],"")
193 if (value_str
== "Plugin"):
195 elif (value_str
== "UtilityPlugin"):
196 return LADSPA_CLASS_UTILITY
197 elif (value_str
== "GeneratorPlugin"):
198 return LADSPA_CLASS_GENERATOR
199 elif (value_str
== "SimulatorPlugin"):
200 return LADSPA_CLASS_SIMULATOR
201 elif (value_str
== "OscillatorPlugin"):
202 return LADSPA_CLASS_OSCILLATOR
203 elif (value_str
== "TimePlugin"):
204 return LADSPA_CLASS_TIME
205 elif (value_str
== "DelayPlugin"):
206 return LADSPA_CLASS_DELAY
207 elif (value_str
== "PhaserPlugin"):
208 return LADSPA_CLASS_PHASER
209 elif (value_str
== "FlangerPlugin"):
210 return LADSPA_CLASS_FLANGER
211 elif (value_str
== "ChorusPlugin"):
212 return LADSPA_CLASS_CHORUS
213 elif (value_str
== "ReverbPlugin"):
214 return LADSPA_CLASS_REVERB
215 elif (value_str
== "FrequencyPlugin"):
216 return LADSPA_CLASS_FREQUENCY
217 elif (value_str
== "FrequencyMeterPlugin"):
218 return LADSPA_CLASS_FREQUENCY_METER
219 elif (value_str
== "FilterPlugin"):
220 return LADSPA_CLASS_FILTER
221 elif (value_str
== "LowpassPlugin"):
222 return LADSPA_CLASS_LOWPASS
223 elif (value_str
== "HighpassPlugin"):
224 return LADSPA_CLASS_HIGHPASS
225 elif (value_str
== "BandpassPlugin"):
226 return LADSPA_CLASS_BANDPASS
227 elif (value_str
== "CombPlugin"):
228 return LADSPA_CLASS_COMB
229 elif (value_str
== "AllpassPlugin"):
230 return LADSPA_CLASS_ALLPASS
231 elif (value_str
in ("EQPlugin", "EqualizerPlugin", "MixerPlugin")):
232 return LADSPA_CLASS_EQ
233 elif (value_str
== "ParaEQPlugin"):
234 return LADSPA_CLASS_PARAEQ
235 elif (value_str
== "MultiEQPlugin"):
236 return LADSPA_CLASS_MULTIEQ
237 elif (value_str
== "AmplitudePlugin"):
238 return LADSPA_CLASS_AMPLITUDE
239 elif (value_str
== "PitchPlugin"):
240 return LADSPA_CLASS_PITCH
241 elif (value_str
== "AmplifierPlugin"):
242 return LADSPA_CLASS_AMPLIFIER
243 elif (value_str
== "WaveshaperPlugin"):
244 return LADSPA_CLASS_WAVESHAPER
245 elif (value_str
in ("ModulatorPlugin", "ModulationPlugin")):
246 return LADSPA_CLASS_MODULATOR
247 elif (value_str
== "DistortionPlugin"):
248 return LADSPA_CLASS_DISTORTION
249 elif (value_str
== "DynamicsPlugin"):
250 return LADSPA_CLASS_DYNAMICS
251 elif (value_str
== "CompressorPlugin"):
252 return LADSPA_CLASS_COMPRESSOR
253 elif (value_str
== "ExpanderPlugin"):
254 return LADSPA_CLASS_EXPANDER
255 elif (value_str
== "LimiterPlugin"):
256 return LADSPA_CLASS_LIMITER
257 elif (value_str
== "GatePlugin"):
258 return LADSPA_CLASS_GATE
259 elif (value_str
== "SpectralPlugin"):
260 return LADSPA_CLASS_SPECTRAL
261 elif (value_str
== "NotchPlugin"):
262 return LADSPA_CLASS_NOTCH
264 print "LADSPA_RDF - Got an unknown plugin type", value_str
267 def get_c_port_type(value
):
268 value_str
= value
.replace(rdf_prefix
['ladspa'],"")
270 if (value_str
== "Port"):
272 elif (value_str
== "ControlPort"):
273 return LADSPA_PORT_CONTROL
274 elif (value_str
== "AudioPort"):
275 return LADSPA_PORT_AUDIO
276 elif (value_str
== "InputPort"):
277 return LADSPA_PORT_INPUT
278 elif (value_str
== "OutputPort"):
279 return LADSPA_PORT_OUTPUT
280 elif (value_str
in ("ControlInputPort", "InputControlPort")):
281 return LADSPA_PORT_CONTROL|LADSPA_PORT_INPUT
282 elif (value_str
in ("ControlOutputPort", "OutputControlPort")):
283 return LADSPA_PORT_CONTROL|LADSPA_PORT_OUTPUT
284 elif (value_str
in ("AudioInputPort", "InputAudioPort")):
285 return LADSPA_PORT_AUDIO|LADSPA_PORT_INPUT
286 elif (value_str
in ("AudioOutputPort", "OutputAudioPort")):
287 return LADSPA_PORT_AUDIO|LADSPA_PORT_OUTPUT
289 print "LADSPA_RDF - Got an unknown port type", value_str
292 def get_c_unit_type(value
):
293 value_str
= value
.replace(rdf_prefix
['ladspa'],"")
295 if (value_str
in ("Unit", "Units", "AmplitudeUnits", "FrequencyUnits", "TimeUnits")):
297 elif (value_str
== "dB"):
298 return LADSPA_UNIT_DB
299 elif (value_str
== "coef"):
300 return LADSPA_UNIT_COEF
301 elif (value_str
== "Hz"):
302 return LADSPA_UNIT_HZ
303 elif (value_str
== "seconds"):
305 elif (value_str
== "milliseconds"):
306 return LADSPA_UNIT_MS
307 elif (value_str
== "minutes"):
308 return LADSPA_UNIT_MIN
310 print "LADSPA_RDF - Got an unknown unit type", value_str
313 # -------------------------------------------------------------------------------
314 # RDF query for LADSPA
318 from copy
import deepcopy
321 global LADSPA_RDF_PATH
, LADSPA_Plugins
324 LADSPA_RDF_PATH
= ["/usr/share/ladspa/rdf", "/usr/local/share/ladspa/rdf"]
326 LADSPA_RDF_TYPE_PLUGIN
= 1
327 LADSPA_RDF_TYPE_PORT
= 2
329 # Set LADSPA_RDF_PATH variable
330 def set_rdf_path(PATH
):
331 global LADSPA_RDF_PATH
332 LADSPA_RDF_PATH
= PATH
334 def to_float(string
):
335 return float(str(string
).replace("f",""))
337 # Convert RDF LADSPA Type into a number
338 def to_plugin_number(rdf_type
):
339 return str(rdf_type
).replace(rdf_prefix
['ladspa'],"")
341 # Convert RDF LADSPA Type into 2 numbers
342 def to_plugin_numbers(rdf_type
):
343 numbers
= str(rdf_type
).replace(rdf_prefix
['ladspa'],"").split(".")
344 return (numbers
[0], numbers
[1])
346 # Convert RDF LADSPA Type into a port number
347 def to_plugin_port(rdf_type
):
348 return to_plugin_numbers(rdf_type
)[1]
351 def rdf_is_type(rdf_type
, compare
):
352 if (compare
== LADSPA_RDF_TYPE_PLUGIN
):
353 if (type(rdf_type
) == URIRef
and rdf_prefix
['ladspa'] in rdf_type
and to_plugin_number(rdf_type
).isdigit()):
357 elif (compare
== LADSPA_RDF_TYPE_PORT
):
358 if (type(rdf_type
) == URIRef
and rdf_prefix
['ladspa'] in rdf_type
and "." in to_plugin_number(rdf_type
)):
363 def check_and_add_plugin(plugin_id
):
364 global LADSPA_Plugins
365 for i
in range(len(LADSPA_Plugins
)):
366 if (LADSPA_Plugins
[i
]['UniqueID'] == plugin_id
):
369 plugin
= deepcopy(PyLADSPA_RDF_Descriptor
)
370 plugin
['UniqueID'] = plugin_id
371 LADSPA_Plugins
.append(plugin
)
372 return len(LADSPA_Plugins
)-1
374 def set_plugin_value(plugin_id
, key
, value
):
375 global LADSPA_Plugins
376 index
= check_and_add_plugin(plugin_id
)
377 LADSPA_Plugins
[index
][key
] = value
379 def add_plugin_value(plugin_id
, key
, value
):
380 global LADSPA_Plugins
381 index
= check_and_add_plugin(plugin_id
)
382 LADSPA_Plugins
[index
][key
] += value
384 def or_plugin_value(plugin_id
, key
, value
):
385 global LADSPA_Plugins
386 index
= check_and_add_plugin(plugin_id
)
387 LADSPA_Plugins
[index
][key
] |
= value
389 def append_plugin_value(plugin_id
, key
, value
):
390 global LADSPA_Plugins
391 index
= check_and_add_plugin(plugin_id
)
392 LADSPA_Plugins
[index
][key
].append(value
)
394 def check_and_add_port(plugin_id
, port_id
):
395 global LADSPA_Plugins
396 index
= check_and_add_plugin(plugin_id
)
397 Ports
= LADSPA_Plugins
[index
]['Ports']
398 for i
in range(len(Ports
)):
399 if (Ports
[i
]['index'] == port_id
):
402 pcount
= LADSPA_Plugins
[index
]['PortCount']
403 port
= deepcopy(PyLADSPA_RDF_Port
)
404 port
['index'] = port_id
406 LADSPA_Plugins
[index
]['PortCount'] += 1
407 return (index
, pcount
)
409 def set_port_value(plugin_id
, port_id
, key
, value
):
410 global LADSPA_Plugins
411 i
, j
= check_and_add_port(plugin_id
, port_id
)
412 LADSPA_Plugins
[i
]['Ports'][j
][key
] = value
414 def add_port_value(plugin_id
, port_id
, key
, value
):
415 global LADSPA_Plugins
416 i
, j
= check_and_add_port(plugin_id
, port_id
)
417 LADSPA_Plugins
[i
]['Ports'][j
][key
] += value
419 def or_port_value(plugin_id
, port_id
, key
, value
):
420 global LADSPA_Plugins
421 i
, j
= check_and_add_port(plugin_id
, port_id
)
422 LADSPA_Plugins
[i
]['Ports'][j
][key
] |
= value
424 def append_port_value(plugin_id
, port_id
, key
, value
):
425 global LADSPA_Plugins
426 i
, j
= check_and_add_port(plugin_id
, port_id
)
427 LADSPA_Plugins
[i
]['Ports'][j
][key
].append(value
)
429 def add_scalepoint(plugin_id
, port_id
, value
, label
):
430 global LADSPA_Plugins
431 i
, j
= check_and_add_port(plugin_id
, port_id
)
432 Port
= LADSPA_Plugins
[i
]['Ports'][j
]
433 scalepoint
= deepcopy(PyLADSPA_RDF_ScalePoint
)
434 scalepoint
['Value'] = value
435 scalepoint
['Label'] = label
436 Port
['ScalePoints'].append(scalepoint
)
437 Port
['ScalePointCount'] += 1
439 def set_port_default(plugin_id
, port_id
, value
):
440 global LADSPA_Plugins
441 i
, j
= check_and_add_port(plugin_id
, port_id
)
442 Port
= LADSPA_Plugins
[i
]['Ports'][j
]
443 Port
['Default'] = value
444 Port
['Hints'] |
= LADSPA_PORT_DEFAULT
446 def get_node_values(value_nodes
, node_index
):
448 for node
in value_nodes
:
449 index
, uri
, value
= node
450 if (node_index
== index
):
451 ret_nodes
.append((uri
, value
))
454 # -------------------------------------------------------------------------------
455 # RDF sort data methods
457 # Fully parse rdf file
458 def parse_rdf_file(filename
):
459 primer
= ConjunctiveGraph()
462 primer
.parse(filename
, format
='xml')
463 rdf_list
= [(x
, y
, z
) for x
, y
, z
in primer
]
468 index_nodes
= [] # index, URI, Plugin, Port
469 value_nodes
= [] # index, URI, Value
471 for i
in range(len(rdf_list
)):
472 rdf_type
= rdf_list
[i
][0]
473 rdf_uri
= rdf_list
[i
][1]
474 rdf_value
= rdf_list
[i
][2]
476 if (rdf_is_type(rdf_type
, LADSPA_RDF_TYPE_PLUGIN
)):
477 plugin_id
= long(to_plugin_number(rdf_type
))
479 if (rdf_uri
== URIRef(rdf_prefix
['dc:creator'])):
480 set_plugin_value(plugin_id
, 'Creator', str(rdf_value
))
481 or_plugin_value(plugin_id
, 'Hints', LADSPA_PLUGIN_CREATOR
)
483 elif (rdf_uri
== URIRef(rdf_prefix
['dc:rights'])):
484 set_plugin_value(plugin_id
, 'Rights', str(rdf_value
))
485 or_plugin_value(plugin_id
, 'Hints', LADSPA_PLUGIN_RIGHTS
)
487 elif (rdf_uri
== URIRef(rdf_prefix
['dc:title'])):
488 set_plugin_value(plugin_id
, 'Title', str(rdf_value
))
489 or_plugin_value(plugin_id
, 'Hints', LADSPA_PLUGIN_TITLE
)
491 elif (rdf_uri
== URIRef(rdf_prefix
['rdf:type'])):
492 c_class
= get_c_plugin_class(str(rdf_value
))
493 or_plugin_value(plugin_id
, 'Type', c_class
)
495 elif (rdf_uri
== URIRef(rdf_prefix
['ladspa:hasPort'])):
496 pass # No useful information here
498 elif (rdf_uri
== URIRef(rdf_prefix
['ladspa:hasSetting'])):
499 index_nodes
.append((rdf_value
, rdf_uri
, plugin_id
, None))
502 print "LADSPA_RDF - Plugin URI", rdf_uri
, "not handled"
504 elif (rdf_is_type(rdf_type
, LADSPA_RDF_TYPE_PORT
)):
505 plugin_port
= to_plugin_numbers(rdf_type
)
506 plugin_id
= int(plugin_port
[0])
507 port_id
= int(plugin_port
[1])
509 if (rdf_uri
== URIRef(rdf_prefix
['rdf:type'])):
510 c_class
= get_c_port_type(str(rdf_value
))
511 or_port_value(plugin_id
, port_id
, 'Type', c_class
)
513 elif (rdf_uri
== URIRef(rdf_prefix
['ladspa:hasLabel'])):
514 set_port_value(plugin_id
, port_id
, 'Label', str(rdf_value
))
515 or_port_value(plugin_id
, port_id
, 'Hints', LADSPA_PORT_LABEL
)
517 elif (rdf_uri
== URIRef(rdf_prefix
['ladspa:hasScale'])):
518 index_nodes
.append((rdf_value
, rdf_uri
, plugin_id
, port_id
))
520 elif (rdf_uri
in (URIRef(rdf_prefix
['ladspa:hasUnit']), URIRef(rdf_prefix
['ladspa:hasUnits']))):
521 c_unit
= get_c_unit_type(str(rdf_value
))
522 set_port_value(plugin_id
, port_id
, 'Unit', c_unit
)
523 or_port_value(plugin_id
, port_id
, 'Hints', LADSPA_PORT_UNIT
)
526 print "LADSPA_RDF - Port URI", rdf_uri
, "not handled"
528 elif (rdf_type
in (URIRef(rdf_prefix
['ladspa:NotchPlugin']), URIRef(rdf_prefix
['ladspa:SpectralPlugin']))):
529 pass # These "extensions" are already implemented
531 elif (type(rdf_type
) == BNode
):
532 value_nodes
.append((rdf_type
, rdf_uri
, rdf_value
))
535 print "LADSPA_RDF - Unknown URI Type", rdf_type
537 # Parse BNodes, indexes
538 bnodes_data_dump
= []
540 for i
in range(len(index_nodes
)):
541 node_index
= index_nodes
[i
][0]
542 node_uri
= index_nodes
[i
][1]
543 plugin_id
= index_nodes
[i
][2]
544 port_id
= index_nodes
[i
][3]
546 node_values
= get_node_values(value_nodes
, node_index
)
548 for j
in range(len(node_values
)):
549 subnode_uri
= node_values
[j
][0]
550 subnode_index
= node_values
[j
][1]
552 subnode_values
= get_node_values(value_nodes
, subnode_index
)
554 for k
in range(len(subnode_values
)):
555 real_uri
= subnode_values
[k
][0]
556 real_value
= subnode_values
[k
][1]
558 if (node_uri
== URIRef(rdf_prefix
['ladspa:hasScale']) and subnode_uri
== URIRef(rdf_prefix
['ladspa:hasPoint'])):
559 bnodes_data_dump
.append(("scalepoint", subnode_index
, plugin_id
, port_id
, real_uri
, real_value
))
560 elif (node_uri
== URIRef(rdf_prefix
['ladspa:hasSetting']) and subnode_uri
== URIRef(rdf_prefix
['ladspa:hasPortValue'])):
561 # FIXME - needs another check for 'default'
562 bnodes_data_dump
.append(("port_default", subnode_index
, plugin_id
, port_id
, real_uri
, real_value
))
564 print "LADSPA_RDF - Unknown SubNode Combo", node_uri
, subnode_uri
566 # Process BNodes, values
570 for i
in range(len(bnodes_data_dump
)):
571 node_type
= bnodes_data_dump
[i
][0]
572 node_index
= bnodes_data_dump
[i
][1]
573 node_plugin
= bnodes_data_dump
[i
][2]
574 node_port
= bnodes_data_dump
[i
][3]
575 node_vtype
= bnodes_data_dump
[i
][4]
576 node_value
= bnodes_data_dump
[i
][5]
578 if (node_type
== "scalepoint"):
579 for j
in range(len(scalepoints
)):
580 if (scalepoints
[j
][0] == node_index
):
584 scalepoints
.append([node_index
, node_plugin
, node_port
, None, None])
585 index
= len(scalepoints
)-1
587 if (node_vtype
== URIRef(rdf_prefix
['rdf:value'])):
588 scalepoints
[index
][3] = to_float(node_value
)
589 elif (node_vtype
== URIRef(rdf_prefix
['ladspa:hasLabel'])):
590 scalepoints
[index
][4] = str(node_value
)
592 elif (node_type
== "port_default"):
593 for j
in range(len(port_defaults
)):
594 if (port_defaults
[j
][0] == node_index
):
598 port_defaults
.append([node_index
, node_plugin
, None, None])
599 index
= len(port_defaults
)-1
601 if (node_vtype
== URIRef(rdf_prefix
['rdf:value'])):
602 port_defaults
[index
][3] = to_float(node_value
)
603 elif (node_vtype
== URIRef(rdf_prefix
['ladspa:forPort'])):
604 port_defaults
[index
][2] = int(to_plugin_port(node_value
))
606 # Now add the last information
607 for scalepoint
in scalepoints
:
608 index
, plugin_id
, port_id
, value
, label
= scalepoint
609 add_scalepoint(plugin_id
, port_id
, value
, label
)
611 for port_default
in port_defaults
:
612 index
, plugin_id
, port_id
, value
= port_default
613 set_port_default(plugin_id
, port_id
, value
)
615 def append_and_sort(value
, vlist
):
616 if (len(vlist
) == 0):
618 elif (value
< vlist
[0]):
619 vlist
.insert(0, value
)
620 elif (value
> vlist
[len(vlist
)-1]):
623 for i
in range(len(vlist
)):
624 if (value
< vlist
[i
]):
625 vlist
.insert(i
, value
)
628 print "LADSPA_RDF - CRITICAL ERROR #001"
632 def get_value_index(value
, vlist
):
633 for i
in range(len(vlist
)):
634 if (vlist
[i
] == value
):
637 print "LADSPA_RDF - CRITICAL ERROR #002"
640 # Sort the plugin's port's ScalePoints by value
641 def SORT_PyLADSPA_RDF_ScalePoints(old_dict_list
):
645 for i
in range(len(old_dict_list
)):
646 new_dict_list
.append(deepcopy(PyLADSPA_RDF_ScalePoint
))
647 append_and_sort(old_dict_list
[i
]['Value'], indexes_list
)
649 for i
in range(len(old_dict_list
)):
650 index
= get_value_index(old_dict_list
[i
]['Value'], indexes_list
)
651 new_dict_list
[index
]['Value'] = old_dict_list
[i
]['Value']
652 new_dict_list
[index
]['Label'] = old_dict_list
[i
]['Label']
656 # Sort the plugin's port by index
657 def SORT_PyLADSPA_RDF_Ports(old_dict_list
):
661 for i
in range(len(old_dict_list
)):
662 if (old_dict_list
[i
]['index'] > max_index
):
663 max_index
= old_dict_list
[i
]['index']
665 for i
in range(max_index
+1):
666 new_dict_list
.append(deepcopy(PyLADSPA_RDF_Port
))
668 for i
in range(len(old_dict_list
)):
669 index
= old_dict_list
[i
]['index']
670 new_dict_list
[index
]['index'] = old_dict_list
[i
]['index']
671 new_dict_list
[index
]['Type'] = old_dict_list
[i
]['Type']
672 new_dict_list
[index
]['Hints'] = old_dict_list
[i
]['Hints']
673 new_dict_list
[index
]['Unit'] = old_dict_list
[i
]['Unit']
674 new_dict_list
[index
]['Default'] = old_dict_list
[i
]['Default']
675 new_dict_list
[index
]['Label'] = old_dict_list
[i
]['Label']
676 new_dict_list
[index
]['ScalePointCount'] = old_dict_list
[i
]['ScalePointCount']
677 new_dict_list
[index
]['ScalePoints'] = SORT_PyLADSPA_RDF_ScalePoints(old_dict_list
[i
]['ScalePoints'])
681 # Main function - check all rdfs for information about ladspa plugins
682 def recheck_all_plugins(qobject
=None):
683 global LADSPA_RDF_PATH
, LADSPA_Plugins
686 rdf_extensions
= (".rdf", ".rdF", ".rDF", ".RDF", ".RDf", "Rdf")
689 for PATH
in LADSPA_RDF_PATH
:
690 for root
, dirs
, files
in os
.walk(PATH
):
691 for name
in [name
for name
in files
if name
.endswith(rdf_extensions
)]:
692 rdf_files
.append(os
.path
.join(root
, name
))
694 for i
in range(len(rdf_files
)):
695 rdf_file
= rdf_files
[i
]
697 # Tell GUI we're parsing this bundle
699 percent
= (qobject
.percent_value
* 0.80) + ( (float(i
) / len(rdf_files
) ) * qobject
.percent_value
* 0.20 )
700 qobject
.pluginLook(percent
, rdf_file
)
703 parse_rdf_file(rdf_file
)
705 return LADSPA_Plugins
707 # Convert [PyQt] LADSPA_Plugins into ctype structs
708 def get_c_ladspa_rdfs(PyPluginList
):
709 C_LADSPA_Plugins
= []
711 for plugin
in PyPluginList
:
712 # Sort the ports by index
713 ladspa_ports
= SORT_PyLADSPA_RDF_Ports(plugin
['Ports'])
716 desc
= LADSPA_RDF_Descriptor()
717 desc
.Type
= plugin
['Type']
718 desc
.Hints
= plugin
['Hints']
719 desc
.UniqueID
= plugin
['UniqueID']
722 desc
.Creator
= plugin
['Creator']
724 desc
.Creator
= "(unicode error)"
727 desc
.Title
= plugin
['Title']
729 desc
.Title
= "(unicode error)"
732 desc
.Rights
= plugin
['Rights']
734 desc
.Rights
= "(unicode error)"
736 desc
.PortCount
= plugin
['PortCount']
739 _PortType
= LADSPA_RDF_Port
*desc
.PortCount
740 desc
.Ports
= _PortType()
742 for i
in range(desc
.PortCount
):
743 port
= LADSPA_RDF_Port()
744 py_port
= ladspa_ports
[i
]
746 port
.Type
= py_port
['Type']
747 port
.Hints
= py_port
['Hints']
748 port
.Unit
= py_port
['Unit']
749 port
.Default
= py_port
['Default']
750 port
.Label
= py_port
['Label']
753 port
.ScalePointCount
= py_port
['ScalePointCount']
755 _ScalePointType
= LADSPA_RDF_ScalePoint
*port
.ScalePointCount
756 port
.ScalePoints
= _ScalePointType()
758 for j
in range(port
.ScalePointCount
):
759 scalepoint
= LADSPA_RDF_ScalePoint()
760 py_scalepoint
= py_port
['ScalePoints'][j
]
762 scalepoint
.Label
= py_scalepoint
['Label']
763 scalepoint
.Value
= py_scalepoint
['Value']
765 port
.ScalePoints
[j
] = scalepoint
769 C_LADSPA_Plugins
.append(desc
)
771 return C_LADSPA_Plugins
774 # Implementation test
775 #if __name__ == '__main__':
776 #plugins = recheck_all_plugins()
780 #f = open('ladspa_rdf.dump.txt', 'w')
781 #json.dump(plugins, f)
784 ## Read back from file
785 #fr = open('ladspa_rdf.dump.txt', 'r')
786 #plugins_json = json.load(fr)
788 ## Check if saved stuff is valid (print to std-out)
789 #for plugin in plugins_json:
790 #print "----------------------"
791 #print "Type: ", plugin["Type"]
792 #print "Hints: ", plugin["Hints"]
793 #print "UniqueID: ", plugin["UniqueID"]
794 #print "Creator: ", plugin["Creator"]
795 #print "Title: ", plugin["Title"]
796 #print "Rights: ", plugin["Rights"]
797 #print "Ports: (%i)" % (plugin["PortCount"])
798 #for i in range(plugin["PortCount"]):
799 #port = plugin["Ports"][i]
800 #print " Type: ", port["Type"]
801 #print " Hints: ", port["Hints"]
802 #print " Unit: ", port["Unit"]
803 #print " Default: ", port["Default"]
804 #print " Label: ", port["Label"]
805 #print " ScalePoints: (%i)" % (port["ScalePointCount"])
806 #for j in range(port["ScalePointCount"]):
807 #scalepoint = port["ScalePoints"][j]
808 #print " Value: ", scalepoint["Value"]
809 #print " Label: ", scalepoint["Label"]