edit_code
Modify existing Strudel music code by sending exact old-to-new text replacements; all edits apply together, or the call is rejected when a match fails.
Instructions
Changes part of the code that will play by exact text replacement, sending only the change. Use it to change an existing piece; use set_code for a new piece or a rewrite of most of its lines. Each edit has old_string, new_string and optional replace_all, as in your own Edit tool. Every old_string must match exactly once (or set replace_all), and every edit is matched against the code as it is before this call, so edits must not overlap and one edit cannot match text another edit writes. An edit that matches nowhere, matches more than once, overlaps another edit or changes nothing refuses the whole call with the reason and the edit number: nothing is applied and nothing reaches the page. CRLF counts as LF. The edits apply to the newest code that will play: the change waiting for its bar or phrase line when one waits (get_code shows the code playing until then), otherwise the code playing now with the user's evaluated hand edits; text typed in the page but not evaluated is replaced, as with set_code. Pass base, the version number get_code shows, to have the edit refused when the music moved on since. at, phraseCycles and label work as in set_code, and the edited program goes through the same checks, history entry and notices. The reply gives the version, when the change takes over and the changed lines with a few lines around them, not the whole program; get_code returns it. Put all replacements for one change in a single call: a second edit_code sent before the first reply is refused. It edits music that already plays, so before Moontide is started it is refused and starts nothing: use set_code first. Call get_code before changing existing music.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| at | No | When the change takes over: 'now' (the default) within a fraction of a second, 'bar' on the next bar line, 'phrase' on the next phrase line (4 cycles, counted from Play). The code is checked at once; the reply says the cycle and about how many seconds away it is. | |
| base | No | The version number get_code shows (#N); the edit is refused when another version plays now | |
| edits | Yes | The replacements, 1 to 50, applied all together or not at all | |
| label | No | A few words saying what this change is, for example "added a bass"; shown by list_history | |
| answering | No | The id of the page request this change answers, from its request line; the page shows that request as applied only when the change names it here | |
| glideBars | No | Whole bars, 1 to 64, to move the tempo smoothly from the tempo that plays to the one this code sets with setcps or setcpm; with at, it starts at the line. Refused when nothing plays, no tempo is set or it already plays. Stop, or code with another tempo or none, cancels it | |
| phraseCycles | No | How many cycles one phrase lasts, for at: 'phrase' (2 to 64, default 4) |