godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 97 forks source link

Expose the currently playing clip in AudioStreamInteractive #10494

Open GustJc opened 2 months ago

GustJc commented 2 months ago

Describe the project you are working on

Currently testing the new AudioStreamInteractive.

Describe the problem or limitation you are having in your project

I wanted to debug the audiostream with a running game, and as you can't see currently playing clips in the inspector when the game is running like you can in the editor. I tried to print the currently playing music clip to debug and realized there is no way to currently do that.

The AudioStreamInteractive exposes ways to get the clip_names by index, get the clip stream, and the initial clip. But no way to actually get what clip is currently being played.

This can also be useful if you want to only call switch_to_clip if a certain music is playing, otherwise, do nothing. As it currently is, even if you had no transitions added calling a switch_to_clip will still change clips, it just doesn't add a transition fade to it. (Not sure if this behavior is intended or not)

So adding a way to check for the currently playing clip can allow us to manually check if we should call switch_to_clip or not.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Very simple, just expose the playback_current from the AudioStreamPlaybackInteractive. For simplicity's sake, I've added a get_current_clip_index(). You can then use the already exposed AudioStreamInteractive::get_clip_name() to find its name. Or get its AudioStream.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Very simple. I've implemented it here https://github.com/GustJc/godot_fork/commit/0a6158d3772650c246748f16968dc9fc5f9b8bff

(needs audio)

https://github.com/user-attachments/assets/dd157967-fa31-400c-90c2-262ffb64960c

It can be used like this:

func _physics_process(_delta: float) -> void:
    var music_playback := get_stream_playback()
    %MusicLabel.text = stream.get_clip_name(music_playback.get_current_clip_index())

If this enhancement will not be used often, can it be worked around with a few lines of script?

No.

Is there a reason why this should be core and not an add-on in the asset library?

This is a basic functionality the interactive stream player should have.

Calinou commented 2 months ago

Feel free to open a pull request for this 🙂

GustJc commented 2 months ago

Thanks for the reply! Opened the PR.