2018-01-04 23:50:27 +00:00
|
|
|
/**************************************************************************/
|
2017-06-19 00:07:32 +00:00
|
|
|
/* audio_stream_player_2d.cpp */
|
2018-01-04 23:50:27 +00:00
|
|
|
/**************************************************************************/
|
2017-09-07 01:03:04 +00:00
|
|
|
/* This file is part of: */
|
2018-01-04 23:50:27 +00:00
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
2017-08-22 21:27:17 +00:00
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
2018-01-04 23:50:27 +00:00
|
|
|
/* */
|
2017-06-19 00:07:32 +00:00
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
2017-09-10 13:37:49 +00:00
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
2017-09-07 01:03:04 +00:00
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
2017-06-19 00:07:32 +00:00
|
|
|
/* the following conditions: */
|
2018-01-04 23:50:27 +00:00
|
|
|
/* */
|
2017-09-07 01:03:04 +00:00
|
|
|
/* The above copyright notice and this permission notice shall be */
|
2017-06-19 00:07:32 +00:00
|
|
|
/* included in all copies or substantial portions of the Software. */
|
2018-01-04 23:50:27 +00:00
|
|
|
/* */
|
2017-09-07 01:03:04 +00:00
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
2017-08-22 21:27:17 +00:00
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
2017-09-07 01:03:04 +00:00
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
2018-01-04 23:50:27 +00:00
|
|
|
/**************************************************************************/
|
2017-06-19 00:07:32 +00:00
|
|
|
|
|
|
|
#include "audio_stream_player_2d.h"
|
2024-01-07 02:29:43 +00:00
|
|
|
#include "audio_stream_player_2d.compat.inc"
|
2017-08-18 23:02:56 +00:00
|
|
|
|
2022-03-06 16:53:56 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2021-09-16 19:28:20 +00:00
|
|
|
#include "scene/2d/audio_listener_2d.h"
|
2024-02-26 06:15:31 +00:00
|
|
|
#include "scene/2d/physics/area_2d.h"
|
2024-01-10 20:48:16 +00:00
|
|
|
#include "scene/audio/audio_stream_player_internal.h"
|
|
|
|
#include "scene/main/viewport.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "scene/resources/world_2d.h"
|
2024-01-10 20:48:16 +00:00
|
|
|
#include "servers/audio/audio_stream.h"
|
|
|
|
#include "servers/audio_server.h"
|
2023-12-23 16:30:32 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer2D::_notification(int p_what) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->notification(p_what);
|
|
|
|
|
2022-02-15 17:06:48 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
|
|
|
|
} break;
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2022-02-15 17:06:48 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
|
|
|
|
} break;
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2022-02-15 17:06:48 +00:00
|
|
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
|
|
|
// Update anything related to position first, if possible of course.
|
2024-01-10 20:48:16 +00:00
|
|
|
if (setplay.get() > 0 || (internal->active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count()) || force_update_panning) {
|
2023-04-06 01:29:09 +00:00
|
|
|
force_update_panning = false;
|
2022-02-15 17:06:48 +00:00
|
|
|
_update_panning();
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2023-01-27 18:25:49 +00:00
|
|
|
if (setplayback.is_valid() && setplay.get() >= 0) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->active.set();
|
|
|
|
AudioServer::get_singleton()->start_playback_stream(setplayback, _get_actual_bus(), volume_vector, setplay.get(), internal->pitch_scale);
|
2023-01-27 18:25:49 +00:00
|
|
|
setplayback.unref();
|
2022-02-15 17:06:48 +00:00
|
|
|
setplay.set(-1);
|
|
|
|
}
|
2021-08-28 04:51:03 +00:00
|
|
|
|
2024-01-10 20:48:16 +00:00
|
|
|
if (!internal->stream_playbacks.is_empty() && internal->active.is_set()) {
|
|
|
|
internal->process();
|
2022-02-15 17:06:48 +00:00
|
|
|
}
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->ensure_playback_limit();
|
2022-02-15 17:06:48 +00:00
|
|
|
} break;
|
2021-08-27 17:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2024-01-10 20:48:16 +00:00
|
|
|
// Interacts with PhysicsServer2D, so can only be called during _physics_process.
|
2021-08-27 17:28:23 +00:00
|
|
|
StringName AudioStreamPlayer2D::_get_actual_bus() {
|
|
|
|
Vector2 global_pos = get_global_position();
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
//check if any area is diverting sound into a bus
|
|
|
|
Ref<World2D> world_2d = get_world_2d();
|
2023-09-04 15:01:33 +00:00
|
|
|
ERR_FAIL_COND_V(world_2d.is_null(), SceneStringName(Master));
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
PhysicsDirectSpaceState2D *space_state = PhysicsServer2D::get_singleton()->space_get_direct_state(world_2d->get_space());
|
2024-05-14 05:07:12 +00:00
|
|
|
ERR_FAIL_NULL_V(space_state, SceneStringName(Master));
|
2021-08-27 17:28:23 +00:00
|
|
|
PhysicsDirectSpaceState2D::ShapeResult sr[MAX_INTERSECT_AREAS];
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-11-02 01:00:58 +00:00
|
|
|
PhysicsDirectSpaceState2D::PointParameters point_params;
|
|
|
|
point_params.position = global_pos;
|
|
|
|
point_params.collision_mask = area_mask;
|
|
|
|
point_params.collide_with_bodies = false;
|
|
|
|
point_params.collide_with_areas = true;
|
|
|
|
|
|
|
|
int areas = space_state->intersect_point(point_params, sr, MAX_INTERSECT_AREAS);
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
for (int i = 0; i < areas; i++) {
|
|
|
|
Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider);
|
|
|
|
if (!area2d) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
if (!area2d->is_overriding_audio_bus()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
return area2d->get_audio_bus_name();
|
|
|
|
}
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->bus;
|
2021-08-27 17:28:23 +00:00
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2023-04-06 01:29:09 +00:00
|
|
|
// Interacts with PhysicsServer2D, so can only be called during _physics_process
|
2021-08-27 17:28:23 +00:00
|
|
|
void AudioStreamPlayer2D::_update_panning() {
|
2024-01-10 20:48:16 +00:00
|
|
|
if (!internal->active.is_set() || internal->stream.is_null()) {
|
2021-08-27 17:28:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
Ref<World2D> world_2d = get_world_2d();
|
|
|
|
ERR_FAIL_COND(world_2d.is_null());
|
2021-06-15 20:33:24 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
Vector2 global_pos = get_global_position();
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2022-05-19 15:00:06 +00:00
|
|
|
HashSet<Viewport *> viewports = world_2d->get_viewports();
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
volume_vector.resize(4);
|
|
|
|
volume_vector.write[0] = AudioFrame(0, 0);
|
|
|
|
volume_vector.write[1] = AudioFrame(0, 0);
|
|
|
|
volume_vector.write[2] = AudioFrame(0, 0);
|
|
|
|
volume_vector.write[3] = AudioFrame(0, 0);
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2024-04-18 14:50:34 +00:00
|
|
|
StringName actual_bus = _get_actual_bus();
|
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
for (Viewport *vp : viewports) {
|
|
|
|
if (!vp->is_audio_listener_2d()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//compute matrix to convert to screen
|
|
|
|
Vector2 screen_size = vp->get_visible_rect().size;
|
2020-12-31 20:34:09 +00:00
|
|
|
Vector2 listener_in_global;
|
|
|
|
Vector2 relative_to_listener;
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
//screen in global is used for attenuation
|
2021-09-16 19:28:20 +00:00
|
|
|
AudioListener2D *listener = vp->get_audio_listener_2d();
|
2022-11-22 20:37:38 +00:00
|
|
|
Transform2D full_canvas_transform = vp->get_global_canvas_transform() * vp->get_canvas_transform();
|
2020-12-31 20:34:09 +00:00
|
|
|
if (listener) {
|
|
|
|
listener_in_global = listener->get_global_position();
|
2022-11-22 20:37:38 +00:00
|
|
|
relative_to_listener = (global_pos - listener_in_global).rotated(-listener->get_global_rotation());
|
|
|
|
relative_to_listener *= full_canvas_transform.get_scale(); // Default listener scales with canvas size, do the same here.
|
2020-12-31 20:34:09 +00:00
|
|
|
} else {
|
2022-11-22 20:37:38 +00:00
|
|
|
listener_in_global = full_canvas_transform.affine_inverse().xform(screen_size * 0.5);
|
|
|
|
relative_to_listener = full_canvas_transform.xform(global_pos) - screen_size * 0.5;
|
2020-12-31 20:34:09 +00:00
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2020-12-31 20:34:09 +00:00
|
|
|
float dist = global_pos.distance_to(listener_in_global); // Distance to listener, or screen if none.
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
if (dist > max_distance) {
|
2023-05-03 20:57:15 +00:00
|
|
|
continue; // Can't hear this sound in this viewport.
|
2021-08-27 17:28:23 +00:00
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
float multiplier = Math::pow(1.0f - dist / max_distance, attenuation);
|
2024-01-10 20:48:16 +00:00
|
|
|
multiplier *= Math::db_to_linear(internal->volume_db); // Also apply player volume!
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2022-03-06 16:53:56 +00:00
|
|
|
float pan = relative_to_listener.x / screen_size.x;
|
|
|
|
// Don't let the panning effect extend (too far) beyond the screen.
|
|
|
|
pan = CLAMP(pan, -1, 1);
|
|
|
|
|
|
|
|
// Bake in a constant factor here to allow the project setting defaults for 2d and 3d to be normalized to 1.0.
|
|
|
|
pan *= panning_strength * cached_global_panning_strength * 0.5f;
|
|
|
|
|
|
|
|
pan = CLAMP(pan + 0.5, 0.0, 1.0);
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-27 17:28:23 +00:00
|
|
|
float l = 1.0 - pan;
|
|
|
|
float r = pan;
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2023-05-03 20:57:15 +00:00
|
|
|
const AudioFrame &prev_sample = volume_vector[0];
|
|
|
|
AudioFrame new_sample = AudioFrame(l, r) * multiplier;
|
2024-04-18 14:50:34 +00:00
|
|
|
|
2023-05-03 20:57:15 +00:00
|
|
|
volume_vector.write[0] = AudioFrame(MAX(prev_sample[0], new_sample[0]), MAX(prev_sample[1], new_sample[1]));
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
2021-08-27 17:28:23 +00:00
|
|
|
|
2024-01-10 20:48:16 +00:00
|
|
|
for (const Ref<AudioStreamPlayback> &playback : internal->stream_playbacks) {
|
2024-04-18 14:50:34 +00:00
|
|
|
AudioServer::get_singleton()->set_playback_bus_exclusive(playback, actual_bus, volume_vector);
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
2024-04-18 14:50:34 +00:00
|
|
|
for (const Ref<AudioStreamPlayback> &playback : internal->stream_playbacks) {
|
2024-01-10 20:48:16 +00:00
|
|
|
AudioServer::get_singleton()->set_playback_pitch_scale(playback, internal->pitch_scale);
|
2024-04-18 14:50:34 +00:00
|
|
|
if (playback->get_is_sample() && playback->get_sample_playback().is_valid()) {
|
|
|
|
Ref<AudioSamplePlayback> sample_playback = playback->get_sample_playback();
|
|
|
|
AudioServer::get_singleton()->update_sample_playback_pitch_scale(sample_playback, internal->pitch_scale);
|
|
|
|
}
|
2018-06-19 11:56:05 +00:00
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
|
2021-08-28 04:51:03 +00:00
|
|
|
last_mix_count = AudioServer::get_singleton()->get_mix_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->set_stream(p_stream);
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<AudioStream> AudioStreamPlayer2D::get_stream() const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->stream;
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_volume_db(float p_volume) {
|
2024-04-18 15:28:57 +00:00
|
|
|
ERR_FAIL_COND_MSG(Math::is_nan(p_volume), "Volume can't be set to NaN.");
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->volume_db = p_volume;
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
float AudioStreamPlayer2D::get_volume_db() const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->volume_db;
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 21:23:16 +00:00
|
|
|
void AudioStreamPlayer2D::set_pitch_scale(float p_pitch_scale) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->set_pitch_scale(p_pitch_scale);
|
2018-01-01 21:23:16 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2018-01-01 21:23:16 +00:00
|
|
|
float AudioStreamPlayer2D::get_pitch_scale() const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->pitch_scale;
|
2018-01-01 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer2D::play(float p_from_pos) {
|
2024-01-10 20:48:16 +00:00
|
|
|
Ref<AudioStreamPlayback> stream_playback = internal->play_basic();
|
|
|
|
if (stream_playback.is_null()) {
|
2021-08-28 04:51:03 +00:00
|
|
|
return;
|
2018-07-11 01:57:50 +00:00
|
|
|
}
|
2023-01-27 18:25:49 +00:00
|
|
|
setplayback = stream_playback;
|
2021-08-28 04:51:03 +00:00
|
|
|
setplay.set(p_from_pos);
|
2024-04-18 14:50:34 +00:00
|
|
|
|
|
|
|
// Sample handling.
|
|
|
|
if (stream_playback->get_is_sample() && stream_playback->get_sample_playback().is_valid()) {
|
|
|
|
Ref<AudioSamplePlayback> sample_playback = stream_playback->get_sample_playback();
|
|
|
|
sample_playback->offset = p_from_pos;
|
|
|
|
sample_playback->bus = _get_actual_bus();
|
|
|
|
|
|
|
|
AudioServer::get_singleton()->start_sample_playback(sample_playback);
|
|
|
|
}
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::seek(float p_seconds) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->seek(p_seconds);
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::stop() {
|
2021-08-28 04:51:03 +00:00
|
|
|
setplay.set(-1);
|
2024-08-11 12:27:15 +00:00
|
|
|
internal->stop_basic();
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioStreamPlayer2D::is_playing() const {
|
2022-09-05 20:08:12 +00:00
|
|
|
if (setplay.get() >= 0) {
|
|
|
|
return true; // play() has been called this frame, but no playback exists just yet.
|
|
|
|
}
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->is_playing();
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 03:31:36 +00:00
|
|
|
float AudioStreamPlayer2D::get_playback_position() {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->get_playback_position();
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_bus(const StringName &p_bus) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->bus = p_bus; // This will be pushed to the audio server during the next physics timestep, which is fast enough.
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
StringName AudioStreamPlayer2D::get_bus() const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->get_bus();
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_autoplay(bool p_enable) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->autoplay = p_enable;
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2024-01-07 02:29:43 +00:00
|
|
|
bool AudioStreamPlayer2D::is_autoplay_enabled() const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->autoplay;
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::_set_playing(bool p_enable) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->set_playing(p_enable);
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2022-08-12 20:57:11 +00:00
|
|
|
void AudioStreamPlayer2D::_validate_property(PropertyInfo &p_property) const {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->validate_property(p_property);
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_max_distance(float p_pixels) {
|
|
|
|
ERR_FAIL_COND(p_pixels <= 0.0);
|
|
|
|
max_distance = p_pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
float AudioStreamPlayer2D::get_max_distance() const {
|
|
|
|
return max_distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_attenuation(float p_curve) {
|
|
|
|
attenuation = p_curve;
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
float AudioStreamPlayer2D::get_attenuation() const {
|
|
|
|
return attenuation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_area_mask(uint32_t p_mask) {
|
|
|
|
area_mask = p_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t AudioStreamPlayer2D::get_area_mask() const {
|
|
|
|
return area_mask;
|
|
|
|
}
|
|
|
|
|
2018-05-27 18:29:10 +00:00
|
|
|
void AudioStreamPlayer2D::set_stream_paused(bool p_pause) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->set_stream_paused(p_pause);
|
2018-05-27 18:29:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioStreamPlayer2D::get_stream_paused() const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->get_stream_paused();
|
2018-05-27 18:29:10 +00:00
|
|
|
}
|
|
|
|
|
2023-01-27 18:25:49 +00:00
|
|
|
bool AudioStreamPlayer2D::has_stream_playback() {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->has_stream_playback();
|
2023-01-27 18:25:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 15:57:03 +00:00
|
|
|
Ref<AudioStreamPlayback> AudioStreamPlayer2D::get_stream_playback() {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->get_stream_playback();
|
2021-08-28 04:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_max_polyphony(int p_max_polyphony) {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->set_max_polyphony(p_max_polyphony);
|
2021-08-28 04:51:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AudioStreamPlayer2D::get_max_polyphony() const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->max_polyphony;
|
2019-04-10 15:57:03 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 16:53:56 +00:00
|
|
|
void AudioStreamPlayer2D::set_panning_strength(float p_panning_strength) {
|
|
|
|
ERR_FAIL_COND_MSG(p_panning_strength < 0, "Panning strength must be a positive number.");
|
|
|
|
panning_strength = p_panning_strength;
|
|
|
|
}
|
|
|
|
|
|
|
|
float AudioStreamPlayer2D::get_panning_strength() const {
|
|
|
|
return panning_strength;
|
|
|
|
}
|
|
|
|
|
2024-04-18 14:50:34 +00:00
|
|
|
AudioServer::PlaybackType AudioStreamPlayer2D::get_playback_type() const {
|
|
|
|
return internal->get_playback_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::set_playback_type(AudioServer::PlaybackType p_playback_type) {
|
|
|
|
internal->set_playback_type(p_playback_type);
|
|
|
|
}
|
|
|
|
|
2023-12-23 16:30:32 +00:00
|
|
|
bool AudioStreamPlayer2D::_set(const StringName &p_name, const Variant &p_value) {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->set(p_name, p_value);
|
2023-12-23 16:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioStreamPlayer2D::_get(const StringName &p_name, Variant &r_ret) const {
|
2024-01-10 20:48:16 +00:00
|
|
|
return internal->get(p_name, r_ret);
|
2023-12-23 16:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamPlayer2D::_get_property_list(List<PropertyInfo> *p_list) const {
|
2024-01-10 20:48:16 +00:00
|
|
|
internal->get_property_list(p_list);
|
2023-12-23 16:30:32 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
void AudioStreamPlayer2D::_bind_methods() {
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer2D::set_stream);
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer2D::get_stream);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer2D::set_volume_db);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer2D::get_volume_db);
|
|
|
|
|
2018-01-01 21:23:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer2D::set_pitch_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer2D::get_pitch_scale);
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer2D::play, DEFVAL(0.0));
|
|
|
|
ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer2D::seek);
|
2017-06-19 00:07:32 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer2D::stop);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer2D::is_playing);
|
2017-09-21 03:31:36 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer2D::get_playback_position);
|
2017-06-19 00:07:32 +00:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer2D::set_bus);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer2D::get_bus);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_autoplay", "enable"), &AudioStreamPlayer2D::set_autoplay);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_autoplay_enabled"), &AudioStreamPlayer2D::is_autoplay_enabled);
|
|
|
|
|
2024-08-15 14:22:57 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_playing", "enable"), &AudioStreamPlayer2D::_set_playing);
|
2017-06-19 00:07:32 +00:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_max_distance", "pixels"), &AudioStreamPlayer2D::set_max_distance);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_max_distance"), &AudioStreamPlayer2D::get_max_distance);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_attenuation", "curve"), &AudioStreamPlayer2D::set_attenuation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_attenuation"), &AudioStreamPlayer2D::get_attenuation);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_area_mask", "mask"), &AudioStreamPlayer2D::set_area_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_area_mask"), &AudioStreamPlayer2D::get_area_mask);
|
|
|
|
|
2018-05-27 18:29:10 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_stream_paused", "pause"), &AudioStreamPlayer2D::set_stream_paused);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_stream_paused"), &AudioStreamPlayer2D::get_stream_paused);
|
|
|
|
|
2021-08-28 04:51:03 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_max_polyphony", "max_polyphony"), &AudioStreamPlayer2D::set_max_polyphony);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_max_polyphony"), &AudioStreamPlayer2D::get_max_polyphony);
|
|
|
|
|
2022-03-06 16:53:56 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_panning_strength", "panning_strength"), &AudioStreamPlayer2D::set_panning_strength);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_panning_strength"), &AudioStreamPlayer2D::get_panning_strength);
|
|
|
|
|
2023-01-27 18:25:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("has_stream_playback"), &AudioStreamPlayer2D::has_stream_playback);
|
2019-04-10 15:57:03 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_stream_playback"), &AudioStreamPlayer2D::get_stream_playback);
|
|
|
|
|
2024-04-18 14:50:34 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_playback_type", "playback_type"), &AudioStreamPlayer2D::set_playback_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_playback_type"), &AudioStreamPlayer2D::get_playback_type);
|
|
|
|
|
2017-06-19 00:07:32 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
|
2021-12-03 00:09:19 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,suffix:dB"), "set_volume_db", "get_volume_db");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale");
|
2024-08-15 14:22:57 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_playing", "is_playing");
|
2017-06-19 00:07:32 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");
|
2018-05-27 18:29:10 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused");
|
2021-12-03 00:09:19 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_RANGE, "1,4096,1,or_greater,exp,suffix:px"), "set_max_distance", "get_max_distance");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_attenuation", "get_attenuation");
|
2021-08-28 04:51:03 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_polyphony", PROPERTY_HINT_NONE, ""), "set_max_polyphony", "get_max_polyphony");
|
2022-03-06 16:53:56 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "panning_strength", PROPERTY_HINT_RANGE, "0,3,0.01,or_greater"), "set_panning_strength", "get_panning_strength");
|
2020-02-20 21:58:05 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
|
2017-06-19 00:07:32 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask");
|
2024-04-18 14:50:34 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_type", PROPERTY_HINT_ENUM, "Default,Stream,Sample"), "set_playback_type", "get_playback_type");
|
2017-08-25 14:58:21 +00:00
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("finished"));
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioStreamPlayer2D::AudioStreamPlayer2D() {
|
2024-08-11 12:27:15 +00:00
|
|
|
internal = memnew(AudioStreamPlayerInternal(this, callable_mp(this, &AudioStreamPlayer2D::play), callable_mp(this, &AudioStreamPlayer2D::stop), true));
|
2022-10-18 14:43:37 +00:00
|
|
|
cached_global_panning_strength = GLOBAL_GET("audio/general/2d_panning_strength");
|
2023-01-26 12:17:26 +00:00
|
|
|
set_hide_clip_children(true);
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioStreamPlayer2D::~AudioStreamPlayer2D() {
|
2024-01-10 20:48:16 +00:00
|
|
|
memdelete(internal);
|
2017-06-19 00:07:32 +00:00
|
|
|
}
|