| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*  editor_audio_buses.cpp                                                */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*                         This file is part of:                          */ | 
					
						
							|  |  |  | /*                             GODOT ENGINE                               */ | 
					
						
							|  |  |  | /*                        https://godotengine.org                         */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
					
						
							|  |  |  | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the        */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including    */ | 
					
						
							|  |  |  | /* 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  */ | 
					
						
							|  |  |  | /* the following conditions:                                              */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be         */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.        */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
					
						
							|  |  |  | /* 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-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | #include "editor_audio_buses.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-12 02:46:22 +01:00
										 |  |  | #include "core/config/project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-28 15:19:37 +02:00
										 |  |  | #include "core/input/input.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/io/resource_saver.h"
 | 
					
						
							|  |  |  | #include "core/os/keyboard.h"
 | 
					
						
							| 
									
										
										
										
											2022-02-12 02:46:22 +01:00
										 |  |  | #include "editor/editor_node.h"
 | 
					
						
							| 
									
										
										
										
											2022-07-31 21:14:15 +03:00
										 |  |  | #include "editor/editor_settings.h"
 | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | #include "editor/editor_string_names.h"
 | 
					
						
							| 
									
										
										
										
											2022-03-25 18:06:46 +01:00
										 |  |  | #include "editor/editor_undo_redo_manager.h"
 | 
					
						
							| 
									
										
										
										
											2023-04-07 18:59:49 +02:00
										 |  |  | #include "editor/filesystem_dock.h"
 | 
					
						
							|  |  |  | #include "editor/gui/editor_file_dialog.h"
 | 
					
						
							| 
									
										
										
										
											2024-01-15 13:14:55 +01:00
										 |  |  | #include "editor/themes/editor_scale.h"
 | 
					
						
							| 
									
										
										
										
											2024-01-17 15:03:55 +01:00
										 |  |  | #include "editor/themes/editor_theme_manager.h"
 | 
					
						
							| 
									
										
										
										
											2022-11-19 12:45:49 +01:00
										 |  |  | #include "scene/gui/separator.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | #include "scene/resources/font.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | #include "servers/audio_server.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 13:38:40 -03:00
										 |  |  | void EditorAudioBus::_update_visible_channels() { | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 	for (; i < cc; i++) { | 
					
						
							|  |  |  | 		if (!channel[i].vu_l->is_visible()) { | 
					
						
							|  |  |  | 			channel[i].vu_l->show(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!channel[i].vu_r->is_visible()) { | 
					
						
							|  |  |  | 			channel[i].vu_r->show(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (; i < CHANNELS_MAX; i++) { | 
					
						
							|  |  |  | 		if (channel[i].vu_l->is_visible()) { | 
					
						
							|  |  |  | 			channel[i].vu_l->hide(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (channel[i].vu_r->is_visible()) { | 
					
						
							|  |  |  | 			channel[i].vu_r->hide(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | void EditorAudioBus::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2022-08-29 11:04:31 +02:00
										 |  |  | 		case NOTIFICATION_ENTER_TREE: | 
					
						
							| 
									
										
										
										
											2021-07-31 22:14:14 +03:00
										 |  |  | 		case NOTIFICATION_THEME_CHANGED: { | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 			Ref<Texture2D> active_bus_texture = get_editor_theme_icon(SNAME("BusVuActive")); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			for (int i = 0; i < CHANNELS_MAX; i++) { | 
					
						
							| 
									
										
										
										
											2023-05-12 01:55:52 +02:00
										 |  |  | 				channel[i].vu_l->set_under_texture(active_bus_texture); | 
					
						
							|  |  |  | 				channel[i].vu_l->set_tint_under(Color(0.75, 0.75, 0.75)); | 
					
						
							|  |  |  | 				channel[i].vu_l->set_progress_texture(active_bus_texture); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				channel[i].vu_r->set_under_texture(active_bus_texture); | 
					
						
							|  |  |  | 				channel[i].vu_r->set_tint_under(Color(0.75, 0.75, 0.75)); | 
					
						
							|  |  |  | 				channel[i].vu_r->set_progress_texture(active_bus_texture); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 				channel[i].prev_active = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 			disabled_vu = get_editor_theme_icon(SNAME("BusVuFrozen")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-17 15:03:55 +01:00
										 |  |  | 			Color solo_color = EditorThemeManager::is_dark_theme() ? Color(1.0, 0.89, 0.22) : Color(1.0, 0.92, 0.44); | 
					
						
							|  |  |  | 			Color mute_color = EditorThemeManager::is_dark_theme() ? Color(1.0, 0.16, 0.16) : Color(1.0, 0.44, 0.44); | 
					
						
							|  |  |  | 			Color bypass_color = EditorThemeManager::is_dark_theme() ? Color(0.13, 0.8, 1.0) : Color(0.44, 0.87, 1.0); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 			solo->set_icon(get_editor_theme_icon(SNAME("AudioBusSolo"))); | 
					
						
							| 
									
										
										
										
											2022-02-08 10:14:58 +01:00
										 |  |  | 			solo->add_theme_color_override("icon_pressed_color", solo_color); | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 			mute->set_icon(get_editor_theme_icon(SNAME("AudioBusMute"))); | 
					
						
							| 
									
										
										
										
											2022-02-08 10:14:58 +01:00
										 |  |  | 			mute->add_theme_color_override("icon_pressed_color", mute_color); | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 			bypass->set_icon(get_editor_theme_icon(SNAME("AudioBusBypass"))); | 
					
						
							| 
									
										
										
										
											2022-02-08 10:14:58 +01:00
										 |  |  | 			bypass->add_theme_color_override("icon_pressed_color", bypass_color); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 			bus_options->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl"))); | 
					
						
							| 
									
										
										
										
											2018-12-07 13:38:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 10:14:58 +01:00
										 |  |  | 			audio_value_preview_label->add_theme_color_override("font_color", get_theme_color(SNAME("font_color"), SNAME("TooltipLabel"))); | 
					
						
							|  |  |  | 			audio_value_preview_label->add_theme_color_override("font_shadow_color", get_theme_color(SNAME("font_shadow_color"), SNAME("TooltipLabel"))); | 
					
						
							|  |  |  | 			audio_value_preview_box->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel"))); | 
					
						
							| 
									
										
										
										
											2022-03-05 01:55:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (int i = 0; i < effect_options->get_item_count(); i++) { | 
					
						
							|  |  |  | 				String class_name = effect_options->get_item_metadata(i); | 
					
						
							|  |  |  | 				Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(class_name); | 
					
						
							|  |  |  | 				effect_options->set_item_icon(i, icon); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-07-31 22:14:14 +03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case NOTIFICATION_READY: { | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			update_bus(); | 
					
						
							|  |  |  | 			set_process(true); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_DRAW: { | 
					
						
							|  |  |  | 			if (is_master) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 				draw_style_box(get_theme_stylebox(SNAME("disabled"), SNAME("Button")), Rect2(Vector2(), get_size())); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			} else if (has_focus()) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 				draw_style_box(get_theme_stylebox(SNAME("focus"), SNAME("Button")), Rect2(Vector2(), get_size())); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 				draw_style_box(get_theme_stylebox(SNAME("panel"), SNAME("TabContainer")), Rect2(Vector2(), get_size())); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			if (get_index() != 0 && hovering_drop) { | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 				Color accent = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 				accent.a *= 0.7; | 
					
						
							|  |  |  | 				draw_rect(Rect2(Point2(), get_size()), accent, false); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_PROCESS: { | 
					
						
							|  |  |  | 			if (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) { | 
					
						
							|  |  |  | 				cc = AudioServer::get_singleton()->get_bus_channels(get_index()); | 
					
						
							|  |  |  | 				_update_visible_channels(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			for (int i = 0; i < cc; i++) { | 
					
						
							|  |  |  | 				float real_peak[2] = { -100, -100 }; | 
					
						
							|  |  |  | 				bool activity_found = false; | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 				if (AudioServer::get_singleton()->is_bus_channel_active(get_index(), i)) { | 
					
						
							|  |  |  | 					activity_found = true; | 
					
						
							|  |  |  | 					real_peak[0] = MAX(real_peak[0], AudioServer::get_singleton()->get_bus_peak_volume_left_db(get_index(), i)); | 
					
						
							|  |  |  | 					real_peak[1] = MAX(real_peak[1], AudioServer::get_singleton()->get_bus_peak_volume_right_db(get_index(), i)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (real_peak[0] > channel[i].peak_l) { | 
					
						
							|  |  |  | 					channel[i].peak_l = real_peak[0]; | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 					channel[i].peak_l -= get_process_delta_time() * 60.0; | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 				if (real_peak[1] > channel[i].peak_r) { | 
					
						
							|  |  |  | 					channel[i].peak_r = real_peak[1]; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					channel[i].peak_r -= get_process_delta_time() * 60.0; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 				channel[i].vu_l->set_value(channel[i].peak_l); | 
					
						
							|  |  |  | 				channel[i].vu_r->set_value(channel[i].peak_r); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 				if (activity_found != channel[i].prev_active) { | 
					
						
							|  |  |  | 					if (activity_found) { | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 						channel[i].vu_l->set_over_texture(Ref<Texture2D>()); | 
					
						
							|  |  |  | 						channel[i].vu_r->set_over_texture(Ref<Texture2D>()); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						channel[i].vu_l->set_over_texture(disabled_vu); | 
					
						
							|  |  |  | 						channel[i].vu_r->set_over_texture(disabled_vu); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 					channel[i].prev_active = activity_found; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_VISIBILITY_CHANGED: { | 
					
						
							|  |  |  | 			for (int i = 0; i < CHANNELS_MAX; i++) { | 
					
						
							|  |  |  | 				channel[i].peak_l = -100; | 
					
						
							|  |  |  | 				channel[i].peak_r = -100; | 
					
						
							|  |  |  | 				channel[i].prev_active = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 23:04:16 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			set_process(is_visible_in_tree()); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2018-02-25 23:04:16 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_MOUSE_EXIT: | 
					
						
							|  |  |  | 		case NOTIFICATION_DRAG_END: { | 
					
						
							|  |  |  | 			if (hovering_drop) { | 
					
						
							|  |  |  | 				hovering_drop = false; | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 				queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2018-02-25 23:04:16 +07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::update_send() { | 
					
						
							|  |  |  | 	send->clear(); | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | 	if (is_master) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		send->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 		send->set_text(TTR("Speakers")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		send->set_disabled(false); | 
					
						
							|  |  |  | 		StringName current_send = AudioServer::get_singleton()->get_bus_send(get_index()); | 
					
						
							|  |  |  | 		int current_send_index = 0; //by default to master
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < get_index(); i++) { | 
					
						
							|  |  |  | 			StringName send_name = AudioServer::get_singleton()->get_bus_name(i); | 
					
						
							|  |  |  | 			send->add_item(send_name); | 
					
						
							|  |  |  | 			if (send_name == current_send) { | 
					
						
							|  |  |  | 				current_send_index = i; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		send->select(current_send_index); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::update_bus() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating_bus) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int index = get_index(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 	float db_value = AudioServer::get_singleton()->get_bus_volume_db(index); | 
					
						
							|  |  |  | 	slider->set_value(_scaled_db_to_normalized_volume(db_value)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	track_name->set_text(AudioServer::get_singleton()->get_bus_name(index)); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (is_master) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		track_name->set_editable(false); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	solo->set_pressed(AudioServer::get_singleton()->is_bus_solo(index)); | 
					
						
							|  |  |  | 	mute->set_pressed(AudioServer::get_singleton()->is_bus_mute(index)); | 
					
						
							|  |  |  | 	bypass->set_pressed(AudioServer::get_singleton()->is_bus_bypassing_effects(index)); | 
					
						
							|  |  |  | 	// effects..
 | 
					
						
							|  |  |  | 	effects->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *root = effects->create_item(); | 
					
						
							|  |  |  | 	for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) { | 
					
						
							|  |  |  | 		Ref<AudioEffect> afx = AudioServer::get_singleton()->get_bus_effect(index, i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		TreeItem *fx = effects->create_item(root); | 
					
						
							|  |  |  | 		fx->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); | 
					
						
							|  |  |  | 		fx->set_editable(0, true); | 
					
						
							|  |  |  | 		fx->set_checked(0, AudioServer::get_singleton()->is_bus_effect_enabled(index, i)); | 
					
						
							|  |  |  | 		fx->set_text(0, afx->get_name()); | 
					
						
							|  |  |  | 		fx->set_metadata(0, i); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *add = effects->create_item(root); | 
					
						
							|  |  |  | 	add->set_cell_mode(0, TreeItem::CELL_MODE_CUSTOM); | 
					
						
							|  |  |  | 	add->set_editable(0, true); | 
					
						
							|  |  |  | 	add->set_selectable(0, false); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	add->set_text(0, TTR("Add Effect")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	update_send(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::_name_changed(const String &p_new_name) { | 
					
						
							| 
									
										
										
										
											2023-03-07 17:22:58 +01:00
										 |  |  | 	if (updating_bus) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	updating_bus = true; | 
					
						
							|  |  |  | 	track_name->release_focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index())) { | 
					
						
							| 
									
										
										
										
											2023-03-07 17:22:58 +01:00
										 |  |  | 		updating_bus = false; | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String attempt = p_new_name; | 
					
						
							|  |  |  | 	int attempts = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (true) { | 
					
						
							|  |  |  | 		bool name_free = true; | 
					
						
							|  |  |  | 		for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { | 
					
						
							|  |  |  | 			if (AudioServer::get_singleton()->get_bus_name(i) == attempt) { | 
					
						
							|  |  |  | 				name_free = false; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (name_free) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		attempts++; | 
					
						
							|  |  |  | 		attempt = p_new_name + " " + itos(attempts); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	StringName current = AudioServer::get_singleton()->get_bus_name(get_index()); | 
					
						
							| 
									
										
										
										
											2023-03-07 17:22:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Rename Audio Bus")); | 
					
						
							| 
									
										
										
										
											2023-03-07 17:22:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_name", get_index(), attempt); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_name", get_index(), current); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { | 
					
						
							|  |  |  | 		if (AudioServer::get_singleton()->get_bus_send(i) == current) { | 
					
						
							|  |  |  | 			ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", i, attempt); | 
					
						
							|  |  |  | 			ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", i, current); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_sends"); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_sends"); | 
					
						
							| 
									
										
										
										
											2023-03-07 17:22:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | void EditorAudioBus::_volume_changed(float p_normalized) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating_bus) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = true; | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-28 21:51:39 +01:00
										 |  |  | 	const float p_db = _normalized_volume_to_scaled_db(p_normalized); | 
					
						
							| 
									
										
										
										
											2019-09-07 00:15:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-08 23:24:00 +02:00
										 |  |  | 	if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) { | 
					
						
							| 
									
										
										
										
											2019-09-07 00:15:17 +02:00
										 |  |  | 		// Snap the value when holding Ctrl for easier editing.
 | 
					
						
							|  |  |  | 		// To do so, it needs to be converted back to normalized volume (as the slider uses that unit).
 | 
					
						
							|  |  |  | 		slider->set_value(_scaled_db_to_normalized_volume(Math::round(p_db))); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-12-02 16:58:58 +07:00
										 |  |  | 	ur->create_action(TTR("Change Audio Bus Volume"), UndoRedo::MERGE_ENDS); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), p_db); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), AudioServer::get_singleton()->get_bus_volume_db(get_index())); | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | float EditorAudioBus::_normalized_volume_to_scaled_db(float normalized) { | 
					
						
							|  |  |  | 	/* There are three different formulas for the conversion from normalized
 | 
					
						
							| 
									
										
										
										
											2019-05-19 12:34:40 +02:00
										 |  |  | 	 * values to relative decibal values. | 
					
						
							|  |  |  | 	 * One formula is an exponential graph which intends to counteract | 
					
						
							| 
									
										
										
											
												Fix various typos
Found via `codespell -q 3 -S ./thirdparty,*.po,./DONORS.md -L ackward,ang,ans,ba,beng,cas,childs,childrens,dof,doubleclick,expct,fave,findn,gird,hist,inh,inout,leapyear,lod,nd,numer,ois,ony,paket,ro,seeked,sinc,switchs,te,uint,varn,vew`
											
										 
											2022-01-02 13:47:52 -05:00
										 |  |  | 	 * the logarithmic nature of human hearing. This is an approximation | 
					
						
							| 
									
										
										
										
											2022-11-01 15:29:38 +01:00
										 |  |  | 	 * of the behavior of a 'logarithmic potentiometer' found on most | 
					
						
							| 
									
										
										
										
											2019-05-19 12:34:40 +02:00
										 |  |  | 	 * musical instruments and also emulated in popular software. | 
					
						
							|  |  |  | 	 * The other two equations are hand-tuned linear tapers that intend to | 
					
						
							|  |  |  | 	 * try to ease the exponential equation in areas where it makes sense.*/ | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (normalized > 0.6f) { | 
					
						
							|  |  |  | 		return 22.22f * normalized - 16.2f; | 
					
						
							|  |  |  | 	} else if (normalized < 0.05f) { | 
					
						
							|  |  |  | 		return 830.72 * normalized - 80.0f; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return 45.0f * Math::pow(normalized - 1.0, 3); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | float EditorAudioBus::_scaled_db_to_normalized_volume(float db) { | 
					
						
							|  |  |  | 	/* Inversion of equations found in _normalized_volume_to_scaled_db.
 | 
					
						
							| 
									
										
										
										
											2019-05-19 12:34:40 +02:00
										 |  |  | 	 * IMPORTANT: If one function changes, the other much change to reflect it. */ | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 	if (db > -2.88) { | 
					
						
							|  |  |  | 		return (db + 16.2f) / 22.22f; | 
					
						
							|  |  |  | 	} else if (db < -38.602f) { | 
					
						
							|  |  |  | 		return (db + 80.00f) / 830.72f; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (db < 0.0) { | 
					
						
							| 
									
										
										
										
											2019-05-19 12:34:40 +02:00
										 |  |  | 			/* To accommodate for NaN on negative numbers for root, we will mirror the
 | 
					
						
							|  |  |  | 			 * results of the positive db range in order to get the desired numerical | 
					
						
							|  |  |  | 			 * value on the negative side. */ | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 			float positive_x = Math::pow(Math::abs(db) / 45.0f, 1.0f / 3.0f) + 1.0f; | 
					
						
							|  |  |  | 			Vector2 translation = Vector2(1.0f, 0.0f) - Vector2(positive_x, Math::abs(db)); | 
					
						
							|  |  |  | 			Vector2 reflected_position = Vector2(1.0, 0.0f) + translation; | 
					
						
							|  |  |  | 			return reflected_position.x; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return Math::pow(db / 45.0f, 1.0f / 3.0f) + 1.0f; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::_show_value(float slider_value) { | 
					
						
							| 
									
										
										
										
											2019-09-07 00:15:17 +02:00
										 |  |  | 	float db; | 
					
						
							| 
									
										
										
										
											2023-06-08 23:24:00 +02:00
										 |  |  | 	if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) { | 
					
						
							| 
									
										
										
										
											2019-09-07 00:15:17 +02:00
										 |  |  | 		// Display the correct (snapped) value when holding Ctrl
 | 
					
						
							|  |  |  | 		db = Math::round(_normalized_volume_to_scaled_db(slider_value)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		db = _normalized_volume_to_scaled_db(slider_value); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-27 09:58:44 +02:00
										 |  |  | 	String text; | 
					
						
							|  |  |  | 	if (Math::is_zero_approx(Math::snapped(db, 0.1))) { | 
					
						
							|  |  |  | 		// Prevent displaying `-0.0 dB` and show ` 0.0 dB` instead.
 | 
					
						
							|  |  |  | 		// The leading space makes the text visually line up with its positive/negative counterparts.
 | 
					
						
							|  |  |  | 		text = " 0.0 dB"; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// Show an explicit `+` sign if positive.
 | 
					
						
							|  |  |  | 		text = vformat("%+.1f dB", db); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-27 09:58:44 +02:00
										 |  |  | 	// Also set the preview text as a standard Control tooltip.
 | 
					
						
							|  |  |  | 	// This way, it can be seen when the slider is merely hovered (instead of dragged).
 | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	slider->set_tooltip_text(text); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 	audio_value_preview_label->set_text(text); | 
					
						
							| 
									
										
										
										
											2021-05-27 09:58:44 +02:00
										 |  |  | 	const Vector2 slider_size = slider->get_size(); | 
					
						
							|  |  |  | 	const Vector2 slider_position = slider->get_global_position(); | 
					
						
							|  |  |  | 	const float vert_padding = 10.0f; | 
					
						
							|  |  |  | 	const Vector2 box_position = Vector2(slider_size.x, (slider_size.y - vert_padding) * (1.0f - slider->get_value()) - vert_padding); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 	audio_value_preview_box->set_position(slider_position + box_position); | 
					
						
							|  |  |  | 	audio_value_preview_box->set_size(audio_value_preview_label->get_size()); | 
					
						
							|  |  |  | 	if (slider->has_focus() && !audio_value_preview_box->is_visible()) { | 
					
						
							|  |  |  | 		audio_value_preview_box->show(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	preview_timer->start(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::_hide_value_preview() { | 
					
						
							|  |  |  | 	audio_value_preview_box->hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | void EditorAudioBus::_solo_toggled() { | 
					
						
							|  |  |  | 	updating_bus = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Toggle Audio Bus Solo")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), solo->is_pressed()); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), AudioServer::get_singleton()->is_bus_solo(get_index())); | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | void EditorAudioBus::_mute_toggled() { | 
					
						
							|  |  |  | 	updating_bus = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Toggle Audio Bus Mute")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), mute->is_pressed()); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), AudioServer::get_singleton()->is_bus_mute(get_index())); | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | void EditorAudioBus::_bypass_toggled() { | 
					
						
							|  |  |  | 	updating_bus = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Toggle Audio Bus Bypass Effects")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), bypass->is_pressed()); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), AudioServer::get_singleton()->is_bus_bypassing_effects(get_index())); | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::_send_selected(int p_which) { | 
					
						
							|  |  |  | 	updating_bus = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2019-02-21 16:41:01 -03:00
										 |  |  | 	ur->create_action(TTR("Select Audio Bus Send")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", get_index(), send->get_item_text(p_which)); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", get_index(), AudioServer::get_singleton()->get_bus_send(get_index())); | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::_effect_selected() { | 
					
						
							|  |  |  | 	TreeItem *effect = effects->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!effect) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	updating_bus = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (effect->get_metadata(0) != Variant()) { | 
					
						
							|  |  |  | 		int index = effect->get_metadata(0); | 
					
						
							| 
									
										
										
										
											2019-02-12 21:10:08 +01:00
										 |  |  | 		Ref<AudioEffect> effect2 = AudioServer::get_singleton()->get_bus_effect(get_index(), index); | 
					
						
							|  |  |  | 		if (effect2.is_valid()) { | 
					
						
							|  |  |  | 			EditorNode::get_singleton()->push_item(effect2.ptr()); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_bus = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::_effect_edited() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating_bus) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *effect = effects->get_edited(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!effect) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (effect->get_metadata(0) == Variant()) { | 
					
						
							|  |  |  | 		Rect2 area = effects->get_item_rect(effect); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-31 17:43:35 +02:00
										 |  |  | 		effect_options->set_position(effects->get_screen_position() + area.position + Vector2(0, area.size.y)); | 
					
						
							|  |  |  | 		effect_options->reset_size(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		effect_options->popup(); | 
					
						
							|  |  |  | 		//add effect
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		int index = effect->get_metadata(0); | 
					
						
							|  |  |  | 		updating_bus = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 		EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 		ur->create_action(TTR("Select Audio Bus Send")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, effect->is_checked(0)); | 
					
						
							|  |  |  | 		ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, AudioServer::get_singleton()->is_bus_effect_enabled(get_index(), index)); | 
					
						
							|  |  |  | 		ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 		ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 		ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		updating_bus = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::_effect_add(int p_which) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating_bus) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	StringName name = effect_options->get_item_metadata(p_which); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 16:03:09 -06:00
										 |  |  | 	Object *fx = ClassDB::instantiate(name); | 
					
						
							| 
									
										
										
										
											2023-09-09 17:24:40 +02:00
										 |  |  | 	ERR_FAIL_NULL(fx); | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	AudioEffect *afx = Object::cast_to<AudioEffect>(fx); | 
					
						
							| 
									
										
										
										
											2023-09-09 17:24:40 +02:00
										 |  |  | 	ERR_FAIL_NULL(afx); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	Ref<AudioEffect> afxr = Ref<AudioEffect>(afx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	afxr->set_name(effect_options->get_item_text(p_which)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Add Audio Bus Effect")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), afxr, -1); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect_count(get_index())); | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-22 12:37:22 -03:00
										 |  |  | void EditorAudioBus::gui_input(const Ref<InputEvent> &p_event) { | 
					
						
							| 
									
										
										
										
											2021-04-05 08:52:21 +02:00
										 |  |  | 	ERR_FAIL_COND(p_event.is_null()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseButton> mb = p_event; | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2021-08-31 17:43:35 +02:00
										 |  |  | 		bus_popup->set_position(get_screen_position() + mb->get_position()); | 
					
						
							|  |  |  | 		bus_popup->reset_size(); | 
					
						
							| 
									
										
										
										
											2017-08-26 21:42:28 +07:00
										 |  |  | 		bus_popup->popup(); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 11:37:12 +10:00
										 |  |  | void EditorAudioBus::_effects_gui_input(Ref<InputEvent> p_event) { | 
					
						
							| 
									
										
										
										
											2020-06-15 00:32:50 +02:00
										 |  |  | 	Ref<InputEventKey> k = p_event; | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == Key::KEY_DELETE) { | 
					
						
							| 
									
										
										
										
											2020-06-15 00:32:50 +02:00
										 |  |  | 		TreeItem *current_effect = effects->get_selected(); | 
					
						
							|  |  |  | 		if (current_effect && current_effect->get_metadata(0).get_type() == Variant::INT) { | 
					
						
							|  |  |  | 			_delete_effect_pressed(0); | 
					
						
							|  |  |  | 			accept_event(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 21:42:28 +07:00
										 |  |  | void EditorAudioBus::_bus_popup_pressed(int p_option) { | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:31 -03:00
										 |  |  | 	if (p_option == 2) { | 
					
						
							|  |  |  | 		// Reset volume
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		emit_signal(SNAME("vol_reset_request")); | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:31 -03:00
										 |  |  | 	} else if (p_option == 1) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		emit_signal(SNAME("delete_request")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	} else if (p_option == 0) { | 
					
						
							|  |  |  | 		//duplicate
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		emit_signal(SNAME("duplicate_request"), get_index()); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Variant EditorAudioBus::get_drag_data(const Point2 &p_point) { | 
					
						
							|  |  |  | 	if (get_index() == 0) { | 
					
						
							|  |  |  | 		return Variant(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Control *c = memnew(Control); | 
					
						
							|  |  |  | 	Panel *p = memnew(Panel); | 
					
						
							|  |  |  | 	c->add_child(p); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	p->set_modulate(Color(1, 1, 1, 0.7)); | 
					
						
							| 
									
										
										
										
											2022-02-08 10:14:58 +01:00
										 |  |  | 	p->add_theme_style_override("panel", get_theme_stylebox(SNAME("focus"), SNAME("Button"))); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	p->set_size(get_size()); | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | 	p->set_position(-p_point); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	set_drag_preview(c); | 
					
						
							|  |  |  | 	Dictionary d; | 
					
						
							|  |  |  | 	d["type"] = "move_audio_bus"; | 
					
						
							|  |  |  | 	d["index"] = get_index(); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (get_index() < AudioServer::get_singleton()->get_bus_count() - 1) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		emit_signal(SNAME("drop_end_request")); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	return d; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool EditorAudioBus::can_drop_data(const Point2 &p_point, const Variant &p_data) const { | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	if (get_index() == 0) { | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	Dictionary d = p_data; | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	if (d.has("type") && String(d["type"]) == "move_audio_bus" && (int)d["index"] != get_index()) { | 
					
						
							|  |  |  | 		hovering_drop = true; | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | void EditorAudioBus::drop_data(const Point2 &p_point, const Variant &p_data) { | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 	Dictionary d = p_data; | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	emit_signal(SNAME("dropped"), d["index"], get_index()); | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from) { | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	TreeItem *item = effects->get_item_at_position(p_point); | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 	if (!item) { | 
					
						
							|  |  |  | 		return Variant(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Variant md = item->get_metadata(0); | 
					
						
							|  |  |  | 	if (md.get_type() == Variant::INT) { | 
					
						
							|  |  |  | 		Dictionary fxd; | 
					
						
							|  |  |  | 		fxd["type"] = "audio_bus_effect"; | 
					
						
							|  |  |  | 		fxd["bus"] = get_index(); | 
					
						
							|  |  |  | 		fxd["effect"] = md; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Label *l = memnew(Label); | 
					
						
							|  |  |  | 		l->set_text(item->get_text(0)); | 
					
						
							|  |  |  | 		effects->set_drag_preview(l); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return fxd; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Variant(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool EditorAudioBus::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!d.has("type") || String(d["type"]) != "audio_bus_effect") { | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	TreeItem *item = effects->get_item_at_position(p_point); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!item) { | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	TreeItem *item = effects->get_item_at_position(p_point); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!item) { | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	int pos = effects->get_drop_section_at_position(p_point); | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 	Variant md = item->get_metadata(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int paste_at; | 
					
						
							|  |  |  | 	int bus = d["bus"]; | 
					
						
							|  |  |  | 	int effect = d["effect"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (md.get_type() == Variant::INT) { | 
					
						
							|  |  |  | 		paste_at = md; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (pos > 0) { | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 			paste_at++; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (bus == get_index() && paste_at > effect) { | 
					
						
							|  |  |  | 			paste_at--; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		paste_at = -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool enabled = AudioServer::get_singleton()->is_bus_effect_enabled(bus, effect); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Move Bus Effect")); | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", bus, effect); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(bus, effect), paste_at); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (paste_at == -1) { | 
					
						
							|  |  |  | 		paste_at = AudioServer::get_singleton()->get_bus_effect_count(get_index()); | 
					
						
							|  |  |  | 		if (bus == get_index()) { | 
					
						
							|  |  |  | 			paste_at--; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!enabled) { | 
					
						
							|  |  |  | 		ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), paste_at, false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), paste_at); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", bus, AudioServer::get_singleton()->get_bus_effect(bus, effect), effect); | 
					
						
							|  |  |  | 	if (!enabled) { | 
					
						
							|  |  |  | 		ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", bus, effect, false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	if (get_index() != bus) { | 
					
						
							|  |  |  | 		ur->add_do_method(buses, "_update_bus", bus); | 
					
						
							|  |  |  | 		ur->add_undo_method(buses, "_update_bus", bus); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | void EditorAudioBus::_delete_effect_pressed(int p_option) { | 
					
						
							|  |  |  | 	TreeItem *item = effects->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!item) { | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (item->get_metadata(0).get_type() != Variant::INT) { | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int index = item->get_metadata(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Delete Bus Effect")); | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), index); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(get_index(), index), index); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, AudioServer::get_singleton()->is_bus_effect_enabled(get_index(), index)); | 
					
						
							|  |  |  | 	ur->add_do_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->add_undo_method(buses, "_update_bus", get_index()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 09:33:18 +02:00
										 |  |  | void EditorAudioBus::_effect_rmb(const Vector2 &p_pos, MouseButton p_button) { | 
					
						
							|  |  |  | 	if (p_button != MouseButton::RIGHT) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 	TreeItem *item = effects->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!item) { | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (item->get_metadata(0).get_type() != Variant::INT) { | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-31 17:43:35 +02:00
										 |  |  | 	delete_effect_popup->set_position(get_screen_position() + get_local_mouse_position()); | 
					
						
							|  |  |  | 	delete_effect_popup->reset_size(); | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 	delete_effect_popup->popup(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | void EditorAudioBus::_bind_methods() { | 
					
						
							|  |  |  | 	ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus); | 
					
						
							|  |  |  | 	ClassDB::bind_method("update_send", &EditorAudioBus::update_send); | 
					
						
							| 
									
										
										
										
											2021-08-22 12:37:22 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("duplicate_request")); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("delete_request")); | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:31 -03:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("vol_reset_request")); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("drop_end_request")); | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("dropped")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	buses = p_buses; | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | 	is_master = p_is_master; | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	set_tooltip_text(TTR("Drag & drop to rearrange.")); | 
					
						
							| 
									
										
										
										
											2017-08-10 18:07:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	VBoxContainer *vb = memnew(VBoxContainer); | 
					
						
							|  |  |  | 	add_child(vb); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	track_name = memnew(LineEdit); | 
					
						
							| 
									
										
										
										
											2021-06-16 09:43:34 -07:00
										 |  |  | 	track_name->connect("text_submitted", callable_mp(this, &EditorAudioBus::_name_changed)); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	track_name->connect("focus_exited", callable_mp(this, &EditorAudioBus::_name_focus_exit)); | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | 	vb->add_child(track_name); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	HBoxContainer *hbc = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	vb->add_child(hbc); | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	solo = memnew(Button); | 
					
						
							| 
									
										
										
										
											2023-09-19 18:03:10 +02:00
										 |  |  | 	solo->set_theme_type_variation("FlatButton"); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	solo->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	solo->set_tooltip_text(TTR("Solo")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	solo->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	solo->connect("pressed", callable_mp(this, &EditorAudioBus::_solo_toggled)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	hbc->add_child(solo); | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	mute = memnew(Button); | 
					
						
							| 
									
										
										
										
											2023-09-19 18:03:10 +02:00
										 |  |  | 	mute->set_theme_type_variation("FlatButton"); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	mute->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	mute->set_tooltip_text(TTR("Mute")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	mute->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	mute->connect("pressed", callable_mp(this, &EditorAudioBus::_mute_toggled)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	hbc->add_child(mute); | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	bypass = memnew(Button); | 
					
						
							| 
									
										
										
										
											2023-09-19 18:03:10 +02:00
										 |  |  | 	bypass->set_theme_type_variation("FlatButton"); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	bypass->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	bypass->set_tooltip_text(TTR("Bypass")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	bypass->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	bypass->connect("pressed", callable_mp(this, &EditorAudioBus::_bypass_toggled)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	hbc->add_child(bypass); | 
					
						
							|  |  |  | 	hbc->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | 	Ref<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty); | 
					
						
							|  |  |  | 	for (int i = 0; i < hbc->get_child_count(); i++) { | 
					
						
							|  |  |  | 		Control *child = Object::cast_to<Control>(hbc->get_child(i)); | 
					
						
							| 
									
										
										
										
											2023-10-19 18:05:19 +02:00
										 |  |  | 		child->begin_bulk_theme_override(); | 
					
						
							| 
									
										
										
										
											2022-02-08 10:14:58 +01:00
										 |  |  | 		child->add_theme_style_override("normal", sbempty); | 
					
						
							|  |  |  | 		child->add_theme_style_override("hover", sbempty); | 
					
						
							|  |  |  | 		child->add_theme_style_override("focus", sbempty); | 
					
						
							|  |  |  | 		child->add_theme_style_override("pressed", sbempty); | 
					
						
							| 
									
										
										
										
											2023-10-19 18:05:19 +02:00
										 |  |  | 		child->end_bulk_theme_override(); | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	HSeparator *separator = memnew(HSeparator); | 
					
						
							|  |  |  | 	separator->set_mouse_filter(MOUSE_FILTER_PASS); | 
					
						
							|  |  |  | 	vb->add_child(separator); | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	HBoxContainer *hb = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	vb->add_child(hb); | 
					
						
							|  |  |  | 	slider = memnew(VSlider); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 	slider->set_min(0.0); | 
					
						
							|  |  |  | 	slider->set_max(1.0); | 
					
						
							|  |  |  | 	slider->set_step(0.0001); | 
					
						
							|  |  |  | 	slider->set_clip_contents(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	audio_value_preview_box = memnew(Panel); | 
					
						
							| 
									
										
										
										
											2021-07-31 22:14:14 +03:00
										 |  |  | 	slider->add_child(audio_value_preview_box); | 
					
						
							|  |  |  | 	audio_value_preview_box->set_as_top_level(true); | 
					
						
							|  |  |  | 	audio_value_preview_box->set_mouse_filter(MOUSE_FILTER_PASS); | 
					
						
							|  |  |  | 	audio_value_preview_box->hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	HBoxContainer *audioprev_hbc = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	audioprev_hbc->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	audioprev_hbc->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	audio_value_preview_box->add_child(audioprev_hbc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	audio_value_preview_label = memnew(Label); | 
					
						
							|  |  |  | 	audio_value_preview_label->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	audio_value_preview_label->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	audio_value_preview_label->set_mouse_filter(MOUSE_FILTER_PASS); | 
					
						
							|  |  |  | 	audioprev_hbc->add_child(audio_value_preview_label); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 	preview_timer = memnew(Timer); | 
					
						
							|  |  |  | 	preview_timer->set_wait_time(0.8f); | 
					
						
							|  |  |  | 	preview_timer->set_one_shot(true); | 
					
						
							|  |  |  | 	add_child(preview_timer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	slider->connect("value_changed", callable_mp(this, &EditorAudioBus::_volume_changed)); | 
					
						
							|  |  |  | 	slider->connect("value_changed", callable_mp(this, &EditorAudioBus::_show_value)); | 
					
						
							|  |  |  | 	preview_timer->connect("timeout", callable_mp(this, &EditorAudioBus::_hide_value_preview)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	hb->add_child(slider); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 13:38:40 -03:00
										 |  |  | 	cc = 0; | 
					
						
							|  |  |  | 	for (int i = 0; i < CHANNELS_MAX; i++) { | 
					
						
							| 
									
										
										
										
											2020-12-14 21:10:09 +01:00
										 |  |  | 		channel[i].vu_l = memnew(TextureProgressBar); | 
					
						
							|  |  |  | 		channel[i].vu_l->set_fill_mode(TextureProgressBar::FILL_BOTTOM_TO_TOP); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 		hb->add_child(channel[i].vu_l); | 
					
						
							|  |  |  | 		channel[i].vu_l->set_min(-80); | 
					
						
							|  |  |  | 		channel[i].vu_l->set_max(24); | 
					
						
							|  |  |  | 		channel[i].vu_l->set_step(0.1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-14 21:10:09 +01:00
										 |  |  | 		channel[i].vu_r = memnew(TextureProgressBar); | 
					
						
							|  |  |  | 		channel[i].vu_r->set_fill_mode(TextureProgressBar::FILL_BOTTOM_TO_TOP); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 		hb->add_child(channel[i].vu_r); | 
					
						
							|  |  |  | 		channel[i].vu_r->set_min(-80); | 
					
						
							|  |  |  | 		channel[i].vu_r->set_max(24); | 
					
						
							|  |  |  | 		channel[i].vu_r->set_step(0.1); | 
					
						
							| 
									
										
										
										
											2018-02-28 21:55:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		channel[i].peak_l = 0.0f; | 
					
						
							|  |  |  | 		channel[i].peak_r = 0.0f; | 
					
						
							| 
									
										
										
										
											2017-08-22 18:27:17 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	EditorAudioMeterNotches *scale = memnew(EditorAudioMeterNotches); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (float db = 6.0f; db >= -80.0f; db -= 6.0f) { | 
					
						
							|  |  |  | 		bool renderNotch = (db >= -6.0f || db == -24.0f || db == -72.0f); | 
					
						
							|  |  |  | 		scale->add_notch(_scaled_db_to_normalized_volume(db), db, renderNotch); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	scale->set_mouse_filter(MOUSE_FILTER_PASS); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	hb->add_child(scale); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	effects = memnew(Tree); | 
					
						
							|  |  |  | 	effects->set_hide_root(true); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	effects->set_custom_minimum_size(Size2(0, 80) * EDSCALE); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	effects->set_hide_folding(true); | 
					
						
							| 
									
										
										
										
											2018-03-02 18:51:47 +07:00
										 |  |  | 	effects->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	vb->add_child(effects); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	effects->connect("item_edited", callable_mp(this, &EditorAudioBus::_effect_edited)); | 
					
						
							|  |  |  | 	effects->connect("cell_selected", callable_mp(this, &EditorAudioBus::_effect_selected)); | 
					
						
							| 
									
										
										
										
											2023-12-06 23:32:40 -05:00
										 |  |  | 	effects->connect("focus_exited", callable_mp(effects, &Tree::deselect_all)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	effects->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); | 
					
						
							| 
									
										
										
										
											2023-01-14 03:37:19 +01:00
										 |  |  | 	SET_DRAG_FORWARDING_GCD(effects, EditorAudioBus); | 
					
						
							| 
									
										
										
										
											2021-09-18 09:33:18 +02:00
										 |  |  | 	effects->connect("item_mouse_selected", callable_mp(this, &EditorAudioBus::_effect_rmb)); | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 	effects->set_allow_rmb_select(true); | 
					
						
							| 
									
										
										
										
											2017-08-10 18:07:24 -05:00
										 |  |  | 	effects->set_focus_mode(FOCUS_CLICK); | 
					
						
							| 
									
										
										
										
											2017-08-18 18:19:12 -03:00
										 |  |  | 	effects->set_allow_reselect(true); | 
					
						
							| 
									
										
										
										
											2020-09-17 11:37:12 +10:00
										 |  |  | 	effects->connect("gui_input", callable_mp(this, &EditorAudioBus::_effects_gui_input)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	send = memnew(OptionButton); | 
					
						
							|  |  |  | 	send->set_clip_text(true); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	send->connect("item_selected", callable_mp(this, &EditorAudioBus::_send_selected)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	vb->add_child(send); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	set_focus_mode(FOCUS_CLICK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	effect_options = memnew(PopupMenu); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	effect_options->connect("index_pressed", callable_mp(this, &EditorAudioBus::_effect_add)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	add_child(effect_options); | 
					
						
							| 
									
										
										
										
											2022-09-29 12:53:28 +03:00
										 |  |  | 	List<StringName> effect_list; | 
					
						
							|  |  |  | 	ClassDB::get_inheriters_from_class("AudioEffect", &effect_list); | 
					
						
							|  |  |  | 	effect_list.sort_custom<StringName::AlphCompare>(); | 
					
						
							|  |  |  | 	for (const StringName &E : effect_list) { | 
					
						
							| 
									
										
										
										
											2022-03-10 08:17:38 +01:00
										 |  |  | 		if (!ClassDB::can_instantiate(E) || ClassDB::is_virtual(E)) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 23:45:57 -04:00
										 |  |  | 		String name = E.operator String().replace("AudioEffect", ""); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		effect_options->add_item(name); | 
					
						
							| 
									
										
										
										
											2022-03-12 01:06:45 +01:00
										 |  |  | 		effect_options->set_item_metadata(-1, E); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 11:40:00 +10:00
										 |  |  | 	bus_options = memnew(MenuButton); | 
					
						
							|  |  |  | 	bus_options->set_shortcut_context(this); | 
					
						
							|  |  |  | 	bus_options->set_h_size_flags(SIZE_SHRINK_END); | 
					
						
							| 
									
										
										
										
											2020-12-22 16:24:29 +00:00
										 |  |  | 	bus_options->set_anchor(SIDE_RIGHT, 0.0); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	bus_options->set_tooltip_text(TTR("Bus Options")); | 
					
						
							| 
									
										
										
										
											2020-09-17 11:40:00 +10:00
										 |  |  | 	hbc->add_child(bus_options); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 21:42:28 +07:00
										 |  |  | 	bus_popup = bus_options->get_popup(); | 
					
						
							| 
									
										
										
										
											2022-09-02 12:37:48 +03:00
										 |  |  | 	bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/duplicate_selected_bus", TTR("Duplicate Bus"), KeyModifierMask::CMD_OR_CTRL | Key::D)); | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/delete_selected_bus", TTR("Delete Bus"), Key::KEY_DELETE)); | 
					
						
							| 
									
										
										
										
											2017-10-01 20:54:34 +07:00
										 |  |  | 	bus_popup->set_item_disabled(1, is_master); | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:31 -03:00
										 |  |  | 	bus_popup->add_item(TTR("Reset Volume")); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	bus_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_bus_popup_pressed)); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 	delete_effect_popup = memnew(PopupMenu); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	delete_effect_popup->add_item(TTR("Delete Effect")); | 
					
						
							| 
									
										
										
										
											2017-01-24 20:11:13 -03:00
										 |  |  | 	add_child(delete_effect_popup); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	delete_effect_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_delete_effect_pressed)); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | void EditorAudioBusDrop::_notification(int p_what) { | 
					
						
							|  |  |  | 	switch (p_what) { | 
					
						
							|  |  |  | 		case NOTIFICATION_DRAW: { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			draw_style_box(get_theme_stylebox(SNAME("normal"), SNAME("Button")), Rect2(Vector2(), get_size())); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (hovering_drop) { | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 				Color accent = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 				accent.a *= 0.7; | 
					
						
							|  |  |  | 				draw_rect(Rect2(Point2(), get_size()), accent, false); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_MOUSE_ENTER: { | 
					
						
							|  |  |  | 			if (!hovering_drop) { | 
					
						
							|  |  |  | 				hovering_drop = true; | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 				queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_MOUSE_EXIT: | 
					
						
							|  |  |  | 		case NOTIFICATION_DRAG_END: { | 
					
						
							|  |  |  | 			if (hovering_drop) { | 
					
						
							|  |  |  | 				hovering_drop = false; | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 				queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | bool EditorAudioBusDrop::can_drop_data(const Point2 &p_point, const Variant &p_data) const { | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							| 
									
										
										
										
											2019-06-26 15:08:25 +02:00
										 |  |  | 	return (d.has("type") && String(d["type"]) == "move_audio_bus"); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | void EditorAudioBusDrop::drop_data(const Point2 &p_point, const Variant &p_data) { | 
					
						
							| 
									
										
										
										
											2017-01-24 00:19:31 -03:00
										 |  |  | 	Dictionary d = p_data; | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	emit_signal(SNAME("dropped"), d["index"], AudioServer::get_singleton()->get_bus_count()); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBusDrop::_bind_methods() { | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("dropped")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EditorAudioBusDrop::EditorAudioBusDrop() { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | void EditorAudioBuses::_rebuild_buses() { | 
					
						
							| 
									
										
										
										
											2023-03-07 17:22:58 +01:00
										 |  |  | 	for (int i = bus_hb->get_child_count() - 1; i >= 0; i--) { | 
					
						
							|  |  |  | 		EditorAudioBus *audio_bus = Object::cast_to<EditorAudioBus>(bus_hb->get_child(i)); | 
					
						
							|  |  |  | 		if (audio_bus) { | 
					
						
							|  |  |  | 			bus_hb->remove_child(audio_bus); | 
					
						
							|  |  |  | 			audio_bus->queue_free(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (drop_end) { | 
					
						
							|  |  |  | 		bus_hb->remove_child(drop_end); | 
					
						
							|  |  |  | 		drop_end->queue_free(); | 
					
						
							|  |  |  | 		drop_end = nullptr; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { | 
					
						
							| 
									
										
										
										
											2019-06-26 15:08:25 +02:00
										 |  |  | 		bool is_master = (i == 0); | 
					
						
							| 
									
										
										
										
											2017-09-25 01:12:18 -05:00
										 |  |  | 		EditorAudioBus *audio_bus = memnew(EditorAudioBus(this, is_master)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		bus_hb->add_child(audio_bus); | 
					
						
							| 
									
										
										
										
											2022-07-28 22:56:41 +02:00
										 |  |  | 		audio_bus->connect("delete_request", callable_mp(this, &EditorAudioBuses::_delete_bus).bind(audio_bus), CONNECT_DEFERRED); | 
					
						
							|  |  |  | 		audio_bus->connect("duplicate_request", callable_mp(this, &EditorAudioBuses::_duplicate_bus), CONNECT_DEFERRED); | 
					
						
							|  |  |  | 		audio_bus->connect("vol_reset_request", callable_mp(this, &EditorAudioBuses::_reset_bus_volume).bind(audio_bus), CONNECT_DEFERRED); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 		audio_bus->connect("drop_end_request", callable_mp(this, &EditorAudioBuses::_request_drop_end)); | 
					
						
							| 
									
										
										
										
											2022-07-28 22:56:41 +02:00
										 |  |  | 		audio_bus->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), CONNECT_DEFERRED); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | EditorAudioBuses *EditorAudioBuses::register_editor() { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	EditorAudioBuses *audio_buses = memnew(EditorAudioBuses); | 
					
						
							| 
									
										
										
										
											2023-06-23 15:23:36 +02:00
										 |  |  | 	EditorNode::get_singleton()->add_bottom_panel_item(TTR("Audio"), audio_buses); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	return audio_buses; | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2022-08-29 11:04:31 +02:00
										 |  |  | 		case NOTIFICATION_ENTER_TREE: | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_THEME_CHANGED: { | 
					
						
							| 
									
										
										
										
											2022-09-06 20:09:32 +03:00
										 |  |  | 			bus_scroll->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree"))); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_READY: { | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | 			_rebuild_buses(); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_DRAG_END: { | 
					
						
							|  |  |  | 			if (drop_end) { | 
					
						
							| 
									
										
										
										
											2023-03-07 17:22:58 +01:00
										 |  |  | 				bus_hb->remove_child(drop_end); | 
					
						
							| 
									
										
										
										
											2022-10-24 22:07:02 +01:00
										 |  |  | 				drop_end->queue_free(); | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 				drop_end = nullptr; | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		case NOTIFICATION_PROCESS: { | 
					
						
							|  |  |  | 			// Check if anything was edited.
 | 
					
						
							|  |  |  | 			bool edited = AudioServer::get_singleton()->is_edited(); | 
					
						
							|  |  |  | 			for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { | 
					
						
							|  |  |  | 				for (int j = 0; j < AudioServer::get_singleton()->get_bus_effect_count(i); j++) { | 
					
						
							|  |  |  | 					Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(i, j); | 
					
						
							|  |  |  | 					if (effect->is_edited()) { | 
					
						
							|  |  |  | 						edited = true; | 
					
						
							|  |  |  | 						effect->set_edited(false); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			AudioServer::get_singleton()->set_edited(false); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			if (edited) { | 
					
						
							|  |  |  | 				save_timer->start(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_add_bus() { | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Add Audio Bus")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count() + 1); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count()); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_update_bus(int p_index) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (p_index >= bus_hb->get_child_count()) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bus_hb->get_child(p_index)->call("update_bus"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_update_sends() { | 
					
						
							|  |  |  | 	for (int i = 0; i < bus_hb->get_child_count(); i++) { | 
					
						
							|  |  |  | 		bus_hb->get_child(i)->call("update_send"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | void EditorAudioBuses::_delete_bus(Object *p_which) { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	int index = bus->get_index(); | 
					
						
							|  |  |  | 	if (index == 0) { | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 		EditorNode::get_singleton()->show_warning(TTR("Master bus can't be deleted!")); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Delete Audio Bus")); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "remove_bus", index); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "add_bus", index); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_name", index, AudioServer::get_singleton()->get_bus_name(index)); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", index, AudioServer::get_singleton()->get_bus_volume_db(index)); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", index, AudioServer::get_singleton()->get_bus_send(index)); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_solo", index, AudioServer::get_singleton()->is_bus_solo(index)); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", index, AudioServer::get_singleton()->is_bus_mute(index)); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", index, AudioServer::get_singleton()->is_bus_bypassing_effects(index)); | 
					
						
							|  |  |  | 	for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) { | 
					
						
							|  |  |  | 		ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", index, AudioServer::get_singleton()->get_bus_effect(index, i)); | 
					
						
							|  |  |  | 		ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", index, i, AudioServer::get_singleton()->is_bus_effect_enabled(index, i)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | void EditorAudioBuses::_duplicate_bus(int p_which) { | 
					
						
							|  |  |  | 	int add_at_pos = p_which + 1; | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Duplicate Audio Bus")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "add_bus", add_at_pos); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_name", add_at_pos, AudioServer::get_singleton()->get_bus_name(p_which) + " Copy"); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", add_at_pos, AudioServer::get_singleton()->get_bus_volume_db(p_which)); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", add_at_pos, AudioServer::get_singleton()->get_bus_send(p_which)); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_solo", add_at_pos, AudioServer::get_singleton()->is_bus_solo(p_which)); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", add_at_pos, AudioServer::get_singleton()->is_bus_mute(p_which)); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", add_at_pos, AudioServer::get_singleton()->is_bus_bypassing_effects(p_which)); | 
					
						
							|  |  |  | 	for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(p_which); i++) { | 
					
						
							|  |  |  | 		ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", add_at_pos, AudioServer::get_singleton()->get_bus_effect(p_which, i)); | 
					
						
							|  |  |  | 		ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", add_at_pos, i, AudioServer::get_singleton()->is_bus_effect_enabled(p_which, i)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "remove_bus", add_at_pos); | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:31 -03:00
										 |  |  | void EditorAudioBuses::_reset_bus_volume(Object *p_which) { | 
					
						
							|  |  |  | 	EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which); | 
					
						
							|  |  |  | 	int index = bus->get_index(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:31 -03:00
										 |  |  | 	ur->create_action(TTR("Reset Bus Volume")); | 
					
						
							|  |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", index, 0.f); | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", index, AudioServer::get_singleton()->get_bus_volume_db(index)); | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | 	ur->add_do_method(this, "_update_bus", index); | 
					
						
							|  |  |  | 	ur->add_undo_method(this, "_update_bus", index); | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:31 -03:00
										 |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | void EditorAudioBuses::_request_drop_end() { | 
					
						
							|  |  |  | 	if (!drop_end && bus_hb->get_child_count()) { | 
					
						
							|  |  |  | 		drop_end = memnew(EditorAudioBusDrop); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bus_hb->add_child(drop_end); | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 		drop_end->set_custom_minimum_size(Object::cast_to<Control>(bus_hb->get_child(0))->get_size()); | 
					
						
							| 
									
										
										
										
											2022-07-28 22:56:41 +02:00
										 |  |  | 		drop_end->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), CONNECT_DEFERRED); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) { | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 	ur->create_action(TTR("Move Audio Bus")); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 	ur->add_do_method(AudioServer::get_singleton(), "move_bus", p_bus, p_index); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	int real_bus = p_index > p_bus ? p_bus : p_bus + 1; | 
					
						
							|  |  |  | 	int real_index = p_index > p_bus ? p_index - 1 : p_index; | 
					
						
							|  |  |  | 	ur->add_undo_method(AudioServer::get_singleton(), "move_bus", real_index, real_bus); | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ur->commit_action(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | void EditorAudioBuses::_server_save() { | 
					
						
							|  |  |  | 	Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout(); | 
					
						
							| 
									
										
										
										
											2022-06-03 01:33:42 +02:00
										 |  |  | 	ResourceSaver::save(state, edited_path); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_select_layout() { | 
					
						
							| 
									
										
										
										
											2023-11-14 03:55:36 -08:00
										 |  |  | 	FileSystemDock::get_singleton()->navigate_to_path(edited_path); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_save_as_layout() { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); | 
					
						
							| 
									
										
										
										
											2018-04-22 19:36:01 +02:00
										 |  |  | 	file_dialog->set_title(TTR("Save Audio Bus Layout As...")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	file_dialog->set_current_path(edited_path); | 
					
						
							| 
									
										
										
										
											2020-07-11 18:45:19 +02:00
										 |  |  | 	file_dialog->popup_file_dialog(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	new_layout = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_new_layout() { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); | 
					
						
							| 
									
										
										
										
											2018-04-22 19:36:01 +02:00
										 |  |  | 	file_dialog->set_title(TTR("Location for New Layout...")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	file_dialog->set_current_path(edited_path); | 
					
						
							| 
									
										
										
										
											2020-07-11 18:45:19 +02:00
										 |  |  | 	file_dialog->popup_file_dialog(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	new_layout = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_load_layout() { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	file_dialog->set_title(TTR("Open Audio Bus Layout")); | 
					
						
							|  |  |  | 	file_dialog->set_current_path(edited_path); | 
					
						
							| 
									
										
										
										
											2020-07-11 18:45:19 +02:00
										 |  |  | 	file_dialog->popup_file_dialog(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	new_layout = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_load_default_layout() { | 
					
						
							| 
									
										
										
										
											2022-10-18 16:43:37 +02:00
										 |  |  | 	String layout_path = GLOBAL_GET("audio/buses/default_bus_layout"); | 
					
						
							| 
									
										
										
										
											2019-04-05 17:19:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 14:18:45 -03:00
										 |  |  | 	Ref<AudioBusLayout> state = ResourceLoader::load(layout_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	if (state.is_null()) { | 
					
						
							| 
									
										
										
										
											2019-04-05 17:19:25 +02:00
										 |  |  | 		EditorNode::get_singleton()->show_warning(vformat(TTR("There is no '%s' file."), layout_path)); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-05 17:19:25 +02:00
										 |  |  | 	edited_path = layout_path; | 
					
						
							| 
									
										
										
										
											2022-06-08 11:42:51 +02:00
										 |  |  | 	file->set_text(String(TTR("Layout:")) + " " + layout_path.get_file()); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	AudioServer::get_singleton()->set_bus_layout(state); | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | 	_rebuild_buses(); | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY); | 
					
						
							| 
									
										
										
										
											2023-12-18 15:46:56 +01:00
										 |  |  | 	callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioBuses::_file_dialog_callback(const String &p_string) { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_OPEN_FILE) { | 
					
						
							| 
									
										
										
										
											2021-02-11 14:18:45 -03:00
										 |  |  | 		Ref<AudioBusLayout> state = ResourceLoader::load(p_string, "", ResourceFormatLoader::CACHE_MODE_IGNORE); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 		if (state.is_null()) { | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 			EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout.")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		edited_path = p_string; | 
					
						
							| 
									
										
										
										
											2022-06-08 11:42:51 +02:00
										 |  |  | 		file->set_text(String(TTR("Layout:")) + " " + p_string.get_file()); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 		AudioServer::get_singleton()->set_bus_layout(state); | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | 		_rebuild_buses(); | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 		EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY); | 
					
						
							| 
									
										
										
										
											2023-12-18 15:46:56 +01:00
										 |  |  | 		callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	} else if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) { | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 		if (new_layout) { | 
					
						
							|  |  |  | 			Ref<AudioBusLayout> empty_state; | 
					
						
							| 
									
										
										
										
											2021-06-17 16:03:09 -06:00
										 |  |  | 			empty_state.instantiate(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 			AudioServer::get_singleton()->set_bus_layout(empty_state); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 01:33:42 +02:00
										 |  |  | 		Error err = ResourceSaver::save(AudioServer::get_singleton()->generate_bus_layout(), p_string); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (err != OK) { | 
					
						
							| 
									
										
										
										
											2020-01-04 13:33:52 +08:00
										 |  |  | 			EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file: %s"), p_string)); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		edited_path = p_string; | 
					
						
							| 
									
										
										
										
											2022-06-08 11:42:51 +02:00
										 |  |  | 		file->set_text(String(TTR("Layout:")) + " " + p_string.get_file()); | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | 		_rebuild_buses(); | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 		EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY); | 
					
						
							| 
									
										
										
										
											2023-12-18 15:46:56 +01:00
										 |  |  | 		callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-23 23:12:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | void EditorAudioBuses::_bind_methods() { | 
					
						
							|  |  |  | 	ClassDB::bind_method("_update_bus", &EditorAudioBuses::_update_bus); | 
					
						
							|  |  |  | 	ClassDB::bind_method("_update_sends", &EditorAudioBuses::_update_sends); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EditorAudioBuses::EditorAudioBuses() { | 
					
						
							|  |  |  | 	top_hb = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	add_child(top_hb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	file = memnew(Label); | 
					
						
							| 
									
										
										
										
											2022-10-18 16:43:37 +02:00
										 |  |  | 	String layout_path = GLOBAL_GET("audio/buses/default_bus_layout"); | 
					
						
							| 
									
										
										
										
											2022-06-08 11:42:51 +02:00
										 |  |  | 	file->set_text(String(TTR("Layout:")) + " " + layout_path.get_file()); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	file->set_clip_text(true); | 
					
						
							|  |  |  | 	file->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-08-07 21:55:24 -05:00
										 |  |  | 	top_hb->add_child(file); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	add = memnew(Button); | 
					
						
							|  |  |  | 	top_hb->add_child(add); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	add->set_text(TTR("Add Bus")); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	add->set_tooltip_text(TTR("Add a new Audio Bus to this layout.")); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	add->connect("pressed", callable_mp(this, &EditorAudioBuses::_add_bus)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	VSeparator *separator = memnew(VSeparator); | 
					
						
							|  |  |  | 	top_hb->add_child(separator); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	load = memnew(Button); | 
					
						
							|  |  |  | 	load->set_text(TTR("Load")); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	load->set_tooltip_text(TTR("Load an existing Bus Layout.")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	top_hb->add_child(load); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	load->connect("pressed", callable_mp(this, &EditorAudioBuses::_load_layout)); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	save_as = memnew(Button); | 
					
						
							|  |  |  | 	save_as->set_text(TTR("Save As")); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	save_as->set_tooltip_text(TTR("Save this Bus Layout to a file.")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	top_hb->add_child(save_as); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	save_as->connect("pressed", callable_mp(this, &EditorAudioBuses::_save_as_layout)); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_default = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-08-10 18:07:24 -05:00
										 |  |  | 	_default->set_text(TTR("Load Default")); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	_default->set_tooltip_text(TTR("Load the default Bus Layout.")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	top_hb->add_child(_default); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	_default->connect("pressed", callable_mp(this, &EditorAudioBuses::_load_default_layout)); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_new = memnew(Button); | 
					
						
							|  |  |  | 	_new->set_text(TTR("Create")); | 
					
						
							| 
									
										
										
										
											2022-08-25 12:42:17 +02:00
										 |  |  | 	_new->set_tooltip_text(TTR("Create a new Bus Layout.")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	top_hb->add_child(_new); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	_new->connect("pressed", callable_mp(this, &EditorAudioBuses::_new_layout)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bus_scroll = memnew(ScrollContainer); | 
					
						
							|  |  |  | 	bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2021-12-07 17:15:18 +01:00
										 |  |  | 	bus_scroll->set_vertical_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	add_child(bus_scroll); | 
					
						
							|  |  |  | 	bus_hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2018-03-02 18:51:47 +07:00
										 |  |  | 	bus_hb->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 	bus_scroll->add_child(bus_hb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	save_timer = memnew(Timer); | 
					
						
							|  |  |  | 	save_timer->set_wait_time(0.8); | 
					
						
							|  |  |  | 	save_timer->set_one_shot(true); | 
					
						
							|  |  |  | 	add_child(save_timer); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	save_timer->connect("timeout", callable_mp(this, &EditorAudioBuses::_server_save)); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-18 16:43:37 +02:00
										 |  |  | 	edited_path = GLOBAL_GET("audio/buses/default_bus_layout"); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	file_dialog = memnew(EditorFileDialog); | 
					
						
							|  |  |  | 	List<String> ext; | 
					
						
							| 
									
										
										
										
											2017-05-20 22:49:34 +02:00
										 |  |  | 	ResourceLoader::get_recognized_extensions_for_type("AudioBusLayout", &ext); | 
					
						
							| 
									
										
										
										
											2021-07-24 15:46:25 +02:00
										 |  |  | 	for (const String &E : ext) { | 
					
						
							| 
									
										
										
										
											2022-07-04 16:26:26 -05:00
										 |  |  | 		file_dialog->add_filter("*." + E, TTR("Audio Bus Layout")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	add_child(file_dialog); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	file_dialog->connect("file_selected", callable_mp(this, &EditorAudioBuses::_file_dialog_callback)); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | 	AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &EditorAudioBuses::_rebuild_buses)); | 
					
						
							| 
									
										
										
										
											2022-10-31 15:53:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	set_process(true); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | void EditorAudioBuses::open_layout(const String &p_path) { | 
					
						
							|  |  |  | 	EditorNode::get_singleton()->make_bottom_panel_item_visible(this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 14:18:45 -03:00
										 |  |  | 	Ref<AudioBusLayout> state = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 	if (state.is_null()) { | 
					
						
							| 
									
										
										
										
											2017-08-23 22:25:14 +02:00
										 |  |  | 		EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout.")); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	edited_path = p_path; | 
					
						
							|  |  |  | 	file->set_text(p_path.get_file()); | 
					
						
							|  |  |  | 	AudioServer::get_singleton()->set_bus_layout(state); | 
					
						
							| 
									
										
										
										
											2023-09-14 13:39:23 +03:00
										 |  |  | 	_rebuild_buses(); | 
					
						
							| 
									
										
										
										
											2022-12-23 23:53:16 +01:00
										 |  |  | 	EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY); | 
					
						
							| 
									
										
										
										
											2023-12-18 15:46:56 +01:00
										 |  |  | 	callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioBusesEditorPlugin::edit(Object *p_node) { | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	if (Object::cast_to<AudioBusLayout>(p_node)) { | 
					
						
							|  |  |  | 		String path = Object::cast_to<AudioBusLayout>(p_node)->get_path(); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | 		if (path.is_resource_file()) { | 
					
						
							|  |  |  | 			audio_bus_editor->open_layout(path); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AudioBusesEditorPlugin::handles(Object *p_node) const { | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	return (Object::cast_to<AudioBusLayout>(p_node) != nullptr); | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioBusesEditorPlugin::make_visible(bool p_visible) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) { | 
					
						
							|  |  |  | 	audio_bus_editor = p_node; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 14:30:40 -03:00
										 |  |  | AudioBusesEditorPlugin::~AudioBusesEditorPlugin() { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:00:25 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | void EditorAudioMeterNotches::add_notch(float p_normalized_offset, float p_db_value, bool p_render_value) { | 
					
						
							|  |  |  | 	notches.push_back(AudioNotch(p_normalized_offset, p_db_value, p_render_value)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Size2 EditorAudioMeterNotches::get_minimum_size() const { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	float font_height = font->get_height(font_size); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	float width = 0; | 
					
						
							|  |  |  | 	float height = top_padding + btm_padding; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-22 18:45:08 +02:00
										 |  |  | 	for (int i = 0; i < notches.size(); i++) { | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		if (notches[i].render_db_value) { | 
					
						
							| 
									
										
										
										
											2022-05-09 12:47:10 +03:00
										 |  |  | 			width = MAX(width, font->get_string_size(String::num(Math::abs(notches[i].db_value)) + "dB", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x); | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 			height += font_height; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	width += line_length + label_space; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Size2(width, height); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-03 18:01:11 +02:00
										 |  |  | void EditorAudioMeterNotches::_update_theme_item_cache() { | 
					
						
							|  |  |  | 	Control::_update_theme_item_cache(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 	theme_cache.notch_color = get_theme_color(SNAME("font_color"), EditorStringName(Editor)); | 
					
						
							| 
									
										
										
										
											2023-04-03 18:01:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	theme_cache.font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	theme_cache.font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | void EditorAudioMeterNotches::_bind_methods() { | 
					
						
							|  |  |  | 	ClassDB::bind_method("add_notch", &EditorAudioMeterNotches::add_notch); | 
					
						
							|  |  |  | 	ClassDB::bind_method("_draw_audio_notches", &EditorAudioMeterNotches::_draw_audio_notches); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioMeterNotches::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 	switch (p_what) { | 
					
						
							|  |  |  | 		case NOTIFICATION_DRAW: { | 
					
						
							|  |  |  | 			_draw_audio_notches(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorAudioMeterNotches::_draw_audio_notches() { | 
					
						
							| 
									
										
										
										
											2023-04-03 18:01:11 +02:00
										 |  |  | 	float font_height = theme_cache.font->get_height(theme_cache.font_size); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-22 18:45:08 +02:00
										 |  |  | 	for (int i = 0; i < notches.size(); i++) { | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 		AudioNotch n = notches[i]; | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 		draw_line(Vector2(0, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding), | 
					
						
							| 
									
										
										
										
											2021-05-27 09:58:44 +02:00
										 |  |  | 				Vector2(line_length * EDSCALE, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding), | 
					
						
							| 
									
										
										
										
											2023-04-03 18:01:11 +02:00
										 |  |  | 				theme_cache.notch_color, | 
					
						
							| 
									
										
										
										
											2021-05-27 09:58:44 +02:00
										 |  |  | 				Math::round(EDSCALE)); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (n.render_db_value) { | 
					
						
							| 
									
										
										
										
											2023-04-03 18:01:11 +02:00
										 |  |  | 			draw_string(theme_cache.font, | 
					
						
							| 
									
										
										
										
											2021-05-27 09:58:44 +02:00
										 |  |  | 					Vector2((line_length + label_space) * EDSCALE, | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 							(1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding), | 
					
						
							| 
									
										
										
										
											2019-06-08 02:26:39 -03:00
										 |  |  | 					String::num(Math::abs(n.db_value)) + "dB", | 
					
						
							| 
									
										
										
										
											2023-04-03 18:01:11 +02:00
										 |  |  | 					HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size, | 
					
						
							|  |  |  | 					theme_cache.notch_color); | 
					
						
							| 
									
										
										
										
											2019-02-10 21:50:55 -08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |