Macro selection help for crossfading multiple audio clips

I’m trying to crossfade a series of audio clips. I know how to do this using 2 overlapping clips on different tracks, but I want to be able to crossfade many more than 2 – in fact, about 100. I obtain the clips as isolated clips in a single track, as shown in the top of the figure. I know that I can use sound finder to label these, export them, re-drag in that ordered sequence and then align the tracks end-to-end, as at the bottom of the figure.

But to crossfade I would need to select across every adjacent track – which would be a lot of work.

So I looked into Audacity’s Macro feature. But I became really puzzled as to how to make each selection prior to the crossfade? I looked and looked for tutorials and did learn a few things. But I can’t figure it out. Any help would be appreciated.
Screen Shot 2020-01-17 at 5.21.38 PM.jpg

Macros only provide a “list of commands”. There is no “control logic”, so you can’t say “repeat these steps until the end”.
This means that to do this job with a Macro, you need to know exactly how many clips are in the track, and adjust the script to suit.

This example is for 6 clips in the track (5 crossfades), and the crossfade is the last 0.2 seconds of one clip with the first 0.2 seconds of the next clip.

SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"

SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

Unfortunately we don’t yet have the facility to import/export macros, but you can do it manually. See here for details: https://manual.audacityteam.org/man/manage_macros.html#store

Thank you for your help. I made a file containing one track with 5 clips to test your code and ran into the error shown in the top portion of the figure below. I then tried to reproduce the steps of your code manually up to the point where the error occurs and from what I can tell it looks like your code worked for the first crossfade – but I’m not sure.

Here are the details of what I did:

  1. I went to the folder where the Audacity macros are stored and opened one of the txt files, renamed it to MultipleCrossFade.txt
  2. pasted in all your code, closed it
  3. closed Audacity & restarted Audacity
  4. made a test.aup having 5 clips in one track
  5. Put my cursor in that track and ran the MultipleCrossFade macro

I did this all twice just to make sure and got the exact same error each time, and took the screenshot

I then manually moved together all 5 clips on the one track, selected 0.2 on either side of the first 2 clips, and used Effect–>Crossfade clips and took the screenshot. I’m not used to using Crossfade clips, but I assume they work the same – even though the clips version has no way to enter parameters.

Let me know if there’s something else I can try. If this works, I can handle doing what’s needed for 100+ clips
Screen Shot 2020-01-17 at 6.53.03 PM.jpg

Which version of Audacity are you using? (look in “Audacity menu > About Audacity”)

I’m using Audacity 2.3.2 on Catalina(Mac)

I did a little more to investigate. First, I see that you want me to use 6, not 5, clips, so I added one. Second, I removed the gap preceding the first clip and found it did 2 crossfades. So I removed all the gaps between and when I ran it, this time it seemed to work.

This is great and I think I can work with it – just remove the gaps first – but if you have more to offer, I’ll take it.

Looking forward to more Macro capability in the future!

Are you sure that you included the first two lines:

SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"

They should remove all of the gaps.

I believe I have the first 2 lines you mention. See the first screenshot.
Screen Shot 2020-01-17 at 8.24.56 PM.jpg
I decided to make another test file with 6 clips, and I made a 2nd macro called removeGaps.txt with just those 2 lines and as the 2nd and 3rd screenshots show, do indeed remove the gaps.
Screen Shot 2020-01-17 at 8.30.51 PM.jpg
Screen Shot 2020-01-17 at 8.31.06 PM.jpg
But as you can see in the 4th screenshot, when I try the original macro it is now giving another error.
Screen Shot 2020-01-17 at 8.31.33 PM.jpg

and when I remove the first gap in front of the clips, I get the original error again:
Screen Shot 2020-01-17 at 8.37.52 PM.jpg

You will need to do some troubleshooting - it works for me, and I’ve even tried on the old Audacity 2.3.2 :confused:

In the Macro Editor, build the script up one line at a time, and test.

First test:

SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"

Expected result = Selects all, and removes the gaps.


Second test:

SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"
SelNextClip:

Expected result = All gaps removed, and second clip is selected.


Third test:

SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"

Expected result = All gaps removed, selected region is 0.4 seconds long, spanning the “split” between the first and second clips.



