Currently, I’m in FMOD v2.02.22. In my script, I’m attempting to import any tracks that have the name “BRP” in them to a new project that is identical to the old one, basically a copy and paste, it works great, but I’m planning on importing Master Track data too. This is what I’m having issues with, I’m not able to copy over the track config for those events.
Specifically, I need to recreate the event master track’s pre-fader effects, effect property values, and automation/action-sheet lanes. I’m using targetEvent.masterTrack.mixerGroup.effectChain.addEffect(effectType) and then trying to move the created effect with targetEvent.masterTrack.mixerGroup.effectChain.relationships.effects.insert(index, effect), but the result doesn’t ever actually happen on the other project, it just remains unchanged.
My questions would be, how can I remove or replace existing effects on an event’s master track, add effects before the fader in the same order, apply copied effect property values, and recreate master track automation lanes for those effect properties?
Maybe there’s a better solution to my madness and I’m just completely off the rails.
This is a snippet of the code:
function importMasterEffects(targetEvent, exportedEffects)
{
var masterTrack = targetEvent.masterTrack;
var mixerGroup = masterTrack.mixerGroup;
var effectChain = mixerGroup.effectChain;
var effects = effectChain.effects;
// Clear existing master effects
for (var i = effects.length - 1; i >= 0; i--)
{
studio.project.deleteObject(effects[i]);
}
for (var j = 0; j < exportedEffects.length; j++)
{
var data = exportedEffects[j];
// Example values:
// data.effectType = "GainEffect" / "MultibandEqEffect"
// data.index = original effect-chain index
// data.properties = exported copyable effect properties
// data.automators = exported automator/curve data
var effect = effectChain.addEffect(data.effectType);
// Tried to move effect before fader / restore original chain index. This is the part I am least confident about.
try
{
effectChain.relationships.effects.insert(data.index, effect);
}
catch (e)
{
// For proxy/shared effects, tried using the last relationship destination.
var destinations = effectChain.relationships.effects.destinations;
if (destinations && destinations.length > 0)
{
effectChain.relationships.effects.insert(
data.index,
destinations[destinations.length - 1]
);
}
}
for (var prop in data.properties)
{
if (data.properties.hasOwnProperty(prop))
{
try
{
effect[prop] = data.properties[prop];
}
catch (e2)
{
}
}
}
// Trying to recreate automation/action-sheet lanes for this master effect.
for (var a = 0; a < data.automators.length; a++)
{
var automatorData = data.automators[a];
var propertyName = automatorData.propertyName;
try
{
// masterTrack.addAutomationTrack(gainEffect, "gain");
masterTrack.addAutomationTrack(effect, propertyName);
}
catch (e3)
{
}
try
{
var automator = effect.addAutomator(propertyName);
for (var c = 0; c < automatorData.curves.length; c++)
{
var curveData = automatorData.curves[c];
// parameterTarget may be targetEvent.timeline
// or a local/game parameter object.
var curve =
automator.addAutomationCurve(parameterTarget);
for (var p = 0; p < curveData.points.length; p++)
{
curve.addAutomationPoint(
curveData.points[p].position,
curveData.points[p].value
);
}
}
}
catch (e4)
{
}
}
}
}