Filter Fade Button

Hi, I have a fade button setup already and a slider for volume and filter seperate.
I was just wondering if I could have some help setting up a fade button for the filter also?
Basically just want a parameter to fade down over a certain period of time.
It would be also good if it could have a variable so that when it hits 0, my button can change colour and icon.

Thanks heaps! :smiley:

Would I be able to get some help with this please?

Hey @Adam_Molinaro,

Please excuse my late reply!

Since you already have your filter slider working, and if I remember correctly, you’ve also got the AbletonOSC connection set up and know your track/device/parameter indices, so we’d just need to build the button on top of that.

The idea is to sweep the parameter from its current value down to 0 in small steps over a fixed duration, and store the state in a shared variable so your button’s colour and icon can react to it.

Button Type: Script

Script on Press:

const tracks = [TRACK_INDEX];  // add more indices here if you need several tracks
const device = DEVICE_INDEX;
const param = PARAM_INDEX;
const fadeDuration = 8000;     // ms — total duration of the sweep
const steps = 300;
const stepTime = fadeDuration / steps;

// Prevents overlapping sweeps if the button is pressed mid-fade
if (shared("filterFading", false)) return;
setShared("filterFading", true);

const isClosed = shared("filterClosed", false);

if (isClosed) {
  // Sweep back up to the previous value
  const prev = shared("filterPrev", 1.0);
  for (let i = 1; i <= steps; i++) {
    const v = (i / steps) * prev;
    for (const t of tracks) {
      sendOsc(":AbletonOSC/live/device/set/parameter/value", int(t), int(device), int(param), v);
    }
    await sleep(stepTime);
  }
  setShared("filterClosed", false);
} else {
  // Save the current value, then sweep down to 0
  const current = osc(":AbletonOSC/live/device/TRACK_INDEX/DEVICE_INDEX/get/parameter/value", 1) ?? 1.0;
  setShared("filterPrev", current);
  for (let i = 1; i <= steps; i++) {
    const v = current * (1 - i / steps);
    for (const t of tracks) {
      sendOsc(":AbletonOSC/live/device/set/parameter/value", int(t), int(device), int(param), v);
    }
    await sleep(stepTime);
  }
  setShared("filterClosed", true);
}

setShared("filterFading", false);

Replace TRACK_INDEX, DEVICE_INDEX and PARAM_INDEX with the same values you’re already using in your filter slider. Note that the osc() line needs the indices written directly into the path, not as variables.

Label:

${shared("filterClosed") ? "Filter In" : "Filter Out"}

Dynamic Background Color:

${shared("filterClosed") ? "pink-400" : "pink-900"}

Icon:

The Icon field doesn’t have a separate Dynamic toggle — you just type the template straight in:

${shared("filterClosed") ? "ICON_CLOSED" : "ICON_OPEN"}

Swap in whichever icon names you’re using elsewhere in your Canvas.

Worth noting that if you drag your existing filter slider by hand, the button won’t know about it and the colour/icon could end up out of sync. To avoid that, add this line at the end of the slider’s Script on Change:

setShared("filterClosed", value <= 0);

That way the button’s state follows the slider too, and it should flip its colour and icon the moment the filter reaches 0 regardless of how it got there.

Keep in mind that 300 steps over 8 seconds is around one message every 26 ms, which should be smooth for a single track. If you’re driving several tracks at once, each step multiplies by the number of tracks, so if you notice any lag try lowering steps to 150 or 100. Adjust fadeDuration to taste as well.

Let me know how this behaves on your end!

Thank you!

At the moment it doesn’t seem to be working, here’s what I adapted it to as per your messages…

const tracks = [89, 90, 91, 92, 93]; // add more indices here if you need several tracks

const device = 1;

const param = 1;

const fadeDuration = 8000; // ms — total duration of the sweep

const steps = 300;

const stepTime = fadeDuration / steps;

// Prevents overlapping sweeps if the button is pressed mid-fade

if (shared(“filterFading”, false)) return;

setShared(“filterFading”, true);

const isClosed = shared(“filterClosed”, false);

if (isClosed) {

// Sweep back up to the previous value

const prev = shared(“filterPrev”, 1.0);

for (let i = 1; i <= steps; i++) {

const v = (i / steps) * prev;

for (const t of tracks) {

  sendOsc(":AbletonOSC/live/device/set/parameter/value", int(t), int(device), int(param), v);

}

await sleep(stepTime);

}

setShared(“filterClosed”, false);

} else {

// Save the current value, then sweep down to 0

const current = osc(“:AbletonOSC/live/device/90/1/get/parameter/value”, 1) ?? 1.0;

setShared(“filterPrev”, current);

for (let i = 1; i <= steps; i++) {

const v = current * (1 - i / steps);

for (const t of tracks) {

  sendOsc(":AbletonOSC/live/device/set/parameter/value", int(t), int(device), int(param), v);

}

await sleep(stepTime);

}

setShared(“filterClosed”, true);

}

