Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting the UI sound volume independently #29

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions addons/sound_manager/sound_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,9 @@ func get_sound_volume() -> float:
return db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(sound_effects.bus)))


func get_ui_sound_volume() -> float:
return db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(ui_sound_effects.bus)))


func set_sound_volume(volume_between_0_and_1: float) -> void:
_show_shared_bus_warning()
AudioServer.set_bus_volume_db(AudioServer.get_bus_index(sound_effects.bus), linear_to_db(volume_between_0_and_1))
AudioServer.set_bus_volume_db(AudioServer.get_bus_index(ui_sound_effects.bus), linear_to_db(volume_between_0_and_1))


func play_sound(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer:
Expand All @@ -82,6 +77,24 @@ func stop_sound(resource: AudioStream) -> void:
return sound_effects.stop(resource)


func set_default_sound_bus(bus: String) -> void:
sound_effects.bus = bus


#endregion

#region UI sounds


func get_ui_sound_volume() -> float:
return db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(ui_sound_effects.bus)))


func set_ui_sound_volume(volume_between_0_and_1: float) -> void:
_show_shared_bus_warning()
AudioServer.set_bus_volume_db(AudioServer.get_bus_index(ui_sound_effects.bus), linear_to_db(volume_between_0_and_1))


func play_ui_sound(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer:
return ui_sound_effects.play(resource, override_bus)

Expand All @@ -96,10 +109,6 @@ func stop_ui_sound(resource: AudioStream) -> void:
return ui_sound_effects.stop(resource)


func set_default_sound_bus(bus: String) -> void:
sound_effects.bus = bus


func set_default_ui_sound_bus(bus: String) -> void:
ui_sound_effects.bus = bus

Expand Down Expand Up @@ -209,6 +218,8 @@ func set_default_music_bus(bus: String) -> void:


func _show_shared_bus_warning() -> void:
if "Master" in [music.bus, sound_effects.bus, ui_sound_effects.bus, ambient_sounds.bus]:
push_warning("Using the Master sound bus directly isn't recommended.")
if music.bus == sound_effects.bus or music.bus == ui_sound_effects.bus:
push_warning("Both music and sounds are using the same bus: %s" % music.bus)

Expand Down
6 changes: 5 additions & 1 deletion docs/Sounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ Playing sound effects is broken up into playing general sounds (ie. in the game

- **`SoundManager.set_sound_volume(volume_between_0_and_1: float) -> void:`**

Sets the volume for sounds (both general and UI sounds) using a given float between 0 and 1.
Sets the volume for sounds using a given float between 0 and 1.

- **`SoundManager.set_ui_sound_volume(volume_between_0_and_1: float) -> void:`**

Sets the volume for UI sounds using a given float between 0 and 1.

- **`SoundManager.play_sound(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer`**

Expand Down