Compilation of Working Macros

Discussion about: tracktion.com
RELATED
PRODUCTS

Post

whyterabbyt wrote: Sun May 10, 2020 1:35 pm Okay, now I'll post.

The OP hasnt been around for a while, but I still think its nice to have a central repository of scripts so here are some more...
...
Thanks for adding that!

I’m still lurking about, but have not had time to add to this thread. I hope everyone continues to add bits and pieces as they develop macros and scripts.
iMacPro 1,1 | 64gb | OSX 10.15.7
http://www.gesslr.com
http://www.storyaudio.com

Post

gesslr wrote: Sat Nov 21, 2020 12:44 pm As mentioned in the OP, this is for posting working macros.

This is the main thread from which most of these were pulled and where a lot of discussion occurs. You might have more luck posting your question there.

viewtopic.php?f=22&t=441475&hilit=macro
ohhh my apologies, Thx for the link.

Post

Hi all.

Can anyone help me with something?

I'm trying to create a two macros:

1- Allows me to select any clip on a track and invoke the macro to select all following clips on the same track

2 - Allows me to select any clip on a track and invoke the macro to select all following clips on all tracks. (It doesn't matter if clips on other tracks that occur at the same time as the initial starting clip are selected or not.)

In either case, at the end of the process, the view of the project would not have changed.

This code will select ALL clips on a track, but I don't know how to give it directionality and selectivity.

Code: Select all

var track = Tracktion.getTrackFromSelectedObject();
var clips = Tracktion.getClipsFromTracks (track);
var position = Tracktion.getPosition (selected);
Tracktion.addObjectsToSelection (clips);
This next is adapted from other code found here or in the API. It tests whether or not a clip follows AFTER the starting clip and then selects it, but I couldn't get anything but the last clip on the track to be selected.

Code: Select all

//SELECT FOLLOWING CLIPS

var track = Tracktion.getTrackFromSelectedObject();
var clips = Tracktion.getClipsFromTracks (track);
var position = Tracktion.getPosition (selected);

var minSeparation = 0.1;
var newPosition = 36000;

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

    	if (clipStart > position && clipStart < newPosition)
        	if (clipStart > (position + minSeparation))
        		Tracktion.addObjectsToSelection (clip[i]);
            		Tracktion.selectItem ('right');
            		newPosition = clipStart;
}

if (newPosition != 36000)
{
    Tracktion.setPosition ('transport', position);
    Tracktion.setViewBoundsAroundTime (position, 0.6);
}
I imagine macro #2 would build on a working version of this, but with an additional iterative level to determine how many tracks had clips...? (My coding days are long passed me I'm afraid.)

Anyway, if anyone has a moment and is willing, I'd appreciate any insights. Thank you.
iMacPro 1,1 | 64gb | OSX 10.15.7
http://www.gesslr.com
http://www.storyaudio.com

Post

NVM.
iMacPro 1,1 | 64gb | OSX 10.15.7
http://www.gesslr.com
http://www.storyaudio.com

Post

Can someone Please help me with creating a macro to add a instants of a plugin to every track.

Post

I think this will do it.
viewtopic.php?f=22&t=539280&p=7657680#p7657680
Thanks again to AGreen for sharing that macro.

Post

:tu:

Erik

Post

Some macros I have developed form my needs of editing a click track and applying a tempo map.

Duplicate selected range in clip
This macro duplicates the selected range as a clip before the selection. The rest of tracks with an empty space.

Usage:
1. Select a range with the mouse.
2. then select the clip containing the click track.
3. execute the macro.

Code: Select all

function pasteClip(clip, start, end)
{
    Tracktion.log("Pasting clip " + clip + " starting at " + start);
    Tracktion.deselectAll();
    Tracktion.addObjectsToSelection(clip);
    Tracktion.copy();
    Tracktion.insertSpaceIntoEdit (start, end - start); // for all tracks
    Tracktion.paste();
    Tracktion.setPosition ('cursor', start);
    Tracktion.moveStartOfSelectedClipsToCursor();
    var trclips = Tracktion.getClipsFromTracks (Tracktion.getTrackFromSelectedObject());
    var seclips = Tracktion.getSelectedEditElements ('clip');
    Tracktion.log("After pasting, there are " + seclips.length + " selected clips out of " + trclips.length);
}

function splitMarkedRegion(old_method)
{
    var start = Tracktion.getPosition ('markIn');
    var end   = Tracktion.getPosition ('markOut');
    if ( ! old_method) {
        Tracktion.log("Using API split method");
        Tracktion.splitMarkedRegion();
    } else {
        Tracktion.log("Using old split method");
        Tracktion.setPosition ('cursor', start);
        Tracktion.splitClips();
        Tracktion.setPosition ('cursor', end);
        Tracktion.splitClips();
        Tracktion.log("Selected Region: start = " + start + ", end = " + end);
    }
    return [start, end];
}

