clip toggle loop macro

Discussion about: tracktion.com
Post Reply New Topic
RELATED
PRODUCTS

Post

[Edit] Found an issue with this: this only works properly in 120 BPM clips. Other BPM values require the length values to be scaled, but I don't know how to access the BPM property from javascript... The API is rather limited, so if anyone has suggestions, I'm all ears!

Hey, not sure if am missing something in the macro/scripting functions, but I wanted to have the "L" loop toggle on a clip trigger with a hotkey, and I could not find it as an available macro function anywhere, so I decided to write a little script for it. I've tested it on some of my midi clips and it seems to work fine. If I've missed something (script-wise) or this function actually is available as a macro, feel free to let me know. Otherwise I thought this might be useful to some of you

Code: Select all

var clips = Tracktion.getSelectedEditElements ('clip');

// math.round both rounds numbers and ensures values are returned as float. It seems they sometimes are not otherwise
 
var lsb = Math.round(clips[0].getProperty('loopStartBeats'));
var llb =  Math.round(clips[0].getProperty('loopLengthBeats'));

// current length
var l = Math.round(clips[0].getProperty('length'));

// offset changes loopstarbeats
var o = Math.round(clips[0].getProperty('offset'));


//llb > 0 means we have a loop. So we disable looping. Otherwise we enable it.
if(llb > 0)
{
    // unloop
    clips[0].setProperty('loopLengthBeats', 0);

    // reset length
    clips[0].setProperty('length', llb * 0.5);

    l = clips[0].getProperty('length');

    // start offset
    clips[0].setProperty('offset', lsb * 0.5);
}
else
{
    
    clips[0].setProperty('loopLengthBeats', l *2);
    clips[0].setProperty('length', l * 2);

    // start offset to 0
    clips[0].setProperty('offset', 0);
    // loop offset to offset * 2
    clips[0].setProperty('loopStartBeats', o * 2);

}

Last edited by stuffkikker on Fri Nov 27, 2020 11:28 am, edited 1 time in total.

Post

and you know what, another one I personally find very useful, so perhaps someone else does as well;
this one selects all clips after the transport position. My songs tend to start as a whole series of individual clips scattered around, and when I start arranging them into a proper composition I find it useful to be able to just do 'select all clips after this point' without having to manually drag a selection field

Code: Select all

// get position in seconds
var position = Tracktion.getPosition ('cursor');

var clips = Tracktion.getEditElements ('clip');

var selectedClips = [];
Tracktion.deselectAll();

for (var i = 0; i < clips.length; ++i)
{
    var clipStart = parseFloat (clips[i].getProperty ('start'));

    if (clipStart > position)
    {
        selectedClips.push(clips[i]);        
    }        
}

Tracktion.addObjectsToSelection(selectedClips);


Post Reply

Return to “Tracktion”