Adding audio files automatically to a parameter sheet label

Hello everyone,

I have been trying to figure out how to script the addition of an audio file to each label of a parameter sheet.

So far, I have been manually dropping the audio file into the track for each label, but this process is quite tedious, as I have to do it for dozens of parameter sheets.

I am using project.importAudioFile to import the audiofiles with their paths and I tried to use GroupTrack.addSound but I can’t figure out how to use it with a parameter sheet, I only found usages of it with timelines.

My parameter sheets are based on a global parameter in case it could be important.

I would really appreciate if someone could help out by giving a simple example of how to do it, if that’s possible in the first place of course.

Thank you!

(I already created this topic yesterday but just accidentally deleted it, sorry for the inconvenience.)

Here’s a simple example of how to create an instrument on a parameter sheet, and add an audio file to it via script:

// import audio file
var newFile = studio.project.importAudioFile("C:\\your\\file\\path\\here.wav");

// get first parameter in event currently selected in event browser
var param = studio.window.browserCurrent().parameters[0];

// create single instrument between range of 0 and 1 on parameter's sheet's first group track 
var instrument = studio.window.browserCurrent().groupTracks[0].addSound(param, 'SingleSound', 0, 1);

// add new file to instrument

You check the name of a parameter i with studio.window.browserCurrent(). parameters[i], which you can use to compare between parameters to indentify which to place the instrument on.

Additionally, you can add instruments to the event’s master track instead of a group track by using addSound() on the event master track, i.e.: studio.window.browserCurrent().masterTrack.addSound(param, 'SingleSound', 0, 1)

I could not manage to add a sound to the group track of my event with your first method (it seems that parameter sheets using a labeled parameter don’t use group tracks). However, adding instruments to the master track with your last command worked perfectly, thank you!

I would like to ask you a last question about this.
Before adding audio files to the event parameter sheet, I create my global labeled parameter then I link it to my event to create my parameter sheet.
It seems to work, but only the first label is then visible in the FMOD project, even when trying to zoom out.


The only way I found to circumvent that is to edit the parameter, click on “OK” and zoom out to make the missing labels reappear after executing the script.

Here is how I do it, maybe I do something wrong?

// create global labeled parameter
var param = studio.project.workspace.addGameParameter({name: 'Language', type: studio.project.parameterType.UserEnumeration})
param.isGlobal = 1;

// give labels and initial value to parameter
var paramArr = ["ENG", "ESP", "FRA", "PTB"];
param.enumerationLabels = paramArr;
param.initialValue = 0;

// link global parameter to event
event = studio.window.browserCurrent()

Thanks again for your precious help.

This is likely because your event has no group tracks. If they don’t exist (event.groupTracks is empty), you can add them to the event with addGroupTrack() - i.e.:

var event = studio.window.browserCurrent();

This is due to the parameter’s maximum value being set to lower than the number of labels. If you specify the maximum value yourself when you create the parameter, it should resolve the issue:

// give labels and initial value to parameter
var paramArr = ["ENG", "ESP", "FRA", "PTB"];
param.enumerationLabels = paramArr;
param.initialValue = 0;
param.maximum = paramArr.length; // in this case, 4

My last issues have been resolved thanks to your last instructions.
Everything works as expected now.
Thanks a lot for your answers.

1 Like