function duplicateSelectedRegion()
{
    var clips   = Tracktion.getSelectedEditElements ('clip');
    if (clips.length == 0) {
        Tracktion.showMessage('No clips selected');
        return;
    }
    Tracktion.log("========================================");
    var clickTrack = Tracktion.getTrackFromSelectedObject();
    var clickTrackName = Tracktion.getName(clickTrack);
    var marks = splitMarkedRegion(true);
    var start = marks[0];
    var end   = marks[1];
    clips = Tracktion.getClipsFromTracks (clickTrack);
    Tracktion.log("Click Track has " + clips.length + " clips selected.");
    var index = 0;
    if (clips.length == 3) {
        index = 1;
    }
    pasteClip(clips[index], start, end);
}
duplicateSelectedRegion();
Insert padding for selected tracks
This macro inserts padding at the beginning of selected tracks. This is necessary for the Groove Doctor not to shift clips in tracks where there are empty spaces.
Usage:
1. Select tracks in the track header.
2. Execute the macro.

Code: Select all

function logTrack(track, i, clips)
{
    name = Tracktion.getName(track);
    Tracktion.log("Track[" + i + "] = " + name + " has " + clips.length + " clips");
}

function padTracks(tracks, start)
{
    for(var t = 0; t < tracks.length; ++t ) {
        name = Tracktion.getName(tracks[t]);
        Tracktion.log("Padding Track[" + t + "] name  (" + name + ")");
        Tracktion.deselectAll();
        Tracktion.addObjectsToSelection(tracks[t]);
        Tracktion.setPosition ('cursor', start);
        Tracktion.insertClip ('wave');
    }
}

function mergeAllClips(tracks)
{
    Tracktion.deselectAll();
    for(var t = 0; t < tracks.length; ++t ) {
        var clips = Tracktion.getClipsFromTracks (tracks[t]);
        logTrack(tracks[t], t, clips);
        for(var c = 0; c < clips.length; ++c ) {
            Tracktion.addObjectsToSelection(clips[c]);
            var clipName = Tracktion.getName(clips[c]);
            Tracktion.log("Processing Track " + t + ", clip " + c + " (" + clipName + ")");
            if (clipName === 'New Audio Clip') {
                var newName = Tracktion.getName(clips[c-1]);
                Tracktion.log("Setting clip " + c + " name to (" + newName + ")");
                Tracktion.setName (clips[c], newName);
            }
        } 
    }
    // Even though we have selected all clips, merge processing is per track
    Tracktion.mergeSelectedClips (true);
}

function selectedTracksPadding() {
 var tracks   = Tracktion.getSelectedEditElements ('track');
    if (tracks.length == 0) {
        Tracktion.showMessage('No tracks selected');
        return;
    }
    Tracktion.log("Selected " + tracks.length + " tracks");
    padTracks(tracks, 0);
    mergeAllClips(tracks);
}
selectedTracksPadding();
Pick every 4th transient in clip
The following macro picks up every Nth transient in the selected clip. The code is for every 4th transient. You can produce duplicates of this macro and change the decimation factor to 3 or 2, as needed.
Usage:
1. Select clip.
2. Execute the macro.

Code: Select all

// ---------------------------------------------------
// Decimates a click track pulses every 'decimationFactor'
// User must select the clip to be decimated.
// Only one clip must be selected.
// --------------------------------------------------

var decimationFactor = 4;     // usually 4 in 99% of the use cases
var offset           = 0;     // from 0 to decimationFactor-1
var inverted         = false; // inverted decimation condition

function removeSilence(track)
{
    Tracktion.removeSilence(true);
    return Tracktion.getClipsFromTracks (track);
}

function mergeClips(track, clips) {
    Tracktion.deselectAll();
    Tracktion.addObjectsToSelection(clips);
    Tracktion.mergeSelectedClips();
    return Tracktion.getClipsFromTracks (track);
}

function decimateClips(track, clips, N, offset, inverted) {
    Tracktion.deselectAll();
    for (var c = 0; c < clips.length; ++c) {
        var modulus = (c + N - offset) % N;
        if ( ! inverted && modulus != 0) {
            Tracktion.addObjectsToSelection (clips[c]);
        } else if (inverted && modulus == 0) {
            Tracktion.addObjectsToSelection (clips[c]);
        }
    }
    Tracktion.deleteSelected();
    return Tracktion.getClipsFromTracks (track);
}   


function pickTransientsInClipEvery(N, offset)
{
    var clips = Tracktion.getSelectedEditElements ('clip');
    var track = Tracktion.getTrackFromSelectedObject();

    if (clips === null) {
        Tracktion.showMessage('No clip selected');
        return;
    }
    if (clips.length > 1) {
        Tracktion.showMessage('Too many clips selected');
        return false;
    }
    var track = Tracktion.getTrackFromSelectedObject();
    var name = (inverted ? 'upbeats' : 'downbeats');
    Tracktion.setName (track, name);   // name track depending on condition
    clips = removeSilence(track);
    clips = Tracktion.getClipsFromTracks (track);
    clips = decimateClips(track, clips, N, offset, inverted);
    clips = mergeClips(track, clips);
    Tracktion.setName (clips[0], name);   // final clip name
}

pickTransientsInClipEvery(decimationFactor, offset, inverted);
Last edited by musirafael on Thu Dec 08, 2022 7:46 pm, edited 2 times in total.

Post

Updated macro. Everithing is automatic until GrooveDoctor is called.

Post

Refactored macros. Instead of a single macro handling everything, the whole process is more modular (and a bit more manual) but the following macros are reusable in other contexts. I intend to produce a document explaining the workflow. Don't have the time and the skills for nice videos. :-(

The macros are also available in my Github repository ready to be imported.

Post Reply

Return to “Tracktion”