BUG: undocumented behavior with recursive macros


Exact version number of Audacity: 2.3.0 (sorry - I could not find a bug report forum for non-alpha versions)

Operating system version: Windows 10 64 bit, up to date, regular update channel (not insider)

Brief description of the problem:
There are two undocumented behaviors with recursive macros.

  • When adding a macro to its own commands recursively, applying the macro applies the operations only twice instead of repeatedly / until the first error.
  • Using Undo reverts only the second macro application.

    Detailed, step by step instructions for how to reproduce the problem:
  1. Create a new project.

  2. Generate three tone clips (I used three 2 second, 440hz sine tones, spaced 0.5 seconds apart).

  3. Confirm they are two unconnected clips with “select next clip” and “select previous clip”.

  4. Create a new macro named “TestMacro”:

  • Select Next Clip
  • Amplify: -29db
  • TestMacro (Macro_TestMacro)
  • END

Project setup at this stage:

  1. Close the macro window.

  2. Move the cursor to the start of the project (Home key).

  3. Use Tools > Apply Macro > TestMacro
    The first two clips are turned down. The third clip is not.
    This is the first undocumented behavior: I would expect the macro to keep running recursively and also be applied to the third clip.

  1. Use Edit > Undo Apply ‘TestMacro’
    Only the second clip returns to original volume.
    The first clip is still reduced in volume.
    The next “Undo” step is the tone generator.

I think this is intentional.

Normal Macros do not provide any mechanism to escape from a loop. In fact, normal Macros don’t provide any control logic at all (this is mentioned in the documentation). Because of this, if recursion was allowed, it would result in “stack overflow”.

Consider the simplest example of a macro called “do-recursion”, where the macro contains one command, and the command is “do-recursion”. If recursion were allowed, Audacity would attempt to expand the macro to:
do-recursion > do-recursion > do-recursion > do-recursion > do-recursion > do-recursion > do-recursion > … ad infinitum
which would immediately crash. What Audacity does instead is: do-recursion > do-recursion (NOT recursively) > End.

If you wish to use loops or other control structures and if you don’t need to use any Nyquist effects in the Macro, then the way to do it would be to write a “Nyquist-Macro” (see: https://manual.audacityteam.org/man/nyquist_macros.html)

This is a bug. Macros are not always recorded correctly in the Undo history.
I believe that the developer’s intention, is that a Macro should count as one action. This does not always happen.
This bug may have been fixed in the upcoming Audacity 2.3.1, though I’ve not yet had chance to test thoroughly.

Thank you for your comment.

Regarding the overflow error, I expected the software to handle that differently. For example, stop execution if one of the commands fails (such as no next clip existing to select). It hadn’t occurred to me there were edge cases that would not be covered by such an escape mechanism.

Perhaps it would be useful to have some sort of warning in case of recursive usage in regular macros (with a “don’t show this again”-option)?

Regardless I guess I’ll have to learn the proper syntax for Nyquist to achieve my original goal.

I’ve just checked, and it’s not fixed, so I’ll log it on the bug tracker.

If you need help with that, start a new topic on the Nyquist forum board: https://forum.audacityteam.org/viewforum.php?f=39

For non-alpha versions, just post to the normal “Windows” board.