Creating tracks inside a submix track via script
-
- KVRer
- 22 posts since 21 Jul, 2023
Hey folks, i'm having an issue with scripting, which is driving me nuts. I want to create tracks inside a submix track via script. Creating a track or submix track via .insertTrack() method is no problem, but i still couldn't find a way to create tracks INSIDE a submix track, or move it into an existing submix track alternatively.
Any ideas?
Any ideas?
- KVRian
- 764 posts since 25 Jul, 2010 from Northern Ireland
It seems that 'Pack selected tracks to a Submix track' is not exposed to the API, so this will not be possible AFAIK
-
- KVRer
- Topic Starter
- 22 posts since 21 Jul, 2023
Thanks for your reply! Yeah, i was afraid, this would be the case. I already read the API up and down but couldn't find a solution too.
I hope the API will be extended soon. It still lacks a lot of features, although it could be such a powerful tool.
I hope the API will be extended soon. It still lacks a lot of features, although it could be such a powerful tool.
- KVRian
- 764 posts since 25 Jul, 2010 from Northern Ireland
Yeah I agree, the API needs updating. I found the Tracktion Engine source related to Submix tracks here :-
https://github.com/Tracktion/tracktion_ ... derTrack.h
https://github.com/Tracktion/tracktion_ ... rTrack.cpp
Not sure if it will be any help.
https://github.com/Tracktion/tracktion_ ... derTrack.h
https://github.com/Tracktion/tracktion_ ... rTrack.cpp
Not sure if it will be any help.
- KVRian
- 764 posts since 25 Jul, 2010 from Northern Ireland
I see from the 'compilation of working macros' section that you are proficient in javascript. 
You might be the person to work out how to implement a request of mine to render out all the clips on a track sequentially.
I did have this somewhat working in the past , but it would always bug out when it came to the last clip in the track where the loop would get stuck as there were no more clips to the right.
I can go into more detail if it is something you would consider taking a look at ?
Thanks.
You might be the person to work out how to implement a request of mine to render out all the clips on a track sequentially.
I did have this somewhat working in the past , but it would always bug out when it came to the last clip in the track where the loop would get stuck as there were no more clips to the right.
I can go into more detail if it is something you would consider taking a look at ?
Thanks.
- KVRian
- 764 posts since 25 Jul, 2010 from Northern Ireland
Ok cool, thanks ..below is what I am trying to accomplish :-
(1) Set loop range over selected clip/s ( this is only needed as a visual to show the progress )
Tracktion.markAroundSelected();
.....................................
I manually select the 1st clip here , but there is probably a method to do this by just selecting the track ?
(2) Merge is really Flatten if done on a single audio clip. This renders the clip to the ->Project/Rendered folder.
Tracktion.mergeSelectedClips();
.....................................
(3) Select the next audio clip to the right of currently selected audio clip
Tracktion.selectItem ('right');
....................................
The 3 steps (1) (2) and (3) above need to repeat continuously until step (3) is no longer true
....................................
With the help of chatgpt I have been able to get it to run the loop, but the problem is the loop gets stuck when there are no more clips to the right of the last clip ...so it therefore iterates rendering the last clip until I hard kill Waveform.
Basically a reliable/working check is required that stops the loop when Tracktion.selectItem ('right'); is no longer available.
Here is 1 of the many scritps that I got to work until it goes into a forever loop on the last clip:-
while (true)
{
// Step 1: mark the loop range visually
Tracktion.markAroundSelected();
// Step 2: merge (flatten) the selected clip(s)
Tracktion.mergeSelectedClips();
// Step 3: remember currently selected clip(s)
var before = Tracktion.getSelectedEditElements('clip');
// move to the next clip on the right
Tracktion.selectItem('right');
// get newly selected clip(s)
var after = Tracktion.getSelectedEditElements('clip');
// if same clip (or nothing changed), stop looping
if (!before.length == after.length &&
before.every((v, i) => v === after))
break;
}
(1) Set loop range over selected clip/s ( this is only needed as a visual to show the progress )
Tracktion.markAroundSelected();
.....................................
I manually select the 1st clip here , but there is probably a method to do this by just selecting the track ?
(2) Merge is really Flatten if done on a single audio clip. This renders the clip to the ->Project/Rendered folder.
Tracktion.mergeSelectedClips();
.....................................
(3) Select the next audio clip to the right of currently selected audio clip
Tracktion.selectItem ('right');
....................................
The 3 steps (1) (2) and (3) above need to repeat continuously until step (3) is no longer true
....................................
With the help of chatgpt I have been able to get it to run the loop, but the problem is the loop gets stuck when there are no more clips to the right of the last clip ...so it therefore iterates rendering the last clip until I hard kill Waveform.
Basically a reliable/working check is required that stops the loop when Tracktion.selectItem ('right'); is no longer available.
Here is 1 of the many scritps that I got to work until it goes into a forever loop on the last clip:-
while (true)
{
// Step 1: mark the loop range visually
Tracktion.markAroundSelected();
// Step 2: merge (flatten) the selected clip(s)
Tracktion.mergeSelectedClips();
// Step 3: remember currently selected clip(s)
var before = Tracktion.getSelectedEditElements('clip');
// move to the next clip on the right
Tracktion.selectItem('right');
// get newly selected clip(s)
var after = Tracktion.getSelectedEditElements('clip');
// if same clip (or nothing changed), stop looping
if (!before.length == after.length &&
before.every((v, i) => v === after))
break;
}
-
- KVRer
- Topic Starter
- 22 posts since 21 Jul, 2023
I tried by iterating through all clips of a selected track and merge clip by clip, but actually it stops after flattening the first clip. Seems i will need some trial and error 
Edit: Just to show, what I've tried...
Edit: Just to show, what I've tried...
Code: Select all
var selTracks = Tracktion.getSelectedEditElements('track')
if (selTracks !== null)
{
var trackObject = selTracks[0]
var clips = Tracktion.getClipsFromTracks (trackObject)
for (i=0;i<clips.length;++i)
{
Tracktion.deselectAll()
Tracktion.addObjectsToSelection(clips[i])
Tracktion.mergeSelectedClips ()
}
}
else Tracktion.showMessage('Please select a track, containing at least one clip')
- KVRian
- 764 posts since 25 Jul, 2010 from Northern Ireland
This is very interesting and it's great that you are working on this too.
I notice in your script that the Tracktion.showMessage is only displayed if no tracks are selected and does not show when we select a track that contains no clips.
I wonder if there is a way to show using 'Tracktion.showMessage' the array of clips ( clip names ) that are being iterated ? This would at least be useful to show what is working perhaps ?
I notice in your script that the Tracktion.showMessage is only displayed if no tracks are selected and does not show when we select a track that contains no clips.
I wonder if there is a way to show using 'Tracktion.showMessage' the array of clips ( clip names ) that are being iterated ? This would at least be useful to show what is working perhaps ?
- KVRian
- 764 posts since 25 Jul, 2010 from Northern Ireland
Code: Select all
(function() {
var processedClipNames = new Set();
// Get initial selected clip(s)
var clip = Tracktion.getSelectedEditElements('clip');
if (!clip || clip.length === 0) {
Tracktion.showMessage("No clip selected to start.");
return;
}
while (true) {
var currentClip = clip[0];
// Safely get the clip name
var clipName = "[unknown]";
try {
if (typeof currentClip.getProperty === 'function') {
var tmp = currentClip.getProperty('name');
if (tmp) clipName = tmp;
} else if (currentClip.name) {
clipName = currentClip.name;
}
} catch(e){}
// Skip if this clip name has already been processed
if (processedClipNames.has(clipName)) {
break; // stop loop
}
// Add to processed set
processedClipNames.add(clipName);
// Select only this clip
try { Tracktion.deselectAllEditElements('clip'); } catch(e){}
try { Tracktion.selectEditElement(currentClip); } catch(e){}
// Mark loop range visually (optional)
try { Tracktion.markAroundSelected(); } catch(e){}
// Flatten/merge this clip
try { Tracktion.mergeSelectedClips(); } catch(e){
Tracktion.showMessage("Error flattening clip: " + clipName);
}
// Move to the next clip on the right
try { Tracktion.selectItem('right'); } catch(e){}
// Get newly selected clip(s)
var nextClips = Tracktion.getSelectedEditElements('clip');
if (!nextClips || nextClips.length === 0) {
break; // no more clips
}
// Prepare for next iteration
clip = nextClips;
}
Tracktion.showMessage("All clips flattened individually (by name).");
})();
OK I have found a working solution, all we do is select the 1st Clip on A track & run the script. All Clips are then flattened sequentially.
-
- KVRer
- Topic Starter
- 22 posts since 21 Jul, 2023
Ok, I also found a solution, so just for the sake of completion... 
To run the code, you need to select a track. The script flattens all the clips on the track.
I mostly try to avoid while-loops, they can freeze your machine, if there's no proper condition to stop it. I just didn' comment the code and saved a few lines, but I guess, the code is quite simple and should be obvious, what happens in each line.
To run the code, you need to select a track. The script flattens all the clips on the track.
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')
- KVRian
- 764 posts since 25 Jul, 2010 from Northern Ireland
wow this is a very clean solution, great work
Yeah I have hard crashed Waveform a lot using while loops lol
