Esempio n. 1
0
EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {

	buses = p_buses;
	updating_bus = false;
	is_master = p_is_master;

	set_tooltip(TTR("Audio Bus, Drag and Drop to rearrange."));

	VBoxContainer *vb = memnew(VBoxContainer);
	add_child(vb);

	set_v_size_flags(SIZE_EXPAND_FILL);
	set_custom_minimum_size(Size2(100, 0) * EDSCALE);

	track_name = memnew(LineEdit);
	track_name->connect("text_entered", this, "_name_changed");
	track_name->connect("focus_exited", this, "_name_focus_exit");
	vb->add_child(track_name);

	HBoxContainer *hbc = memnew(HBoxContainer);
	vb->add_child(hbc);
	solo = memnew(ToolButton);
	solo->set_toggle_mode(true);
	solo->set_tooltip(TTR("Solo"));
	solo->set_focus_mode(FOCUS_NONE);
	solo->connect("pressed", this, "_solo_toggled");
	hbc->add_child(solo);
	mute = memnew(ToolButton);
	mute->set_toggle_mode(true);
	mute->set_tooltip(TTR("Mute"));
	mute->set_focus_mode(FOCUS_NONE);
	mute->connect("pressed", this, "_mute_toggled");
	hbc->add_child(mute);
	bypass = memnew(ToolButton);
	bypass->set_toggle_mode(true);
	bypass->set_tooltip(TTR("Bypass"));
	bypass->set_focus_mode(FOCUS_NONE);
	bypass->connect("pressed", this, "_bypass_toggled");
	hbc->add_child(bypass);
	hbc->add_spacer();

	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));

	HBoxContainer *hb = memnew(HBoxContainer);
	vb->add_child(hb);
	slider = memnew(VSlider);
	slider->set_min(-80);
	slider->set_max(24);
	slider->set_step(0.1);

	slider->connect("value_changed", this, "_volume_db_changed");
	hb->add_child(slider);

	cc = 0;
	for (int i = 0; i < CHANNELS_MAX; 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);

		channel[i].peak_l = 0.0f;
		channel[i].peak_r = 0.0f;
	}

	scale = memnew(TextureRect);
	hb->add_child(scale);

	effects = memnew(Tree);
	effects->set_hide_root(true);
	effects->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
	effects->set_hide_folding(true);
	effects->set_v_size_flags(SIZE_EXPAND_FILL);
	vb->add_child(effects);
	effects->connect("item_edited", this, "_effect_edited");
	effects->connect("cell_selected", this, "_effect_selected");
	effects->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
	effects->set_drag_forwarding(this);
	effects->connect("item_rmb_selected", this, "_effect_rmb");
	effects->set_allow_rmb_select(true);
	effects->set_focus_mode(FOCUS_CLICK);
	effects->set_allow_reselect(true);

	send = memnew(OptionButton);
	send->set_clip_text(true);
	send->connect("item_selected", this, "_send_selected");
	vb->add_child(send);

	set_focus_mode(FOCUS_CLICK);

	effect_options = memnew(PopupMenu);
	effect_options->connect("index_pressed", this, "_effect_add");
	add_child(effect_options);
	List<StringName> effects;
	ClassDB::get_inheriters_from_class("AudioEffect", &effects);
	effects.sort_custom<StringName::AlphCompare>();
	for (List<StringName>::Element *E = effects.front(); E; E = E->next()) {
		if (!ClassDB::can_instance(E->get()))
			continue;

		Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(E->get());
		String name = E->get().operator String().replace("AudioEffect", "");
		effect_options->add_item(name);
		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);
	}

	bus_popup = bus_options->get_popup();
	bus_popup->add_item(TTR("Duplicate"));
	bus_popup->add_item(TTR("Delete"));
	bus_popup->set_item_disabled(1, is_master);
	bus_popup->add_item(TTR("Reset Volume"));
	bus_popup->connect("index_pressed", this, "_bus_popup_pressed");

	delete_effect_popup = memnew(PopupMenu);
	delete_effect_popup->add_item(TTR("Delete Effect"));
	add_child(delete_effect_popup);
	delete_effect_popup->connect("index_pressed", this, "_delete_effect_pressed");
}