BUG: undocumented behavior with recursive macros

Help for Audacity on Windows.
Forum rules
ImageThis forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".


Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Post Reply
audentis
Posts: 12
Joined: Thu Mar 07, 2019 8:31 am
Operating System: Windows 10

BUG: undocumented behavior with recursive macros

Post by audentis » Thu Mar 07, 2019 10:16 am

Greetings,

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:
Image

5. Close the macro window.
6. Move the cursor to the start of the project (Home key).

7. 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.

Image

8. 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.

Image

steve
Site Admin
Posts: 80693
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: BUG: undocumented behavior with recursive macros

Post by steve » Thu Mar 07, 2019 11:36 am

audentis wrote:
Thu Mar 07, 2019 10:16 am
When adding a macro to its own commands recursively, applying the macro applies the operations only twice instead of repeatedly / until the first error.
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)
audentis wrote:
Thu Mar 07, 2019 10:16 am
- Using Undo reverts only the second macro application.
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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

audentis
Posts: 12
Joined: Thu Mar 07, 2019 8:31 am
Operating System: Windows 10

Re: BUG: undocumented behavior with recursive macros

Post by audentis » Thu Mar 07, 2019 11:54 am

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.

steve
Site Admin
Posts: 80693
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: BUG: undocumented behavior with recursive macros

Post by steve » Thu Mar 07, 2019 12:30 pm

steve wrote:
Thu Mar 07, 2019 11:36 am
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.
I've just checked, and it's not fixed, so I'll log it on the bug tracker.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 80693
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: BUG: undocumented behavior with recursive macros

Post by steve » Thu Mar 07, 2019 12:33 pm

audentis wrote:
Thu Mar 07, 2019 11:54 am
Regardless I guess I'll have to learn the proper syntax for Nyquist to achieve my original goal.
If you need help with that, start a new topic on the Nyquist forum board: viewforum.php?f=39
audentis wrote:
Thu Mar 07, 2019 10:16 am
I could not find a bug report forum for non-alpha versions
For non-alpha versions, just post to the normal "Windows" board.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply