ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Changing sound volume (https://www.esoui.com/forums/showthread.php?t=10475)

mirrorman009 03/11/23 05:39 AM

Changing sound volume
 
Hi,

I would like to temporarily change the volume of a played sound in my addon. From https://wiki.esoui.com/Sounds I can apparently do this by:

You can also play with volume by modifying audio settings before playing your sound (settingId = AUDIO_SETTING_UI_VOLUME)


Forgive my newb-ness, but how do I change this settingId? Is it just an additional parameter to the PlaySound call?

Thanks for any help,
Mirrorman

Baertram 03/11/23 05:52 AM

If you just want to change the volume of that 1 sound just call PlaySound with the same parameters more than once. It will get louder that way but that does not work with all sounds of the SOUNDS table! So you need to test it.

Lua Code:
  1. PlaySound(SOUNDS.VOLUME_DING_ALL)
  2. PlaySound(SOUNDS.VOLUME_DING_ALL) --should make it 2times as loud as normal
  3. PlaySound(SOUNDS.VOLUME_DING_ALL) --should make it 3times as loud as normal

About your question with the settings:
Changing the overall sound volume will affect ALL sounds played and other effects too so it might make your whole game be loud, not only that 1 sound :D
If you want to achieve this you need to use the GetSetting* and SetSetting* API functions to set/get the correct category and index in that category.
There should be one category constant for the audio settings e.g. and then different index constants for the volumes.
You can fidn those at the vailla source code, where the settings menu is build:

https://github.com/esoui/esoui/blob/...shared.lua#L11

If I'm not wrong the main category(or system) would be SETTING_TYPE_AUDIO and the index AUDIO_SETTING_AUDIO_VOLUME

Code:

--- @param system [SettingSystemType|#SettingSystemType]
--- @param settingId integer
--- @param value string
--- @param setOptions [SetOptions|#SetOptions]
--- @return void
function SetSetting(system, settingId, value, setOptions) end

--- @param system [SettingSystemType|#SettingSystemType]
--- @param settingId integer
--- @return value string
function GetSetting(system, settingId) end

--- @param system [SettingSystemType|#SettingSystemType]
--- @param settingId integer
--- @return value bool
function GetSetting_Bool(system, settingId) end

Afaik the value you pass in to SetSetting must be a string! So convert the value you want to set via tostring(valueToSet)
and if you use GetSetting convert that value with tonumber(GetSetting(SETTING_TYPE_AUDIO, AUDIO_SETTING_AUDIO_VOLUME)) so you can do mathematics with it properly (allthough lua should accept mathematics with string numbers too I guess :-) )

mirrorman009 03/11/23 08:04 AM

@Baertram, thanks very much! Your repeating the PlaySound command worked for what I needed. Now back to listening to all 500 or so sounds to find the one that I want!

Baertram 03/12/23 04:01 AM

Install merTorchbug, ingame type /tb and click on the Sounds tab. Clicking a row will play it as preview.

Is your want the user to choose a sound and your addon uses LibAddonMenu for settings, try the LibAddonMenu SoundSlider widget. You can choose a sound there and let it preview upon selection.


All times are GMT -6. The time now is 09:01 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI