Max patch agent

From taylorbrook/MAX-MSP_CC_Framework · View interactive version

Max patch agent is an AI agent skill from the GitHub repository taylorbrook/MAX-MSP_CC_Framework. Generate MAX patches with control flow, message routing, subpatcher organization, and MIDI handling

How to use this skill

Skill file

Patch Generation Specialist

The Patch agent generates MAX/MSP .maxpat files focused on control-rate operations: object routing, message passing, subpatcher organization, MIDI handling, and data management.

Domain Context Loading

Before any generation:

  1. Read CLAUDE.md at project root -- follow every rule (Rules #1-#9) and the patch style guidelines
  2. Read .claude/skills/references/shared-capabilities.md for the rules moved out of CLAUDE.md: "Multislider as Labeled Parameter Bank" (manual multislider banks, reading values by index), "Max for Live Device Rules" (any M4L / .amxd device), "bach (package) Rules" (any bach object)
  3. Use ObjectDatabase from src.maxpat.db_lookup for all object lookups -- it loads all domains, resolves aliases, checks PD blocklist, and provides relationship data automatically
  4. Read .claude/max-objects/relationships.json for common object pairings (if needed for design decisions)
  5. Read project config.json via load_project_config() from src.maxpat.project for allowed packages. Pass allowed_packages to Patcher(allowed_packages=allowed) so package objects outside the project's selection are blocked at creation time. If load_project_config() returns None (no config.json), use allowed = [] (core-only), never None -- None allows every package.

Domain focus: Max control/data/UI objects. Signal processing and RNBO are handled by their respective agents.

Capabilities

Patch Construction

Key Functions

Object Expertise

Bpatcher Argument Substitution

Pattern Application

Shared Capabilities: See .claude/skills/references/shared-capabilities.md for Control-Rate Fan-Out Rule, Assistance Comments, Aesthetic Capabilities, Layout Options, Editing Functions, and Edit Workflow reference.

Builder API (Phase 31)

Prefer the Patcher builders over restating their recipes: add_overlay_readout, add_labeled_param_bank, add_m4l_device (device skeleton of any kind, then export_amxd; experimental), add_m4l_gen_synth (experimental) and the passive _ROLE_COMPANION_MAP companion placement applied by apply_layout. Signatures, arguments and the quick-reference table: "Builder API" in .claude/skills/references/shared-capabilities.md.

Package Intelligence

When generating patches with package objects (BEAP, Vizzie, etc.), read .claude/max-objects/PACKAGES.md for:

BEAP Modular Patching

BEAP modules are bpatchers that emulate analog modular synthesis:

Community Packages

Community packages (FluCoMa, CNMAT, Bach, Odot, ml-lib, IRCAM Spat, Cage, Dada, EARS, Rhythmic Time Toolkit) have stub DB entries but require local extraction before generation.

Before using any community package object:

  1. Check ObjectDatabase().get_package_info(package_name)["extracted"]
  2. If false: inform the user they must install and extract first (see max-lifecycle SKILL.md for exact messages)
  3. If true: proceed normally -- extracted data is verified and safe for generation

Package-specific notes:

Vizzie Video Chains

Vizzie modules pass Jitter matrices (video frames) between bpatchers:

Package Workflow Templates

Structured workflow blueprints for generating working package patches. Each template specifies objects, connection order, I/O types, parameter ranges, and gotchas. Templates are generation guidance -- not pre-built .maxpat files.

Bach: llll Construction and Manipulation

Use case: Build nested list structures for algorithmic composition

Chain: data source (flat MAX list) -> bach.join / bach.flat / bach.nth (llll manipulation) -> bach.score or bach.roll

| # | Source | Outlet | Destination | Inlet | Type |

|---|--------|--------|-------------|-------|------|

| 1 | (flat MAX list source) | 0 | bach.join | 0 (llll in 1) | list |

| 2 | (flat MAX list source) | 0 | bach.join | 1 (llll in 2) | list |

| 3 | bach.join | 0 (joined llll) | bach.flat | 0 (llll in) | llll |

| 4 | bach.flat | 0 (flattened llll) | bach.nth | 0 (llll in) | llll |

| 5 | bach.nth | 0 (extracted element) | bach.score | 0 (llll data) | llll |

Parameter ranges:

Gotchas:

Bach: Notation Display Workflow

Use case: Display and edit musical notation with bach.score or bach.roll

Chain: bach.score (or bach.roll) <- llll data via inlet 0; message box commands (addchord, delete) via inlet 0

| # | Source | Outlet | Destination | Inlet | Type |

|---|--------|--------|-------------|-------|------|

| 1 | (llll data source) | 0 | bach.score | 0 (llll data / commands) | llll |

| 2 | message box ("addchord ...") | 0 | bach.score | 0 (command) | message |

| 3 | bach.score | 0 (modified llll) | (downstream bach processing) | 0 | llll |

| 4 | bach.score | 1 (notifications) | (status display) | 0 | list |

Parameter ranges:

Gotchas:

Bach: Algorithmic Composition Pipeline

Use case: Generate musical material algorithmically and display in notation

Chain: algorithm source (metro + counter / random) -> bach.collect -> bach.quantize -> bach.score

| # | Source | Outlet | Destination | Inlet | Type |

|---|--------|--------|-------------|-------|------|

| 1 | metro | 0 (bang) | trigger b b | 0 | bang |

| 2 | trigger | 0 | random 12700 | 0 (bang) | bang |

| 3 | random | 0 (pitch value) | bach.collect | 0 (llll in) | int |

| 4 | trigger | 1 | bach.collect | 0 (bang to flush) | bang |

| 5 | bach.collect | 0 (collected llll) | bach.quantize | 0 (llll in) | llll |

| 6 | bach.quantize | 0 (quantized llll) | bach.score | 0 (llll data) | llll |

Parameter ranges:

Gotchas:

Editing Existing Patches (via /max-iterate)

Domain focus: Edit control flow routing, message handling, subpatcher organization.

Output Protocol (New Patches)

  1. Create Patcher and build patch structure
  2. Finalize patch: finalize_patch(patcher, is_new=True) -- applies styling, layout, assistance comments, and midpoint generation for all patchers and subpatchers.
  1. Serialize and validate a copy: patch_dict = patcher.to_dict(), then results = validate_patch(copy.deepcopy(patch_dict), db=patcher.db). Validation never mutates its input; the deepcopy is defense in depth.
  2. Proposed removals mean inspect, don't save. If has_blocking_errors(results, is_new=True) is True, or any result has proposed_removal set, do NOT save. Inspect each (src_id, outlet, dst_id, inlet): a real wiring mistake -> fix the build and re-validate; a validator false positive -> keep the cord and report the checker gap. Call apply_fixes(patch_dict, results) only when removal is explicitly wanted, then re-validate.
  3. Return (patch_dict, results) tuple for critic review
  4. Apply revisions if critic requests them
  5. Only after the step-4 gate passes, write final output via save_patch_roundtrip(patch_dict, path) to project's generated/ directory

Output Protocol (Edited Patches)

Follow "Output Protocol (Edited Patches)" in .claude/skills/references/shared-capabilities.md.

When to Use

When NOT to Use

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.