Script to register child events in MultiSound?

on selected events
Add multi-sound,
add a child event,
Add programmer sound to child event
I would like to register a child event for the added multi-sound.
I tried a few things but failed.

var event = studio.window.browserSelection()[0];
var track = event.addGroupTrack("audio 1");
var multiInstrument = track.addSound(event.timeline, 'MultiSound', 0, 10);

var childEvent = studio.project.create("Event");
childEvent.name = 'voc1';
childEvent.folder = event;

var childtrack = childEvent.addGroupTrack("Audio 1");

var programInstrument = childtrack.addSound(childEvent.timeline, 'ProgrammerSound', 0, 10);
programInstrument.name = "ProgrammerSound test";


//programInstrument.owner = multiInstrument;  <- fail
//multiInstrument.sounds.push(childEvent); <- fail
//multiInstrument.sounds.push(programInstrument); <- fail

These fail because the programmer instrument belongs to the childEvent.timeline already. You’ll want to create the instrument independently of the timeline, and then add it to the multi instrument, like so:

var programmerInstrument = studio.project.create('ProgrammerSound');
programmerInstrument.owner = multiInstrument;
// or
multiInstrument.relationships.sounds.add(programmerInstrument);

This fails because childEvent isn’t actually an instrument/sound, it’s an event. You’ll need to do create an event instrument, assign the child event to it, then add it to the multi instrument:

var eventInstrument = studio.project.create('EventSound');
eventInstrument.event = childEvent;
eventInstrument.owner = multiInstrument;
// or
multiInstrument.relationships.sounds.add(eventInstrument);

Using the code below means,
multiInstrument.relationships.sounds.add(programInstrument);

This error occurs.
15:35:02 [script-error] An error in the callback “onClicked”: Error: Cannot modify relationship ‘sounds’ as the objects belong to different files., callstack:

I want to insert the child event’s programmer’s instrument into the parent’s multi-instrument.

Just to be clear, are you trying to transfer ownership of the programmer instrument from the child “voc1” event to the parent “attack” event? Or are you trying to have child event retain ownership while also having the programming instrument as an item in the multi instrument?

I would like to maintain ownership and place the programming instrument within the multi-instrument.


To be precise, child tracks are registered under multi instrument.

Unfortunately, it’s not possible to place an instrument belonging to another event in a multi-instrument’s playlist. An instrument can only belong to a single thing at once.

What audio behavior are you trying to accomplish by placing an existing programmer instrument in the multi-instrument’s playlist? With more detail, I may be able to suggest an alternative way to implement the desired behavior.

If you drag it directly, it will be registered. Is it not supported in the script?

Dragging directly into a multi-instrument cannot be done with programmer instruments. However, it can be done with events like “voc1” - dragging “voc1” into the multi-instrument will create an event instrument that plays the “voc1” event.

Below, I’ve modified your original code snippet to do what you seem to want - it will create an event “voc1”, add “voc1” to an event instrument, and add the event instrument to a multi-instrument:

var event = studio.window.browserSelection()[0];
var track = event.addGroupTrack("audio 1");
var multiInstrument = track.addSound(event.timeline, 'MultiSound', 0, 10);

var childEvent = studio.project.create("Event");
childEvent.name = 'voc1';
childEvent.folder = event;

var eventInstrument = studio.project.create('EventSound');
eventInstrument.event = childEvent;
eventInstrument.owner = multiInstrument;