audio_stream_player_2d.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /**************************************************************************/
  2. /* audio_stream_player_2d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "audio_stream_player_2d.h"
  31. #include "core/config/project_settings.h"
  32. #include "scene/2d/area_2d.h"
  33. #include "scene/2d/audio_listener_2d.h"
  34. #include "scene/main/window.h"
  35. #include "scene/resources/world_2d.h"
  36. void AudioStreamPlayer2D::_notification(int p_what) {
  37. switch (p_what) {
  38. case NOTIFICATION_ENTER_TREE: {
  39. AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
  40. if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
  41. play();
  42. }
  43. set_stream_paused(!can_process());
  44. } break;
  45. case NOTIFICATION_EXIT_TREE: {
  46. set_stream_paused(true);
  47. AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
  48. } break;
  49. case NOTIFICATION_PREDELETE: {
  50. stop();
  51. } break;
  52. case NOTIFICATION_PAUSED: {
  53. if (!can_process()) {
  54. // Node can't process so we start fading out to silence.
  55. set_stream_paused(true);
  56. }
  57. } break;
  58. case NOTIFICATION_UNPAUSED: {
  59. set_stream_paused(false);
  60. } break;
  61. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  62. // Update anything related to position first, if possible of course.
  63. if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count()) || force_update_panning) {
  64. force_update_panning = false;
  65. _update_panning();
  66. }
  67. if (setplayback.is_valid() && setplay.get() >= 0) {
  68. active.set();
  69. AudioServer::get_singleton()->start_playback_stream(setplayback, _get_actual_bus(), volume_vector, setplay.get(), pitch_scale);
  70. setplayback.unref();
  71. setplay.set(-1);
  72. }
  73. if (!stream_playbacks.is_empty() && active.is_set()) {
  74. // Stop playing if no longer active.
  75. Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
  76. for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
  77. if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
  78. playbacks_to_remove.push_back(playback);
  79. }
  80. }
  81. // Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
  82. for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
  83. stream_playbacks.erase(playback);
  84. }
  85. if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
  86. // This node is no longer actively playing audio.
  87. active.clear();
  88. set_physics_process_internal(false);
  89. }
  90. if (!playbacks_to_remove.is_empty()) {
  91. emit_signal(SNAME("finished"));
  92. }
  93. }
  94. while (stream_playbacks.size() > max_polyphony) {
  95. AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
  96. stream_playbacks.remove_at(0);
  97. }
  98. } break;
  99. }
  100. }
  101. // Interacts with PhysicsServer2D, so can only be called during _physics_process
  102. StringName AudioStreamPlayer2D::_get_actual_bus() {
  103. Vector2 global_pos = get_global_position();
  104. //check if any area is diverting sound into a bus
  105. Ref<World2D> world_2d = get_world_2d();
  106. ERR_FAIL_COND_V(world_2d.is_null(), SceneStringNames::get_singleton()->Master);
  107. PhysicsDirectSpaceState2D *space_state = PhysicsServer2D::get_singleton()->space_get_direct_state(world_2d->get_space());
  108. ERR_FAIL_NULL_V(space_state, SceneStringNames::get_singleton()->Master);
  109. PhysicsDirectSpaceState2D::ShapeResult sr[MAX_INTERSECT_AREAS];
  110. PhysicsDirectSpaceState2D::PointParameters point_params;
  111. point_params.position = global_pos;
  112. point_params.collision_mask = area_mask;
  113. point_params.collide_with_bodies = false;
  114. point_params.collide_with_areas = true;
  115. int areas = space_state->intersect_point(point_params, sr, MAX_INTERSECT_AREAS);
  116. for (int i = 0; i < areas; i++) {
  117. Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider);
  118. if (!area2d) {
  119. continue;
  120. }
  121. if (!area2d->is_overriding_audio_bus()) {
  122. continue;
  123. }
  124. return area2d->get_audio_bus_name();
  125. }
  126. return default_bus;
  127. }
  128. // Interacts with PhysicsServer2D, so can only be called during _physics_process
  129. void AudioStreamPlayer2D::_update_panning() {
  130. if (!active.is_set() || stream.is_null()) {
  131. return;
  132. }
  133. Ref<World2D> world_2d = get_world_2d();
  134. ERR_FAIL_COND(world_2d.is_null());
  135. Vector2 global_pos = get_global_position();
  136. HashSet<Viewport *> viewports = world_2d->get_viewports();
  137. volume_vector.resize(4);
  138. volume_vector.write[0] = AudioFrame(0, 0);
  139. volume_vector.write[1] = AudioFrame(0, 0);
  140. volume_vector.write[2] = AudioFrame(0, 0);
  141. volume_vector.write[3] = AudioFrame(0, 0);
  142. for (Viewport *vp : viewports) {
  143. if (!vp->is_audio_listener_2d()) {
  144. continue;
  145. }
  146. //compute matrix to convert to screen
  147. Vector2 screen_size = vp->get_visible_rect().size;
  148. Vector2 listener_in_global;
  149. Vector2 relative_to_listener;
  150. //screen in global is used for attenuation
  151. AudioListener2D *listener = vp->get_audio_listener_2d();
  152. Transform2D full_canvas_transform = vp->get_global_canvas_transform() * vp->get_canvas_transform();
  153. if (listener) {
  154. listener_in_global = listener->get_global_position();
  155. relative_to_listener = (global_pos - listener_in_global).rotated(-listener->get_global_rotation());
  156. relative_to_listener *= full_canvas_transform.get_scale(); // Default listener scales with canvas size, do the same here.
  157. } else {
  158. listener_in_global = full_canvas_transform.affine_inverse().xform(screen_size * 0.5);
  159. relative_to_listener = full_canvas_transform.xform(global_pos) - screen_size * 0.5;
  160. }
  161. float dist = global_pos.distance_to(listener_in_global); // Distance to listener, or screen if none.
  162. if (dist > max_distance) {
  163. continue; // Can't hear this sound in this viewport.
  164. }
  165. float multiplier = Math::pow(1.0f - dist / max_distance, attenuation);
  166. multiplier *= Math::db_to_linear(volume_db); // Also apply player volume!
  167. float pan = relative_to_listener.x / screen_size.x;
  168. // Don't let the panning effect extend (too far) beyond the screen.
  169. pan = CLAMP(pan, -1, 1);
  170. // Bake in a constant factor here to allow the project setting defaults for 2d and 3d to be normalized to 1.0.
  171. pan *= panning_strength * cached_global_panning_strength * 0.5f;
  172. pan = CLAMP(pan + 0.5, 0.0, 1.0);
  173. float l = 1.0 - pan;
  174. float r = pan;
  175. const AudioFrame &prev_sample = volume_vector[0];
  176. AudioFrame new_sample = AudioFrame(l, r) * multiplier;
  177. volume_vector.write[0] = AudioFrame(MAX(prev_sample[0], new_sample[0]), MAX(prev_sample[1], new_sample[1]));
  178. }
  179. for (const Ref<AudioStreamPlayback> &playback : stream_playbacks) {
  180. AudioServer::get_singleton()->set_playback_bus_exclusive(playback, _get_actual_bus(), volume_vector);
  181. }
  182. for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
  183. AudioServer::get_singleton()->set_playback_pitch_scale(playback, pitch_scale);
  184. }
  185. last_mix_count = AudioServer::get_singleton()->get_mix_count();
  186. }
  187. void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) {
  188. stop();
  189. stream = p_stream;
  190. }
  191. Ref<AudioStream> AudioStreamPlayer2D::get_stream() const {
  192. return stream;
  193. }
  194. void AudioStreamPlayer2D::set_volume_db(float p_volume) {
  195. volume_db = p_volume;
  196. }
  197. float AudioStreamPlayer2D::get_volume_db() const {
  198. return volume_db;
  199. }
  200. void AudioStreamPlayer2D::set_pitch_scale(float p_pitch_scale) {
  201. ERR_FAIL_COND(!(p_pitch_scale > 0.0));
  202. pitch_scale = p_pitch_scale;
  203. for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
  204. AudioServer::get_singleton()->set_playback_pitch_scale(playback, p_pitch_scale);
  205. }
  206. }
  207. float AudioStreamPlayer2D::get_pitch_scale() const {
  208. return pitch_scale;
  209. }
  210. void AudioStreamPlayer2D::play(float p_from_pos) {
  211. if (stream.is_null()) {
  212. return;
  213. }
  214. ERR_FAIL_COND_MSG(!is_inside_tree(), "Playback can only happen when a node is inside the scene tree");
  215. if (stream->is_monophonic() && is_playing()) {
  216. stop();
  217. }
  218. Ref<AudioStreamPlayback> stream_playback = stream->instantiate_playback();
  219. ERR_FAIL_COND_MSG(stream_playback.is_null(), "Failed to instantiate playback.");
  220. stream_playbacks.push_back(stream_playback);
  221. setplayback = stream_playback;
  222. setplay.set(p_from_pos);
  223. active.set();
  224. set_physics_process_internal(true);
  225. }
  226. void AudioStreamPlayer2D::seek(float p_seconds) {
  227. if (is_playing()) {
  228. stop();
  229. play(p_seconds);
  230. }
  231. }
  232. void AudioStreamPlayer2D::stop() {
  233. setplay.set(-1);
  234. for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
  235. AudioServer::get_singleton()->stop_playback_stream(playback);
  236. }
  237. stream_playbacks.clear();
  238. active.clear();
  239. set_physics_process_internal(false);
  240. }
  241. bool AudioStreamPlayer2D::is_playing() const {
  242. for (const Ref<AudioStreamPlayback> &playback : stream_playbacks) {
  243. if (AudioServer::get_singleton()->is_playback_active(playback)) {
  244. return true;
  245. }
  246. }
  247. if (setplay.get() >= 0) {
  248. return true; // play() has been called this frame, but no playback exists just yet.
  249. }
  250. return false;
  251. }
  252. float AudioStreamPlayer2D::get_playback_position() {
  253. // Return the playback position of the most recently started playback stream.
  254. if (!stream_playbacks.is_empty()) {
  255. return AudioServer::get_singleton()->get_playback_position(stream_playbacks[stream_playbacks.size() - 1]);
  256. }
  257. return 0;
  258. }
  259. void AudioStreamPlayer2D::set_bus(const StringName &p_bus) {
  260. default_bus = p_bus; // This will be pushed to the audio server during the next physics timestep, which is fast enough.
  261. }
  262. StringName AudioStreamPlayer2D::get_bus() const {
  263. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  264. if (AudioServer::get_singleton()->get_bus_name(i) == default_bus) {
  265. return default_bus;
  266. }
  267. }
  268. return SceneStringNames::get_singleton()->Master;
  269. }
  270. void AudioStreamPlayer2D::set_autoplay(bool p_enable) {
  271. autoplay = p_enable;
  272. }
  273. bool AudioStreamPlayer2D::is_autoplay_enabled() {
  274. return autoplay;
  275. }
  276. void AudioStreamPlayer2D::_set_playing(bool p_enable) {
  277. if (p_enable) {
  278. play();
  279. } else {
  280. stop();
  281. }
  282. }
  283. bool AudioStreamPlayer2D::_is_active() const {
  284. return active.is_set();
  285. }
  286. void AudioStreamPlayer2D::_validate_property(PropertyInfo &p_property) const {
  287. if (p_property.name == "bus") {
  288. String options;
  289. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  290. if (i > 0) {
  291. options += ",";
  292. }
  293. String name = AudioServer::get_singleton()->get_bus_name(i);
  294. options += name;
  295. }
  296. p_property.hint_string = options;
  297. }
  298. }
  299. void AudioStreamPlayer2D::set_max_distance(float p_pixels) {
  300. ERR_FAIL_COND(p_pixels <= 0.0);
  301. max_distance = p_pixels;
  302. }
  303. float AudioStreamPlayer2D::get_max_distance() const {
  304. return max_distance;
  305. }
  306. void AudioStreamPlayer2D::set_attenuation(float p_curve) {
  307. attenuation = p_curve;
  308. }
  309. float AudioStreamPlayer2D::get_attenuation() const {
  310. return attenuation;
  311. }
  312. void AudioStreamPlayer2D::set_area_mask(uint32_t p_mask) {
  313. area_mask = p_mask;
  314. }
  315. uint32_t AudioStreamPlayer2D::get_area_mask() const {
  316. return area_mask;
  317. }
  318. void AudioStreamPlayer2D::set_stream_paused(bool p_pause) {
  319. // TODO this does not have perfect recall, fix that maybe? If there are zero playbacks registered with the AudioServer, this bool isn't persisted.
  320. for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
  321. AudioServer::get_singleton()->set_playback_paused(playback, p_pause);
  322. }
  323. }
  324. bool AudioStreamPlayer2D::get_stream_paused() const {
  325. // There's currently no way to pause some playback streams but not others. Check the first and don't bother looking at the rest.
  326. if (!stream_playbacks.is_empty()) {
  327. return AudioServer::get_singleton()->is_playback_paused(stream_playbacks[0]);
  328. }
  329. return false;
  330. }
  331. bool AudioStreamPlayer2D::has_stream_playback() {
  332. return !stream_playbacks.is_empty();
  333. }
  334. Ref<AudioStreamPlayback> AudioStreamPlayer2D::get_stream_playback() {
  335. ERR_FAIL_COND_V_MSG(stream_playbacks.is_empty(), Ref<AudioStreamPlayback>(), "Player is inactive. Call play() before requesting get_stream_playback().");
  336. return stream_playbacks[stream_playbacks.size() - 1];
  337. }
  338. void AudioStreamPlayer2D::set_max_polyphony(int p_max_polyphony) {
  339. if (p_max_polyphony > 0) {
  340. max_polyphony = p_max_polyphony;
  341. }
  342. }
  343. int AudioStreamPlayer2D::get_max_polyphony() const {
  344. return max_polyphony;
  345. }
  346. void AudioStreamPlayer2D::set_panning_strength(float p_panning_strength) {
  347. ERR_FAIL_COND_MSG(p_panning_strength < 0, "Panning strength must be a positive number.");
  348. panning_strength = p_panning_strength;
  349. }
  350. float AudioStreamPlayer2D::get_panning_strength() const {
  351. return panning_strength;
  352. }
  353. void AudioStreamPlayer2D::_on_bus_layout_changed() {
  354. notify_property_list_changed();
  355. }
  356. void AudioStreamPlayer2D::_on_bus_renamed(int p_bus_index, const StringName &p_old_name, const StringName &p_new_name) {
  357. notify_property_list_changed();
  358. }
  359. void AudioStreamPlayer2D::_bind_methods() {
  360. ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer2D::set_stream);
  361. ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer2D::get_stream);
  362. ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer2D::set_volume_db);
  363. ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer2D::get_volume_db);
  364. ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer2D::set_pitch_scale);
  365. ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer2D::get_pitch_scale);
  366. ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer2D::play, DEFVAL(0.0));
  367. ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer2D::seek);
  368. ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer2D::stop);
  369. ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer2D::is_playing);
  370. ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer2D::get_playback_position);
  371. ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer2D::set_bus);
  372. ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer2D::get_bus);
  373. ClassDB::bind_method(D_METHOD("set_autoplay", "enable"), &AudioStreamPlayer2D::set_autoplay);
  374. ClassDB::bind_method(D_METHOD("is_autoplay_enabled"), &AudioStreamPlayer2D::is_autoplay_enabled);
  375. ClassDB::bind_method(D_METHOD("_set_playing", "enable"), &AudioStreamPlayer2D::_set_playing);
  376. ClassDB::bind_method(D_METHOD("_is_active"), &AudioStreamPlayer2D::_is_active);
  377. ClassDB::bind_method(D_METHOD("set_max_distance", "pixels"), &AudioStreamPlayer2D::set_max_distance);
  378. ClassDB::bind_method(D_METHOD("get_max_distance"), &AudioStreamPlayer2D::get_max_distance);
  379. ClassDB::bind_method(D_METHOD("set_attenuation", "curve"), &AudioStreamPlayer2D::set_attenuation);
  380. ClassDB::bind_method(D_METHOD("get_attenuation"), &AudioStreamPlayer2D::get_attenuation);
  381. ClassDB::bind_method(D_METHOD("set_area_mask", "mask"), &AudioStreamPlayer2D::set_area_mask);
  382. ClassDB::bind_method(D_METHOD("get_area_mask"), &AudioStreamPlayer2D::get_area_mask);
  383. ClassDB::bind_method(D_METHOD("set_stream_paused", "pause"), &AudioStreamPlayer2D::set_stream_paused);
  384. ClassDB::bind_method(D_METHOD("get_stream_paused"), &AudioStreamPlayer2D::get_stream_paused);
  385. ClassDB::bind_method(D_METHOD("set_max_polyphony", "max_polyphony"), &AudioStreamPlayer2D::set_max_polyphony);
  386. ClassDB::bind_method(D_METHOD("get_max_polyphony"), &AudioStreamPlayer2D::get_max_polyphony);
  387. ClassDB::bind_method(D_METHOD("set_panning_strength", "panning_strength"), &AudioStreamPlayer2D::set_panning_strength);
  388. ClassDB::bind_method(D_METHOD("get_panning_strength"), &AudioStreamPlayer2D::get_panning_strength);
  389. ClassDB::bind_method(D_METHOD("has_stream_playback"), &AudioStreamPlayer2D::has_stream_playback);
  390. ClassDB::bind_method(D_METHOD("get_stream_playback"), &AudioStreamPlayer2D::get_stream_playback);
  391. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
  392. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,suffix:dB"), "set_volume_db", "get_volume_db");
  393. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale");
  394. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing");
  395. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");
  396. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused");
  397. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_RANGE, "1,4096,1,or_greater,exp,suffix:px"), "set_max_distance", "get_max_distance");
  398. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "attenuation", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_attenuation", "get_attenuation");
  399. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_polyphony", PROPERTY_HINT_NONE, ""), "set_max_polyphony", "get_max_polyphony");
  400. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "panning_strength", PROPERTY_HINT_RANGE, "0,3,0.01,or_greater"), "set_panning_strength", "get_panning_strength");
  401. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
  402. ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask");
  403. ADD_SIGNAL(MethodInfo("finished"));
  404. }
  405. AudioStreamPlayer2D::AudioStreamPlayer2D() {
  406. AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &AudioStreamPlayer2D::_on_bus_layout_changed));
  407. AudioServer::get_singleton()->connect("bus_renamed", callable_mp(this, &AudioStreamPlayer2D::_on_bus_renamed));
  408. cached_global_panning_strength = GLOBAL_GET("audio/general/2d_panning_strength");
  409. set_hide_clip_children(true);
  410. }
  411. AudioStreamPlayer2D::~AudioStreamPlayer2D() {
  412. }