2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_audio_buses.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-03-05 14:47:28 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2017-01-21 22:00:25 +00:00
|
|
|
#include "editor_audio_buses.h"
|
2017-03-05 14:47:28 +00:00
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
#include "editor_node.h"
|
2017-01-25 17:30:40 +00:00
|
|
|
#include "filesystem_dock.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "io/resource_saver.h"
|
|
|
|
#include "os/keyboard.h"
|
|
|
|
#include "servers/audio_server.h"
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
void EditorAudioBus::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_READY) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
for (int i = 0; i < cc; i++) {
|
|
|
|
channel[i].vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
|
|
|
|
channel[i].vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
|
|
|
|
channel[i].vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
|
|
|
|
channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
|
|
|
|
channel[i].prev_active = true;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
scale->set_texture(get_icon("BusVuDb", "EditorIcons"));
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-07-12 18:38:47 +00:00
|
|
|
solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
|
|
|
|
mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
|
|
|
|
bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
|
|
|
|
|
2017-08-10 23:07:24 +00:00
|
|
|
bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
|
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
update_bus();
|
|
|
|
set_process(true);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (has_focus()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
draw_style_box(get_stylebox("focus", "Button"), Rect2(Vector2(), get_size()));
|
2017-09-25 06:12:18 +00:00
|
|
|
} else if (is_master) {
|
|
|
|
draw_style_box(get_stylebox("disabled", "Button"), Rect2(Vector2(), get_size()));
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_PROCESS) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < cc; i++) {
|
2017-08-22 21:27:17 +00:00
|
|
|
float real_peak[2] = { -100, -100 };
|
|
|
|
bool activity_found = false;
|
|
|
|
|
2017-03-05 15:44:50 +00: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));
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
if (real_peak[0] > channel[i].peak_l) {
|
|
|
|
channel[i].peak_l = real_peak[0];
|
|
|
|
} else {
|
|
|
|
channel[i].peak_l -= get_process_delta_time() * 60.0;
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
if (real_peak[1] > channel[i].peak_r) {
|
|
|
|
channel[i].peak_r = real_peak[1];
|
2017-01-21 22:00:25 +00:00
|
|
|
} else {
|
2017-08-22 21:27:17 +00:00
|
|
|
channel[i].peak_r -= get_process_delta_time() * 60.0;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
channel[i].vu_l->set_value(channel[i].peak_l);
|
|
|
|
channel[i].vu_r->set_value(channel[i].peak_r);
|
|
|
|
|
|
|
|
if (activity_found != channel[i].prev_active) {
|
|
|
|
if (activity_found) {
|
|
|
|
channel[i].vu_l->set_over_texture(Ref<Texture>());
|
|
|
|
channel[i].vu_r->set_over_texture(Ref<Texture>());
|
|
|
|
} else {
|
|
|
|
channel[i].vu_l->set_over_texture(disabled_vu);
|
|
|
|
channel[i].vu_r->set_over_texture(disabled_vu);
|
|
|
|
}
|
|
|
|
|
|
|
|
channel[i].prev_active = activity_found;
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-22 21:27:17 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
channel[i].peak_l = -100;
|
|
|
|
channel[i].peak_r = -100;
|
|
|
|
channel[i].prev_active = true;
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
set_process(is_visible_in_tree());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBus::update_send() {
|
|
|
|
|
|
|
|
send->clear();
|
2017-09-25 06:12:18 +00:00
|
|
|
if (is_master) {
|
2017-01-21 22:00:25 +00:00
|
|
|
send->set_disabled(true);
|
2017-08-23 20:25:14 +00:00
|
|
|
send->set_text(TTR("Speakers"));
|
2017-01-21 22:00:25 +00:00
|
|
|
} else {
|
|
|
|
send->set_disabled(false);
|
|
|
|
StringName current_send = AudioServer::get_singleton()->get_bus_send(get_index());
|
2017-03-05 15:44:50 +00:00
|
|
|
int current_send_index = 0; //by default to master
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < get_index(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
StringName send_name = AudioServer::get_singleton()->get_bus_name(i);
|
|
|
|
send->add_item(send_name);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (send_name == current_send) {
|
|
|
|
current_send_index = i;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send->select(current_send_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBus::update_bus() {
|
|
|
|
|
|
|
|
if (updating_bus)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
int index = get_index();
|
|
|
|
|
|
|
|
slider->set_value(AudioServer::get_singleton()->get_bus_volume_db(index));
|
|
|
|
track_name->set_text(AudioServer::get_singleton()->get_bus_name(index));
|
2017-09-25 06:12:18 +00:00
|
|
|
if (is_master)
|
2017-01-21 22:00:25 +00:00
|
|
|
track_name->set_editable(false);
|
|
|
|
|
2017-03-05 15:44:50 +00: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));
|
2017-01-21 22:00:25 +00:00
|
|
|
// effects..
|
|
|
|
effects->clear();
|
|
|
|
|
|
|
|
TreeItem *root = effects->create_item();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<AudioEffect> afx = AudioServer::get_singleton()->get_bus_effect(index, i);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
TreeItem *fx = effects->create_item(root);
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *add = effects->create_item(root);
|
2017-03-05 15:44:50 +00:00
|
|
|
add->set_cell_mode(0, TreeItem::CELL_MODE_CUSTOM);
|
|
|
|
add->set_editable(0, true);
|
|
|
|
add->set_selectable(0, false);
|
2017-08-23 20:25:14 +00:00
|
|
|
add->set_text(0, TTR("Add Effect"));
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
update_send();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::_name_changed(const String &p_new_name) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index()))
|
2017-01-21 22:00:25 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String attempt = p_new_name;
|
|
|
|
int attempts = 1;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool name_free = true;
|
|
|
|
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (AudioServer::get_singleton()->get_bus_name(i) == attempt) {
|
|
|
|
name_free = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name_free) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
attempts++;
|
2017-03-05 15:44:50 +00:00
|
|
|
attempt = p_new_name + " " + itos(attempts);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
|
|
|
|
StringName current = AudioServer::get_singleton()->get_bus_name(get_index());
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Rename Audio Bus"));
|
2017-03-05 15:44:50 +00: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);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_do_method(buses, "_update_bus", get_index());
|
|
|
|
ur->add_undo_method(buses, "_update_bus", get_index());
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_do_method(buses, "_update_sends");
|
|
|
|
ur->add_undo_method(buses, "_update_sends");
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-09-25 06:12:18 +00:00
|
|
|
|
|
|
|
track_name->release_focus();
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::_volume_db_changed(float p_db) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
if (updating_bus)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-24 03:19:31 +00:00
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-12-02 09:58:58 +00:00
|
|
|
ur->create_action(TTR("Change Audio Bus Volume"), UndoRedo::MERGE_ENDS);
|
2017-03-05 15:44:50 +00: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());
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::_solo_toggled() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Toggle Audio Bus Solo"));
|
2017-03-05 15:44:50 +00: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());
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::_mute_toggled() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Toggle Audio Bus Mute"));
|
2017-03-05 15:44:50 +00: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());
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::_bypass_toggled() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Toggle Audio Bus Bypass Effects"));
|
2017-03-05 15:44:50 +00: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());
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBus::_send_selected(int p_which) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
ur->create_action("Select Audio Bus Send");
|
2017-03-05 15:44:50 +00: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());
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBus::_effect_selected() {
|
|
|
|
|
|
|
|
TreeItem *effect = effects->get_selected();
|
|
|
|
if (!effect)
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (effect->get_metadata(0) != Variant()) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
int index = effect->get_metadata(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(get_index(), index);
|
2017-01-21 22:00:25 +00:00
|
|
|
if (effect.is_valid()) {
|
|
|
|
EditorNode::get_singleton()->push_item(effect.ptr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBus::_effect_edited() {
|
|
|
|
|
|
|
|
if (updating_bus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TreeItem *effect = effects->get_edited();
|
|
|
|
if (!effect)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (effect->get_metadata(0) == Variant()) {
|
2017-01-21 22:00:25 +00:00
|
|
|
Rect2 area = effects->get_item_rect(effect);
|
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
effect_options->set_position(effects->get_global_position() + area.position + Vector2(0, area.size.y));
|
2017-01-21 22:00:25 +00:00
|
|
|
effect_options->popup();
|
|
|
|
//add effect
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
2017-01-21 22:00:25 +00:00
|
|
|
int index = effect->get_metadata(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = true;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Select Audio Bus Send"));
|
2017-03-05 15:44:50 +00: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());
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_bus = false;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBus::_effect_add(int p_which) {
|
|
|
|
|
|
|
|
if (updating_bus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
StringName name = effect_options->get_item_metadata(p_which);
|
|
|
|
|
|
|
|
Object *fx = ClassDB::instance(name);
|
|
|
|
ERR_FAIL_COND(!fx);
|
2017-08-24 20:58:51 +00:00
|
|
|
AudioEffect *afx = Object::cast_to<AudioEffect>(fx);
|
2017-01-21 22:00:25 +00:00
|
|
|
ERR_FAIL_COND(!afx);
|
|
|
|
Ref<AudioEffect> afxr = Ref<AudioEffect>(afx);
|
|
|
|
|
|
|
|
afxr->set_name(effect_options->get_item_text(p_which));
|
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Add Audio Bus Effect"));
|
2017-03-05 15:44:50 +00: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());
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> k = p_event;
|
|
|
|
if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && !k->is_echo()) {
|
2017-01-24 02:12:08 +00:00
|
|
|
accept_event();
|
|
|
|
emit_signal("delete_request");
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> mb = p_event;
|
|
|
|
if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
|
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y);
|
2017-08-26 14:42:28 +00:00
|
|
|
bus_popup->set_position(get_global_position() + pos);
|
|
|
|
bus_popup->popup();
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-26 14:42:28 +00:00
|
|
|
void EditorAudioBus::_bus_popup_pressed(int p_option) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-09-07 00:11:31 +00:00
|
|
|
if (p_option == 2) {
|
|
|
|
// Reset volume
|
|
|
|
emit_signal("vol_reset_request");
|
|
|
|
} else if (p_option == 1) {
|
2017-01-24 02:12:08 +00:00
|
|
|
emit_signal("delete_request");
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_option == 0) {
|
2017-01-25 17:30:40 +00:00
|
|
|
//duplicate
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("duplicate_request", get_index());
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (get_index() == 0) {
|
2017-01-24 02:12:08 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
Control *c = memnew(Control);
|
2017-03-05 15:44:50 +00:00
|
|
|
Panel *p = memnew(Panel);
|
2017-01-24 02:12:08 +00:00
|
|
|
c->add_child(p);
|
2017-03-05 15:44:50 +00:00
|
|
|
p->add_style_override("panel", get_stylebox("focus", "Button"));
|
2017-01-24 02:12:08 +00:00
|
|
|
p->set_size(get_size());
|
2017-03-29 15:29:38 +00:00
|
|
|
p->set_position(-p_point);
|
2017-01-24 02:12:08 +00:00
|
|
|
set_drag_preview(c);
|
|
|
|
Dictionary d;
|
2017-03-05 15:44:50 +00:00
|
|
|
d["type"] = "move_audio_bus";
|
|
|
|
d["index"] = get_index();
|
2017-01-24 02:12:08 +00:00
|
|
|
emit_signal("drop_end_request");
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorAudioBus::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (get_index() == 0)
|
2017-01-24 02:12:08 +00:00
|
|
|
return false;
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = p_data;
|
|
|
|
if (d.has("type") && String(d["type"]) == "move_audio_bus") {
|
2017-01-24 02:12:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::drop_data(const Point2 &p_point, const Variant &p_data) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = p_data;
|
|
|
|
emit_signal("dropped", d["index"], get_index());
|
2017-01-24 03:19:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
|
2017-01-24 03:19:31 +00:00
|
|
|
|
|
|
|
print_line("drag fw");
|
2017-09-10 13:37:49 +00:00
|
|
|
TreeItem *item = effects->get_item_at_position(p_point);
|
2017-01-24 03:19:31 +00:00
|
|
|
if (!item) {
|
|
|
|
print_line("no item");
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant md = item->get_metadata(0);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (md.get_type() == Variant::INT) {
|
2017-01-24 03:19:31 +00:00
|
|
|
Dictionary fxd;
|
2017-03-05 15:44:50 +00:00
|
|
|
fxd["type"] = "audio_bus_effect";
|
|
|
|
fxd["bus"] = get_index();
|
|
|
|
fxd["effect"] = md;
|
2017-01-24 03:19:31 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Label *l = memnew(Label);
|
2017-01-24 03:19:31 +00:00
|
|
|
l->set_text(item->get_text(0));
|
|
|
|
effects->set_drag_preview(l);
|
|
|
|
|
|
|
|
return fxd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorAudioBus::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
|
2017-01-24 03:19:31 +00:00
|
|
|
|
|
|
|
Dictionary d = p_data;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!d.has("type") || String(d["type"]) != "audio_bus_effect")
|
2017-01-24 03:19:31 +00:00
|
|
|
return false;
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
TreeItem *item = effects->get_item_at_position(p_point);
|
2017-01-24 03:19:31 +00:00
|
|
|
if (!item)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
|
2017-01-24 03:19:31 +00:00
|
|
|
|
|
|
|
Dictionary d = p_data;
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
TreeItem *item = effects->get_item_at_position(p_point);
|
2017-01-24 03:19:31 +00:00
|
|
|
if (!item)
|
|
|
|
return;
|
2017-09-10 13:37:49 +00:00
|
|
|
int pos = effects->get_drop_section_at_position(p_point);
|
2017-01-24 03:19:31 +00:00
|
|
|
Variant md = item->get_metadata(0);
|
|
|
|
|
|
|
|
int paste_at;
|
|
|
|
int bus = d["bus"];
|
|
|
|
int effect = d["effect"];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (md.get_type() == Variant::INT) {
|
|
|
|
paste_at = md;
|
|
|
|
if (pos > 0)
|
2017-01-24 03:19:31 +00:00
|
|
|
paste_at++;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (bus == get_index() && paste_at > effect) {
|
2017-01-24 03:19:31 +00:00
|
|
|
paste_at--;
|
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
paste_at = -1;
|
2017-01-24 03:19:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool enabled = AudioServer::get_singleton()->is_bus_effect_enabled(bus, effect);
|
2017-01-24 03:19:31 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Move Bus Effect"));
|
2017-03-05 15:44:50 +00: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);
|
2017-01-24 03:19:31 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (paste_at == -1) {
|
2017-01-24 03:19:31 +00:00
|
|
|
paste_at = AudioServer::get_singleton()->get_bus_effect_count(get_index());
|
2017-03-05 15:44:50 +00:00
|
|
|
if (bus == get_index()) {
|
2017-01-24 03:19:31 +00:00
|
|
|
paste_at--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!enabled) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), paste_at, false);
|
2017-01-24 03:19:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2017-01-24 03:19:31 +00:00
|
|
|
if (!enabled) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", bus, effect, false);
|
2017-01-24 03:19:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2017-01-24 03:19:31 +00:00
|
|
|
}
|
|
|
|
ur->commit_action();
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 23:11:13 +00:00
|
|
|
void EditorAudioBus::_delete_effect_pressed(int p_option) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *item = effects->get_selected();
|
2017-01-24 23:11:13 +00:00
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (item->get_metadata(0).get_type() != Variant::INT)
|
2017-01-24 23:11:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int index = item->get_metadata(0);
|
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Delete Bus Effect"));
|
2017-03-05 15:44:50 +00: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());
|
2017-01-24 23:11:13 +00:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBus::_effect_rmb(const Vector2 &p_pos) {
|
2017-01-24 23:11:13 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *item = effects->get_selected();
|
2017-01-24 23:11:13 +00:00
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (item->get_metadata(0).get_type() != Variant::INT)
|
2017-01-24 23:11:13 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
delete_effect_popup->set_position(get_global_mouse_position());
|
2017-01-24 23:11:13 +00:00
|
|
|
delete_effect_popup->popup();
|
|
|
|
}
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
void EditorAudioBus::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus);
|
|
|
|
ClassDB::bind_method("update_send", &EditorAudioBus::update_send);
|
|
|
|
ClassDB::bind_method("_name_changed", &EditorAudioBus::_name_changed);
|
|
|
|
ClassDB::bind_method("_volume_db_changed", &EditorAudioBus::_volume_db_changed);
|
|
|
|
ClassDB::bind_method("_solo_toggled", &EditorAudioBus::_solo_toggled);
|
|
|
|
ClassDB::bind_method("_mute_toggled", &EditorAudioBus::_mute_toggled);
|
|
|
|
ClassDB::bind_method("_bypass_toggled", &EditorAudioBus::_bypass_toggled);
|
|
|
|
ClassDB::bind_method("_name_focus_exit", &EditorAudioBus::_name_focus_exit);
|
|
|
|
ClassDB::bind_method("_send_selected", &EditorAudioBus::_send_selected);
|
|
|
|
ClassDB::bind_method("_effect_edited", &EditorAudioBus::_effect_edited);
|
|
|
|
ClassDB::bind_method("_effect_selected", &EditorAudioBus::_effect_selected);
|
|
|
|
ClassDB::bind_method("_effect_add", &EditorAudioBus::_effect_add);
|
|
|
|
ClassDB::bind_method("_gui_input", &EditorAudioBus::_gui_input);
|
2017-08-26 14:42:28 +00:00
|
|
|
ClassDB::bind_method("_bus_popup_pressed", &EditorAudioBus::_bus_popup_pressed);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("get_drag_data_fw", &EditorAudioBus::get_drag_data_fw);
|
|
|
|
ClassDB::bind_method("can_drop_data_fw", &EditorAudioBus::can_drop_data_fw);
|
|
|
|
ClassDB::bind_method("drop_data_fw", &EditorAudioBus::drop_data_fw);
|
|
|
|
ClassDB::bind_method("_delete_effect_pressed", &EditorAudioBus::_delete_effect_pressed);
|
|
|
|
ClassDB::bind_method("_effect_rmb", &EditorAudioBus::_effect_rmb);
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("duplicate_request"));
|
2017-01-24 02:12:08 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("delete_request"));
|
2017-09-07 00:11:31 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("vol_reset_request"));
|
2017-01-24 02:12:08 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("drop_end_request"));
|
|
|
|
ADD_SIGNAL(MethodInfo("dropped"));
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 06:12:18 +00:00
|
|
|
EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
buses = p_buses;
|
|
|
|
updating_bus = false;
|
2017-09-25 06:12:18 +00:00
|
|
|
is_master = p_is_master;
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-08-10 23:07:24 +00:00
|
|
|
set_tooltip(TTR("Audio Bus, Drag and Drop to rearrange."));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *vb = memnew(VBoxContainer);
|
2017-01-21 22:00:25 +00:00
|
|
|
add_child(vb);
|
|
|
|
|
|
|
|
set_v_size_flags(SIZE_EXPAND_FILL);
|
2017-09-25 06:12:18 +00:00
|
|
|
set_custom_minimum_size(Size2(100, 0) * EDSCALE);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
track_name = memnew(LineEdit);
|
|
|
|
track_name->connect("text_entered", this, "_name_changed");
|
|
|
|
track_name->connect("focus_exited", this, "_name_focus_exit");
|
2017-09-25 06:12:18 +00:00
|
|
|
vb->add_child(track_name);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2017-01-21 22:00:25 +00:00
|
|
|
vb->add_child(hbc);
|
2017-03-05 15:44:50 +00:00
|
|
|
solo = memnew(ToolButton);
|
2017-01-21 22:00:25 +00:00
|
|
|
solo->set_toggle_mode(true);
|
2017-07-12 18:38:47 +00:00
|
|
|
solo->set_tooltip(TTR("Solo"));
|
2017-01-21 22:00:25 +00:00
|
|
|
solo->set_focus_mode(FOCUS_NONE);
|
2017-03-05 15:44:50 +00:00
|
|
|
solo->connect("pressed", this, "_solo_toggled");
|
2017-01-21 22:00:25 +00:00
|
|
|
hbc->add_child(solo);
|
2017-03-05 15:44:50 +00:00
|
|
|
mute = memnew(ToolButton);
|
2017-01-21 22:00:25 +00:00
|
|
|
mute->set_toggle_mode(true);
|
2017-07-12 18:38:47 +00:00
|
|
|
mute->set_tooltip(TTR("Mute"));
|
2017-01-21 22:00:25 +00:00
|
|
|
mute->set_focus_mode(FOCUS_NONE);
|
2017-05-02 21:02:06 +00:00
|
|
|
mute->connect("pressed", this, "_mute_toggled");
|
2017-01-21 22:00:25 +00:00
|
|
|
hbc->add_child(mute);
|
2017-03-05 15:44:50 +00:00
|
|
|
bypass = memnew(ToolButton);
|
2017-01-21 22:00:25 +00:00
|
|
|
bypass->set_toggle_mode(true);
|
2017-07-12 18:38:47 +00:00
|
|
|
bypass->set_tooltip(TTR("Bypass"));
|
2017-01-21 22:00:25 +00:00
|
|
|
bypass->set_focus_mode(FOCUS_NONE);
|
2017-03-05 15:44:50 +00:00
|
|
|
bypass->connect("pressed", this, "_bypass_toggled");
|
2017-01-21 22:00:25 +00:00
|
|
|
hbc->add_child(bypass);
|
|
|
|
hbc->add_spacer();
|
|
|
|
|
2017-09-25 06:12:18 +00:00
|
|
|
bus_options = memnew(MenuButton);
|
|
|
|
bus_options->set_h_size_flags(SIZE_SHRINK_END);
|
|
|
|
bus_options->set_anchor(MARGIN_RIGHT, 0.0);
|
|
|
|
bus_options->set_tooltip(TTR("Bus options"));
|
|
|
|
hbc->add_child(bus_options);
|
|
|
|
|
|
|
|
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));
|
|
|
|
child->add_style_override("normal", sbempty);
|
|
|
|
child->add_style_override("hover", sbempty);
|
|
|
|
child->add_style_override("focus", sbempty);
|
|
|
|
child->add_style_override("pressed", sbempty);
|
|
|
|
}
|
|
|
|
|
|
|
|
vb->add_child(memnew(HSeparator));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
2017-01-21 22:00:25 +00:00
|
|
|
vb->add_child(hb);
|
2017-03-05 15:44:50 +00:00
|
|
|
slider = memnew(VSlider);
|
2017-01-21 22:00:25 +00:00
|
|
|
slider->set_min(-80);
|
|
|
|
slider->set_max(24);
|
|
|
|
slider->set_step(0.1);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
slider->connect("value_changed", this, "_volume_db_changed");
|
2017-01-21 22:00:25 +00:00
|
|
|
hb->add_child(slider);
|
2017-08-22 21:27:17 +00:00
|
|
|
|
|
|
|
cc = AudioServer::get_singleton()->get_channel_count();
|
|
|
|
|
|
|
|
for (int i = 0; i < cc; i++) {
|
|
|
|
channel[i].vu_l = memnew(TextureProgress);
|
|
|
|
channel[i].vu_l->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP);
|
|
|
|
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);
|
|
|
|
|
|
|
|
channel[i].vu_r = memnew(TextureProgress);
|
|
|
|
channel[i].vu_r->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP);
|
|
|
|
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);
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scale = memnew(TextureRect);
|
2017-01-21 22:00:25 +00:00
|
|
|
hb->add_child(scale);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
effects = memnew(Tree);
|
2017-01-21 22:00:25 +00:00
|
|
|
effects->set_hide_root(true);
|
2017-08-10 23:07:24 +00:00
|
|
|
effects->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
|
2017-01-21 22:00:25 +00:00
|
|
|
effects->set_hide_folding(true);
|
|
|
|
vb->add_child(effects);
|
2017-03-05 15:44:50 +00:00
|
|
|
effects->connect("item_edited", this, "_effect_edited");
|
|
|
|
effects->connect("cell_selected", this, "_effect_selected");
|
2017-01-21 22:00:25 +00:00
|
|
|
effects->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
|
2017-01-24 03:19:31 +00:00
|
|
|
effects->set_drag_forwarding(this);
|
2017-03-05 15:44:50 +00:00
|
|
|
effects->connect("item_rmb_selected", this, "_effect_rmb");
|
2017-01-24 23:11:13 +00:00
|
|
|
effects->set_allow_rmb_select(true);
|
2017-08-10 23:07:24 +00:00
|
|
|
effects->set_focus_mode(FOCUS_CLICK);
|
2017-08-18 21:19:12 +00:00
|
|
|
effects->set_allow_reselect(true);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
send = memnew(OptionButton);
|
2017-01-21 22:00:25 +00:00
|
|
|
send->set_clip_text(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
send->connect("item_selected", this, "_send_selected");
|
2017-01-21 22:00:25 +00:00
|
|
|
vb->add_child(send);
|
|
|
|
|
|
|
|
set_focus_mode(FOCUS_CLICK);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
effect_options = memnew(PopupMenu);
|
|
|
|
effect_options->connect("index_pressed", this, "_effect_add");
|
2017-01-21 22:00:25 +00:00
|
|
|
add_child(effect_options);
|
|
|
|
List<StringName> effects;
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::get_inheriters_from_class("AudioEffect", &effects);
|
2017-01-21 22:00:25 +00:00
|
|
|
effects.sort_custom<StringName::AlphCompare>();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<StringName>::Element *E = effects.front(); E; E = E->next()) {
|
2017-01-21 22:00:25 +00:00
|
|
|
if (!ClassDB::can_instance(E->get()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Ref<Texture> icon;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (has_icon(E->get(), "EditorIcons")) {
|
|
|
|
icon = get_icon(E->get(), "EditorIcons");
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
String name = E->get().operator String().replace("AudioEffect", "");
|
2017-01-21 22:00:25 +00:00
|
|
|
effect_options->add_item(name);
|
2017-03-05 15:44:50 +00:00
|
|
|
effect_options->set_item_metadata(effect_options->get_item_count() - 1, E->get());
|
|
|
|
effect_options->set_item_icon(effect_options->get_item_count() - 1, icon);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-26 14:42:28 +00:00
|
|
|
bus_popup = bus_options->get_popup();
|
|
|
|
bus_popup->add_item(TTR("Duplicate"));
|
2017-10-01 13:54:34 +00:00
|
|
|
bus_popup->add_item(TTR("Delete"));
|
|
|
|
bus_popup->set_item_disabled(1, is_master);
|
2017-09-07 00:11:31 +00:00
|
|
|
bus_popup->add_item(TTR("Reset Volume"));
|
2017-08-26 14:42:28 +00:00
|
|
|
bus_popup->connect("index_pressed", this, "_bus_popup_pressed");
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
delete_effect_popup = memnew(PopupMenu);
|
2017-08-23 20:25:14 +00:00
|
|
|
delete_effect_popup->add_item(TTR("Delete Effect"));
|
2017-01-24 23:11:13 +00:00
|
|
|
add_child(delete_effect_popup);
|
2017-03-05 15:44:50 +00:00
|
|
|
delete_effect_popup->connect("index_pressed", this, "_delete_effect_pressed");
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorAudioBusDrop::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = p_data;
|
|
|
|
if (d.has("type") && String(d["type"]) == "move_audio_bus") {
|
2017-01-24 02:12:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBusDrop::drop_data(const Point2 &p_point, const Variant &p_data) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = p_data;
|
|
|
|
emit_signal("dropped", d["index"], -1);
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBusDrop::_bind_methods() {
|
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("dropped"));
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorAudioBusDrop::EditorAudioBusDrop() {
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_update_buses() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (bus_hb->get_child_count() > 0) {
|
2017-01-21 22:00:25 +00:00
|
|
|
memdelete(bus_hb->get_child(0));
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
drop_end = NULL;
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-09-25 06:12:18 +00:00
|
|
|
bool is_master = i == 0 ? true : false;
|
|
|
|
EditorAudioBus *audio_bus = memnew(EditorAudioBus(this, is_master));
|
2017-01-21 22:00:25 +00:00
|
|
|
bus_hb->add_child(audio_bus);
|
2017-03-05 15:44:50 +00:00
|
|
|
audio_bus->connect("delete_request", this, "_delete_bus", varray(audio_bus), CONNECT_DEFERRED);
|
|
|
|
audio_bus->connect("duplicate_request", this, "_duplicate_bus", varray(), CONNECT_DEFERRED);
|
2017-09-07 00:11:31 +00:00
|
|
|
audio_bus->connect("vol_reset_request", this, "_reset_bus_volume", varray(audio_bus), CONNECT_DEFERRED);
|
2017-03-05 15:44:50 +00:00
|
|
|
audio_bus->connect("drop_end_request", this, "_request_drop_end");
|
|
|
|
audio_bus->connect("dropped", this, "_drop_at_index", varray(), CONNECT_DEFERRED);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
EditorAudioBuses *EditorAudioBuses::register_editor() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorAudioBuses *audio_buses = memnew(EditorAudioBuses);
|
2017-12-02 09:58:58 +00:00
|
|
|
EditorNode::get_singleton()->add_bottom_panel_item(TTR("Audio"), audio_buses);
|
2017-01-25 17:30:40 +00:00
|
|
|
return audio_buses;
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_READY) {
|
2017-01-21 22:00:25 +00:00
|
|
|
_update_buses();
|
|
|
|
}
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAG_END) {
|
2017-01-24 02:12:08 +00:00
|
|
|
if (drop_end) {
|
|
|
|
drop_end->queue_delete();
|
2017-03-05 15:44:50 +00:00
|
|
|
drop_end = NULL;
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_PROCESS) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
//check if anything was edited
|
|
|
|
bool edited = AudioServer::get_singleton()->is_edited();
|
2017-03-05 15:44:50 +00:00
|
|
|
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);
|
2017-01-25 17:30:40 +00:00
|
|
|
if (effect->is_edited()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
edited = true;
|
2017-01-25 17:30:40 +00:00
|
|
|
effect->set_edited(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioServer::get_singleton()->set_edited(false);
|
|
|
|
|
|
|
|
if (edited) {
|
|
|
|
|
|
|
|
save_timer->start();
|
|
|
|
}
|
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_add_bus() {
|
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
|
|
|
|
//need to simulate new name, so we can undi :(
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Add Audio Bus"));
|
2017-03-05 15:44:50 +00: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->add_do_method(this, "_update_buses");
|
|
|
|
ur->add_undo_method(this, "_update_buses");
|
2017-01-21 22:00:25 +00:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_update_bus(int p_index) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index >= bus_hb->get_child_count())
|
2017-01-21 22:00:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bus_hb->get_child(p_index)->call("update_bus");
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_update_sends() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < bus_hb->get_child_count(); i++) {
|
2017-01-21 22:00:25 +00:00
|
|
|
bus_hb->get_child(i)->call("update_send");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBuses::_delete_bus(Object *p_which) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
|
2017-01-24 02:12:08 +00:00
|
|
|
int index = bus->get_index();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (index == 0) {
|
2017-08-23 20:25:14 +00:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Master bus can't be deleted!"));
|
2017-01-24 02:12:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Delete Audio Bus"));
|
2017-03-05 15:44:50 +00: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));
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_do_method(this, "_update_buses");
|
|
|
|
ur->add_undo_method(this, "_update_buses");
|
2017-01-24 02:12:08 +00:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
void EditorAudioBuses::_duplicate_bus(int p_which) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int add_at_pos = p_which + 1;
|
2017-01-25 17:30:40 +00:00
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Duplicate Audio Bus"));
|
2017-03-05 15:44:50 +00: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));
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_undo_method(AudioServer::get_singleton(), "remove_bus", add_at_pos);
|
|
|
|
ur->add_do_method(this, "_update_buses");
|
|
|
|
ur->add_undo_method(this, "_update_buses");
|
2017-01-25 17:30:40 +00:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-09-07 00:11:31 +00:00
|
|
|
void EditorAudioBuses::_reset_bus_volume(Object *p_which) {
|
|
|
|
|
|
|
|
EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
|
|
|
|
int index = bus->get_index();
|
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
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));
|
|
|
|
ur->add_do_method(this, "_update_buses");
|
|
|
|
ur->add_undo_method(this, "_update_buses");
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:12:08 +00:00
|
|
|
void EditorAudioBuses::_request_drop_end() {
|
|
|
|
|
|
|
|
if (!drop_end && bus_hb->get_child_count()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
drop_end = memnew(EditorAudioBusDrop);
|
2017-01-24 02:12:08 +00:00
|
|
|
|
|
|
|
bus_hb->add_child(drop_end);
|
2017-08-24 20:58:51 +00:00
|
|
|
drop_end->set_custom_minimum_size(Object::cast_to<Control>(bus_hb->get_child(0))->get_size());
|
2017-03-05 15:44:50 +00:00
|
|
|
drop_end->connect("dropped", this, "_drop_at_index", varray(), CONNECT_DEFERRED);
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) {
|
2017-01-24 02:12:08 +00:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
|
|
|
|
//need to simulate new name, so we can undi :(
|
2017-08-23 20:25:14 +00:00
|
|
|
ur->create_action(TTR("Move Audio Bus"));
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_do_method(AudioServer::get_singleton(), "move_bus", p_bus, p_index);
|
2017-01-24 02:12:08 +00:00
|
|
|
int final_pos;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index == p_bus) {
|
|
|
|
final_pos = p_bus;
|
|
|
|
} else if (p_index == -1) {
|
|
|
|
final_pos = AudioServer::get_singleton()->get_bus_count() - 1;
|
|
|
|
} else if (p_index < p_bus) {
|
2017-01-24 02:12:08 +00:00
|
|
|
final_pos = p_index;
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
final_pos = p_index - 1;
|
2017-01-24 02:12:08 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_undo_method(AudioServer::get_singleton(), "move_bus", final_pos, p_bus);
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ur->add_do_method(this, "_update_buses");
|
|
|
|
ur->add_undo_method(this, "_update_buses");
|
2017-01-24 02:12:08 +00:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
void EditorAudioBuses::_server_save() {
|
|
|
|
|
|
|
|
Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout();
|
2017-03-05 15:44:50 +00:00
|
|
|
ResourceSaver::save(edited_path, state);
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_select_layout() {
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->get_filesystem_dock()->select_file(edited_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_save_as_layout() {
|
|
|
|
|
|
|
|
file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
|
|
|
file_dialog->set_title(TTR("Save Audio Bus Layout As.."));
|
|
|
|
file_dialog->set_current_path(edited_path);
|
|
|
|
file_dialog->popup_centered_ratio();
|
2017-03-05 15:44:50 +00:00
|
|
|
new_layout = false;
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_new_layout() {
|
|
|
|
|
|
|
|
file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
|
|
|
file_dialog->set_title(TTR("Location for New Layout.."));
|
|
|
|
file_dialog->set_current_path(edited_path);
|
|
|
|
file_dialog->popup_centered_ratio();
|
2017-03-05 15:44:50 +00:00
|
|
|
new_layout = true;
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_load_layout() {
|
|
|
|
|
|
|
|
file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
|
|
|
|
file_dialog->set_title(TTR("Open Audio Bus Layout"));
|
|
|
|
file_dialog->set_current_path(edited_path);
|
|
|
|
file_dialog->popup_centered_ratio();
|
2017-03-05 15:44:50 +00:00
|
|
|
new_layout = false;
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorAudioBuses::_load_default_layout() {
|
|
|
|
|
|
|
|
Ref<AudioBusLayout> state = ResourceLoader::load("res://default_bus_layout.tres");
|
|
|
|
if (state.is_null()) {
|
2017-08-23 20:25:14 +00:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("There is no 'res://default_bus_layout.tres' file."));
|
2017-01-25 17:30:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edited_path = "res://default_bus_layout.tres";
|
2017-01-25 17:30:40 +00:00
|
|
|
file->set_text(edited_path.get_file());
|
|
|
|
AudioServer::get_singleton()->set_bus_layout(state);
|
|
|
|
_update_buses();
|
|
|
|
EditorNode::get_singleton()->get_undo_redo()->clear_history();
|
|
|
|
call_deferred("_select_layout");
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (file_dialog->get_mode() == EditorFileDialog::MODE_OPEN_FILE) {
|
2017-01-25 17:30:40 +00:00
|
|
|
Ref<AudioBusLayout> state = ResourceLoader::load(p_string);
|
|
|
|
if (state.is_null()) {
|
2017-08-23 20:25:14 +00:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout."));
|
2017-01-25 17:30:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edited_path = p_string;
|
2017-01-25 17:30:40 +00:00
|
|
|
file->set_text(p_string.get_file());
|
|
|
|
AudioServer::get_singleton()->set_bus_layout(state);
|
|
|
|
_update_buses();
|
|
|
|
EditorNode::get_singleton()->get_undo_redo()->clear_history();
|
|
|
|
call_deferred("_select_layout");
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (file_dialog->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
if (new_layout) {
|
|
|
|
Ref<AudioBusLayout> empty_state;
|
|
|
|
empty_state.instance();
|
|
|
|
AudioServer::get_singleton()->set_bus_layout(empty_state);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error err = ResourceSaver::save(p_string, AudioServer::get_singleton()->generate_bus_layout());
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (err != OK) {
|
|
|
|
EditorNode::get_singleton()->show_warning("Error saving file: " + p_string);
|
2017-01-25 17:30:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edited_path = p_string;
|
2017-01-25 17:30:40 +00:00
|
|
|
file->set_text(p_string.get_file());
|
|
|
|
_update_buses();
|
|
|
|
EditorNode::get_singleton()->get_undo_redo()->clear_history();
|
|
|
|
call_deferred("_select_layout");
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 02:12:08 +00:00
|
|
|
|
2017-01-21 22:00:25 +00:00
|
|
|
void EditorAudioBuses::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_add_bus", &EditorAudioBuses::_add_bus);
|
|
|
|
ClassDB::bind_method("_update_buses", &EditorAudioBuses::_update_buses);
|
|
|
|
ClassDB::bind_method("_update_bus", &EditorAudioBuses::_update_bus);
|
|
|
|
ClassDB::bind_method("_update_sends", &EditorAudioBuses::_update_sends);
|
|
|
|
ClassDB::bind_method("_delete_bus", &EditorAudioBuses::_delete_bus);
|
|
|
|
ClassDB::bind_method("_request_drop_end", &EditorAudioBuses::_request_drop_end);
|
|
|
|
ClassDB::bind_method("_drop_at_index", &EditorAudioBuses::_drop_at_index);
|
|
|
|
ClassDB::bind_method("_server_save", &EditorAudioBuses::_server_save);
|
|
|
|
ClassDB::bind_method("_select_layout", &EditorAudioBuses::_select_layout);
|
|
|
|
ClassDB::bind_method("_save_as_layout", &EditorAudioBuses::_save_as_layout);
|
|
|
|
ClassDB::bind_method("_load_layout", &EditorAudioBuses::_load_layout);
|
|
|
|
ClassDB::bind_method("_load_default_layout", &EditorAudioBuses::_load_default_layout);
|
|
|
|
ClassDB::bind_method("_new_layout", &EditorAudioBuses::_new_layout);
|
|
|
|
ClassDB::bind_method("_duplicate_bus", &EditorAudioBuses::_duplicate_bus);
|
2017-09-07 00:11:31 +00:00
|
|
|
ClassDB::bind_method("_reset_bus_volume", &EditorAudioBuses::_reset_bus_volume);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
ClassDB::bind_method("_file_dialog_callback", &EditorAudioBuses::_file_dialog_callback);
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorAudioBuses::EditorAudioBuses() {
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-24 02:12:08 +00:00
|
|
|
drop_end = NULL;
|
2017-03-05 15:44:50 +00:00
|
|
|
top_hb = memnew(HBoxContainer);
|
2017-01-21 22:00:25 +00:00
|
|
|
add_child(top_hb);
|
|
|
|
|
2017-08-08 02:55:24 +00:00
|
|
|
file = memnew(ToolButton);
|
|
|
|
file->set_text("default_bus_layout.tres");
|
|
|
|
top_hb->add_child(file);
|
|
|
|
file->connect("pressed", this, "_select_layout");
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
add = memnew(Button);
|
|
|
|
top_hb->add_child(add);
|
2017-01-25 17:30:40 +00:00
|
|
|
add->set_text(TTR("Add Bus"));
|
2017-08-10 23:07:24 +00:00
|
|
|
add->set_tooltip(TTR("Create a new Bus Layout."));
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
add->connect("pressed", this, "_add_bus");
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
top_hb->add_spacer();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
load = memnew(Button);
|
2017-01-25 17:30:40 +00:00
|
|
|
load->set_text(TTR("Load"));
|
2017-08-10 23:07:24 +00:00
|
|
|
load->set_tooltip(TTR("Load an existing Bus Layout."));
|
2017-01-25 17:30:40 +00:00
|
|
|
top_hb->add_child(load);
|
2017-03-05 15:44:50 +00:00
|
|
|
load->connect("pressed", this, "_load_layout");
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
save_as = memnew(Button);
|
2017-01-25 17:30:40 +00:00
|
|
|
save_as->set_text(TTR("Save As"));
|
2017-08-10 23:07:24 +00:00
|
|
|
save_as->set_tooltip(TTR("Save this Bus Layout to a file."));
|
2017-01-25 17:30:40 +00:00
|
|
|
top_hb->add_child(save_as);
|
2017-03-05 15:44:50 +00:00
|
|
|
save_as->connect("pressed", this, "_save_as_layout");
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_default = memnew(Button);
|
2017-08-10 23:07:24 +00:00
|
|
|
_default->set_text(TTR("Load Default"));
|
|
|
|
_default->set_tooltip(TTR("Load the default Bus Layout."));
|
2017-01-25 17:30:40 +00:00
|
|
|
top_hb->add_child(_default);
|
2017-03-05 15:44:50 +00:00
|
|
|
_default->connect("pressed", this, "_load_default_layout");
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_new = memnew(Button);
|
2017-01-25 17:30:40 +00:00
|
|
|
_new->set_text(TTR("Create"));
|
2017-08-10 23:07:24 +00:00
|
|
|
_new->set_tooltip(TTR("Create a new Bus Layout."));
|
2017-01-25 17:30:40 +00:00
|
|
|
top_hb->add_child(_new);
|
2017-03-05 15:44:50 +00:00
|
|
|
_new->connect("pressed", this, "_new_layout");
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bus_scroll = memnew(ScrollContainer);
|
2017-08-08 02:55:24 +00:00
|
|
|
bus_scroll->add_style_override("panel", memnew(StyleBoxEmpty));
|
2017-01-21 22:00:25 +00:00
|
|
|
bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
bus_scroll->set_enable_h_scroll(true);
|
|
|
|
bus_scroll->set_enable_v_scroll(false);
|
|
|
|
add_child(bus_scroll);
|
2017-03-05 15:44:50 +00:00
|
|
|
bus_hb = memnew(HBoxContainer);
|
2017-01-21 22:00:25 +00:00
|
|
|
bus_scroll->add_child(bus_hb);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
save_timer = memnew(Timer);
|
2017-01-25 17:30:40 +00:00
|
|
|
save_timer->set_wait_time(0.8);
|
|
|
|
save_timer->set_one_shot(true);
|
|
|
|
add_child(save_timer);
|
2017-03-05 15:44:50 +00:00
|
|
|
save_timer->connect("timeout", this, "_server_save");
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
set_v_size_flags(SIZE_EXPAND_FILL);
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
edited_path = "res://default_bus_layout.tres";
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
file_dialog = memnew(EditorFileDialog);
|
2017-01-25 17:30:40 +00:00
|
|
|
List<String> ext;
|
2017-05-20 20:49:34 +00:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type("AudioBusLayout", &ext);
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<String>::Element *E = ext.front(); E; E = E->next()) {
|
2017-05-20 20:49:34 +00:00
|
|
|
file_dialog->add_filter("*." + E->get() + "; Audio Bus Layout");
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
add_child(file_dialog);
|
2017-03-05 15:44:50 +00:00
|
|
|
file_dialog->connect("file_selected", this, "_file_dialog_callback");
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
set_process(true);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorAudioBuses::open_layout(const String &p_path) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
|
|
|
EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
|
|
|
|
|
|
|
|
Ref<AudioBusLayout> state = ResourceLoader::load(p_path);
|
|
|
|
if (state.is_null()) {
|
2017-08-23 20:25:14 +00:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout."));
|
2017-01-25 17:30:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edited_path = p_path;
|
2017-01-25 17:30:40 +00:00
|
|
|
file->set_text(p_path.get_file());
|
|
|
|
AudioServer::get_singleton()->set_bus_layout(state);
|
|
|
|
_update_buses();
|
|
|
|
EditorNode::get_singleton()->get_undo_redo()->clear_history();
|
|
|
|
call_deferred("_select_layout");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioBusesEditorPlugin::edit(Object *p_node) {
|
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<AudioBusLayout>(p_node)) {
|
2017-01-25 17:30:40 +00:00
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
String path = Object::cast_to<AudioBusLayout>(p_node)->get_path();
|
2017-01-25 17:30:40 +00:00
|
|
|
if (path.is_resource_file()) {
|
|
|
|
audio_bus_editor->open_layout(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioBusesEditorPlugin::handles(Object *p_node) const {
|
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
return (Object::cast_to<AudioBusLayout>(p_node) != NULL);
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AudioBusesEditorPlugin::make_visible(bool p_visible) {
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
audio_bus_editor = p_node;
|
2017-01-25 17:30:40 +00:00
|
|
|
}
|
2017-01-21 22:00:25 +00:00
|
|
|
|
2017-01-25 17:30:40 +00:00
|
|
|
AudioBusesEditorPlugin::~AudioBusesEditorPlugin() {
|
2017-01-21 22:00:25 +00:00
|
|
|
}
|