Created
December 9, 2012 06:19
-
-
Save psobot/4243573 to your computer and use it in GitHub Desktop.
CoreAudio CAShow -> Graphviz Renderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 1) Be someone crazy working with Apple's CoreAudio. | |
| 2) Put "CAShow(graph)" somewhere in your Objective-C code. | |
| 3) Copy the resulting output from your XCode Console window. | |
| 4) Do `pbpaste | python plot.py && open out.png` | |
| 5) See a very basic rendering of the crazy audio graph you've made. | |
| """ | |
| import re | |
| import sys | |
| import pydot | |
| graph = pydot.Dot(graph_type='graph') | |
| def_re = re.compile("\s*node (\d+):") | |
| con_re = re.compile("\s*node\s+(\d+) bus\s+(\d+)\s+=>\s+node\s+(\d+)\s+bus\s+(\d+)") | |
| for line in sys.stdin: | |
| node_def = def_re.search(line) | |
| if node_def: | |
| graph.add_node(pydot.Node(node_def.groups()[0])) | |
| else: | |
| con_def = con_re.search(line) | |
| if con_def: | |
| src_node, src_bus, dst_node, dst_bus = con_def.groups() | |
| graph.add_edge(pydot.Edge(src_node, dst_node, label=dst_bus)) | |
| graph.write_png('out.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment