# Adding audio files automatically to a parameter sheet label

**URL:** https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662
**Category:** FMOD Studio
**Tags:** javascript
**Created:** [May 24, 2024, 8:07am UTC](https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662 "2024-05-24T08:07:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Lulios](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@Lulios](https://qa.fmod.com/u/Lulios)
#### Post date: [May 24, 2024, 8:07am UTC](https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662/1 "2024-05-24T08:07:46Z")

</div>

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.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/c/c81eda9ffbe07592a9531dbcd9c5216f331bdcf0.png)

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.)

---

<div class="post-metadata">

### Author: ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)
#### Post date: [May 28, 2024, 2:30am UTC](https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662/2 "2024-05-28T02:30:22Z")

</div>

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

```js
// 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
instrument.relationships.audioFile.add(newFile)

```

You check the name of a parameter `i` with `studio.window.browserCurrent(). parameters[i].preset.presetOwner.name`, 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)`

---

<div class="post-metadata">

### Author: ![Lulios](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@Lulios](https://qa.fmod.com/u/Lulios)
#### Post date: [May 28, 2024, 10:10am UTC](https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662/3 "2024-05-28T10:10:35Z")

</div>

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.

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/c/cc23098f21bdf8fd91cbaea85773e9cd5a6f9606.png)

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?

```auto
// 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()
event.addGameParameter(param)

```

Thanks again for your precious help.

---

<div class="post-metadata">

### Author: ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)
#### Post date: [May 30, 2024, 4:35am UTC](https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662/4 "2024-05-30T04:35:07Z")

</div>

> [@Lulios](#):
>
> 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).

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.:

```auto
var event = studio.window.browserCurrent();
event.addGroupTrack();

```

> [@Lulios](#):
>
> 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.

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:

```auto
// 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

```

---

<div class="post-metadata">

### Author: ![Lulios](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@Lulios](https://qa.fmod.com/u/Lulios)
#### Post date: [May 30, 2024, 9:10am UTC](https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662/5 "2024-05-30T09:10:14Z")

</div>

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