Script to toggle mute/unmute for a clip?

Not having furthered my basic programming skills since 1978, and hoping someone could help with a script:

  1. to select the current clip (left arrow, right arrow, ctrl+,)
  2. determine if that clip is muted or not (content and/or amplitude check)
  3. if amplitude > 0 set entire clip volume to 0% using adjustable fade
  4. if amplitude = 0 set entire clip volume to 100% using adjustable fade

ctrl+L is similar, but seems to preclude resurrecting the clip down the road…

Cheers from Munich, Germany!

The easiest way to select an audio clip is to double click on it.

That’s quite tricky with macros. Can’t you just look to see if the clip is grayed out?


Much easier to just “Normalize” to 0 dB (See: Normalize - Audacity Manual)

If you need to do this frequently, you could create a Macro with just the Normalize effect, and then create a keyboard shortcut to run the Macro. (See: Shortcuts Preferences - Audacity Manual). All you would then need to do is:

  1. Double click on the clip
  2. Shortcut for the “Normalize to 0 dB” macro.

Thanks for the quick reply! I learned I need to check out keyboard shortcuts since I want to run this on individual clips. The macros are done, but it is about individual clips and not complete projects or files.

My amplitude check idea is simply to have one shortcut instead of making two – I will survive that.

Normalize to 0 dB would likely restore the clip hotter than the original. How can I restore to the original amplitude? (BTW - I am dealing with live brass recordings which are to be mixed together)

You wrote:

3) if amplitude > 0 set entire clip volume to 0% using adjustable fade
3) if amplitude = 0 set entire clip volume to 100% using adjustable fade



If the original peak amplitude is 0 dB, then “Normalize” to 0 dB will effectively do nothing - the result will have a peak amplitude of 0 dB, so you don’t need the conditional logic.
Try it :slight_smile:

Normalize to 0 dB makes my clip louder than original, and means the dynamic relation to other clips in that track are lost. I don’t want to normalize the tracks until later in the project, after I have heard and selected the final clips.

dB is in minus, whereas I used “amplitude” for waveform size/volume. I want to be able to both mute and restore clips to original volume at will, independent of ctrl+z order.

My macro to mute (now key-associated) works. Fading that clip back in to 100%, however doesn’t even work manually…

To answer your “title” question:

In a macro, if you add the command “UnmuteTracks:” it will un-mute the current track if was muted, and do nothing if it was not muted.


Macros can be very useful for chaining multiple commands, but they don’t do logical operations. They are just a simple list of commands.

There’s no facility in Audacity macros for:

IF
THEN
ELSE

When considering how to implement a chain of actions, ask yourself if it is possible to do what you want without using “conditional” statements. If it is, then Macros are probably the best choice.

If you really must have conditional statements, then you need to use a proper scripting language, such as “Nyquist” (Audacity’s built-in scripting language: https://manual.audacityteam.org/man/nyquist.html

Nyquist scripts can be made into plug-ins that can be installed, though for simple scripts it is easier to just run the script in the “Nyquist Prompt” effect (see: https://manual.audacityteam.org/man/nyquist_prompt.html)


A simple example of a Nyquist script that can be run in the Nyquist Prompt:

Say that you want:
If peak level < 0 dB, scale to half amplitude,
else if peak level >= 0 dB, scale to 10% amplitude.

This example is not possible without conditional logic, so we can’t use a Macro, but we can use Nyquist. For simplicity, this script is for mono tracks only.
Here’s the script:

;version 4

(setf peak (get '*selection* 'peak))

;; 0 dB = +/- 1.0 on linear scale
(if (< peak 1)
    (mult *track* 0.5)
    (mult *track* 0.1))

Then the clip had a peak level below 0 dB.

Sorry we are circling around the meaning of 0 dB. I want to take clips with a visible waveform, flat-line them and retain the possibility of later, making them audible again to the original recorded volume. It is about being able to mute clips, then as desired, very likely in a different order, un-mute to original volume. I can live with two shortcuts and then there is no need for a conditional statement.

Right now I am only able to return clips to the original volume using ctrl+z - adjustable fade-in doesn’t later restore the beginning of any clip that was set at 0% back to 100%. I had thought clips would retain the original amplitude as a memory characteristic, but fade-out seems to override it in the longer term.

The possibilities in audacity are really amazing, really mind-boggling in my case, as you certainly can tell. Will be reverting to cut and paste for this project. Thanks for your ideas and help Steve!

Let’s clear that up to start.

  • The dB scale (for signals) uses “full scale” as the reference level. Thus a waveform that is full track height is said to have a “peak amplitude of 0 dB”.
  • Most normal signal levels are less than “full scale”, so being less that 0 dB they have negative numbers.
  • “dB” is a logarithmic scale: Half track height is about -6 dB, 1/4 track height is about -12 dB, 1/8th track height is about -18 dB … (a factor of 2 is approximately 6 dB).
  • “Silence” is negative infinity dB.

The vertical scale of an audio track in Audacity is +/- 1, which is a linear scale.
If a waveform touches either the top (+1 linear scale) or the bottom (-1 linear scale), then it has a peak amplitude of 0 dB.
On the linear scale, silence has an amplitude of zero.

There’s no really good way to do that right now, but please raise this question again when the next version of Audacity comes out. There is a good way to do it in the next version :slight_smile:


You are correct. When an effect is applied in Audacity, it is directly applied to the track audio. This is called “destructive editing” or “WYSIWYG editing”.


A little “trick” that I sometimes use is to have a muted track (I usually put it at the top of the project) to hold audio clips that I don’t need right away. That track stays muted all the time, so it does not play and is not included when exporting the project.

If I have an audio clip that I want to temporarily silence, I do these steps:

  1. Double click on the clip to select it.
  2. “Ctrl + C” (Copy)
  3. “Ctrl + L” (Silence the selection) - this now acts as a placeholder.
  4. Click on the muted “dummy” track at the top
  5. “Ctrl + V” (paste)

When I want to put that clip back:

  1. Double click on the clip in the muted “dummy” track
  2. “Ctrl + C”
  3. Double click on the silenced clip (the “placeholder”)
  4. “Ctrl + V”