cutcutcodec.core.compilation.graph_to_tree

Compile an assembly graph into an evaluable tree.

Functions

graph_to_tree(graph)

Create the dynamic tree from the assembly graph.

new_node(node_class, in_streams, state)

Instantiate and initialize a new node.

update_trees(graph)

Update on each node the tree attribute.

Details

cutcutcodec.core.compilation.graph_to_tree.graph_to_tree(graph: MultiDiGraph) ContainerOutput[source]

Create the dynamic tree from the assembly graph.

The abstract dynamic tree alows the evaluation of the complete pipeline.

Parameters

graphnetworkx.MultiDiGraph

The assembly graph.

Returns

container_outcutcutcodec.core.classes.container.ContainerOutput

An evaluable multimedia muxer.

Examples

>>> from cutcutcodec.core.classes.container import ContainerOutput
>>> from cutcutcodec.core.compilation.graph_to_tree import graph_to_tree
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
>>> tree = tree_to_graph(ContainerOutput(GeneratorAudioNoise(0).out_streams))
>>> graph_to_tree(tree)
<cutcutcodec.core.classes.container.ContainerOutput object at ...>
>>>
cutcutcodec.core.compilation.graph_to_tree.new_node(node_class: type, in_streams: Iterable[Stream], state: dict) Node[source]

Instantiate and initialize a new node.

Parameters

node_classtype

The uninstantiated class describing the node to be created. This class must be inherited from the cutcutcodec.core.classes.node.Node class.

in_streamstyping.Iterable[Stream]

See cutcutcodec.core.classes.node.Node.setstate.

statedict

See cutcutcodec.core.classes.node.Node.setstate.

Returns

nodeNode

A new instantiated and initialized node.

cutcutcodec.core.compilation.graph_to_tree.update_trees(graph: MultiDiGraph) None[source]

Update on each node the tree attribute.

From the assembly graph, this function reconstructs the dynamic instances and is able to perform the calculations. By adding to each node the attribute tree, it allows not only to keep the graph structure but also to recalculate only the parts that need to be changed.

The operation are applies in-place.

Parameters

graphnetworkx.MultiDiGraph

The assembly graph who is going to have the updated tree attributes.

Examples

>>> from pprint import pprint
>>> from cutcutcodec.core.classes.container import ContainerOutput
>>> from cutcutcodec.core.compilation.graph_to_tree import update_trees
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
>>> from cutcutcodec.core.filter.audio.subclip import FilterAudioSubclip
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
>>> container_out = ContainerOutput(
...     FilterAudioSubclip(GeneratorAudioNoise(0).out_streams, 1, 2).out_streams
... )
>>> graph = tree_to_graph(container_out)
>>> update_trees(graph)
>>> pprint(dict(graph.nodes("cache")))
{'container_output_1': ('b1c67b749185174850a2d5cdce2bcb82',
                        {'tree': <cutcutcodec.core.classes.container.ContainerOutput...>}),
 'filter_audio_subclip_1': ('ab86b53fe424b58e755eac50d87a77f0',
                            {'tree': <...FilterAudioSubclip...>}),
 'generator_audio_noise_1': ('4dc3de85c734bfd23024c381599bfe3f',
                             {'tree': <...GeneratorAudioNoise...>})}
>>> pprint(list(graph.edges(keys=True, data=True)))
[('filter_audio_subclip_1',
  'container_output_1',
  '0->0',
  {'cache': ('ab86b53fe424b58e755eac50d87a77f0|0',
             {'tree': <cutcutcodec.core.filter.audio.cut._StreamAudioCut...>})}),
 ('generator_audio_noise_1',
  'filter_audio_subclip_1',
  '0->0',
  {'cache': ('4dc3de85c734bfd23024c381599bfe3f|0',
             {'tree': <cutcutcodec.core.generation.audio.noise._StreamAudioNoiseUniform...>})})]
>>>