Skip to content

py2max 0.5.1

Choose a tag to compare

@shakfu shakfu released this 10 Oct 02:14
· 3 commits to main since this release

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 local Max install. PY2MAX_MAX_REFPAGES=bundle selects the shipped bundle even when Max is installed. gen_box_props.py, build_single_file.py and gen_js2max_objects.py set it. Before, on a machine with Max 9 (1,178 objects against the bundle's 1,175), all three staleness checks failed on a clean checkout.

  • Connection validation no longer flags 682 valid cords in 942 Max-written patches. All were port-range errors, in three classes. (1) maxref gives one port count per class, but 49 of the 387 classes seen take their counts from arguments, attributes or content: route 0 1 2 3 has 5 inlets, join 3 has 3, js follows its script. 19 classes gained argument resolvers. Content- and attribute-dependent classes (js, gen~, poly~, all mc.*) now have unknown counts and are not range-checked. Text-only counts now match Max's on every newobj box in the corpus. (2) maxref omits the inlet list of 37 objects (midiformat, funnel, if, ...). An empty inlet list now means unknown, and 7 have curated counts. (3) Cords inside rnbo~ and gen~ patchers were checked against Max objects of the same name. Those patchers are now skipped, and their parent box's ports come from its declared counts.

    A loaded box's declared counts widen the maxref bound but never narrow it, since Max wrote them. add_textbox now falls back to maxref counts before the default of 1, so dac~ declares 0 outlets, not 1. The mc.pack~ and mc.matrix~ resolvers were wrong. select/route gain an inlet per match.

  • tempo -> cycle~ is no longer an error. tempo was curated as emitting a bang, but it emits its beat count. Outlets maxref types exactly as bang, int or float now use that type, and 14 more objects are curated. Together they type 1,036 more cords in the corpus, with no new flags.

  • add_textbox declares argument-aware port counts. Counts came from a table keyed by class name only, so route phase info declared 2 outlets while lint and connection validation counted 3; a cord to outlet 2 passed validation and pointed at a port the box did not declare. The box now takes counts from the same resolver, and t/trigger get one outlet per argument. outlettype is padded or truncated to match.

  • Numbers into a signal-typed right inlet are no longer errors. maxref types 53 right inlets as signal that also take numbers or bangs, among them clip~ min/max, scope~ buffer size and minmax~ reset. flonum -> clip~ inlet 1 was flagged. A right inlet is now strict only when its digest describes a plain signal and no method applies to it; 25 remain strict, such as FFT imaginary inputs and oscillator sync.

  • RNBO codeboxes declare ports from their code. add_codebox declared 0 inlets and 1 outlet whatever the code said, and add_textbox("codebox", code=...) declared 1/1. Both now count inN/outN, as gen codeboxes do.

  • The interactive-controller tutorial wired preset wrongly. It connected outlet i to controller i and each controller back into inlet i; preset has 1 inlet. Its left outlet now goes to each controller.

  • Re-inserting an object into MaxRefDB no longer duplicates its child rows. INSERT OR REPLACE gave the row a new id, and with foreign keys off the old id's methods, attributes and ports stayed behind. Every re-populate() or load() grew the cache. Objects are now upserted by name.

  • MaxRefDB.load(export()) no longer corrupts data, and get_object returns what was inserted. get_object rebuilt objects from the normalized tables, under column names (inlet_type, can_get, attrs) that insert_object does not read. A load nested those columns inside attrs, and lost attribute get/set flags, types and port indices. Each object's source dict is now stored compressed (schema v3, about 1.7 MB for all objects) and returned as is, with name filled in when absent. The alternative, mapping rows back to the source shape, cannot be exact: the inserts turn optional="0" and a missing optional into the same 0. Existing caches are backfilled from maxref. Objects maxref does not know, stored before v3, still come back in the old row shape.

  • MaxRefDB has a schema version (PRAGMA user_version) and migrations. A database newer than the running py2max raises DatabaseError instead of being misread. Migration 2 purges the orphaned rows from existing caches. populate() and load() now run in one transaction.

  • Max discovery finds user-level and pointed-at installs. macOS now also searches ~/Applications. PY2MAX_MAX_REFPAGES may name Max.app or a Windows Max 9 folder as well as the refpages folder.

  • A .maxref.xml whose root is not <c74object> is rejected with a warning. It used to load as an object with no ports or methods. Cycling '74 publishes no schema, so the root element is the check.

  • inlet/outlet boxes declare 0/1 and 1/0 ports. maxref lists 1/1 and 2/0.

  • lint and connection validation accept cords to a file-referenced bpatcher. With no embedded patcher, its counts fell back to maxref's (0, 0), so every cord was an out-of-range error. They now use the box's declared counts, as codeboxes already did.

  • graph:ogdf-sugiyama and graph:ogdf-fmmm are reproducible. OGDF breaks crossing-minimization ties randomly per process, so the same patch laid out differently each run. Every OGDF call is now seeded (seed, default 7), and Sugiyama runs once (runs, default 1). graph:ogdf-planarization still varies between processes when seeded; the cause is inside ogdf-py.

  • New inlet/outlet boxes are placed right of existing ones. The grid wraps rows, so a second outlet could land left of the first, and Max would number them in reverse. An explicit patching_rect is kept as given.

  • Layouts no longer renumber a patcher's ports. Max numbers inlet/outlet boxes by x position, so a layout that moved one inlet left of another rewired every cord to that patcher. After layout, port boxes trade positions to restore their pre-layout left-to-right order. Pre-layout x order is kept over creation order because, in a patch loaded from Max, x order is the numbering the user chose.

  • lint warns when inlet/outlet boxes are not left to right in creation order (W-PORT-ORDER).

  • Vertical flow puts every cord downward and patch outputs last. Levels were shortest distances from a source, so a box fed by a short and a long chain sat on the short chain's level. In a typical synth, ezdac~ landed beside the filter, with the chain's last cord climbing two levels. Across 8 random patches, 84 of 272 cords ran backward. Levels are now longest paths (0 backward), and dac~, ezdac~, outlet and the like go on the last level. This replaces window-corner anchors, which a layout would undo and which lengthen cords. The Sugiyama engines already layer this way. Horizontal flow keeps shortest-path levels: Max draws cords from bottom edge to top edge, and in a left-to-right layout the extra levels doubled the crossings (127 to 250). Levels are also spaced by their boxes' real sizes instead of being squeezed into the window.

  • flow layout crosses fewer cords. Separate components no longer interleave, and barycenter sweeps run in both directions. Candidate orderings are placed for real, including overlap removal and the port-order restore, and the one with fewest crossings is kept. The previous ordering is one of the candidates, so no layout gets worse. On 7 test graphs, crossings fell 28% (vertical) and 26% (horizontal); two independent chains went from 8 crossings to 0. A 300-box patch lays out in about 1 s.

  • prevent_overlaps no longer stops with boxes still overlapping. It counted a box as moved only when its net position changed. A box pushed right by one neighbour and back by another ended where it started, so the pass declared convergence. Every layout left overlaps this way: 88 overlapping pairs over 15 layouts × 8 random patches, now 0. If the pushes still oscillate after 50 sweeps, a final pass moves boxes down only, which always terminates.

  • graph:hola works on disconnected patches. HOLA needs a connected graph: an isolated box raised IndexError: map::at, and a second component aborted the Python process from a C++ assertion. Each component is now laid out alone, and the components are packed left to right.

  • graph:hola and graph:ogdf-* keep their own spacing. These engines place boxes from their real sizes, but every result was rescaled to a fixed span. Shrinking HOLA's output created overlaps the overlap pass could not clear (14 over 12 patches). Their output is now only moved to the margin; OGDF's pairwise distances are kept exactly.

  • graph:sugiyama lays out top to bottom. graph-layout's Sugiyama put sources at the bottom despite its top-to-bottom default, so every cord ran upward. Its y axis is now flipped.

  • Object and message boxes are sized from their text. Every box was 60-66 px wide, whatever it held. Width is now text width plus padding, using Arial's glyph widths, with at least 15 px per port. On 392 Max-written boxes this matches Max's own sizing with a 2 px median error. An explicit patching_rect is kept.

  • Every layout grows the window to show all boxes. Only graph layouts did. On an 80-box patch, the other layouts left up to 57 boxes outside the 640×480 window, flagged by lint as W-OFFCANVAS.

  • codebox, gen.codebox~ and nodes are no longer placed off-canvas. Their curated default rects hold absolute coordinates, which get_pos read as fractions of the window, so all three landed on the window's bottom-right corner. Only values in (0, 1] are window anchors now, such as ezdac~'s bottom-left.

  • to_svg wraps comment text to the box width, using the same glyph widths, and grows the box to fit.