From b3811773be452a32fc9b790f6b4f81c990bfa1b1 Mon Sep 17 00:00:00 2001 From: Salia Nifo Date: Sat, 5 Oct 2024 23:14:27 -0400 Subject: [PATCH 1/3] Implement multiple music channels --- addons/dialogic/Modules/Audio/event_music.gd | 35 +++++++- addons/dialogic/Modules/Audio/index.gd | 4 + .../dialogic/Modules/Audio/settings_audio.gd | 17 ++++ .../Modules/Audio/settings_audio.tscn | 26 ++++++ .../dialogic/Modules/Audio/subsystem_audio.gd | 90 +++++++++++-------- addons/dialogic/Modules/Clear/event_clear.gd | 6 +- 6 files changed, 138 insertions(+), 40 deletions(-) create mode 100644 addons/dialogic/Modules/Audio/settings_audio.gd create mode 100644 addons/dialogic/Modules/Audio/settings_audio.tscn diff --git a/addons/dialogic/Modules/Audio/event_music.gd b/addons/dialogic/Modules/Audio/event_music.gd index c54c5bd9d..438af43d6 100644 --- a/addons/dialogic/Modules/Audio/event_music.gd +++ b/addons/dialogic/Modules/Audio/event_music.gd @@ -9,6 +9,8 @@ extends DialogicEvent ## The file to play. If empty, the previous music will be faded out. var file_path := "" +## The channel to use. +var channel_id: int = 0 ## The length of the fade. If 0 (by default) it's an instant change. var fade_length: float = 0 ## The volume the music will be played at. @@ -24,8 +26,8 @@ var loop := true ################################################################################ func _execute() -> void: - if not dialogic.Audio.is_music_playing_resource(file_path): - dialogic.Audio.update_music(file_path, volume, audio_bus, fade_length, loop) + if not dialogic.Audio.is_music_playing_resource(file_path, channel_id): + dialogic.Audio.update_music(file_path, volume, audio_bus, fade_length, loop, channel_id) finish() @@ -55,6 +57,7 @@ func get_shortcode_parameters() -> Dictionary: return { #param_name : property_info "path" : {"property": "file_path", "default": ""}, + "channel" : {"property": "channel_id", "default": 0}, "fade" : {"property": "fade_length", "default": 0}, "volume" : {"property": "volume", "default": 0}, "bus" : {"property": "audio_bus", "default": "", @@ -73,6 +76,24 @@ func build_event_editor() -> void: 'file_filter' : "*.mp3, *.ogg, *.wav; Supported Audio Files", 'placeholder' : "No music", 'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]}) + add_header_edit('channel_id', ValueType.FIXED_OPTIONS, {'left_text':'on:', 'options': get_channel_list()})#[ + #{ + #'label': 'Channel A', + #'value': 0, + #}, + #{ + #'label': 'Channel B', + #'value': 1, + #}, + #{ + #'label': 'Channel C', + #'value': 2, + #}, + #{ + #'label': 'Channel D', + #'value': 3, + #} + #]}) add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Fade Time:'}) add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()') add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()') @@ -84,3 +105,13 @@ func get_bus_suggestions() -> Dictionary: for i in range(AudioServer.bus_count): bus_name_list[AudioServer.get_bus_name(i)] = {'value':AudioServer.get_bus_name(i)} return bus_name_list + + +func get_channel_list() -> Array: + var channel_name_list := [] + for i in ProjectSettings.get_setting('dialogic/audio/max_channels', 4): + channel_name_list.append({ + 'label': 'Channel %s' % (i + 1), + 'value': i, + }) + return channel_name_list diff --git a/addons/dialogic/Modules/Audio/index.gd b/addons/dialogic/Modules/Audio/index.gd index a75bc3d4c..f2ff1270a 100644 --- a/addons/dialogic/Modules/Audio/index.gd +++ b/addons/dialogic/Modules/Audio/index.gd @@ -8,3 +8,7 @@ func _get_events() -> Array: func _get_subsystems() -> Array: return [{'name':'Audio', 'script':this_folder.path_join('subsystem_audio.gd')}] + + +func _get_settings_pages() -> Array: + return [this_folder.path_join('settings_audio.tscn')] diff --git a/addons/dialogic/Modules/Audio/settings_audio.gd b/addons/dialogic/Modules/Audio/settings_audio.gd new file mode 100644 index 000000000..6f2b9227d --- /dev/null +++ b/addons/dialogic/Modules/Audio/settings_audio.gd @@ -0,0 +1,17 @@ +@tool +extends DialogicSettingsPage + +## Settings page that contains settings for the audio subsystem + + +func _ready() -> void: + %MusicChannelCount.value_changed.connect(_on_music_channel_count_value_changed) + + +func _refresh() -> void: + %MusicChannelCount.value = ProjectSettings.get_setting("dialogic/audio/max_channels", 4) + + +func _on_music_channel_count_value_changed(value:float) -> void: + ProjectSettings.set_setting('dialogic/audio/max_channels', value) + ProjectSettings.save() diff --git a/addons/dialogic/Modules/Audio/settings_audio.tscn b/addons/dialogic/Modules/Audio/settings_audio.tscn new file mode 100644 index 000000000..6dc0dcad2 --- /dev/null +++ b/addons/dialogic/Modules/Audio/settings_audio.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=2 format=3 uid="uid://c2qgetjc3mfo3"] + +[ext_resource type="Script" path="res://addons/dialogic/Modules/Audio/settings_audio.gd" id="1_2iyyr"] + +[node name="Audio" type="VBoxContainer"] +offset_right = 121.0 +offset_bottom = 58.0 +script = ExtResource("1_2iyyr") + +[node name="Label" type="Label" parent="."] +layout_mode = 2 +theme_type_variation = &"DialogicSettingsSection" +text = "Music Channels" + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +layout_mode = 2 + +[node name="Label" type="Label" parent="HBoxContainer"] +layout_mode = 2 +text = "Max music channels" + +[node name="MusicChannelCount" type="SpinBox" parent="HBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +min_value = 1.0 +value = 1.0 diff --git a/addons/dialogic/Modules/Audio/subsystem_audio.gd b/addons/dialogic/Modules/Audio/subsystem_audio.gd index e27fbeb42..5a6cf1b71 100644 --- a/addons/dialogic/Modules/Audio/subsystem_audio.gd +++ b/addons/dialogic/Modules/Audio/subsystem_audio.gd @@ -15,6 +15,7 @@ extends DialogicSubsystem ## `volume` | [type float] | The volume of the audio resource that will be set to the [member base_music_player]. [br] ## `audio_bus` | [type String] | The audio bus name that the [member base_music_player] will use. [br] ## `loop` | [type bool] | Whether the audio resource will loop or not once it finishes playing. [br] +## `channel` | [type int] | The channel id to play the audio on. [br] signal music_started(info: Dictionary) @@ -30,12 +31,24 @@ signal music_started(info: Dictionary) signal sound_started(info: Dictionary) +#const MAX_CHANNELS = 6 + +var max_channels: int: + set(value): + if max_channels != value: + max_channels = value + ProjectSettings.set_setting('dialogic/audio/max_channels', value) + ProjectSettings.save() + current_music_player.resize(value) + get: + return ProjectSettings.get_setting('dialogic/audio/max_channels', 4) + ## Audio player base duplicated to play background music. ## ## Background music is long audio. var base_music_player := AudioStreamPlayer.new() ## Reference to the last used music player. -var current_music_player: AudioStreamPlayer +var current_music_player: Array[AudioStreamPlayer] = [] ## Audio player base, that will be duplicated to play sound effects. ## ## Sound effects are short audio. @@ -49,7 +62,8 @@ var base_sound_player := AudioStreamPlayer.new() ## ## If you want to stop sounds only, use [method stop_all_sounds]. func clear_game_state(_clear_flag := DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void: - update_music() + for idx in max_channels: + update_music('', 0.0, '', 0.0, true, idx) stop_all_sounds() @@ -58,10 +72,14 @@ func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void: if load_flag == LoadFlags.ONLY_DNODES: return var info: Dictionary = dialogic.current_state_info.get("music", {}) - if info.is_empty() or info.path.is_empty(): - update_music() + if not info.is_empty() and info.has('path'): + update_music(info.path, info.volume, info.audio_bus, 0, info.loop, 0) else: - update_music(info.path, info.volume, info.audio_bus, 0, info.loop) + for channel_id in info.keys(): + if info[channel_id].is_empty() or info[channel_id].path.is_empty(): + update_music('', 0.0, '', 0.0, true, channel_id) + else: + update_music(info[channel_id].path, info[channel_id].volume, info[channel_id].audio_bus, 0, info[channel_id].loop, channel_id) ## Pauses playing audio. @@ -94,55 +112,54 @@ func _ready() -> void: base_sound_player.name = "Sound" add_child(base_sound_player) + + current_music_player.resize(max_channels) ## Updates the background music. Will fade out previous music. -func update_music(path := "", volume := 0.0, audio_bus := "", fade_time := 0.0, loop := true) -> void: +func update_music(path := "", volume := 0.0, audio_bus := "", fade_time := 0.0, loop := true, channel_id := 0) -> void: + + if not dialogic.current_state_info.has('music'): + dialogic.current_state_info['music'] = {} - dialogic.current_state_info['music'] = {'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop} - music_started.emit(dialogic.current_state_info['music']) + dialogic.current_state_info['music'][channel_id] = {'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop, 'channel':channel_id} + music_started.emit(dialogic.current_state_info['music'][channel_id]) var fader: Tween = null - if is_instance_valid(current_music_player) and current_music_player.playing or !path.is_empty(): + if is_instance_valid(current_music_player[channel_id]) and current_music_player[channel_id].playing or !path.is_empty(): fader = create_tween() var prev_node: Node = null - if is_instance_valid(current_music_player) and current_music_player.playing: - prev_node = current_music_player.duplicate() - add_child(prev_node) - prev_node.play(current_music_player.get_playback_position()) + if is_instance_valid(current_music_player[channel_id]) and current_music_player[channel_id].playing: + prev_node = current_music_player[channel_id] fader.tween_method(interpolate_volume_linearly.bind(prev_node), db_to_linear(prev_node.volume_db),0.0,fade_time) if path: - current_music_player = base_music_player.duplicate() - add_child(current_music_player) - current_music_player.stream = load(path) - current_music_player.volume_db = volume + current_music_player[channel_id] = base_music_player.duplicate() + add_child(current_music_player[channel_id]) + current_music_player[channel_id].stream = load(path) + current_music_player[channel_id].volume_db = volume if audio_bus: - current_music_player.bus = audio_bus - if not current_music_player.stream is AudioStreamWAV: - if "loop" in current_music_player.stream: - current_music_player.stream.loop = loop - elif "loop_mode" in current_music_player.stream: + current_music_player[channel_id].bus = audio_bus + if not current_music_player[channel_id].stream is AudioStreamWAV: + if "loop" in current_music_player[channel_id].stream: + current_music_player[channel_id].stream.loop = loop + elif "loop_mode" in current_music_player[channel_id].stream: if loop: - current_music_player.stream.loop_mode = AudioStreamWAV.LOOP_FORWARD + current_music_player[channel_id].stream.loop_mode = AudioStreamWAV.LOOP_FORWARD else: - current_music_player.stream.loop_mode = AudioStreamWAV.LOOP_DISABLED + current_music_player[channel_id].stream.loop_mode = AudioStreamWAV.LOOP_DISABLED - current_music_player.play(0) - fader.parallel().tween_method(interpolate_volume_linearly.bind(current_music_player), 0.0, db_to_linear(volume),fade_time) - else: - if is_instance_valid(current_music_player): - current_music_player.stop() - current_music_player.queue_free() + current_music_player[channel_id].play(0) + fader.parallel().tween_method(interpolate_volume_linearly.bind(current_music_player[channel_id]), 0.0, db_to_linear(volume),fade_time) if prev_node: fader.tween_callback(prev_node.queue_free) ## Whether music is playing. -func has_music() -> bool: - return !dialogic.current_state_info.get('music', {}).get('path', '').is_empty() +func has_music(channel_id := 0) -> bool: + return !dialogic.current_state_info.get('music', {}).get(channel_id, {}).get('path', '').is_empty() ## Plays a given sound file. @@ -187,10 +204,11 @@ func interpolate_volume_linearly(value: float, node: Node) -> void: ## Returns whether the currently playing audio resource is the same as this -## event's [param resource_path]. -func is_music_playing_resource(resource_path: String) -> bool: - var is_playing_resource: bool = (base_music_player.is_playing() - and base_music_player.stream.resource_path == resource_path) +## event's [param resource_path], for [param channel_id]. +func is_music_playing_resource(resource_path: String, channel_id := 0) -> bool: + var is_playing_resource: bool = (is_instance_valid(current_music_player[channel_id]) + and current_music_player[channel_id].is_playing() + and current_music_player[channel_id].stream.resource_path == resource_path) return is_playing_resource diff --git a/addons/dialogic/Modules/Clear/event_clear.gd b/addons/dialogic/Modules/Clear/event_clear.gd index c125ae96d..7d5d58808 100644 --- a/addons/dialogic/Modules/Clear/event_clear.gd +++ b/addons/dialogic/Modules/Clear/event_clear.gd @@ -43,8 +43,10 @@ func _execute() -> void: dialogic.Backgrounds.update_background('', '', final_time) if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout - if clear_music and dialogic.has_subsystem('Audio') and dialogic.Audio.has_music(): - dialogic.Audio.update_music('', 0.0, "", final_time) + if clear_music and dialogic.has_subsystem('Audio'): + for channel_id in dialogic.Audio.max_channels: + if dialogic.Audio.has_music(channel_id): + dialogic.Audio.update_music('', 0.0, "", final_time, channel_id) if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout if clear_style and dialogic.has_subsystem('Styles'): From 1ee83f86dfac1dbfefc18285a90facca5f06a72c Mon Sep 17 00:00:00 2001 From: Salia Nifo Date: Sat, 5 Oct 2024 23:25:45 -0400 Subject: [PATCH 2/3] Remove commented code, typo --- addons/dialogic/Modules/Audio/event_music.gd | 19 +------------------ .../dialogic/Modules/Audio/subsystem_audio.gd | 4 +--- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/addons/dialogic/Modules/Audio/event_music.gd b/addons/dialogic/Modules/Audio/event_music.gd index 438af43d6..e376fc6bf 100644 --- a/addons/dialogic/Modules/Audio/event_music.gd +++ b/addons/dialogic/Modules/Audio/event_music.gd @@ -76,24 +76,7 @@ func build_event_editor() -> void: 'file_filter' : "*.mp3, *.ogg, *.wav; Supported Audio Files", 'placeholder' : "No music", 'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]}) - add_header_edit('channel_id', ValueType.FIXED_OPTIONS, {'left_text':'on:', 'options': get_channel_list()})#[ - #{ - #'label': 'Channel A', - #'value': 0, - #}, - #{ - #'label': 'Channel B', - #'value': 1, - #}, - #{ - #'label': 'Channel C', - #'value': 2, - #}, - #{ - #'label': 'Channel D', - #'value': 3, - #} - #]}) + add_header_edit('channel_id', ValueType.FIXED_OPTIONS, {'left_text':'on:', 'options': get_channel_list()}) add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Fade Time:'}) add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()') add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()') diff --git a/addons/dialogic/Modules/Audio/subsystem_audio.gd b/addons/dialogic/Modules/Audio/subsystem_audio.gd index 5a6cf1b71..028911e51 100644 --- a/addons/dialogic/Modules/Audio/subsystem_audio.gd +++ b/addons/dialogic/Modules/Audio/subsystem_audio.gd @@ -15,7 +15,7 @@ extends DialogicSubsystem ## `volume` | [type float] | The volume of the audio resource that will be set to the [member base_music_player]. [br] ## `audio_bus` | [type String] | The audio bus name that the [member base_music_player] will use. [br] ## `loop` | [type bool] | Whether the audio resource will loop or not once it finishes playing. [br] -## `channel` | [type int] | The channel id to play the audio on. [br] +## `channel` | [type int] | The channel ID to play the audio on. [br] signal music_started(info: Dictionary) @@ -31,8 +31,6 @@ signal music_started(info: Dictionary) signal sound_started(info: Dictionary) -#const MAX_CHANNELS = 6 - var max_channels: int: set(value): if max_channels != value: From 9f50f1853a3ea7315d089fd62c9e6e26f2190b00 Mon Sep 17 00:00:00 2001 From: Salia Nifo Date: Wed, 16 Oct 2024 16:27:42 -0400 Subject: [PATCH 3/3] Add requested fixes, add note on settings page --- .../Modules/Audio/settings_audio.tscn | 20 ++++++++++++++++++- .../dialogic/Modules/Audio/subsystem_audio.gd | 8 +++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/addons/dialogic/Modules/Audio/settings_audio.tscn b/addons/dialogic/Modules/Audio/settings_audio.tscn index 6dc0dcad2..38ecb5ffc 100644 --- a/addons/dialogic/Modules/Audio/settings_audio.tscn +++ b/addons/dialogic/Modules/Audio/settings_audio.tscn @@ -1,6 +1,19 @@ -[gd_scene load_steps=2 format=3 uid="uid://c2qgetjc3mfo3"] +[gd_scene load_steps=5 format=3 uid="uid://c2qgetjc3mfo3"] [ext_resource type="Script" path="res://addons/dialogic/Modules/Audio/settings_audio.gd" id="1_2iyyr"] +[ext_resource type="PackedScene" uid="uid://dbpkta2tjsqim" path="res://addons/dialogic/Editor/Common/hint_tooltip_icon.tscn" id="2_o1ban"] + +[sub_resource type="Image" id="Image_n4dud"] +data = { +"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0), +"format": "RGBA8", +"height": 16, +"mipmaps": false, +"width": 16 +} + +[sub_resource type="ImageTexture" id="ImageTexture_ek5a1"] +image = SubResource("Image_n4dud") [node name="Audio" type="VBoxContainer"] offset_right = 121.0 @@ -19,6 +32,11 @@ layout_mode = 2 layout_mode = 2 text = "Max music channels" +[node name="HintTooltip" parent="HBoxContainer" instance=ExtResource("2_o1ban")] +layout_mode = 2 +texture = SubResource("ImageTexture_ek5a1") +hint_text = "Lowering this value may invalidate existing music events!" + [node name="MusicChannelCount" type="SpinBox" parent="HBoxContainer"] unique_name_in_owner = true layout_mode = 2 diff --git a/addons/dialogic/Modules/Audio/subsystem_audio.gd b/addons/dialogic/Modules/Audio/subsystem_audio.gd index 028911e51..2c0ff2aaf 100644 --- a/addons/dialogic/Modules/Audio/subsystem_audio.gd +++ b/addons/dialogic/Modules/Audio/subsystem_audio.gd @@ -117,6 +117,11 @@ func _ready() -> void: ## Updates the background music. Will fade out previous music. func update_music(path := "", volume := 0.0, audio_bus := "", fade_time := 0.0, loop := true, channel_id := 0) -> void: + if channel_id > max_channels: + printerr("\tChannel ID (%s) higher than Max Music Channels (%s)" % [channel_id, max_channels]) + dialogic.print_debug_moment() + return + if not dialogic.current_state_info.has('music'): dialogic.current_state_info['music'] = {} @@ -204,7 +209,8 @@ func interpolate_volume_linearly(value: float, node: Node) -> void: ## Returns whether the currently playing audio resource is the same as this ## event's [param resource_path], for [param channel_id]. func is_music_playing_resource(resource_path: String, channel_id := 0) -> bool: - var is_playing_resource: bool = (is_instance_valid(current_music_player[channel_id]) + var is_playing_resource: bool = (current_music_player.size() > channel_id + and is_instance_valid(current_music_player[channel_id]) and current_music_player[channel_id].is_playing() and current_music_player[channel_id].stream.resource_path == resource_path)