Fourth test:

SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

Expected result = All gaps removed, and first split crossfaded.


and so on.


At what point does the script break down?

I can’t work on this right now but I will follow your instructions and get back to you when I can

I did the suggested troubleshooting. The error seems to come after a 2nd crossfade command. This means it is happening when the macro is trying to crossfade the clip that has previously been crossfaded.

I found that the error does not occur when an extra SelNextClip: statement is inserted so that the macro is never trying to crossfade the clip that has previously been crossfaded. But this means that we’re skipping a clip.

So that you can reproduce exactly, I’m attaching a compressed version of a test project (Archive.zip – it’s just something very small I found) and the text for the macros I used. I used 3 macros:

  1. OneCrossFade.txt (works)
SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
  1. TwoCrossFades.txt (errors at 2nd crossfade step)
SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
  1. TwoCrossFadesExtraSelect.txt (works, but skips a clip)
SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
SelNextClip:
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

Here are screenshots showing:
(A) before running any macro
before.jpg
(B) after running TwoCrossFades.txt (which gives the error)
TwoCrossFades.jpg
(C) after running TwoCrossFadesExtraSelect.txt (which works, but skips a clip)
TwoCrossFadesExtraSelect.jpg
Archive.zip (133 KB)

Good idea, but unfortunately “Compressed copy” does not retain gaps in tracks.
I can use “Detach at Silences” to separate the clips, but there is a tiny, one sample length clip at time = 8.749 seconds.
The Macro will fail if any clip is less than 0.2 seconds (the length of the fade).
Check your project carefully and ensure there are no tiny clips hiding in the track.

The exact version of the test file I used above makes a 2.2MB archive – slightly above the limit for this forum’s attachments. So I removed the last 3 clips and that made it small enough; it’s called archive.zip again. I also unarchived it myself and ran all 3 macros mentioned above with the same results.

Before I did that I looked carefully for tiny clips yet saw none. But since you mentioned a very short clip “at time = 8.749”, I selected 8.748 - 8.750 and hit delete. But when I ran the macros, I got the same results – the same error.

So now you should have the exact setup to reproduce what I’m experiencing.

Edit: I can run the Windows version of Audacity 2.3.3 on my Mac via VirtualBox. I just tried it using the archive.zip in this message and got the exact same results as I do running in Mac OSX

Thanks
Archive.zip (1.49 MB)

Congratulations, you’ve uncovered a bug in Audacity.
You can work around it by changing the second line of the Macro to:

TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0.001"

Meanwhile, I’ll try to work out why the bug is happening :wink:

I’ve confirmed that the workaround you offered works. That is, I ran your code with the workaround added on the sample file I provided in my latest Archive.zip. Here is that code if anyone wants to try it in the future:

SelectAll:
TruncateSilence:Action="Truncate Detected Silence" Compress="50" Independent="0" Minimum="0.001" Threshold="-60" Truncate="0.001"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"
SelNextClip:
SelectTime:End="0.2" RelativeTo="SelectionStart" Start="-0.2"
CrossfadeClips:Use_Preset="<Factory Defaults>"

Also, I did 2 more tests, one with 77 clips and one with 200 clips. Here’s the image for the 200 clips in Audacity:
200 clips.jpg
I always made sure there was no blank space before the first clip or after the last clip. Each took less than 15 seconds on my MacBook Pro (late 2015, 2.7GHz with 16MB).

How do you quickly make the 200 clip macro? There might be a better way, but this is what I did:

  1. Put the first 2 lines of code into Excel cell A1
  2. Put the next 3 lines of code (which will be repeated over and over) into cell A2
  3. Drag cell A2 down to A200, which means 199 crossfades which is what you need for 200 clips
  4. Copy A1 to A200 and paste to Word
  5. Copy all within that Word file and paste into a .txt file in the Audacity Macro folder
    which is located here: https://manual.audacityteam.org/man/manage_macros.html#store
  6. close and restart Audacity

Thanks again to steve!!! This was the macro tutorial I needed.

You’re welcome. It would have been a lot easier if we hadn’t encountered that bug, but at least the bug is now logged on the bug tracker.