API js Scripting problem - adding sounds to multi instrument thru scripting

Hello!

I’m having some troubles with assigning the sounds to multisound instrument via js scrpipt;

In my script I create the event, add tracks to it and want to add sounds from the asset bin.

When I use this method for just a single sound instrument:

var sample = track.addSound(wEvent.timeline, 'SingleSound', 0, 10);
sample.audioFile = studio.project.workspace.masterAssetFolder.getAsset("sound.wav");

all looks good, event is playable and doesn’t have any errors;

However, when I try to propagate sounds to multi sound instrument - I just can’t find right answers for how to do it :smiley:
Can’t find anything precise in the api reference. From some tutorials I got the idea that you need to create Multi instrument on the timeline first, and then add single sounds, than make the multi sound “owner” of single sounds, something like this:

var multiInstrument = track.addSound(wEvent.timeline, 'MultiSound', 0, 10);
var sample = track.addSound(wEvent.timeline, 'SingleSound', 0, 10);
sample.audioFile = studio.project.workspace.masterAssetFolder.getAsset("sound.wav");
sample.owner = multiInstrument;

Yet, this approach creates something super wierd - you get the multi instrument that has this single sound in itself, but also single sound is on the timeline on top of multi instrument. Also, fmod can’t play that event at all, the playhead just stays forever in place.

So what should be a proper way to add sounds to multi instrument via script?

Thanks in advance!
Marcin

You’ve got the right idea, you’ll just want to change the way you’re creating the individual sounds you’re assigning to the Multi Instrument - instead of using GroupTrack.addSound(), use Project.create().

Your code snippet with the above change would look something like this:

var multiInstrument = track.addSound(wEvent.timeline, 'MultiSound', 0, 10);
var sample = studio.project.create('SingleSound');
sample.audioFile = studio.project.workspace.masterAssetFolder.getAsset("sound.wav");
sample.owner = multiInstrument;

Hope that helps!