Macro Comments

How about macro comments? Say treating lines beginning with ‘#’ as a comment.

There are no plans to develop language features for macros. The lead developer of macros intends that they remain as a simple list of commands.
You could create a simple Nyquist plug-in that does nothing other than store a comment, and then insert that wherever you want to place a comment.

For users that want more sophisticated language feature, scripting features are being developed.
Currently, Nyquist supports macro commands via the “aud-do” command, though currently Nyquist cannot call Nyquist macros.
Scripting is also available via the optional module “mod-script-pipe”, although this is not yet shipped with Audacity and has to be built from the source code. It is hoped that mod-script-pipe will be shipped in the near future (no date set yet). Mod-script-pipe allows external scripting languages such as Python to control Audacity (via “named pipes”). There are a couple of Python scripts provided that may be imported into a user’s own scripts to make programming easier.

Other topic split to: https://forum.audacityteam.org/t/builing-with-mod-script-pipe-on-ubuntu-linux/50684/1

Here’s one. I’ve only tested it on Linux, but I think it should work on other platforms.
comment.ny (271 Bytes)

This simple idea (a preface character that disables a line) is one of the most helpful features of any programming or scripting language. (FORTRAN II had it as far back as 1967)

Apart from the obvious use as a place holder for descriptive text, the leading-character-as-comment acts as an enable/disable switch; a blessing for the macro-developer.

Here I am with my five-line macro, or worse, my ten-line macro, and I would like to suspend operation of one command while I essay with an alternative command.
Today I have to delete the one command, insert a different command and if that substitute does not satisfy my needs, I must delete that substitute and try to remember exactly how I had configured the original deleted command.

Of course, I know how to use Windows Notepad to edit the text file, but that does not solve the “disable” problem.
Of course I can make a backup copy of the macro.TXT and restore it if things don’t work out.
But once we start doing that we are in the world of a proper macro-management system.

Since 3.1.3 supports only a primitive scripting feature - it does not have to parse nested IF statements or FOR loops - why not add one IF statement in the script processor that says "IF the leftmost non-blank character is a “#” THEN ignore this line ELSE …"?

As for the specific symbol, I’d allow, at most, one hour for voting on the character, then close voting.

I’d give up a day of my life to effect that change - and win it back ten times over.
Cheers
Chris

Perhaps this is of some help?

Thank you Paul, but sadly, not at all useful in the sense that I set out in my post.

Comment:_="This macro assembles three prepared FLAC files to a single FLAC file; pre/appends silences; exports as an MP3 file"
Comment:_=""
Comment:_=""
Comment:_="The specific preface "Preface.FLAC" is copied to our default "ChapterPreface.FLAC" by the BATch file
Import2:Filename="macro-output\\ChapterPreface.FLAC"
Comment:_=""
Comment:_="The specific chapter "SSPOV_001.FLAC" is copied to our default "Chapter.FLAC" by the BATch file
Import2:Filename="macro-output\\Chapter.FLAC"
Comment:_=""
Comment:_="The specific suffix "Suffix.FLAC" is copied to our default "ChapterSuffix.FLAC" by the BATch file
Import2:Filename="macro-output\\ChapterSuffix.FLAC"
Comment:_=""
(etc etc etc)

I know how to use the COMMENT command to insert descriptive comments in Audacity macros

The great advantage of a single character to tell a parser to “ignore everything to the right of this character” is the character’s ability to act as a disabling switch.

C AREA OF A TRIANGLE - HERON'S FORMULA
C INPUT - CARD READER UNIT 5, INTEGER INPUT
C OUTPUT -
C INTEGER VARIABLES START WITH I,J,K,L,M OR N
      READ(5,501) IA,IB,IC
  501 FORMAT(3I5)
      IF (IA) 701, 777, 701
  701 IF (IB) 702, 777, 702
  702 IF (IC) 703, 777, 703
  777 STOP 1

Above is a sample of FORTRAN code borrowed from Fortran/Fortran examples - Wikibooks, open books for an open world

C AREA OF A TRIANGLE - HERON'S FORMULA
C INPUT - CARD READER UNIT 5, INTEGER INPUT
C OUTPUT -
C INTEGER VARIABLES START WITH I,J,K,L,M OR N
C     READ(5,501) IA,IB,IC
  501 FORMAT(3I5)
      IF (IA) 701, 777, 701
  701 IF (IB) 702, 777, 702
  702 IF (IC) 703, 777, 703
  777 STOP 1

Above, the same code but I have disabled the READ statement as a (faked up!) experiment.

There is no need for me to delete the READ statement to disable it. In FORTRAN the symbol “C” in column 1 of the punched card causes the FORTRAN compiler to ignore the line for purposes of execution.

Comment:_="This macro assembles three prepared FLAC files to a single FLAC file; pre/appends silences; exports as an MP3 file"
Comment:_=""
Comment:_=""
Comment:_="The specific preface "Preface.FLAC" is copied to our default "ChapterPreface.FLAC" by the BATch file
Import2:Filename="macro-output\\ChapterPreface.FLAC"
Comment:_=""
Comment:_="The specific chapter "SSPOV_001.FLAC" is copied to our default "Chapter.FLAC" by the BATch file
# Import2:Filename="macro-output\\Chapter.FLAC"
Comment:_=""
Comment:_="The specific suffix "Suffix.FLAC" is copied to our default "ChapterSuffix.FLAC" by the BATch file
################## Import2:Filename="macro-output\\ChapterSuffix.FLAC"
Comment:_=""
(etc etc etc)

