Skip to content

Releases

py2max 0.6.0

Choose a tag to compare

@shakfu shakfu released this 11 Oct 21:57

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 --layout defaults to topdown too, and new --template stereo now 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-anchored ezdac~ shifts too, which is the common case: it no longer sits offset below a vertical chain.

  • layout="topdown": the "vertical" grid with align_ports on by default, so optimize_layout() aligns without the flag. optimize_layout(align_ports=False) still turns it off. Also a py2max new --layout choice.

  • Patcher(auto_layout=True): save()/save_as() runs optimize_layout() first, but only if boxes or cords changed since the last layout. A blanket re-run would discard an explicit optimize_layout(...) call's options, and flow recomputes every position. Moves made by hand after a layout are kept. Off by default, so save() 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 raises TypeError when patching_rect is not 4 numbers. A misplaced positional argument used to be saved as the box's rect: add_message("start", "stop") stored the string "stop", and add_comment("note", box) stored the box.

  • add_table(data=[...]) saved an empty table. The values go in array=, and data was on the attribute whitelist for every object, so the stray key passed without a warning. add_table now raises TypeError for data=. data is now a known attribute only for dict, so add_coll(data=...) (it takes dictionary=) warns as an unknown attribute. The examples and docs used both forms, so their tables and colls were empty.

  • optimize_layout() raised AttributeError: 'list' object has no attribute 'y' on a patch of two or more boxes when one was added with patching_rect=[x, y, w, h]. The list was stored as given, and the overlap pass reads rect.y. Loaded patches were already converted; add_box now 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 through delay~.
  • Several example patches could not make sound:

    • The custom and modular synths never triggered their adsr~. CustomPatcher.add_gate now adds a [1( (note-on) and a [0( (note-off) to each one.
    • The generative tutorial sent start to metro, 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~ from table objects. wave~ reads a buffer~, so the example now writes WAV files that buffer~ loads.
    • The sequencer's colls were empty, and its select was never connected.
  • Subpatcher examples now wire the add_subpatcher box itself, with the p prefix Max needs. Before, they wired a second, empty p box.

  • The matrix mixer is now an abstraction, matrix-mixer.maxpat: 4 signal inlets, a 5th inlet for src dst gain messages, and 4 outlets. A host patch uses it by file name.

  • svg_preview_demo.py imported export_svg from py2max; it now imports from py2max.export.

Tests

  • Test patches are built with validate_connections=True and use only cords Max accepts. Tests about invalid input are the exception.
    • metro no longer feeds cycle~ or scope~, nothing is wired out of scope~, and gain~ no longer feeds +.
    • The random-graph layout tests sample cords until the requested number are valid.
    • The Pure Data osc~ is now cycle~.

Removed

  • The signal_order A/B test fixture. Layout tests run once again, and build/test-output/signal_order_ab.md is no longer written. It saved every patcher under test_layout* twice, which produced too many files to inspect.

py2max 0.5.1

Choose a tag to compare

@shakfu shakfu released this 10 Oct 02:14

Fixed

  • js2max/max/serialize-demo.maxpat is regenerated. 0.5.0 corrected port inference for + 48 and *~ 0.15 (2 inlets; *~ has a signal outlet), but the committed demo kept the 0.4 counts, so make js2max-check failed in CI.

Build

  • The uv_build requirement is relaxed to >=0.11,<0.13.

  • make test also runs gen_v8_harness.py --check, so a stale demo patch fails locally. It needs no bun, unlike make 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. Pass on_invalid="ignore" or validate_attrs=False to opt out.

  • Grid optimize_layout() can move boxes created out of signal order. Patcher(signal_order=False) keeps the 0.4 order.

  • py2max.exceptions.InternalError is removed.

Added

  • scripts/scan_cords.py DIR validates 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 because optimize_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 now ruff 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. Every tests/test_layout* test runs as [signal_on] and [signal_off], saves each patcher it creates under build/test-output, and build/test-output/signal_order_ab.md lists the pairs that differ. test_layout_grid_order.py runs 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.py writes its patches to build/test-output. Each test changed into a fresh tempfile.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 creating inlet, outlet, *~ put the outlet above the *~ that feeds it, and optimize_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. With cluster_connected=True, boxes within a cluster follow signal order instead of string-sorted IDs, which put obj-10 before obj-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_as must keep writing in place, not via a temp file and os.replace.

  • MaxRefDB.search() ranks results. An exact name match comes first, then a name prefix, then results grouped by the first of fields that matches. Each group is alphabetical. Before, all results were alphabetical, so search("filter") put change and console before filtergraph~. A field-priority ORDER BY was chosen over FTS5 bm25: it needs no schema change, and LIKE is already fast enough.

  • add_textbox writes UI objects in their box form. add_textbox("flonum") wrote maxclass: newobj with text: "flonum", and UI boxes such as ezdac~ carried a text key 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/outlet and message. Box classes get no text, except message/comment, whose arguments become their content. UI boxes store state as box attributes, so @attr value arguments 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 @attr unknown to the object therefore warns even without validate_attrs=True.

  • validate_attrs no longer flags keys Max itself saves. maxref omits 20 of them (linecount on comments, index on inlet/outlet, bgfillcolor_*, ...), measured on 476 UI boxes in 60 Max-written patches. They are now known, and a test checks the Max-written fixtures in tests/data/. Code that read box.text to identify a UI box should read box.maxclass or py2max.utils.object_name(box). find_by_text falls 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=True still means "raise", and False now 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 and validate_attrs setting.

    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_attrs is on by default. An unknown property now warns at add_* 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's jbox (base box) attributes and each class's curated defaults. Pass validate_attrs=False to opt out.

    The check found 61 doc and example calls of the form add_floatbox(0.3, name="gain"). These wrote 0.3 as a comment and a meaningless name key; they now read add_floatparam("gain", initial=0.3).

  • graph:ogdf-* layouts require ogdf-py>=0.5.1, the first release with set_seed.

Fixed

  • The dict state example sends messages dict understands. It corded each flonum into dict's left inlet, which has no number method, fed dict's dictionary outlet back into every control, and used store/recall, which are not dict messages. It now stores with prepend set <key>, recalls with get <key> through route, and saves with export/import, as dict.maxhelp does. Fixed in tests/examples/advanced/data_containers.py and 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, so cycle~ -> dial passed 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 correcting pong, which maxref types as a signal outlet but which emits floats.

  • Codeboxes are sized to their code. add_gen_codebox and add_codebox used 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 explicit patching_rect is 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 anchored ezdac~) 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 as times~), the other 48 operators, and abbreviations such as t, sel, p, r and s returned None. They got no help(), 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.py maps 227 typed names to their refpage. It is generated by scripts/gen_maxref_aliases.py from Max's *-objectmappings.txt and from the names the bundle records. Port-count resolvers apply to aliases too, so b 3 has 3 outlets.

  • matrix~ A B declares B+1 outlets. It declared A outlets, so a cord from the info outlet of matrix~ 2 2 was rejected.

  • **Generated files no longer depend on the l...

Read more

py2max 0.4.1

Choose a tag to compare

@shakfu shakfu released this 29 Jul 13:56

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_rect is declared Optional[Rect] and read attribute-wise (rect.y) by the layout managers. Any layout call on a loaded patch therefore died with AttributeError: 'list' object has no attribute 'y' -- including the documented py2max optimize <file> CLI subcommand, which failed on every input file. Patcher.from_dict and Box.from_dict now restore rect-valued keys (rect, patching_rect, presentation_rect) to Rect.

    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 as client_rect, dstrect and storage_rect are left alone.

  • enforce_integer_coords() no longer crashes on a Rect. The rounding helper assigned to rect.x/rect.y/rect.w/rect.h, but Rect is a NamedTuple and immutable, so rounding any programmatically built patch with non-integer coordinates raised AttributeError: can't set attribute. A rounded rect is now rebuilt and assigned back, preserving the storage form (Rect in, Rect out; list in, list out).