Expose audio streams get_length()

This commit is contained in:
MrCdK
2018-01-22 20:35:33 +01:00
parent f4d67433e7
commit 8a9f1c2a5d
6 changed files with 49 additions and 39 deletions

View File

@ -91,6 +91,13 @@ void AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale,
}
////////////////////////////////
void AudioStream::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_length"), &AudioStream::get_length);
}
////////////////////////////////
void AudioStreamRandomPitch::set_audio_stream(const Ref<AudioStream> &p_audio_stream) {
audio_stream = p_audio_stream;
@ -136,6 +143,14 @@ String AudioStreamRandomPitch::get_stream_name() const {
return "RandomPitch";
}
float AudioStreamRandomPitch::get_length() const {
if (audio_stream.is_valid()) {
return audio_stream->get_length();
}
return 0;
}
void AudioStreamRandomPitch::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_audio_stream", "stream"), &AudioStreamRandomPitch::set_audio_stream);
@ -209,14 +224,6 @@ void AudioStreamPlaybackRandomPitch::mix(AudioFrame *p_buffer, float p_rate_scal
}
}
float AudioStreamPlaybackRandomPitch::get_length() const {
if (playing.is_valid()) {
return playing->get_length();
}
return 0;
}
AudioStreamPlaybackRandomPitch::~AudioStreamPlaybackRandomPitch() {
random_pitch->playbacks.erase(this);
}

View File

@ -50,8 +50,6 @@ public:
virtual void seek(float p_time) = 0;
virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) = 0;
virtual float get_length() const = 0; //if supported, otherwise return 0
};
class AudioStreamPlaybackResampled : public AudioStreamPlayback {
@ -85,9 +83,14 @@ class AudioStream : public Resource {
GDCLASS(AudioStream, Resource)
OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged
protected:
static void _bind_methods();
public:
virtual Ref<AudioStreamPlayback> instance_playback() = 0;
virtual String get_stream_name() const = 0;
virtual float get_length() const = 0; //if supported, otherwise return 0
};
class AudioStreamPlaybackRandomPitch;
@ -114,6 +117,8 @@ public:
virtual Ref<AudioStreamPlayback> instance_playback();
virtual String get_stream_name() const;
virtual float get_length() const; //if supported, otherwise return 0
AudioStreamRandomPitch();
};
@ -139,8 +144,6 @@ public:
virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames);
virtual float get_length() const; //if supported, otherwise return 0
~AudioStreamPlaybackRandomPitch();
};