In the example from the top, I have disabled my second Import command. I confess it is difficult to see, but the disabling of the third Import command is easier to see.
To enable those commands I merely delete the comment symbols. There is no need to re-type or paste the complex path.

I hope that this makes sense
Cheers
Chris

The great advantage of a single character to tell a parser to “ignore everything to the right of this character” is the character’s ability to act as a disabling switch.

Fair enough, a single character does make coding in the parser easier, however, you could make the parser look for several characters, i.e.

Comment:_

Are you using Python for the parser?
If so, maybe something like this?
(The variable mystring contains the macros line number you are parsing)

if "Comment:_" in mystring:
    #  Don't process the line
else:
    # do whatever.

I’m not a Python expert, so if Python can’t handle special chars like “:” and “_” in a string,
you could still probably just use “Comment” as I doubt that appears in any other macro command.

Note that this topic began several years ago, before Macros had documented support for comments.
Macros now have documented support for comments.

Easy. Just add the Comment:_ command at the start of the line that you want to skip.

Example macro:

Normalize:ApplyGain="1" PeakLevel="-1" RemoveDcOffset="1" StereoIndependent="0"
ExportMP3:
FadeIn:

Comment out the “Export” command:

Normalize:ApplyGain="1" PeakLevel="-1" RemoveDcOffset="1" StereoIndependent="0"
Comment:_ ExportMP3:
FadeIn:

Hi Paul; I agree that you could make the parser look for several characters, but I am lazy, and would rather type just one character, one key on the keyboard.

Are you using Python for the parser?

I am using Audacity. (Win10/3.1.3) and Audacity stores the macros as text files. Using the Tools, Macros editing pane right now one can’t insert a character; we have to pick a Command from a palette. The single character could be added to the pallet (or else replace the “Comment” Command with “#”) but I think it better to reduce changes to Audacity itself to a minimum. Who likes work, eh?


I created the macro through the Palette, (tested it briefly to make sure it ran without errors), and then dived into Windows Notepad to fancy it up a bit with the “#” symbol.
I now have full-line comments and in-line comments.
Ignoring my style of language in the comments (grin), I think that the macro is more readable with in-line comments. The suggestion is that the format shown above is easier to read and understand than the same executable code littered (in the vertical sense) with long strings such as “Comment:=” and descriptive text interspersed between executable commands.
Of course, my macro as presented will not run in Audacity 3.1.3
What would be required to make it runnable?
I believe that the answer is at the beginning of the block of code that parses or tokenizes the incoming macro. something along the lines of “If I have come to a hash/pound character that is not within a double-quotes string, then ignore the rest of this line and go get the next line”
It would be as if I had stored the macro like this:-

So much for readability.
My point from yesterday is that with a comment symbol such as “#”, as a macro developer I can temporarily disable one or more commands quickly and easily, and re-enable them just as quickly and easily, as shown below:-

Cheers
Chris

Hi Steve. I may have missed something here. So far with the Tools, Macros palette I have been able only to Delete a command and then Insert a command.
Is there a way to splice one or more characters (such as “Comment:=”) at the left hand side of a command and then suffix (") at the right-hand end?

Once I have a working macro, I am reluctant to make large editing changes to any executable line.

Inserting a single character (the example right now is “#”) at the start of the line is all that is required.
In my reply to Paul five minutes ago I thought that replacing the command “Comment” with “#” might do the trick, but still it would need the ability to insert that single character at the start of the line. Once we start making changes to the entire line all bets are off (grin)
Cheers
Chris

The Macro Manager is OK for short, basic macros, but for anything more complex, direct editing of the Macro .txt file with a plain text (such as NotePad++) editor is easier.

Untitled.png
Thanks Steve. This is how I cobbled together this “fake” macro.
All we need now is some sort of front-end in parsing to ignore characters that follow a non-enclosed “hash symbol” (or whatever is chosen).
Cheers
Chris

I don’t understand why you think that a comment must use a single character. While single characters are commonly used these days, there’s plenty of examples where comments are marked by more than one character.
Some examples in various languages:

REM This is a comment



/* This is a comment */



/**
 * This is a comment
 */



// This is a comment



<!-- This is a comment -->



(:comment This is a comment :)



Comment:_ This is a comment

Hi Steve.
Not so much “must” as a thought of less work.
Why type in two characters when just one will do?
I much prefer a single character when it is a script-like file.
I might argue that a Toggle style ( /* this is a comment */ ) might be valuable for inline comments within a programming language, but I would be hard-pressed to argue for anything greater than a single character for Audacity macros.
If a parser discards everything that follows the comment character, then comments can be spaced to the right, as shown in my earlier example.
DOS batch files seem to get away with a single “colon” character.
Cheers
Chris