Path: blob/master/scene/audio/audio_stream_player_internal.h
9896 views
/**************************************************************************/1/* audio_stream_player_internal.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/object/ref_counted.h"33#include "core/templates/safe_refcount.h"34#include "servers/audio_server.h"3536class AudioStream;37class AudioStreamPlayback;38class AudioSamplePlayback;39class Node;4041class AudioStreamPlayerInternal : public Object {42GDCLASS(AudioStreamPlayerInternal, Object);4344private:45struct ParameterData {46StringName path;47Variant value;48};4950static inline const String PARAM_PREFIX = "parameters/";5152Node *node = nullptr;53Callable play_callable;54Callable stop_callable;55bool physical = false;56AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;5758HashMap<StringName, ParameterData> playback_parameters;5960void _set_process(bool p_enabled);61void _update_stream_parameters();6263_FORCE_INLINE_ bool _is_sample() {64return (AudioServer::get_singleton()->get_default_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE && get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT) || get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE;65}6667public:68Vector<Ref<AudioStreamPlayback>> stream_playbacks;69Ref<AudioStream> stream;7071SafeFlag active;7273float pitch_scale = 1.0;74float volume_db = 0.0;75bool autoplay = false;76StringName bus;77int max_polyphony = 1;7879void process();80void ensure_playback_limit();8182void notification(int p_what);83void validate_property(PropertyInfo &p_property) const;84bool set(const StringName &p_name, const Variant &p_value);85bool get(const StringName &p_name, Variant &r_ret) const;86void get_property_list(List<PropertyInfo> *p_list) const;8788void set_stream(Ref<AudioStream> p_stream);89void set_pitch_scale(float p_pitch_scale);90void set_max_polyphony(int p_max_polyphony);9192StringName get_bus() const;9394Ref<AudioStreamPlayback> play_basic();95void seek(float p_seconds);96void stop_basic();97bool is_playing() const;98float get_playback_position();99100void set_playing(bool p_enable);101bool is_active() const;102103void set_stream_paused(bool p_pause);104bool get_stream_paused() const;105106bool has_stream_playback();107Ref<AudioStreamPlayback> get_stream_playback();108109void set_playback_type(AudioServer::PlaybackType p_playback_type);110AudioServer::PlaybackType get_playback_type() const;111112AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, const Callable &p_stop_callable, bool p_physical);113};114115116