Translation =========== This example shows how to translate Pure Data files. For example, from the `.pd` format to other formats such as * `JSON `_ * `Pickle `_ * `XML `_ .. note:: There is a convenience script for this purpose, see ``scripts/translate.py`` The code to run is:: python translate.py -t json -f pd -i tests/hello-world.pd -o tests/hello-world.json The Pd file ----------- The original Pure Data file looks like this:: #N canvas 47 51 450 300 12; #X obj 37 37 loadbang; #X msg 37 61 hello world; #X obj 37 85 print; #X connect 0 0 1 0; #X connect 1 0 2 0; JSON output ----------- The result is something like this in JSON .. code-block:: json { "patchname": "hello-world.pd", "encoding": "utf-8", "__pdpy__": "PdPy", "root": { "__pdpy__": "Canvas", "isroot": true, "name": "hello-world.pd", "vis": 1, "screen": { "__pdpy__": "Point", "x": 47, "y": 51 }, "dimension": { "__pdpy__": "Size", "width": 450, "height": 300 }, "font": 12, "nodes": [ { "__pdpy__": "Object", "id": 0, "position": { "__pdpy__": "Point", "x": 37, "y": 37 }, "className": "loadbang" }, { "__pdpy__": "Msg", "id": 1, "position": { "__pdpy__": "Point", "x": 37, "y": 61 }, "className": "msg", "targets": [ { "__pdpy__": "Message", "address": "outlet", "message": [ "hello world" ] } ] }, { "__pdpy__": "Object", "id": 2, "position": { "__pdpy__": "Point", "x": 37, "y": 85 }, "className": "print" } ], "edges": [ { "__pdpy__": "Edge", "source": { "__pdpy__": "Iolet", "id": "0", "port": "0" }, "sink": { "__pdpy__": "Iolet", "id": "1", "port": "0" } }, { "__pdpy__": "Edge", "source": { "__pdpy__": "Iolet", "id": "1", "port": "0" }, "sink": { "__pdpy__": "Iolet", "id": "2", "port": "0" } } ] } } XML output ---------- .. note:: Run this to get XML:: python translate.py -t xml -f pd -i tests/hello-world.pd -o tests/hello-world.xml The result is something like this .. code-block:: xml 12 hello-world.pd 1 True 47 51 450 300 0 37 37 loadbang 1 37 61
outlet
hello world
2 37 85 print
0 0 1 0 1 0 2 0