No internet connection
  1. Home
  2. How to

How to change target track if overlap exists

By Iain Anderson @Iain_Anderson
    2022-10-04 11:56:41.521Z

    Hi there,

    I'm working on a script that learns the location, start, end, duration and name of a number of clips on a timeline. I'm wanting to paste those clips to a new track(s) whilst catching overlaps. I have the code to calculate if an overlap exists but i'm stuck at how to implement updating the paste track on each clip and subsequent clip that is affected.

    function checkForOverlaps() {
        //sort sceneClips into ascending order based on targetTrack
        sceneClips.sort((a, b) => a.targetTrack - b.targetTrack);
        //calculate if overlap exists
        function doesOverlapExist(a, b) {
            return (a.start < b.end && b.start < a.end);
        }
    

    sceneClips is my list of clips that the script has learned.

    How do I run the function doesOverlapExist on each object in the array? This is the closest i've got.

        sceneClips.forEach(function (element) {
            element.overlap = doesOverlapExist();
        });
    

    Once the sceneClips list has been updated with any overlaps, how do I then add 1 (+1) to paste track for clips that have overlaps and all subsequent clips?

    function updatePasteTrack() {
        sceneClips.forEach(function (element) {
            if (sceneClips.overlap == True) {
                element.targetTrack = element.targetTrack + 1;
            } else {
                element.targetTrack = element.targetTrack
            }
        });
        return sceneClips;
    }
    

    This is where i've got so far.

    Any help greatly appreciated.

    Many thanks,

    Iain

    • 2 replies
    1. O

      This kinda what you're looking to recreate?

      I've also turned this into a Template | AAF Organizer - COPY/CUT to Target Track | in the store.

      But maybe you're building a newer better...

      1. IIain Anderson @Iain_Anderson
          2022-10-05 16:22:55.323Z

          Hi Owen,

          Thanks for the link. The end result will be very similar to this but i'd like to achieve it within the script and not using ProTools to determine and act on the overlap.

          My script will eventually log where all the clips end up on the timeline so I need it to happen in the script.

          Cheers,

          Iain