godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

AudioServer's is_playback_active method is not exposed in godot-cpp

Open saturnian-tides opened this issue 1 year ago • 9 comments

When trying to build the Godot SteamAudio GDExtension, I get the following errors. Examination of the generated files shows that indeed this method is not exposed for GDExtension, despite being in the original AudioServer source code: extension/src/audio_stream_player_steamaudio.cpp: In member function 'void AudioStreamPlayerSteamAudio::_notification(int)': extension/src/audio_stream_player_steamaudio.cpp:51:91: error: 'class godot::AudioServer' has no member named 'is_playback_active' 51 | if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) { | ^~~~~~~~~~~~~~~~~~ extension/src/audio_stream_player_steamaudio.cpp:51:154: error: 'class godot::AudioServer' has no member named 'is_playback_paused' 51 | if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) { | ^~~~~~~~~~~~~~~~~~

saturnian-tides avatar Apr 13 '23 03:04 saturnian-tides

@akien-mga I've been getting some requests to explore godot steamaudio as a GDExtension so revisiting this - should this have been exposed as part of the AudioServer interface? If not, is there some other way to get this kind of information from within a GDExtension (as opposed to an old-fashioned module)? EDIT: And on this note I wonder if anyone has any examples of implementing something like an AudioStream and AudioStreamPlayback (or the polyphonic variants) using GDExtension, which is the main problem I'm trying to solve here.

saturnian-tides avatar Jul 14 '23 23:07 saturnian-tides

Exposing is_playback_active() and is_playback_paused() will need to start with a change to Godot itself to make them available to GDExtension. I'm not familiar at all with the audio subsystem in Godot, but assuming that it'd be safe for those methods to be exposed to GDScript and C# as well, this would be a matter of adding these two lines of code to AudioServer::_bind_methods():

	ClassDB::bind_method(D_METHOD("is_playback_active", "playback"), &AudioServer::is_playback_active);
	ClassDB::bind_method(D_METHOD("is_playback_paused", "playback"), &AudioServer::is_playback_paused);

If this is something that needs to be exposed to only GDExtension, then it's a bit more complicated to expose, but certainly still possible!

EDIT: And on this note I wonder if anyone has any examples of implementing something like an AudioStream and AudioStreamPlayback (or the polyphonic variants) using GDExtension, which is the main problem I'm trying to solve here.

I'm not aware of any examples, and like I said above I'm not very familiar with Godot's audio subsystem, but looking at the code, both AudioStream and AudioStreamPlayback are setup to so that their virtual methods can be implemented from GDExtension.

dsnopek avatar Jul 15 '23 20:07 dsnopek

Thanks for the insight, @dsnopek ! I'll start off with a custom build of Godot to expose the bindings and see where that takes me - if its functional and clean enough I suppose I can raise a PR for the engine itself.

saturnian-tides avatar Jul 15 '23 21:07 saturnian-tides

EDIT: And on this note I wonder if anyone has any examples of implementing something like an AudioStream and AudioStreamPlayback (or the polyphonic variants) using GDExtension, which is the main problem I'm trying to solve here.

I'm not aware of any examples, and like I said above I'm not very familiar with Godot's audio subsystem, but looking at the code, both AudioStream and AudioStreamPlayback are setup to so that their virtual methods can be implemented from GDExtension.

I just published such an example of custom AudioStream defined by a GDExtension: gdextension-custom-audiostream. HTH!

oparisy avatar Aug 27 '23 10:08 oparisy

Exposing is_playback_active() and is_playback_paused() will need to start with a change to Godot itself to make them available to GDExtension. I'm not familiar at all with the audio subsystem in Godot, but assuming that it'd be safe for those methods to be exposed to GDScript and C# as well, this would be a matter of adding these two lines of code to AudioServer::_bind_methods():

	ClassDB::bind_method(D_METHOD("is_playback_active", "playback"), &AudioServer::is_playback_active);
	ClassDB::bind_method(D_METHOD("is_playback_paused", "playback"), &AudioServer::is_playback_paused);

If this is something that needs to be exposed to only GDExtension, then it's a bit more complicated to expose, but certainly still possible!

EDIT: And on this note I wonder if anyone has any examples of implementing something like an AudioStream and AudioStreamPlayback (or the polyphonic variants) using GDExtension, which is the main problem I'm trying to solve here.

I'm not aware of any examples, and like I said above I'm not very familiar with Godot's audio subsystem, but looking at the code, both AudioStream and AudioStreamPlayback are setup to so that their virtual methods can be implemented from GDExtension.

@dsnopek When you say "...assuming that it'd be safe...", what would be the safety criteria to look out for in terms of GDScript and C#? I have successfully tested adding the required classdb fields to AudioServer and AudioStreamPlayback in order to allow for writing custom players and playback mixing in my GDExtensions.

I'd love to contribute this as a PR for others to use as well.

@oparisy Thanks for providing this. It helped me testing and understanding the architecture & setup a lot quicker.

dazKind avatar Sep 15 '23 08:09 dazKind

@oparisy Thanks for providing this. It helped me testing and understanding the architecture & setup a lot quicker.

YMW! I'm also interested in safety criterias: I kept locking code in my plugin but as the TODO indicates I'm not sure it's still useful: https://github.com/oparisy/gdextension-custom-audiostream/blob/2730ef56ea79013afd485725595766bcacdc6ed7/extension/src/audiostream_simple.cpp#L41

oparisy avatar Sep 15 '23 10:09 oparisy

@dsnopek When you say "...assuming that it'd be safe...", what would be the safety criteria to look out for in terms of GDScript and C#?

This is a question for the audio system maintainers, and if they are OK with those methods being exposed to GDScript and C#. One way to find out would be to make a PR with that change and see what review you get? Or, you could ask in #audio channel on RocketChat?

/cc @ellenhp

dsnopek avatar Sep 15 '23 17:09 dsnopek

I don't think I want make this call without consulting @reduz, especially considering we may be changing the way mixing works mid-4.x to move some of the logic into the AudioStreamPlaybacks. In general we wouldn't want to expose something that might change in a minor release because it could break compat.

ellenhp avatar Sep 15 '23 17:09 ellenhp

@dsnopek Makes sense. I was trying to make sure I didnt miss something otherwise obvious to bare in mind when it came to GDScript & C#

@ellenhp That sounds great & I agree. I will try to supply a PR with some more background on my use-case and get some more eyes on it.

dazKind avatar Sep 15 '23 19:09 dazKind