Hi!
I’m in the process of trying to do custom scripts for some operations I have to do on a ton of events, and I’m not sure if some of the things I’m trying to do are not possible currently, or if I just didn’t find them yet.
Here’s the list of what I’m trying to do (in bold what I didn’t manage to find):
- Add a tempo marker at the start: there doesn’t seem to be a function for that, is that correct?
- Add a NamedMarker at start: addNamedMarker.
- Find the position of two bars before the end of my only Single Instrument in the event: I can’t seem to find a way to get the instruments on the event.
- Add a Transition to that named marker: addTransitionMarker
- Add a condition parameter to that transition: addParameterCondition
- Create a transition timeline: By default it’s null, and unless I manually open it, I can’t find how to make it non null.
- Change the transition timeline length: transitionTimeline.length
- Keep playing source during transition timeline: transitionTimeline.modules[0].length
- Start playing destination during transition timeline: I’m not too sure. It looks like transitionTimeline.modules[1].length should do the trick, but it has weird effects I don’t really understand.
If I just set it to some values, it only changes the yellow line in the line with the time/bars. I tried to drag it manually, then update the length through the console and ended up with that weird result:
Is that a bug?
And that’s all for now! The scripting API looks very cool, but it’s a bit complicated to find detailed info on what can be done beyond the high level described in the doc.
Edit: Just thought it may be simpler if I just put the code I have with what’s missing:
studio.menu.addMenuItem({
name: "Scripts\SetupLoop",
isEnabled: function () {
var markers = studio.window.editorSelection();
return markers.length > 0 ? true : false;
},
execute: function () {
//TODO: Check timeline first track single instrument length to get the transitionbarIndex automatically
var transitionBarIndex = parseInt(studio.system.getText("Transition bar", "0"));
var transitionTime = (transitionBarIndex - 1) * 4 * 60 / 105;
var transitionDuration = 2 * 4 * 60 / 105;
var events = studio.window.browserSelection();
for(i = 0; i < events.length; i++)
{
var e = events[i];
//TODO: Add a tempo marker on first markerTrack
if(e.markerTracks.length < 2)
e.addMarkerTrack();
e.uiMaxMarkerTracksVisible = 2;
var mt = e.markerTracks[1];
var nm;
if(mt.markers.length > 0 && mt.markers[0].position == 0)
nm = mt.markers[0];
else
nm = mt.addNamedMarker("Start", 0);
var tm;
if(mt.markers.length > 1 && mt.markers[1].position == transitionTime)
{
tm = mt.markers[1];
}
else
{
tm = mt.addTransitionMarker(transitionTime, nm);
tm.addParameterCondition(studio.project.lookup("parameter:/KeepLooping"), 0.5, 1);
}
//TODO: Create the transition timeline if it doesn't exist.
if(tm.transitionTimeline != null)
{
tm.transitionTimeline.length = transitionDuration;
tm.transitionTimeline.modules[0].length = transitionDuration;
//TODO: Set destination transition length to transitionDuration as well
//TODO: Make sure there's no fade curve on either of the source or destination transitions
}
}
}
});
Note: It somehow looks like accessing the transition timeline or changing its length through the API corrupts it or something, as if I try to manually drag the destination blend into it, it does the same kind of weird thing you can see in my screenshot above.