Working with .tosc files#
Once you have learned the structure of the .tosc file and tosclib, it becomes easier to focus on the algorithm of whatever you want to do rather than dealing with raw XML Element Tree functions and parsing.
The basic concept is to load a regular XML Element and create a new ElementTOSC instance with it. Then you can handle it with tosclib and regular xml.
import tosclib as tosc
root = tosc.load("docs/demos/files/test.tosc")
parent = tosc.ElementTOSC(root[0])
target = tosc.ElementTOSC(parent.findChild("target"))
target.showProperty("color")
colors = {"r":"0", "g":"0", "b":"1", "a":"1"}
target.setProperty("color", params = colors)
target.setColor((1, 0, 0, 1))
target.showProperty("color")
tosc.write(root, "docs/demos/files/out.tosc")
Classes and Functions#
Here are more details on the functions and methods we used:
- tosclib.tosc.load(inputPath)[source]#
Reads a .tosc file and returns the XML root Element
- Parameters
inputPath (str) –
- Return type
- class tosclib.tosc.ElementTOSC[source]#
Contains a Node Element and its SubElements. Creates them if not found.
- __init__(e)[source]#
Find SubElements on init
- Parameters
e (ET.Element) – <node> Element
- properties#
Find <properties>
- Type
ET.Element
- values#
Find <values>
- Type
ET.Element
- messages#
Find <messages>
- Type
ET.Element
- children#
Find <children>
- Type
ET.Element
- __new__(**kwargs)#
- class tosclib.tosc.Property[source]
Struct like object to carry the property values
- __init__(type, key, value=None, params=None)[source]
- __new__(**kwargs)
- tosclib.tosc.ElementTOSC.createProperty(self, property)#
- Parameters
property (tosclib.elements.Property) –
- Return type
- tosclib.tosc.ElementTOSC.setColor(self, params)
- Parameters
self (tosclib.tosc.ElementTOSC) –
- tosclib.tosc.write(root, outputPath)[source]#
Encodes a root Element to .tosc
- Parameters
root (xml.etree.ElementTree.Element) –
outputPath (str) –
- Return type