py2max: a python library for offline generation of Max patcher (.maxpat) files
py2max is a pure python3 library without dependencies intended to facilitate the offline generation of Max patcher files (`.maxpat`, `.maxhelp`, `.rnbopat`)
Features
Scripted offline generation of Max patcher files using Python objects corresponding, on a one-to-one basis, with Max/MSP objects stored in the `.maxpat` JSON-based file format.
Round-trip conversion between (JSON) `.maxpat` files with arbitrary levels of nesting and corresponding `Patcher`, `Box`, and `Patchline` Python objects.
Can handle potentially any Max object or maxclass.
Lots of unit tests and examples, >90% coverage.
Allows precise layout and configuration of Max objects and also experimentation with auto-layout algorithms.
Patcher objects have generic methods such as `add_textbox` and can also have specialized methods such as `add_coll`. For example, the `add_coll` method has a `dictionary` argument to make it easy to prepopulate the `coll` object using a python dictionary.
Possible use cases
Scripted patcher-creation.
Batch modification of existing .maxpat files.
Create parametrizable objects with configuration from offline sources. For example, one-of-a-kind wavetable oscillators configured from random wavetable files.
Generation of test cases and .maxhelp files during external development
Takes the pain out of creating objects with lots of parameters
Prepopulate containers objects such as `coll`, `dict` and `table` objects with data
Save time creating many objects with slightly different arguments
Use graph drawing / layout algorithms on generated patches
Generative patch generation...
Project URL
https://github.com/shakfu/py2max
Examplep = Patcher('my-patch.maxpat')
osc1 = p.add_textbox('cycle~ 440')
gain = p.add_textbox('gain~')
dac = p.add_textbox('ezdac~')
p.add_line(osc1, gain)
p.add_line(gain, dac)
p.add_line(gain, dac, inlet=1)
p.save()
If you end up using this library please provide feedback, scripts, techniques or otherwise via the GitHub project (PRs or Issues), as it would be nice to build up a standard library of useful code for re-use.
Very cool, thanks for sharing! I look forward to finding some time to check this out.
Thanks Rob,
The best way to get a sense of library is to run `pytest` in the root of the project and then check out what is generated from the tests in the 'outputs' folder.
Thanks, excellent addition. I got a basic example working pretty easily. The usage examples are clear.
Suggestions:
Also post about this in the C74 User Projects section: https://cycling74.com/projects. It may get more attention there over time.
For users who may be less experienced in python, add a brief section in the README to cover setup and basic usage - Install repo via git, create python files, import, etc.
Thanks HighHarmonics
Glad to hear it worked for you.
Appreciate the good suggestions too!