Repository navigation
Releases
py2max 0.6.0
The default layout is now "topdown": a vertical grid whose optimize_layout() sorts boxes into signal order and aligns ports.
Upgrading from 0.5.x:
- A patch that names no layout is placed top to bottom instead of left to right.
Patcher(layout="horizontal")restores the 0.5 placement. Named layouts are unchanged.py2max new --layoutdefaults totopdowntoo, andnew --template stereonow lays out its patch.
Added
-
optimize_layout(align_ports=True)shifts boxes sideways so each cord from a box above drops straight; y is kept. It works with every layout manager and is off by default. Boxes with an explicit rect never move, and a shift that would put the box or its cord on another box is skipped. A window-anchoredezdac~shifts too, which is the common case: it no longer sits offset below a vertical chain. -
layout="topdown": the"vertical"grid withalign_portson by default, sooptimize_layout()aligns without the flag.optimize_layout(align_ports=False)still turns it off. Also apy2max new --layoutchoice. -
Patcher(auto_layout=True):save()/save_as()runsoptimize_layout()first, but only if boxes or cords changed since the last layout. A blanket re-run would discard an explicitoptimize_layout(...)call's options, and flow recomputes every position. Moves made by hand after a layout are kept. Off by default, sosave()never moves boxes unless asked. Subpatchers inherit the setting; patches loaded from a file have it off;to_dict()/to_json()never lay out.p = Patcher("patch.maxpat", layout="topdown", auto_layout=True)
Fixed
-
Every
add_*method raisesTypeErrorwhenpatching_rectis not 4 numbers. A misplaced positional argument used to be saved as the box's rect:add_message("start", "stop")stored the string"stop", andadd_comment("note", box)stored the box. -
add_table(data=[...])saved an empty table. The values go inarray=, anddatawas on the attribute whitelist for every object, so the stray key passed without a warning.add_tablenow raisesTypeErrorfordata=.datais now a known attribute only fordict, soadd_coll(data=...)(it takesdictionary=) warns as an unknown attribute. The examples and docs used both forms, so their tables and colls were empty. -
optimize_layout()raisedAttributeError: 'list' object has no attribute 'y'on a patch of two or more boxes when one was added withpatching_rect=[x, y, w, h]. The list was stored as given, and the overlap pass readsrect.y. Loaded patches were already converted;add_boxnow converts too.
Examples and docs
-
The examples (
tests/examples/) and the user guide used objects that do not exist in Max:crossfade~,freeverb~,reverb~,chorus~,compressor~,eq~,inlet~,outlet~. These are now real objects (svf~,lores~,comb~,omx.comp~,selector~,tapin~/tapout~,inlet/outlet).biquad~was given a frequency, Q or filter type, though it takes 5 coefficients.delay~was given a time in ms, though its arguments are in samples.- Delay feedback now goes through
tapin~/tapout~, since MSP rejects a signal loop throughdelay~.
-
Several example patches could not make sound:
- The custom and modular synths never triggered their
adsr~.CustomPatcher.add_gatenow adds a[1((note-on) and a[0((note-off) to each one. - The generative tutorial sent
starttometro, which has no such message. Its stop message was never created:add_message("start", "stop")passed"stop"as the rect. Both are now[1(and[0(. - The custom synth wired the wrong boxes into its oscillator mixer. It also sent the envelope into a filter inlet that does not exist; the envelope now scales a
*~. - The wavetable example read
wave~fromtableobjects.wave~reads abuffer~, so the example now writes WAV files thatbuffer~loads. - The sequencer's
colls were empty, and itsselectwas never connected.
- The custom and modular synths never triggered their
-
Subpatcher examples now wire the
add_subpatcherbox itself, with thepprefix Max needs. Before, they wired a second, emptypbox. -
The matrix mixer is now an abstraction,
matrix-mixer.maxpat: 4 signal inlets, a 5th inlet forsrc dst gainmessages, and 4 outlets. A host patch uses it by file name. -
svg_preview_demo.pyimportedexport_svgfrompy2max; it now imports frompy2max.export.
Tests
- Test patches are built with
validate_connections=Trueand use only cords Max accepts. Tests about invalid input are the exception.metrono longer feedscycle~orscope~, nothing is wired out ofscope~, andgain~no longer feeds+.- The random-graph layout tests sample cords until the requested number are valid.
- The Pure Data
osc~is nowcycle~.
Removed
- The
signal_orderA/B test fixture. Layout tests run once again, andbuild/test-output/signal_order_ab.mdis no longer written. It saved every patcher undertest_layout*twice, which produced too many files to inspect.
py2max 0.5.1
Fixed
js2max/max/serialize-demo.maxpatis regenerated. 0.5.0 corrected port inference for+ 48and*~ 0.15(2 inlets;*~has a signal outlet), but the committed demo kept the 0.4 counts, somake js2max-checkfailed in CI.
Build
-
The
uv_buildrequirement is relaxed to>=0.11,<0.13. -
make testalso runsgen_v8_harness.py --check, so a stale demo patch fails locally. It needs no bun, unlikemake js2max-check.
[0.5.0]
More validation on by default: (a) connection validation (inlet index and message type) should prevent the wrong connects and (b) attribute validation stop usage of properties unknown to the object's Max class. Layouts also changed: code boxes are sized to their content, auto-placed boxes no longer overlap, and grid optimize_layout() follows signal order.
Upgrading from 0.4.x:
-
Invalid connections are logged as warnings, and unknown box properties raise
UserWarning. Passon_invalid="ignore"orvalidate_attrs=Falseto opt out. -
Grid
optimize_layout()can move boxes created out of signal order.Patcher(signal_order=False)keeps the 0.4 order. -
py2max.exceptions.InternalErroris removed.
Added
-
scripts/scan_cords.py DIRvalidates every cord in a folder of Max-written patches and reports what py2max flags. Max wrote every cord, so each flag is a false positive. It checks both the port counts Max wrote and the counts from box text alone. -
Patcher.optimize_layout_subset(boxes)lays out only the given boxes and the cords between them; every other box stays put. The group keeps its top-left corner, and moves down as a whole if it then overlaps a fixed box. It is a separate method becauseoptimize_layout()takes no arguments by design.p.optimize_layout_subset(logic_boxes) # arrange logic around a fixed bpatcher view
Removed
py2max.exceptions.InternalError. Nothing raised it, and no public code on GitHub imports it.
CI
- CI runs on push and pull request to
main, as well as on demand. The repository is nowruff format-clean, which the lint job requires (24 files were not), and the suite passes on Python 3.9, the oldest in the matrix.
Tests
-
Layout tests save A/B patches for
signal_order. Everytests/test_layout*test runs as[signal_on]and[signal_off], saves each patcher it creates underbuild/test-output, andbuild/test-output/signal_order_ab.mdlists the pairs that differ.test_layout_grid_order.pyruns once, since it asserts the signal-order behaviour itself, and so does flat mode (make test-outputs), where both variants would write the same file names. -
test_examples.pywrites its patches tobuild/test-output. Each test changed into a freshtempfile.mkdtemp()directory, which bypassed the per-test output directory and was never removed.
Changed
-
Grid
optimize_layout()places boxes in signal order. Grid placement followed creation order only, so creatinginlet,outlet,*~put the outlet above the*~that feeds it, andoptimize_layout()did not change that. It now gives the grid slots, in creation order, to boxes sorted by their connections, ties broken by creation order. A patch already built in signal order keeps every position. Explicit and window-anchored rects do not move, a feedback loop is placed as a unit, and the existing port-order restore keeps inlet and outlet numbering. Withcluster_connected=True, boxes within a cluster follow signal order instead of string-sorted IDs, which putobj-10beforeobj-2.Patcher(signal_order=False)restores creation order, for comparing layouts. -
Max 9.2 reloads an open patch when py2max saves over it. The README caveat that Max never refreshes from file now applies only before 9.2. The reload resets object state and discards unsaved edits made in Max without a prompt; DSP and window state are kept. Max stops reloading once the file is replaced rather than rewritten, so
save_asmust keep writing in place, not via a temp file andos.replace. -
MaxRefDB.search()ranks results. An exact name match comes first, then a name prefix, then results grouped by the first offieldsthat matches. Each group is alphabetical. Before, all results were alphabetical, sosearch("filter")putchangeandconsolebeforefiltergraph~. A field-priorityORDER BYwas chosen over FTS5 bm25: it needs no schema change, andLIKEis already fast enough. -
add_textboxwrites UI objects in their box form.add_textbox("flonum")wrotemaxclass: newobjwithtext: "flonum", and UI boxes such asezdac~carried atextkey Max does not write. A class is now a box class when its maxref palette entry creates it by name; this covers UI objects,inlet/outletandmessage. Box classes get notext, exceptmessage/comment, whose arguments become their content. UI boxes store state as box attributes, so@attr valuearguments become attributes and positional arguments are dropped with a warning:p.add_textbox("waveform~ @buffername buf") # same as buffername="buf"
These names come from a string, so mypy cannot check them. An
@attrunknown to the object therefore warns even withoutvalidate_attrs=True. -
validate_attrsno longer flags keys Max itself saves. maxref omits 20 of them (linecounton comments,indexoninlet/outlet,bgfillcolor_*, ...), measured on 476 UI boxes in 60 Max-written patches. They are now known, and a test checks the Max-written fixtures intests/data/. Code that readbox.textto identify a UI box should readbox.maxclassorpy2max.utils.object_name(box).find_by_textfalls back to the class name for these boxes. -
Invalid connections warn by default.
Patcher(on_invalid=...)takes"warn"(the new default: log and add the cord),"raise"or"ignore".validate_connections=Truestill means"raise", andFalsenow means"ignore". Before, the check ran only when you opted in. Warning by default matches the save-time linter, and every user now reports a false positive instead of only the few who opted in. Subpatchers inherit the parent's policy andvalidate_attrssetting.The first data found two false-positive classes, both fixed below. After the fixes, all 527 cords in 60 Max-written patches pass, and the test suite flags only its deliberately invalid cords.
-
validate_attrsis on by default. An unknown property now warns atadd_*time. Evidence: 0 false positives on 868 boxes from 60 Max-written patches, 0 on loading those patches, and 0 from py2max's own output across the test suite, which now fails on any such warning. Known keys now also include maxref'sjbox(base box) attributes and each class's curated defaults. Passvalidate_attrs=Falseto opt out.The check found 61 doc and example calls of the form
add_floatbox(0.3, name="gain"). These wrote0.3as a comment and a meaninglessnamekey; they now readadd_floatparam("gain", initial=0.3). -
graph:ogdf-*layouts requireogdf-py>=0.5.1, the first release withset_seed.
Fixed
-
The
dictstate example sends messagesdictunderstands. It corded eachflonumintodict's left inlet, which has no number method, feddict's dictionary outlet back into every control, and usedstore/recall, which are notdictmessages. It now stores withprepend set <key>, recalls withget <key>throughroute, and saves withexport/import, asdict.maxhelpdoes. Fixed intests/examples/advanced/data_containers.pyand the user guide. -
A signal into a control object's left inlet is now an error. maxref types most control inlets with the placeholder
INLET_TYPE, which maps to "accepts anything". That was merged into the method-list vocabulary, socycle~ -> dialpassed validation although Max refuses the cord. The placeholder now adds nothing, and 269 objects' left inlets are checked against their method lists. Across 21,526 cords in 942 Max-written patches this adds no false positives, after correctingpong, which maxref types as a signal outlet but which emits floats. -
Codeboxes are sized to their code.
add_gen_codeboxandadd_codeboxused the 66x22 textbox default, so Max showed only the title row.add("codebox~", code=...)used a fixed 200x200. All three now size the box from the line count and longest line. Max 9 shows a horizontal scrollbar over the last line unless the box has about 36pt beyond the longest line, so that margin is included. An explicitpatching_rectis kept. -
Auto-placed boxes no longer overlap. The grid layouts step by a fixed 144x72pt cell, so a box larger than a cell (a codebox,
scope~, an anchoredezdac~) landed on its neighbours. A box placed by the layout that overlaps an existing box now moves past it, wrapping at the patcher edge. Moving only overlapping boxes was chosen over a size-aware grid, which would have shifted every existing grid patch. Inlets and outlets never wrap, since Max numbers them by x. Explicit rects are not moved. -
maxref finds objects by the name typed into a box. maxref keys objects by refpage file name, so
*~(filed astimes~), the other 48 operators, and abbreviations such ast,sel,p,randsreturnedNone. They got nohelp(), no port or message checks, and an unknown-object warning. In the 942-patch corpus that was 784 of 3,712 distinct object texts.py2max/maxref/aliases.pymaps 227 typed names to their refpage. It is generated byscripts/gen_maxref_aliases.pyfrom Max's*-objectmappings.txtand from the names the bundle records. Port-count resolvers apply to aliases too, sob 3has 3 outlets. -
matrix~ A Bdeclares B+1 outlets. It declared A outlets, so a cord from the info outlet ofmatrix~ 2 2was rejected. -
**Generated files no longer depend on the l...
py2max 0.4.1
Changes since the last release
Two rect-handling bugs, both of which broke documented entry points on any
patch that came off disk rather than out of a script.
Fixed
-
Layout operations work on patches loaded from disk. JSON has no tuple type, so every rect in a loaded patch arrived as a plain list, while
Box.patching_rectis declaredOptional[Rect]and read attribute-wise (rect.y) by the layout managers. Any layout call on a loaded patch therefore died withAttributeError: 'list' object has no attribute 'y'-- including the documentedpy2max optimize <file>CLI subcommand, which failed on every input file.Patcher.from_dictandBox.from_dictnow restore rect-valued keys (rect,patching_rect,presentation_rect) toRect.Round-trip fidelity is unaffected:
to_dict()normalizes those keys back to plain lists, so the serialized form stays pure JSON and a load/save cycle still reproduces its input exactly. Only the three keys py2max actually interprets are touched; opaque passthrough props such asclient_rect,dstrectandstorage_rectare left alone. -
enforce_integer_coords()no longer crashes on aRect. The rounding helper assigned torect.x/rect.y/rect.w/rect.h, butRectis aNamedTupleand immutable, so rounding any programmatically built patch with non-integer coordinates raisedAttributeError: can't set attribute. A rounded rect is now rebuilt and assigned back, preserving the storage form (Rectin,Rectout; list in, list out).