setShared(“filterFading”, false);

Let me know if there’s anything I’ve done wrong there.
I’ll test the icon and colour feedback once I know it’s actually working inside Ableton :smiley:

Hey @Adam_Molinaro,

Thanks for pasting the script. I tested this exact logic on my end and it works, so the script itself is sound. That means the issue is almost certainly in the indices or the connection setup rather than the code.

A couple of quick things to check:

1. Confirm your device index

I noticed you’re using device = 1. Send this in the OSC Command Tester and see what comes back:

:AbletonOSC/live/device/get/name 89 1

If that returns an “index out of range” error, or the name of a device that isn’t your rack, that’s your culprit, as the script will run through completely without moving anything. Try 0 instead and see which one returns your effect rack.

Once you have the right device index, confirm the parameter too:

:AbletonOSC/live/device/get/parameters/name 89 DEVICE_INDEX

Your macro should show up in that list. Count from 0 to get its index.

2. Check that start_listen is set up

The script reads the current value before sweeping, and for that to work AbleSet needs to be subscribed to the parameter. In your AbletonOSC connection settings, under OSC on Create, you should have, for e.g:

/live/device/start_listen/parameter/value 89 0 1

After adding it, reconnect the connection (or restart AbleSet) so it actually fires. You can verify it’s working by moving the macro in Live and watching for the value to appear in the OSC values list at the bottom of the connection settings.

Without this, the script falls back to a default of 1.0, which would make the parameter jump to maximum before sweeping down.

3. Watch out for curly quotes

In what you pasted, the quotes came through as “filterFading” instead of "filterFading". That’s most likely just the forum reformatting them, but if those curly quotes ended up in the actual script editor it would be a syntax error and nothing would run at all. Worth a look.

Let me know what the device name check returns.

I’m looking forward to your reply!

Following up on this. The problem wasn’t your script, it was where it was running. Canvas scripts run in the browser, and browsers throttle timers when the window isn’t in focus to save power. So the moment you pressed the button and switched over to Live to watch the filter move, the sweep slowed to a crawl. With AbleSet in focus it ran at normal speed, which is exactly why it looked like nothing was happening.

The fix is to move the fade into the Project Script, which runs host-side and isn’t affected by this at all. The button just triggers it. I’ve tested this end to end and it runs correctly regardless of which window is in focus.

In Settings → MIDI Mapping, OSC & Scripting → Project Script:

const tracks = [89, 90, 91, 92, 93];
const device = 1;
const param = 1;
const fadeDuration = 8000;
const steps = 300;
const stepTime = fadeDuration / steps;

onOscChange("/shared/runFade", async ([value]) => {
  if (!value) return;

  const isClosed = shared("filterClosed", false);

  if (isClosed) {
    const prev = shared("filterPrev", 1.0);
    for (let i = 1; i <= steps; i++) {
      const v = (i / steps) * prev;
      for (const t of tracks) {
        sendOsc(":AbletonOSC/live/device/set/parameter/value", int(t), int(device), int(param), v);
      }
      await sleep(stepTime);
    }
    setShared("filterClosed", false);
  } else {
    const current = osc(":AbletonOSC/live/device/89/1/get/parameter/value", 1) ?? 1.0;
    setShared("filterPrev", current);
    for (let i = 1; i <= steps; i++) {
      const v = current * (1 - i / steps);
      for (const t of tracks) {
        sendOsc(":AbletonOSC/live/device/set/parameter/value", int(t), int(device), int(param), v);
      }
      await sleep(stepTime);
    }
    setShared("filterClosed", true);
  }
});

And your button’s Script on Press becomes just this:

setShared("runFade", now());

Using now() matters here. onOscChange only fires when the value actually changes, so sending a timestamp guarantees a new value on every press. If you sent true instead, the second press would send the same value and nothing would happen.

Your label and colour templates stay exactly as they are, reading shared("filterClosed").

Save the Project Script.

You can also remove the start_listen line from OSC on Create for this parameter.

And it’s still worth confirming device = 1 is correct, since you had 0 in your earlier setup.
Send :AbletonOSC/live/device/get/name 89 1 in the OSC Command Tester and make sure it returns your effect rack.

Let me know how this behaves on your end!

Thank you guys! Sorry I thought I’d replied already, but my message was sitting there unsent :man_facepalming:
I’ve got it working now!