Query about project script

Hey Leo,

You helped me out a while ago with a project script that automatically makes sure the current section of the song is visible (not matter which “page” of sections it’s on). That’s been working fantastic for a long time now, but I’ve just run into an issue recently.

I remember this previously working, but could just be my clouded memory.
At the moment the script works perfect when a song is playing, but if I stop a song and it’s on the 2nd page of sections, when I click onto another song, it stays on the 2nd page of sections instead of automatically switching back to the first page.

Attached is a video showing you what I’m talking about.

Hey @Adam_Molinaro, could you post your project script again? I’ll check how to fix it then :slight_smile:

// This ensures that the current section is
// always visible in the canvas section jump buttons
onOscChange("/setlist/activeSectionIndex", ([index]) => {
  if (index !== undefined) {
    const sectionOffset = Math.floor(index / 15) * 15;
    setShared("sectionOffset", sectionOffset);
  }
}, true);

This is it :smiling_face:

Hey @Adam_Molinaro,

I think this happens because the active section index doesn’t change when you jump between songs – it always stays at 0, so the sectionOffset isn’t recalculated. We can fix this like so:

// This ensures that the current section is
// always visible in the canvas section jump buttons
function handleSectionOffset() {
  await sleep(50); // wait for active section index to update
  const index = osc("/setlist/activeSectionIndex");

  if (index !== undefined) {
    const sectionOffset = Math.floor(index / 15) * 15;
    setShared("sectionOffset", sectionOffset);
  }
}

handleSectionOffset();
onOscChange("/setlist/activeSongIndex", handleSectionOffset);
onOscChange("/setlist/activeSectionIndex", handleSectionOffset);

This now calls the handleSectionOffset function when either the current song or the current section changes.

Let me know if this works for you :slight_smile:

Hey Leo,

Thanks for this!
I’m getting some errors unfortunately.

Sorry about that, I made two mistakes in the script, here’s an updated version:

// This ensures that the current section is
// always visible in the canvas section jump buttons
async function handleSectionOffset() {
  await sleep(50); // wait for active section index to update
  const index = osc("/setlist/activeSectionIndex");

  if (index !== null) {
    const sectionOffset = Math.floor(index / 15) * 15;
    setShared("sectionOffset", sectionOffset);
  }
}

handleSectionOffset();
onOscChange("/setlist/activeSongIndex", handleSectionOffset);
onOscChange("/setlist/activeSectionIndex", handleSectionOffset);

Does this work better? :slight_smile:

Thanks Leo! This seems to work now, I’ll update if any issues with it.

Thanks heaps! :smiley: