Compilation of Working Macros

Discussion about: tracktion.com
RELATED
PRODUCTS

Post

I created a small helper script that displays the properties and values of a selected element (plugin, clip, or track) in a clear and organized way.

Code: Select all

var elementTypes = ['track','clip','plugin']
var propNames
var propNamesArray = [[],[]] 
var combined = [] 
var elements 
var j
var type 

for (i=0;i<elementTypes.length;++i)
{

elements = Tracktion.getSelectedEditElements(elementTypes[i])
if (elements !== null) 
    {
    type = elementTypes[i]
    propNames = elements[0].getPropertyNames() 
    if (typeof propNames === 'string') 
        {
        propNamesArray[0] = propNames.split(', ')
        for (j=0;j<propNamesArray[0].length;++j) 
            {
            combined[j] = propNamesArray[0][j] + ' : \t' +  elements[0].getProperty(propNamesArray[0][j]) 
            }
        }
    }   
}

Tracktion.showMessage(type.toUpperCase() + '\n' + '-----------------------------' + '\n' + combined.join('\n'))
Since the Tracktion.showMessage() method makes the message disappear too quickly, I found a workaround. In the following version of the code, I use a text plugin on any track of my choice, which I name "Console". This plugin then displays the text permanently until the next execution.

Code: Select all

var elementTypes = ['track','clip','plugin']
var propNames
var propNamesArray = [[],[]] 
var combined = [] 
var elements 
var j
var type 

for (i=0;i<elementTypes.length;++i)
{

elements = Tracktion.getSelectedEditElements(elementTypes[i])
if (elements !== null) 
    {
    type = elementTypes[i]
    propNames = elements[0].getPropertyNames() 
    if (typeof propNames === 'string') 
        {
        propNamesArray[0] = propNames.split(', ')
        for (j=0;j<propNamesArray[0].length;++j) 
            {
            combined[j] = propNamesArray[0][j] + ' : \t' +  elements[0].getProperty(propNamesArray[0][j]) 
            }
        }
    }   
}

console(type.toUpperCase() + '\n' + '-----------------------------' + '\n' + combined.join('\n'))

// FUNCTION to output messages to a console
// Setup a text field plugin on any track with Name 'Console' to output messages
function console (string)
{
    var allPlugins = Tracktion.getEditElements('plugin')
    for (i=0;i<allPlugins.length;++i)
    {
        var type = allPlugins[i].getProperty('type')
        var title = allPlugins[i].getProperty('title')
        if (type = 'text' && title == 'Console')
        {
        allPlugins[i].setProperty('body', string)
        }
    }
}

Post

I like the idea of using text fileds as a scripting interface, since you can also use it as an input.
The next code snippet generates a number of aux sends to all tracks of the actual selection.
The amount of the sends per track and the names of their busses are specified by a comma-delimited string typed in the body of the textfield.
To use the script, insert a text plugin to the master track, type 'Input' in the title area, and add some names for the aux busses to the body of the textfield (for example: Test_1, Test_2, Test_3).
Now select a couple of tracks and run the script.

Code: Select all

// This script adds a number of aux sends to selected tracks, following a comma-delimited string of bus names in a text field called 'Input'
// To use the script, first add a text plugin to i.E. the master track, name it 'Input' and enter a comma delimited string of names for the Aux Busses to the text plugin's body
// Select the tracks, you want to add the aux sends to, then run the script
// CAUTION: the script also renames the aux busses following the name string, beginning with the first bus

var consoleArray = readInput()
var tracks = Tracktion.getSelectedEditElements('track')
if (consoleArray !== undefined) 
{
    
    for (x=0; x<consoleArray.length;++x)
    {
    Tracktion.setAuxBusName(x, consoleArray[x])
    }
    
    for (i=0; i<tracks.length; ++i)
    {
        for (j=0;j<consoleArray.length;++j)
        {
            Tracktion.insertPlugin(tracks[i], 'Aux Send')
            var plugins = Tracktion.getPluginsFromTracks(tracks[i])
            plugins[0].setProperty('busNum',consoleArray.length - 1 - j)
        }
    }
}

// function to read out a text field plugin body called 'Input'
// If it contains a comma-delimited string of terms, the function will return an array, containing the single terms
function readInput()
{
    var allPlugins = Tracktion.getEditElements('plugin')
    for (i=0;i<allPlugins.length;++i)
    {
        var type = allPlugins[i].getProperty('type')
        var title = allPlugins[i].getProperty('title')
        if (type == 'text' && title == 'Input')
        {
        var string = allPlugins[i].getProperty('body')
        return string.split(', ')
        }
        else Tracktion.showMessage('Please first set up a text field plugin named "Console" \n and use the text body as input device')
    }
}

Post

One more: Another forum user asked, how to flatten all clips of a track in a batch process, so the single clips will be rendered to project's "Rendered" folder.
Here's what i came up with... You'll need to select a track before you run the script in order to render all it's clips.

Code: Select all

var selTrack = Tracktion.getSelectedEditElements('track')
var clips = Tracktion.getClipsFromTracks(selTrack)
Tracktion.deselectAll()
if (clips !== null)
{
    Tracktion.addObjectsToSelection(clips[0])
    for (i=0; i<clips.length; ++i)
    {
    Tracktion.mergeSelectedClips()
    Tracktion.selectItem('right')
    }
}
else Tracktion.showMessage('Please select a track, containing at least one clip to flatten')

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Delete the gaps between all clips of the selected track(s)

EDIT: use this instead viewtopic.php?p=9239963#p9239963

Code: Select all (#)

// Remove Gaps Between Clips
// Author: TracktionIsNiceBro

var tracks = Tracktion.getSelectedEditElements('track');
if (!tracks || tracks.length === 0) {
    Tracktion.showMessage('No tracks selected');
} else {


    for (var i = 0; i < tracks.length; ++i) {
        var track = tracks[i]
        var trackName = Tracktion.getName(track);
        var clips = Tracktion.getClipsFromTracks(tracks[i]);
        Tracktion.showMessage(trackName + ' has ' + clips.length + ' clips');
        // Select only clips on this track
        Tracktion.deselectAll();
        Tracktion.addObjectsToSelection(clips[0]);
        for (var j = 0; j < clips.length - 1; ++j) {
            var clip = clips[j];
            var next = clips[j + 1];
            var start =
                parseFloat(clip.getProperty('start')) +
                parseFloat(clip.getProperty('length'));
            var end =
                parseFloat(next.getProperty('start'));
            if (end - start > 0.001) {
                Tracktion.setPosition('cursor', start);
                Tracktion.selectItem('right');
                Tracktion.moveStartOfSelectedClipsToCursor();
            }
        }
    }
}
Image
Last edited by TracktionIsNiceBro on Fri May 08, 2026 12:37 pm, edited 1 time in total.
:!: Custom Waveform macros & scripts — Email me

Post

The "Remove Gaps Between Clips" macro does not work for me (tested on Win11 and on Linux).
The following line appears to not select the clip to the right. The before selected clip stays selected. In consequence, the selected clip is moved to now start where before it ended.

Code: Select all

Tracktion.selectItem('right');
The last clip on the track finally stays untouched.

SOLUTION:
Replace this block:

Code: Select all

Tracktion.setPosition('cursor', start);
Tracktion.selectItem('right');
Tracktion.moveStartOfSelectedClipsToCursor();
with:

Code: Select all

Tracktion.deselectAll();
Tracktion.addObjectsToSelection(next);
Tracktion.setPosition('cursor', start);
Tracktion.moveStartOfSelectedClipsToCursor();
Also, this line right before the loop is now obsolete:

Code: Select all

Tracktion.addObjectsToSelection(clips[0]);
Finally, the last touched clip stays selected, but might better become unselected, which I suggest to solve by:

Code: Select all

Tracktion.deselectAll();
So, I suggest to improve the code to the following solution:

Code: Select all

var tracks = Tracktion.getSelectedEditElements('track');
if (!tracks || tracks.length === 0) {
    Tracktion.showMessage('No tracks selected');
} else {


    for (var i = 0; i < tracks.length; ++i) {
        var track = tracks[i]
        var trackName = Tracktion.getName(track);
        var clips = Tracktion.getClipsFromTracks(tracks[i]);
        Tracktion.showMessage(trackName + ' has ' + clips.length + ' clips');
        // Select only clips on this track
        Tracktion.deselectAll();

        for (var j = 0; j < clips.length - 1; ++j) {
            var clip = clips[j];
            var next = clips[j + 1];
            var start =
                parseFloat(clip.getProperty('start')) +
                parseFloat(clip.getProperty('length'));
            var end =
                parseFloat(next.getProperty('start'));
            if (end - start > 0.001) {
                Tracktion.deselectAll();
                Tracktion.addObjectsToSelection(next);
                Tracktion.setPosition('cursor', start);
                Tracktion.moveStartOfSelectedClipsToCursor();
            }
        }
    }
Tracktion.deselectAll();
}
Still, thanks a lot for the very nice idea and draft!
Classical guitar --> Line Audio CM4 @ SSL12 --> KDE-Plasma @ Debian-Linux --> Waveform PRO 13.5

Post Reply

Return to “Tracktion”