audio_stream_interactive.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. /**************************************************************************/
  2. /* audio_stream_interactive.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_interactive.h"
  31. #include "core/math/math_funcs.h"
  32. #include "core/string/print_string.h"
  33. AudioStreamInteractive::AudioStreamInteractive() {
  34. }
  35. Ref<AudioStreamPlayback> AudioStreamInteractive::instantiate_playback() {
  36. Ref<AudioStreamPlaybackInteractive> playback_transitioner;
  37. playback_transitioner.instantiate();
  38. playback_transitioner->stream = Ref<AudioStreamInteractive>(this);
  39. return playback_transitioner;
  40. }
  41. String AudioStreamInteractive::get_stream_name() const {
  42. return "Transitioner";
  43. }
  44. void AudioStreamInteractive::set_clip_count(int p_count) {
  45. ERR_FAIL_COND(p_count < 0 || p_count > MAX_CLIPS);
  46. AudioServer::get_singleton()->lock();
  47. if (p_count < clip_count) {
  48. // Removing should stop players.
  49. version++;
  50. }
  51. #ifdef TOOLS_ENABLED
  52. stream_name_cache = "";
  53. if (p_count < clip_count) {
  54. for (int i = 0; i < clip_count; i++) {
  55. if (clips[i].auto_advance_next_clip >= p_count) {
  56. clips[i].auto_advance_next_clip = 0;
  57. clips[i].auto_advance = AUTO_ADVANCE_DISABLED;
  58. }
  59. }
  60. for (KeyValue<TransitionKey, Transition> &K : transition_map) {
  61. if (K.value.filler_clip >= p_count) {
  62. K.value.use_filler_clip = false;
  63. K.value.filler_clip = 0;
  64. }
  65. }
  66. if (initial_clip >= p_count) {
  67. initial_clip = 0;
  68. }
  69. }
  70. #endif
  71. clip_count = p_count;
  72. AudioServer::get_singleton()->unlock();
  73. notify_property_list_changed();
  74. emit_signal(SNAME("parameter_list_changed"));
  75. }
  76. void AudioStreamInteractive::set_initial_clip(int p_clip) {
  77. ERR_FAIL_INDEX(p_clip, clip_count);
  78. initial_clip = p_clip;
  79. }
  80. int AudioStreamInteractive::get_initial_clip() const {
  81. return initial_clip;
  82. }
  83. int AudioStreamInteractive::get_clip_count() const {
  84. return clip_count;
  85. }
  86. void AudioStreamInteractive::set_clip_name(int p_clip, const StringName &p_name) {
  87. ERR_FAIL_INDEX(p_clip, MAX_CLIPS);
  88. clips[p_clip].name = p_name;
  89. }
  90. StringName AudioStreamInteractive::get_clip_name(int p_clip) const {
  91. ERR_FAIL_COND_V(p_clip < -1 || p_clip >= MAX_CLIPS, StringName());
  92. if (p_clip == CLIP_ANY) {
  93. return RTR("All Clips");
  94. }
  95. return clips[p_clip].name;
  96. }
  97. void AudioStreamInteractive::set_clip_stream(int p_clip, const Ref<AudioStream> &p_stream) {
  98. ERR_FAIL_INDEX(p_clip, MAX_CLIPS);
  99. AudioServer::get_singleton()->lock();
  100. if (clips[p_clip].stream.is_valid()) {
  101. version++;
  102. }
  103. clips[p_clip].stream = p_stream;
  104. AudioServer::get_singleton()->unlock();
  105. #ifdef TOOLS_ENABLED
  106. if (Engine::get_singleton()->is_editor_hint()) {
  107. if (clips[p_clip].name == StringName() && p_stream.is_valid()) {
  108. String n;
  109. if (!clips[p_clip].stream->get_name().is_empty()) {
  110. n = clips[p_clip].stream->get_name().replace(",", " ");
  111. } else if (clips[p_clip].stream->get_path().is_resource_file()) {
  112. n = clips[p_clip].stream->get_path().get_file().get_basename().replace(",", " ");
  113. n = n.capitalize();
  114. }
  115. if (n != "") {
  116. clips[p_clip].name = n;
  117. }
  118. }
  119. }
  120. #endif
  121. #ifdef TOOLS_ENABLED
  122. stream_name_cache = "";
  123. notify_property_list_changed(); // Hints change if stream changes.
  124. emit_signal(SNAME("parameter_list_changed"));
  125. #endif
  126. }
  127. Ref<AudioStream> AudioStreamInteractive::get_clip_stream(int p_clip) const {
  128. ERR_FAIL_INDEX_V(p_clip, MAX_CLIPS, Ref<AudioStream>());
  129. return clips[p_clip].stream;
  130. }
  131. void AudioStreamInteractive::set_clip_auto_advance(int p_clip, AutoAdvanceMode p_mode) {
  132. ERR_FAIL_INDEX(p_clip, MAX_CLIPS);
  133. ERR_FAIL_INDEX(p_mode, 3);
  134. clips[p_clip].auto_advance = p_mode;
  135. notify_property_list_changed();
  136. }
  137. AudioStreamInteractive::AutoAdvanceMode AudioStreamInteractive::get_clip_auto_advance(int p_clip) const {
  138. ERR_FAIL_INDEX_V(p_clip, MAX_CLIPS, AUTO_ADVANCE_DISABLED);
  139. return clips[p_clip].auto_advance;
  140. }
  141. void AudioStreamInteractive::set_clip_auto_advance_next_clip(int p_clip, int p_index) {
  142. ERR_FAIL_INDEX(p_clip, MAX_CLIPS);
  143. clips[p_clip].auto_advance_next_clip = p_index;
  144. }
  145. int AudioStreamInteractive::get_clip_auto_advance_next_clip(int p_clip) const {
  146. ERR_FAIL_INDEX_V(p_clip, MAX_CLIPS, -1);
  147. return clips[p_clip].auto_advance_next_clip;
  148. }
  149. // TRANSITIONS
  150. void AudioStreamInteractive::_set_transitions(const Dictionary &p_transitions) {
  151. List<Variant> keys;
  152. p_transitions.get_key_list(&keys);
  153. for (const Variant &K : keys) {
  154. Vector2i k = K;
  155. Dictionary data = p_transitions[K];
  156. ERR_CONTINUE(!data.has("from_time"));
  157. ERR_CONTINUE(!data.has("to_time"));
  158. ERR_CONTINUE(!data.has("fade_mode"));
  159. ERR_CONTINUE(!data.has("fade_beats"));
  160. bool use_filler_clip = false;
  161. int filler_clip = 0;
  162. if (data.has("use_filler_clip") && data.has("filler_clip")) {
  163. use_filler_clip = data["use_filler_clip"];
  164. filler_clip = data["filler_clip"];
  165. }
  166. bool hold_previous = data.has("hold_previous") ? bool(data["hold_previous"]) : false;
  167. add_transition(k.x, k.y, TransitionFromTime(int(data["from_time"])), TransitionToTime(int(data["to_time"])), FadeMode(int(data["fade_mode"])), data["fade_beats"], use_filler_clip, filler_clip, hold_previous);
  168. }
  169. }
  170. Dictionary AudioStreamInteractive::_get_transitions() const {
  171. Vector<Vector2i> keys;
  172. for (const KeyValue<TransitionKey, Transition> &K : transition_map) {
  173. keys.push_back(Vector2i(K.key.from_clip, K.key.to_clip));
  174. }
  175. keys.sort();
  176. Dictionary ret;
  177. for (int i = 0; i < keys.size(); i++) {
  178. const Transition &tr = transition_map[TransitionKey(keys[i].x, keys[i].y)];
  179. Dictionary data;
  180. data["from_time"] = tr.from_time;
  181. data["to_time"] = tr.to_time;
  182. data["fade_mode"] = tr.fade_mode;
  183. data["fade_beats"] = tr.fade_beats;
  184. if (tr.use_filler_clip) {
  185. data["use_filler_clip"] = true;
  186. data["filler_clip"] = tr.filler_clip;
  187. }
  188. if (tr.hold_previous) {
  189. data["hold_previous"] = true;
  190. }
  191. ret[keys[i]] = data;
  192. }
  193. return ret;
  194. }
  195. bool AudioStreamInteractive::has_transition(int p_from_clip, int p_to_clip) const {
  196. TransitionKey tk(p_from_clip, p_to_clip);
  197. return transition_map.has(tk);
  198. }
  199. void AudioStreamInteractive::erase_transition(int p_from_clip, int p_to_clip) {
  200. TransitionKey tk(p_from_clip, p_to_clip);
  201. ERR_FAIL_COND(!transition_map.has(tk));
  202. AudioDriver::get_singleton()->lock();
  203. transition_map.erase(tk);
  204. AudioDriver::get_singleton()->unlock();
  205. }
  206. PackedInt32Array AudioStreamInteractive::get_transition_list() const {
  207. PackedInt32Array ret;
  208. for (const KeyValue<TransitionKey, Transition> &K : transition_map) {
  209. ret.push_back(K.key.from_clip);
  210. ret.push_back(K.key.to_clip);
  211. }
  212. return ret;
  213. }
  214. void AudioStreamInteractive::add_transition(int p_from_clip, int p_to_clip, TransitionFromTime p_from_time, TransitionToTime p_to_time, FadeMode p_fade_mode, float p_fade_beats, bool p_use_filler_flip, int p_filler_clip, bool p_hold_previous) {
  215. ERR_FAIL_COND(p_from_clip < CLIP_ANY || p_from_clip >= clip_count);
  216. ERR_FAIL_COND(p_to_clip < CLIP_ANY || p_to_clip >= clip_count);
  217. ERR_FAIL_UNSIGNED_INDEX(p_from_time, TRANSITION_FROM_TIME_MAX);
  218. ERR_FAIL_UNSIGNED_INDEX(p_to_time, TRANSITION_TO_TIME_MAX);
  219. ERR_FAIL_UNSIGNED_INDEX(p_fade_mode, FADE_MAX);
  220. Transition tr;
  221. tr.from_time = p_from_time;
  222. tr.to_time = p_to_time;
  223. tr.fade_mode = p_fade_mode;
  224. tr.fade_beats = p_fade_beats;
  225. tr.use_filler_clip = p_use_filler_flip;
  226. tr.filler_clip = p_filler_clip;
  227. tr.hold_previous = p_hold_previous;
  228. TransitionKey tk(p_from_clip, p_to_clip);
  229. AudioDriver::get_singleton()->lock();
  230. transition_map[tk] = tr;
  231. AudioDriver::get_singleton()->unlock();
  232. }
  233. AudioStreamInteractive::TransitionFromTime AudioStreamInteractive::get_transition_from_time(int p_from_clip, int p_to_clip) const {
  234. TransitionKey tk(p_from_clip, p_to_clip);
  235. ERR_FAIL_COND_V(!transition_map.has(tk), TRANSITION_FROM_TIME_END);
  236. return transition_map[tk].from_time;
  237. }
  238. AudioStreamInteractive::TransitionToTime AudioStreamInteractive::get_transition_to_time(int p_from_clip, int p_to_clip) const {
  239. TransitionKey tk(p_from_clip, p_to_clip);
  240. ERR_FAIL_COND_V(!transition_map.has(tk), TRANSITION_TO_TIME_START);
  241. return transition_map[tk].to_time;
  242. }
  243. AudioStreamInteractive::FadeMode AudioStreamInteractive::get_transition_fade_mode(int p_from_clip, int p_to_clip) const {
  244. TransitionKey tk(p_from_clip, p_to_clip);
  245. ERR_FAIL_COND_V(!transition_map.has(tk), FADE_DISABLED);
  246. return transition_map[tk].fade_mode;
  247. }
  248. float AudioStreamInteractive::get_transition_fade_beats(int p_from_clip, int p_to_clip) const {
  249. TransitionKey tk(p_from_clip, p_to_clip);
  250. ERR_FAIL_COND_V(!transition_map.has(tk), -1);
  251. return transition_map[tk].fade_beats;
  252. }
  253. bool AudioStreamInteractive::is_transition_using_filler_clip(int p_from_clip, int p_to_clip) const {
  254. TransitionKey tk(p_from_clip, p_to_clip);
  255. ERR_FAIL_COND_V(!transition_map.has(tk), false);
  256. return transition_map[tk].use_filler_clip;
  257. }
  258. int AudioStreamInteractive::get_transition_filler_clip(int p_from_clip, int p_to_clip) const {
  259. TransitionKey tk(p_from_clip, p_to_clip);
  260. ERR_FAIL_COND_V(!transition_map.has(tk), -1);
  261. return transition_map[tk].filler_clip;
  262. }
  263. bool AudioStreamInteractive::is_transition_holding_previous(int p_from_clip, int p_to_clip) const {
  264. TransitionKey tk(p_from_clip, p_to_clip);
  265. ERR_FAIL_COND_V(!transition_map.has(tk), false);
  266. return transition_map[tk].hold_previous;
  267. }
  268. #ifdef TOOLS_ENABLED
  269. PackedStringArray AudioStreamInteractive::_get_linked_undo_properties(const String &p_property, const Variant &p_new_value) const {
  270. PackedStringArray ret;
  271. if (p_property.begins_with("clip_") && p_property.ends_with("/stream")) {
  272. int clip = p_property.get_slicec('_', 1).to_int();
  273. if (clip < clip_count) {
  274. ret.push_back("clip_" + itos(clip) + "/name");
  275. }
  276. }
  277. if (p_property == "clip_count") {
  278. int new_clip_count = p_new_value;
  279. if (new_clip_count < clip_count) {
  280. for (int i = 0; i < clip_count; i++) {
  281. if (clips[i].auto_advance_next_clip >= new_clip_count) {
  282. ret.push_back("clip_" + itos(i) + "/auto_advance");
  283. ret.push_back("clip_" + itos(i) + "/next_clip");
  284. }
  285. }
  286. ret.push_back("_transitions");
  287. if (initial_clip >= new_clip_count) {
  288. ret.push_back("initial_clip");
  289. }
  290. }
  291. }
  292. return ret;
  293. }
  294. template <class T>
  295. static void _test_and_swap(T &p_elem, uint32_t p_a, uint32_t p_b) {
  296. if ((uint32_t)p_elem == p_a) {
  297. p_elem = p_b;
  298. } else if (uint32_t(p_elem) == p_b) {
  299. p_elem = p_a;
  300. }
  301. }
  302. void AudioStreamInteractive::_inspector_array_swap_clip(uint32_t p_item_a, uint32_t p_item_b) {
  303. ERR_FAIL_UNSIGNED_INDEX(p_item_a, (uint32_t)clip_count);
  304. ERR_FAIL_UNSIGNED_INDEX(p_item_b, (uint32_t)clip_count);
  305. for (int i = 0; i < clip_count; i++) {
  306. _test_and_swap(clips[i].auto_advance_next_clip, p_item_a, p_item_b);
  307. }
  308. Vector<TransitionKey> to_remove;
  309. HashMap<TransitionKey, Transition, TransitionKeyHasher> to_add;
  310. for (KeyValue<TransitionKey, Transition> &K : transition_map) {
  311. if (K.key.from_clip == p_item_a || K.key.from_clip == p_item_b || K.key.to_clip == p_item_a || K.key.to_clip == p_item_b) {
  312. to_remove.push_back(K.key);
  313. TransitionKey new_key = K.key;
  314. _test_and_swap(new_key.from_clip, p_item_a, p_item_b);
  315. _test_and_swap(new_key.to_clip, p_item_a, p_item_b);
  316. to_add[new_key] = K.value;
  317. }
  318. }
  319. for (int i = 0; i < to_remove.size(); i++) {
  320. transition_map.erase(to_remove[i]);
  321. }
  322. for (KeyValue<TransitionKey, Transition> &K : to_add) {
  323. transition_map.insert(K.key, K.value);
  324. }
  325. SWAP(clips[p_item_a], clips[p_item_b]);
  326. stream_name_cache = "";
  327. notify_property_list_changed();
  328. emit_signal(SNAME("parameter_list_changed"));
  329. }
  330. String AudioStreamInteractive::_get_streams_hint() const {
  331. if (!stream_name_cache.is_empty()) {
  332. return stream_name_cache;
  333. }
  334. for (int i = 0; i < clip_count; i++) {
  335. if (i > 0) {
  336. stream_name_cache += ",";
  337. }
  338. String n = String(clips[i].name).replace(",", " ");
  339. if (n == "" && clips[i].stream.is_valid()) {
  340. if (!clips[i].stream->get_name().is_empty()) {
  341. n = clips[i].stream->get_name().replace(",", " ");
  342. } else if (clips[i].stream->get_path().is_resource_file()) {
  343. n = clips[i].stream->get_path().get_file().replace(",", " ");
  344. }
  345. }
  346. if (n == "") {
  347. n = "Clip " + itos(i);
  348. }
  349. stream_name_cache += n;
  350. }
  351. return stream_name_cache;
  352. }
  353. #endif
  354. void AudioStreamInteractive::_validate_property(PropertyInfo &r_property) const {
  355. String prop = r_property.name;
  356. #ifdef TOOLS_ENABLED
  357. if (prop == "switch_to") {
  358. r_property.hint_string = _get_streams_hint();
  359. return;
  360. }
  361. #endif
  362. if (prop == "initial_clip") {
  363. #ifdef TOOLS_ENABLED
  364. r_property.hint_string = _get_streams_hint();
  365. #endif
  366. } else if (prop.begins_with("clip_") && prop != "clip_count") {
  367. int clip = prop.get_slicec('_', 1).to_int();
  368. if (clip >= clip_count) {
  369. r_property.usage = PROPERTY_USAGE_INTERNAL;
  370. } else if (prop == "clip_" + itos(clip) + "/next_clip") {
  371. if (clips[clip].auto_advance != AUTO_ADVANCE_ENABLED) {
  372. r_property.usage = 0;
  373. } else {
  374. #ifdef TOOLS_ENABLED
  375. r_property.hint_string = _get_streams_hint();
  376. #endif
  377. }
  378. }
  379. }
  380. }
  381. void AudioStreamInteractive::get_parameter_list(List<Parameter> *r_parameters) {
  382. String clip_names;
  383. for (int i = 0; i < clip_count; i++) {
  384. clip_names += ",";
  385. clip_names += clips[i].name;
  386. }
  387. r_parameters->push_back(Parameter(PropertyInfo(Variant::STRING, "switch_to_clip", PROPERTY_HINT_ENUM, clip_names, PROPERTY_USAGE_EDITOR), ""));
  388. }
  389. void AudioStreamInteractive::_bind_methods() {
  390. #ifdef TOOLS_ENABLED
  391. ClassDB::bind_method(D_METHOD("_get_linked_undo_properties", "for_property", "for_value"), &AudioStreamInteractive::_get_linked_undo_properties);
  392. ClassDB::bind_method(D_METHOD("_inspector_array_swap_clip", "a", "b"), &AudioStreamInteractive::_inspector_array_swap_clip);
  393. #endif
  394. // CLIPS
  395. ClassDB::bind_method(D_METHOD("set_clip_count", "clip_count"), &AudioStreamInteractive::set_clip_count);
  396. ClassDB::bind_method(D_METHOD("get_clip_count"), &AudioStreamInteractive::get_clip_count);
  397. ClassDB::bind_method(D_METHOD("set_initial_clip", "clip_index"), &AudioStreamInteractive::set_initial_clip);
  398. ClassDB::bind_method(D_METHOD("get_initial_clip"), &AudioStreamInteractive::get_initial_clip);
  399. ClassDB::bind_method(D_METHOD("set_clip_name", "clip_index", "name"), &AudioStreamInteractive::set_clip_name);
  400. ClassDB::bind_method(D_METHOD("get_clip_name", "clip_index"), &AudioStreamInteractive::get_clip_name);
  401. ClassDB::bind_method(D_METHOD("set_clip_stream", "clip_index", "stream"), &AudioStreamInteractive::set_clip_stream);
  402. ClassDB::bind_method(D_METHOD("get_clip_stream", "clip_index"), &AudioStreamInteractive::get_clip_stream);
  403. ClassDB::bind_method(D_METHOD("set_clip_auto_advance", "clip_index", "mode"), &AudioStreamInteractive::set_clip_auto_advance);
  404. ClassDB::bind_method(D_METHOD("get_clip_auto_advance", "clip_index"), &AudioStreamInteractive::get_clip_auto_advance);
  405. ClassDB::bind_method(D_METHOD("set_clip_auto_advance_next_clip", "clip_index", "auto_advance_next_clip"), &AudioStreamInteractive::set_clip_auto_advance_next_clip);
  406. ClassDB::bind_method(D_METHOD("get_clip_auto_advance_next_clip", "clip_index"), &AudioStreamInteractive::get_clip_auto_advance_next_clip);
  407. ADD_PROPERTY(PropertyInfo(Variant::INT, "initial_clip", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT), "set_initial_clip", "get_initial_clip");
  408. ADD_PROPERTY(PropertyInfo(Variant::INT, "clip_count", PROPERTY_HINT_RANGE, "1," + itos(MAX_CLIPS), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_ARRAY, "Clips,clip_,page_size=999,unfoldable,numbered,swap_method=_inspector_array_swap_clip,add_button_text=" + String(RTR("Add Clip"))), "set_clip_count", "get_clip_count");
  409. for (int i = 0; i < MAX_CLIPS; i++) {
  410. ADD_PROPERTYI(PropertyInfo(Variant::STRING_NAME, "clip_" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_clip_name", "get_clip_name", i);
  411. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "clip_" + itos(i) + "/stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_clip_stream", "get_clip_stream", i);
  412. ADD_PROPERTYI(PropertyInfo(Variant::INT, "clip_" + itos(i) + "/auto_advance", PROPERTY_HINT_ENUM, "Disabled,Enabled,ReturnToHold", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_clip_auto_advance", "get_clip_auto_advance", i);
  413. ADD_PROPERTYI(PropertyInfo(Variant::INT, "clip_" + itos(i) + "/next_clip", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_clip_auto_advance_next_clip", "get_clip_auto_advance_next_clip", i);
  414. }
  415. // TRANSITIONS
  416. ClassDB::bind_method(D_METHOD("add_transition", "from_clip", "to_clip", "from_time", "to_time", "fade_mode", "fade_beats", "use_filler_clip", "filler_clip", "hold_previous"), &AudioStreamInteractive::add_transition, DEFVAL(false), DEFVAL(-1), DEFVAL(false));
  417. ClassDB::bind_method(D_METHOD("has_transition", "from_clip", "to_clip"), &AudioStreamInteractive::has_transition);
  418. ClassDB::bind_method(D_METHOD("erase_transition", "from_clip", "to_clip"), &AudioStreamInteractive::erase_transition);
  419. ClassDB::bind_method(D_METHOD("get_transition_list"), &AudioStreamInteractive::get_transition_list);
  420. ClassDB::bind_method(D_METHOD("get_transition_from_time", "from_clip", "to_clip"), &AudioStreamInteractive::get_transition_from_time);
  421. ClassDB::bind_method(D_METHOD("get_transition_to_time", "from_clip", "to_clip"), &AudioStreamInteractive::get_transition_to_time);
  422. ClassDB::bind_method(D_METHOD("get_transition_fade_mode", "from_clip", "to_clip"), &AudioStreamInteractive::get_transition_fade_mode);
  423. ClassDB::bind_method(D_METHOD("get_transition_fade_beats", "from_clip", "to_clip"), &AudioStreamInteractive::get_transition_fade_beats);
  424. ClassDB::bind_method(D_METHOD("is_transition_using_filler_clip", "from_clip", "to_clip"), &AudioStreamInteractive::is_transition_using_filler_clip);
  425. ClassDB::bind_method(D_METHOD("get_transition_filler_clip", "from_clip", "to_clip"), &AudioStreamInteractive::get_transition_filler_clip);
  426. ClassDB::bind_method(D_METHOD("is_transition_holding_previous", "from_clip", "to_clip"), &AudioStreamInteractive::is_transition_holding_previous);
  427. ClassDB::bind_method(D_METHOD("_set_transitions", "transitions"), &AudioStreamInteractive::_set_transitions);
  428. ClassDB::bind_method(D_METHOD("_get_transitions"), &AudioStreamInteractive::_get_transitions);
  429. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_transitions", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_transitions", "_get_transitions");
  430. BIND_ENUM_CONSTANT(TRANSITION_FROM_TIME_IMMEDIATE);
  431. BIND_ENUM_CONSTANT(TRANSITION_FROM_TIME_NEXT_BEAT);
  432. BIND_ENUM_CONSTANT(TRANSITION_FROM_TIME_NEXT_BAR);
  433. BIND_ENUM_CONSTANT(TRANSITION_FROM_TIME_END);
  434. BIND_ENUM_CONSTANT(TRANSITION_TO_TIME_SAME_POSITION);
  435. BIND_ENUM_CONSTANT(TRANSITION_TO_TIME_START);
  436. BIND_ENUM_CONSTANT(FADE_DISABLED);
  437. BIND_ENUM_CONSTANT(FADE_IN);
  438. BIND_ENUM_CONSTANT(FADE_OUT);
  439. BIND_ENUM_CONSTANT(FADE_CROSS);
  440. BIND_ENUM_CONSTANT(FADE_AUTOMATIC);
  441. BIND_ENUM_CONSTANT(AUTO_ADVANCE_DISABLED);
  442. BIND_ENUM_CONSTANT(AUTO_ADVANCE_ENABLED);
  443. BIND_ENUM_CONSTANT(AUTO_ADVANCE_RETURN_TO_HOLD);
  444. BIND_CONSTANT(CLIP_ANY);
  445. }
  446. ///////////////////////////////////////////////////////////
  447. ///////////////////////////////////////////////////////////
  448. ///////////////////////////////////////////////////////////
  449. AudioStreamPlaybackInteractive::AudioStreamPlaybackInteractive() {
  450. }
  451. AudioStreamPlaybackInteractive::~AudioStreamPlaybackInteractive() {
  452. }
  453. void AudioStreamPlaybackInteractive::stop() {
  454. if (!active) {
  455. return;
  456. }
  457. active = false;
  458. for (int i = 0; i < AudioStreamInteractive::MAX_CLIPS; i++) {
  459. if (states[i].playback.is_valid()) {
  460. states[i].playback->stop();
  461. }
  462. states[i].fade_speed = 0.0;
  463. states[i].fade_volume = 0.0;
  464. states[i].fade_wait = 0.0;
  465. states[i].reset_fade();
  466. states[i].active = false;
  467. states[i].auto_advance = -1;
  468. states[i].first_mix = true;
  469. }
  470. }
  471. void AudioStreamPlaybackInteractive::start(double p_from_pos) {
  472. if (active) {
  473. stop();
  474. }
  475. if (version != stream->version) {
  476. for (int i = 0; i < AudioStreamInteractive::MAX_CLIPS; i++) {
  477. Ref<AudioStream> src_stream;
  478. if (i < stream->clip_count) {
  479. src_stream = stream->clips[i].stream;
  480. }
  481. if (states[i].stream != src_stream) {
  482. states[i].stream.unref();
  483. states[i].playback.unref();
  484. states[i].stream = src_stream;
  485. states[i].playback = src_stream->instantiate_playback();
  486. }
  487. }
  488. version = stream->version;
  489. }
  490. int current = stream->initial_clip;
  491. if (current < 0 || current >= stream->clip_count) {
  492. return; // No playback possible.
  493. }
  494. if (!states[current].playback.is_valid()) {
  495. return; //no playback possible
  496. }
  497. active = true;
  498. _queue(current, false);
  499. }
  500. void AudioStreamPlaybackInteractive::_queue(int p_to_clip_index, bool p_is_auto_advance) {
  501. ERR_FAIL_INDEX(p_to_clip_index, stream->clip_count);
  502. ERR_FAIL_COND(states[p_to_clip_index].playback.is_null());
  503. if (playback_current == -1) {
  504. // Nothing to do, start.
  505. int current = p_to_clip_index;
  506. State &state = states[current];
  507. state.active = true;
  508. state.fade_wait = 0;
  509. state.fade_volume = 1.0;
  510. state.fade_speed = 0;
  511. state.first_mix = true;
  512. state.playback->start(0);
  513. playback_current = current;
  514. if (stream->clips[current].auto_advance == AudioStreamInteractive::AUTO_ADVANCE_ENABLED && stream->clips[current].auto_advance_next_clip >= 0 && stream->clips[current].auto_advance_next_clip < stream->clip_count && stream->clips[current].auto_advance_next_clip != current) {
  515. //prepare auto advance
  516. state.auto_advance = stream->clips[current].auto_advance_next_clip;
  517. }
  518. return;
  519. }
  520. for (int i = 0; i < stream->clip_count; i++) {
  521. if (i == playback_current || i == p_to_clip_index) {
  522. continue;
  523. }
  524. if (states[i].active && states[i].fade_wait > 0) { // Waiting to kick in, terminate because change of plans.
  525. states[i].playback->stop();
  526. states[i].reset_fade();
  527. states[i].active = false;
  528. }
  529. }
  530. State &from_state = states[playback_current];
  531. State &to_state = states[p_to_clip_index];
  532. AudioStreamInteractive::Transition transition; // Use an empty transition by default
  533. AudioStreamInteractive::TransitionKey tkeys[4] = {
  534. AudioStreamInteractive::TransitionKey(playback_current, p_to_clip_index),
  535. AudioStreamInteractive::TransitionKey(playback_current, AudioStreamInteractive::CLIP_ANY),
  536. AudioStreamInteractive::TransitionKey(AudioStreamInteractive::CLIP_ANY, p_to_clip_index),
  537. AudioStreamInteractive::TransitionKey(AudioStreamInteractive::CLIP_ANY, AudioStreamInteractive::CLIP_ANY)
  538. };
  539. for (int i = 0; i < 4; i++) {
  540. if (stream->transition_map.has(tkeys[i])) {
  541. transition = stream->transition_map[tkeys[i]];
  542. break;
  543. }
  544. }
  545. if (transition.fade_mode == AudioStreamInteractive::FADE_AUTOMATIC) {
  546. // Adjust automatic mode based on context.
  547. if (transition.to_time == AudioStreamInteractive::TRANSITION_TO_TIME_START) {
  548. transition.fade_mode = AudioStreamInteractive::FADE_OUT;
  549. } else {
  550. transition.fade_mode = AudioStreamInteractive::FADE_CROSS;
  551. }
  552. }
  553. if (p_is_auto_advance) {
  554. transition.from_time = AudioStreamInteractive::TRANSITION_FROM_TIME_END;
  555. if (transition.to_time == AudioStreamInteractive::TRANSITION_TO_TIME_SAME_POSITION) {
  556. transition.to_time = AudioStreamInteractive::TRANSITION_TO_TIME_START;
  557. }
  558. }
  559. // Prepare the fadeout
  560. float current_pos = from_state.playback->get_playback_position();
  561. float src_fade_wait = 0;
  562. float dst_seek_to = 0;
  563. float fade_speed = 0;
  564. bool src_no_loop = false;
  565. if (from_state.stream->get_bpm()) {
  566. // Check if source speed has BPM, if so, transition syncs to BPM
  567. float beat_sec = 60 / float(from_state.stream->get_bpm());
  568. switch (transition.from_time) {
  569. case AudioStreamInteractive::TRANSITION_FROM_TIME_IMMEDIATE: {
  570. src_fade_wait = 0;
  571. } break;
  572. case AudioStreamInteractive::TRANSITION_FROM_TIME_NEXT_BEAT: {
  573. float remainder = Math::fmod(current_pos, beat_sec);
  574. src_fade_wait = beat_sec - remainder;
  575. } break;
  576. case AudioStreamInteractive::TRANSITION_FROM_TIME_NEXT_BAR: {
  577. float bar_sec = beat_sec * from_state.stream->get_bar_beats();
  578. float remainder = Math::fmod(current_pos, bar_sec);
  579. src_fade_wait = bar_sec - remainder;
  580. } break;
  581. case AudioStreamInteractive::TRANSITION_FROM_TIME_END: {
  582. float end = from_state.stream->get_beat_count() > 0 ? float(from_state.stream->get_beat_count() * beat_sec) : from_state.stream->get_length();
  583. if (end == 0) {
  584. // Stream does not have a length.
  585. src_fade_wait = 0;
  586. } else {
  587. src_fade_wait = end - current_pos;
  588. }
  589. if (!from_state.stream->has_loop()) {
  590. src_no_loop = true;
  591. }
  592. } break;
  593. default: {
  594. }
  595. }
  596. // Fade speed also aligned to BPM
  597. fade_speed = 1.0 / (transition.fade_beats * beat_sec);
  598. } else {
  599. // Source has no BPM, so just simple transition.
  600. if (transition.from_time == AudioStreamInteractive::TRANSITION_FROM_TIME_END && from_state.stream->get_length() > 0) {
  601. float end = from_state.stream->get_length();
  602. src_fade_wait = end - current_pos;
  603. if (!from_state.stream->has_loop()) {
  604. src_no_loop = true;
  605. }
  606. } else {
  607. src_fade_wait = 0;
  608. }
  609. fade_speed = 1.0 / transition.fade_beats;
  610. }
  611. if (transition.to_time == AudioStreamInteractive::TRANSITION_TO_TIME_PREVIOUS_POSITION && to_state.stream->get_length() > 0.0) {
  612. dst_seek_to = to_state.previous_position;
  613. } else if (transition.to_time == AudioStreamInteractive::TRANSITION_TO_TIME_SAME_POSITION && transition.from_time != AudioStreamInteractive::TRANSITION_FROM_TIME_END && to_state.stream->get_length() > 0.0) {
  614. // Seeking to basically same position as when we start fading.
  615. dst_seek_to = current_pos + src_fade_wait;
  616. float end;
  617. if (to_state.stream->get_bpm() > 0 && to_state.stream->get_beat_count()) {
  618. float beat_sec = 60 / float(to_state.stream->get_bpm());
  619. end = to_state.stream->get_beat_count() * beat_sec;
  620. } else {
  621. end = to_state.stream->get_length();
  622. }
  623. if (dst_seek_to > end) {
  624. // Seeking too far away.
  625. dst_seek_to = 0; //past end, loop to beginning.
  626. }
  627. } else {
  628. // Seek to Start
  629. dst_seek_to = 0.0;
  630. }
  631. if (transition.fade_mode == AudioStreamInteractive::FADE_DISABLED || transition.fade_mode == AudioStreamInteractive::FADE_IN) {
  632. if (src_no_loop) {
  633. // If there is no fade in the source stream, then let it continue until it ends.
  634. from_state.fade_wait = 0;
  635. from_state.fade_speed = 0;
  636. } else {
  637. // Otherwise force a very quick fade to avoid clicks
  638. from_state.fade_wait = src_fade_wait;
  639. from_state.fade_speed = 1.0 / -0.001;
  640. }
  641. } else {
  642. // Regular fade.
  643. from_state.fade_wait = src_fade_wait;
  644. from_state.fade_speed = -fade_speed;
  645. }
  646. // keep volume, since it may have been fading in from something else.
  647. to_state.playback->start(dst_seek_to);
  648. to_state.active = true;
  649. to_state.fade_volume = 0.0;
  650. to_state.first_mix = true;
  651. int auto_advance_to = -1;
  652. if (stream->clips[p_to_clip_index].auto_advance == AudioStreamInteractive::AUTO_ADVANCE_ENABLED) {
  653. int next_clip = stream->clips[p_to_clip_index].auto_advance_next_clip;
  654. if (next_clip >= 0 && next_clip < (int)stream->clip_count && states[next_clip].playback.is_valid() && next_clip != p_to_clip_index && (!transition.use_filler_clip || next_clip != transition.filler_clip)) {
  655. auto_advance_to = next_clip;
  656. }
  657. }
  658. if (return_memory != -1 && stream->clips[p_to_clip_index].auto_advance == AudioStreamInteractive::AUTO_ADVANCE_RETURN_TO_HOLD) {
  659. auto_advance_to = return_memory;
  660. return_memory = -1;
  661. }
  662. if (transition.hold_previous) {
  663. return_memory = playback_current;
  664. }
  665. if (transition.use_filler_clip && transition.filler_clip >= 0 && transition.filler_clip < (int)stream->clip_count && states[transition.filler_clip].playback.is_valid() && playback_current != transition.filler_clip && p_to_clip_index != transition.filler_clip) {
  666. State &filler_state = states[transition.filler_clip];
  667. filler_state.playback->start(0);
  668. filler_state.active = true;
  669. // Filler state does not fade (bake fade in the audio clip if you want fading.
  670. filler_state.fade_volume = 1.0;
  671. filler_state.fade_speed = 0.0;
  672. filler_state.fade_wait = src_fade_wait;
  673. filler_state.first_mix = true;
  674. float filler_end;
  675. if (filler_state.stream->get_bpm() > 0 && filler_state.stream->get_beat_count() > 0) {
  676. float filler_beat_sec = 60 / float(filler_state.stream->get_bpm());
  677. filler_end = filler_beat_sec * filler_state.stream->get_beat_count();
  678. } else {
  679. filler_end = filler_state.stream->get_length();
  680. }
  681. if (!filler_state.stream->has_loop()) {
  682. src_no_loop = true;
  683. }
  684. if (transition.fade_mode == AudioStreamInteractive::FADE_DISABLED || transition.fade_mode == AudioStreamInteractive::FADE_OUT) {
  685. // No fading, immediately start at full volume.
  686. to_state.fade_volume = 0.0;
  687. to_state.fade_speed = 1.0; //start at full volume, as filler is meant as a transition.
  688. } else {
  689. // Fade enable, prepare fade.
  690. to_state.fade_volume = 0.0;
  691. to_state.fade_speed = fade_speed;
  692. }
  693. to_state.fade_wait = src_fade_wait + filler_end;
  694. } else {
  695. to_state.fade_wait = src_fade_wait;
  696. if (transition.fade_mode == AudioStreamInteractive::FADE_DISABLED || transition.fade_mode == AudioStreamInteractive::FADE_OUT) {
  697. to_state.fade_volume = 1.0;
  698. to_state.fade_speed = 0.0;
  699. } else {
  700. to_state.fade_volume = 0.0;
  701. to_state.fade_speed = fade_speed;
  702. }
  703. to_state.auto_advance = auto_advance_to;
  704. }
  705. }
  706. void AudioStreamPlaybackInteractive::seek(double p_time) {
  707. // Seek not supported
  708. }
  709. int AudioStreamPlaybackInteractive::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {
  710. if (active && version != stream->version) {
  711. stop();
  712. }
  713. if (switch_request != -1) {
  714. _queue(switch_request, false);
  715. switch_request = -1;
  716. }
  717. if (!active) {
  718. return 0;
  719. }
  720. int todo = p_frames;
  721. while (todo) {
  722. int to_mix = MIN(todo, BUFFER_SIZE);
  723. _mix_internal(to_mix);
  724. for (int i = 0; i < to_mix; i++) {
  725. p_buffer[i] = mix_buffer[i];
  726. }
  727. p_buffer += to_mix;
  728. todo -= to_mix;
  729. }
  730. return p_frames;
  731. }
  732. void AudioStreamPlaybackInteractive::_mix_internal(int p_frames) {
  733. for (int i = 0; i < p_frames; i++) {
  734. mix_buffer[i] = AudioFrame(0, 0);
  735. }
  736. for (int i = 0; i < stream->clip_count; i++) {
  737. if (!states[i].active) {
  738. continue;
  739. }
  740. _mix_internal_state(i, p_frames);
  741. }
  742. }
  743. void AudioStreamPlaybackInteractive::_mix_internal_state(int p_state_idx, int p_frames) {
  744. State &state = states[p_state_idx];
  745. double mix_rate = double(AudioServer::get_singleton()->get_mix_rate());
  746. double frame_inc = 1.0 / mix_rate;
  747. int from_frame = 0;
  748. int queue_next = -1;
  749. if (state.first_mix) {
  750. // Did not start mixing yet, wait.
  751. double mix_time = p_frames * frame_inc;
  752. if (state.fade_wait < mix_time) {
  753. // time to start!
  754. from_frame = state.fade_wait * mix_rate;
  755. state.fade_wait = 0;
  756. if (state.fade_speed == 0.0) {
  757. queue_next = state.auto_advance;
  758. }
  759. playback_current = p_state_idx;
  760. state.first_mix = false;
  761. } else {
  762. // This is for fade in of new stream.
  763. state.fade_wait -= mix_time;
  764. return; // Nothing to do
  765. }
  766. }
  767. state.previous_position = state.playback->get_playback_position();
  768. state.playback->mix(temp_buffer + from_frame, 1.0, p_frames - from_frame);
  769. double frame_fade_inc = state.fade_speed * frame_inc;
  770. for (int i = from_frame; i < p_frames; i++) {
  771. if (state.fade_wait) {
  772. // This is for fade out of existing stream;
  773. state.fade_wait -= frame_inc;
  774. if (state.fade_wait < 0.0) {
  775. state.fade_wait = 0.0;
  776. }
  777. } else if (frame_fade_inc > 0) {
  778. state.fade_volume += frame_fade_inc;
  779. if (state.fade_volume >= 1.0) {
  780. state.fade_speed = 0.0;
  781. frame_fade_inc = 0.0;
  782. state.fade_volume = 1.0;
  783. queue_next = state.auto_advance;
  784. }
  785. } else if (frame_fade_inc < 0.0) {
  786. state.fade_volume += frame_fade_inc;
  787. if (state.fade_volume <= 0.0) {
  788. state.fade_speed = 0.0;
  789. frame_fade_inc = 0.0;
  790. state.fade_volume = 0.0;
  791. state.playback->stop(); // Stop playback and break, no point to continue mixing
  792. break;
  793. }
  794. }
  795. mix_buffer[i] += temp_buffer[i] * state.fade_volume;
  796. state.previous_position += frame_inc;
  797. }
  798. if (!state.playback->is_playing()) {
  799. // It finished because it either reached end or faded out, so deactivate and continue.
  800. state.active = false;
  801. }
  802. if (queue_next != -1) {
  803. _queue(queue_next, true);
  804. }
  805. }
  806. void AudioStreamPlaybackInteractive::tag_used_streams() {
  807. for (int i = 0; i < stream->clip_count; i++) {
  808. if (states[i].active && !states[i].first_mix && states[i].playback->is_playing()) {
  809. states[i].stream->tag_used(states[i].playback->get_playback_position());
  810. }
  811. }
  812. stream->tag_used(0);
  813. }
  814. void AudioStreamPlaybackInteractive::switch_to_clip_by_name(const StringName &p_name) {
  815. if (p_name == StringName()) {
  816. switch_request = -1;
  817. return;
  818. }
  819. ERR_FAIL_COND_MSG(stream.is_null(), "Attempted to switch while not playing back any stream.");
  820. for (int i = 0; i < stream->get_clip_count(); i++) {
  821. if (stream->get_clip_name(i) == p_name) {
  822. switch_request = i;
  823. return;
  824. }
  825. }
  826. ERR_FAIL_MSG("Clip not found: " + String(p_name));
  827. }
  828. void AudioStreamPlaybackInteractive::set_parameter(const StringName &p_name, const Variant &p_value) {
  829. if (p_name == SNAME("switch_to_clip")) {
  830. switch_to_clip_by_name(p_value);
  831. }
  832. }
  833. Variant AudioStreamPlaybackInteractive::get_parameter(const StringName &p_name) const {
  834. if (p_name == SNAME("switch_to_clip")) {
  835. for (int i = 0; i < stream->get_clip_count(); i++) {
  836. if (switch_request != -1) {
  837. if (switch_request == i) {
  838. return String(stream->get_clip_name(i));
  839. }
  840. } else if (playback_current == i) {
  841. return String(stream->get_clip_name(i));
  842. }
  843. }
  844. return "";
  845. }
  846. return Variant();
  847. }
  848. void AudioStreamPlaybackInteractive::switch_to_clip(int p_index) {
  849. switch_request = p_index;
  850. }
  851. int AudioStreamPlaybackInteractive::get_loop_count() const {
  852. return 0; // Looping not supported
  853. }
  854. double AudioStreamPlaybackInteractive::get_playback_position() const {
  855. return 0.0;
  856. }
  857. bool AudioStreamPlaybackInteractive::is_playing() const {
  858. return active;
  859. }
  860. void AudioStreamPlaybackInteractive::_bind_methods() {
  861. ClassDB::bind_method(D_METHOD("switch_to_clip_by_name", "clip_name"), &AudioStreamPlaybackInteractive::switch_to_clip_by_name);
  862. ClassDB::bind_method(D_METHOD("switch_to_clip", "clip_index"), &AudioStreamPlaybackInteractive::switch_to_clip);
  863. }