Implement the following plan: Plan: LowestNote Native Max Version (No v8/JS) Context The…
- User
Implement the following plan:
Plan: LowestNote Native Max Version (No v8/JS)
Context
The current
LowestNote.maxpatuses a v8 JavaScript file (lowest_note_filter.js) for its core logic. The user wants a version that uses only native Max objects, eliminating the JavaScript dependency. This makes the patch more portable and educational.Approach
Replace the
v8 lowest_note_filter.jsobject + externaldelay 5with a single subpatcherp LowestNoteLogiccontaining ~45 native Max objects organized into 5 functional sections.Key Design Decisions
collfor state: Two named colls (tempNotesfor buffering,sentNotesfor tracking sent notes).collsupportssort+nth 1to find the lowest pitch efficiently.delay 5for chord window: Moved inside the subpatcher. Stop + restart on each note-on.gate 2for note-on/off routing:unpacksplits pitch/vel,> 0++ 1sets gate control (1=off, 2=on), then pitch routes through the gate.- No thresh: Using
delay+collinstead ofthreshto support removing notes from the buffer during the window (matches JS behavior exactly).
Subpatcher Internal Structure
codeinlet (notes + reset) | route reset -----> RESET PATH: stop delay, dump sentNotes (send note-offs), clear both colls | unpack 0 0 | | pitch vel -> > 0 -> + 1 -> gate control | gate 2 | | NOTE-OFF NOTE-ON | | t i i i pack pitch+vel -> coll tempNotes store + restart delay 5 | lookup DELAY FIRES: sort tempNotes -> nth 1 -> lowest [pitch,vel] sentNotes -> output + store in sentNotes + clear tempNotes | if found: pack [pitch, 0] -> output remove from both collsRoot Patcher Changes
- Remove (v8) and (delay 5) and their connections
Assistant
I'll implement this plan step by step. Let me start by setting up the worktree and reading the current patch file.
Assistant
Now I have a clear picture of the current patch structure and the JS logic. Let me build the native Max version. I need to carefully design the subpatcher to replicate all the JS behavior.
Assistant
I need to read the worktree copy first.
Assistant
Assistant
Wait - I need to re-examine a critical issue in my subpatcher design. The note-on path has a problem: when
unpackfires, the velocity goes out outlet 1 (right) first, then pitch goes out outlet 0 (left). But I'm connecting pitch (outlet 0) to both inlet 1 AND the note-on (obj-25 which no longer exists). Actually, looking at my design more carefully:Assistant
Assistant
I need to rewrite the entire subpatcher section with the corrected chord window output logic. Rather than doing incremental edits on this large JSON, let me write the complete corrected file.
Assistant
Assistant
Now let me trace through all paths one final time to verify correctness.
RESET PATH (obj-5
t b b b, fires R→L: 2, 1, 0):- [2] → obj-10 (
clear) fans out: → obj-11 (sentNotes, order 1), → obj-12 (tempNotes, order 0). Clears both. - [1] → obj-7 (
dump) → obj-8 (sentNotes). Each entry: outlet 1 = key (pitch) → obj-9 (pack 0 0) left inlet → [pitch, 0] → outlet. - [0] → obj-6 (
stop) → obj-36 (delay). Stops pending timer.
Sequence: clear colls, then dump (which outputs from now-empty sentNotes... hmm!). BUG: Clearing before dumping means dump has nothing to output!
I need to reorder: dump first, then clear. Since
t b b bfires R→L (2→1→0):- [2] should be: clear both colls (fires 1st)
- [1] should be: dump sentNotes (fires 2nd)
- [2] → obj-10 (
Assistant
I need to fix the reset path wiring. Currently:
- obj-5 outlet 2 → obj-10 (clear) — fires 1st (WRONG, should be last)
- obj-5 outlet 1 → obj-7 (dump) — fires 2nd (should be before clear)
- obj-5 outlet 0 → obj-6 (stop) — fires 3rd (should be before dump too, per JS)
The correct order from
t b b b(R→L = 2,1,0):- outlet 2 (fires 1st): stop delay
- outlet 1 (fires 2nd): dump sentNotes for note-offs
- outlet 0 (fires 3rd): clear both colls
Let me fix the connections:
Assistant
Now let me re-trace ALL paths:
RESET PATH (obj-5 , R→L: 2→1→0):
Assistant
All warnings (multi-connection inlets) are intentional design patterns — no errors. Let me verify the exit code:
Assistant
Exit code 0 — validation passes. All warnings are intentional:
- obj-5 (p LowestNoteLogic): receives both note data from midiparse and reset messages — correct
- obj-12 (reset message): receives bangs from both live.thisdevice and sel 0 — correct
- delay obj-36: receives stop + bang from note-on path and stop from reset — correct
- outlet obj-2: receives from note-off, note-on, and chord window paths — correct
- coll obj-41: receives sort and nth 1 — correct
Now let me delete the JS file that's no longer needed.
Assistant
Let me check if the
code/directory is now empty and can be removed.Assistant
Now let me verify the git status and run validation one final time from the worktree.
Assistant
Let me also run the validation one more time from the worktree directory to make sure everything is good.
Assistant
Validation passes (exit code 0). All done. Here's a summary of the changes:
Summary
Modified:
patches/LowestNote/LowestNote.maxpat- Replaced
v8 lowest_note_filter.js(obj-5) + externaldelay 5(obj-6) with a singlep LowestNoteLogicsubpatcher containing ~49 native Max objects - Removed
obj-9comment ("5ms chord detection window") since the delay is now inside the subpatcher - Cleared
dependency_cache(no more JS dependency)
Deleted:
patches/LowestNote/code/lowest_note_filter.jsSubpatcher Architecture (
p LowestNoteLogic)The subpatcher has 1 inlet (notes or
reset) and 1 outlet (filtered notes), organized into 5 sections:- Reset path: Stops delay, dumps sentNotes as note-offs (
[pitch, 0]), clears both colls - Note routing: → + → (1=off, 2=on)
- Replaced
- User
Go ahead and open a PR
Assistant
Let me check the current state and prepare for the PR.
Assistant
No commits yet on the branch — I need to stage, commit, then push and create the PR.
Assistant