2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* sample_library_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "sample_library_editor_plugin.h"
|
|
|
|
|
2017-03-18 22:45:45 +00:00
|
|
|
#include "editor/editor_settings.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "globals.h"
|
|
|
|
#include "io/resource_loader.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "sample_editor_plugin.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "scene/main/viewport.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void SampleLibraryEditor::_input_event(InputEvent p_event) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleLibraryEditor::_notification(int p_what) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_PROCESS) {
|
2016-03-13 13:37:47 +00:00
|
|
|
if (is_playing && !player->is_active()) {
|
2017-03-18 23:36:26 +00:00
|
|
|
TreeItem *tl = last_sample_playing->cast_to<TreeItem>();
|
|
|
|
tl->set_button(0, 0, get_icon("Play", "EditorIcons"));
|
2016-03-13 13:37:47 +00:00
|
|
|
is_playing = false;
|
|
|
|
set_process(false);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
|
|
|
load->set_icon(get_icon("Folder", "EditorIcons"));
|
2016-05-04 01:25:37 +00:00
|
|
|
load->set_tooltip(TTR("Open Sample File(s)"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_READY) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// NodePath("/root")->connect("node_removed", this,"_node_removed",Vector<Variant>(),true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SampleLibraryEditor::_file_load_request(const DVector<String> &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_path.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String path = p_path[i];
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<Sample> sample = ResourceLoader::load(path, "Sample");
|
2014-02-10 01:10:30 +00:00
|
|
|
if (sample.is_null()) {
|
2016-05-04 01:25:37 +00:00
|
|
|
dialog->set_text(TTR("ERROR: Couldn't load sample!"));
|
|
|
|
dialog->set_title(TTR("Error!"));
|
2016-05-20 23:18:35 +00:00
|
|
|
//dialog->get_cancel()->set_text("Close");
|
2016-05-04 01:25:37 +00:00
|
|
|
dialog->get_ok()->set_text(TTR("Close"));
|
2015-04-08 17:02:13 +00:00
|
|
|
dialog->popup_centered_minsize();
|
2014-02-10 01:10:30 +00:00
|
|
|
return; ///beh should show an error i guess
|
|
|
|
}
|
|
|
|
String basename = path.get_file().basename();
|
2017-03-18 23:36:26 +00:00
|
|
|
String name = basename;
|
|
|
|
int counter = 0;
|
|
|
|
while (sample_library->has_sample(name)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
counter++;
|
2017-03-18 23:36:26 +00:00
|
|
|
name = basename + "_" + itos(counter);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Add Sample"));
|
2017-03-18 23:36:26 +00:00
|
|
|
undo_redo->add_do_method(sample_library.operator->(), "add_sample", name, sample);
|
|
|
|
undo_redo->add_undo_method(sample_library.operator->(), "remove_sample", name);
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleLibraryEditor::_load_pressed() {
|
|
|
|
|
|
|
|
file->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SampleLibraryEditor::_button_pressed(Object *p_item, int p_column, int p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
TreeItem *ti = p_item->cast_to<TreeItem>();
|
2014-02-10 01:10:30 +00:00
|
|
|
String name = ti->get_text(0);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_column == 0) { // Play/Stop
|
2016-03-13 13:37:47 +00:00
|
|
|
|
|
|
|
String btn_type;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!is_playing) {
|
2016-03-13 13:37:47 +00:00
|
|
|
is_playing = true;
|
2016-05-04 01:25:37 +00:00
|
|
|
btn_type = TTR("Stop");
|
2017-03-18 23:36:26 +00:00
|
|
|
player->play(name, true);
|
2016-03-13 13:37:47 +00:00
|
|
|
last_sample_playing = p_item;
|
|
|
|
set_process(true);
|
|
|
|
} else {
|
2016-03-13 13:57:01 +00:00
|
|
|
player->stop_all();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (last_sample_playing != p_item) {
|
|
|
|
TreeItem *tl = last_sample_playing->cast_to<TreeItem>();
|
|
|
|
tl->set_button(p_column, 0, get_icon("Play", "EditorIcons"));
|
2016-05-04 01:25:37 +00:00
|
|
|
btn_type = TTR("Stop");
|
2017-03-18 23:36:26 +00:00
|
|
|
player->play(name, true);
|
2016-03-13 13:37:47 +00:00
|
|
|
last_sample_playing = p_item;
|
|
|
|
} else {
|
2016-05-04 01:25:37 +00:00
|
|
|
btn_type = TTR("Play");
|
2016-03-13 13:37:47 +00:00
|
|
|
is_playing = false;
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
ti->set_button(p_column, 0, get_icon(btn_type, "EditorIcons"));
|
|
|
|
} else if (p_column == 1) { // Edit
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
get_tree()->get_root()->get_child(0)->call("_resource_selected", sample_library->get_sample(name));
|
2017-04-16 22:28:29 +00:00
|
|
|
} else if (p_column == 6) { // Delete
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-13 13:37:47 +00:00
|
|
|
ti->select(0);
|
|
|
|
_delete_pressed();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleLibraryEditor::_item_edited() {
|
|
|
|
|
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
|
|
|
|
|
|
|
TreeItem *s = tree->get_selected();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tree->get_selected_column() == 0) { // Name
|
2014-02-10 01:10:30 +00:00
|
|
|
// renamed
|
2017-03-18 23:36:26 +00:00
|
|
|
String old_name = s->get_metadata(0);
|
|
|
|
String new_name = s->get_text(0);
|
|
|
|
if (old_name == new_name)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (new_name == "" || new_name.find("\\") != -1 || new_name.find("/") != -1 || sample_library->has_sample(new_name)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
s->set_text(0, old_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Sample> samp = sample_library->get_sample(old_name);
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Rename Sample"));
|
2017-03-18 23:36:26 +00:00
|
|
|
undo_redo->add_do_method(sample_library.operator->(), "remove_sample", old_name);
|
|
|
|
undo_redo->add_do_method(sample_library.operator->(), "add_sample", new_name, samp);
|
|
|
|
undo_redo->add_undo_method(sample_library.operator->(), "remove_sample", new_name);
|
|
|
|
undo_redo->add_undo_method(sample_library.operator->(), "add_sample", old_name, samp);
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (tree->get_selected_column() == 3) { // Volume dB
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
StringName n = s->get_text(0);
|
2017-03-18 23:36:26 +00:00
|
|
|
sample_library->sample_set_volume_db(n, s->get_range(3));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (tree->get_selected_column() == 4) { // Pitch scale
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
StringName n = s->get_text(0);
|
2017-03-18 23:36:26 +00:00
|
|
|
sample_library->sample_set_pitch_scale(n, s->get_range(4));
|
2017-04-06 17:00:19 +00:00
|
|
|
|
|
|
|
} else if (tree->get_selected_column() == 5) { // Priority
|
|
|
|
|
|
|
|
StringName n = s->get_text(0);
|
|
|
|
sample_library->sample_set_priority(n, s->get_range(5));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-13 13:57:01 +00:00
|
|
|
void SampleLibraryEditor::_delete_pressed() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tree->get_selected())
|
|
|
|
return;
|
|
|
|
|
|
|
|
String to_remove = tree->get_selected()->get_text(0);
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Delete Sample"));
|
2017-03-18 23:36:26 +00:00
|
|
|
undo_redo->add_do_method(sample_library.operator->(), "remove_sample", to_remove);
|
|
|
|
undo_redo->add_undo_method(sample_library.operator->(), "add_sample", to_remove, sample_library->get_sample(to_remove));
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleLibraryEditor::_update_library() {
|
|
|
|
|
|
|
|
player->stop_all();
|
|
|
|
|
|
|
|
tree->clear();
|
|
|
|
tree->set_hide_root(true);
|
|
|
|
TreeItem *root = tree->create_item(NULL);
|
|
|
|
|
|
|
|
List<StringName> names;
|
|
|
|
sample_library->get_sample_list(&names);
|
2015-03-25 02:57:35 +00:00
|
|
|
names.sort_custom<StringName::AlphCompare>();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
TreeItem *ti = tree->create_item(root);
|
2016-03-13 13:37:47 +00:00
|
|
|
|
|
|
|
// Name + Play/Stop
|
2017-03-18 23:36:26 +00:00
|
|
|
ti->set_cell_mode(0, TreeItem::CELL_MODE_STRING);
|
|
|
|
ti->set_editable(0, true);
|
|
|
|
ti->set_selectable(0, true);
|
|
|
|
ti->set_text(0, E->get());
|
|
|
|
ti->set_metadata(0, E->get());
|
|
|
|
ti->add_button(0, get_icon("Play", "EditorIcons"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Ref<Sample> smp = sample_library->get_sample(E->get());
|
|
|
|
|
2016-03-13 13:37:47 +00:00
|
|
|
// Preview/edit
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ImageTexture> preview(memnew(ImageTexture));
|
|
|
|
preview->create(128, 16, Image::FORMAT_RGB);
|
|
|
|
SampleEditor::generate_preview_texture(smp, preview);
|
|
|
|
ti->set_cell_mode(1, TreeItem::CELL_MODE_ICON);
|
|
|
|
ti->set_selectable(1, false);
|
|
|
|
ti->set_editable(1, false);
|
|
|
|
ti->set_icon(1, preview);
|
|
|
|
ti->add_button(1, get_icon("Edit", "EditorIcons"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-13 13:37:47 +00:00
|
|
|
// Format
|
2017-03-18 23:36:26 +00:00
|
|
|
ti->set_cell_mode(2, TreeItem::CELL_MODE_STRING);
|
|
|
|
ti->set_editable(2, false);
|
|
|
|
ti->set_selectable(2, false);
|
|
|
|
ti->set_text(2, String() + (smp->get_format() == Sample::FORMAT_PCM16 ? TTR("16 Bits") + ", " : (smp->get_format() == Sample::FORMAT_PCM8 ? TTR("8 Bits") + ", " : "IMA-ADPCM,")) + (smp->is_stereo() ? TTR("Stereo") : TTR("Mono")));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-13 13:37:47 +00:00
|
|
|
// Volume dB
|
2017-03-18 23:36:26 +00:00
|
|
|
ti->set_cell_mode(3, TreeItem::CELL_MODE_RANGE);
|
|
|
|
ti->set_range_config(3, -60, 24, 0.01);
|
|
|
|
ti->set_selectable(3, true);
|
|
|
|
ti->set_editable(3, true);
|
|
|
|
ti->set_range(3, sample_library->sample_get_volume_db(E->get()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-13 13:37:47 +00:00
|
|
|
// Pitch scale
|
2017-03-18 23:36:26 +00:00
|
|
|
ti->set_cell_mode(4, TreeItem::CELL_MODE_RANGE);
|
|
|
|
ti->set_range_config(4, 0.01, 100, 0.01);
|
|
|
|
ti->set_selectable(4, true);
|
|
|
|
ti->set_editable(4, true);
|
|
|
|
ti->set_range(4, sample_library->sample_get_pitch_scale(E->get()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-06 17:00:19 +00:00
|
|
|
// Priority
|
|
|
|
ti->set_cell_mode(5, TreeItem::CELL_MODE_RANGE);
|
|
|
|
ti->set_range_config(5, 0, 100, 1);
|
|
|
|
ti->set_selectable(5, true);
|
|
|
|
ti->set_editable(5, true);
|
|
|
|
ti->set_range(5, sample_library->sample_get_priority(E->get()));
|
|
|
|
|
2016-03-13 13:37:47 +00:00
|
|
|
// Delete
|
2017-04-06 17:00:19 +00:00
|
|
|
ti->set_cell_mode(6, TreeItem::CELL_MODE_STRING);
|
|
|
|
ti->add_button(6, get_icon("Remove", "EditorIcons"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//player->add_sample("default",sample);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleLibraryEditor::edit(Ref<SampleLibrary> p_sample_library) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
sample_library = p_sample_library;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!sample_library.is_null()) {
|
|
|
|
player->set_sample_library(sample_library);
|
|
|
|
_update_library();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant SampleLibraryEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
|
2016-05-15 02:48:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
TreeItem *ti = tree->get_item_at_pos(p_point);
|
2016-05-15 02:48:23 +00:00
|
|
|
if (!ti)
|
|
|
|
return Variant();
|
|
|
|
|
|
|
|
String name = ti->get_metadata(0);
|
|
|
|
|
|
|
|
RES res = sample_library->get_sample(name);
|
|
|
|
if (!res.is_valid())
|
|
|
|
return Variant();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return EditorNode::get_singleton()->drag_resource(res, p_from);
|
2016-05-15 02:48:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool SampleLibraryEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
|
2016-05-15 02:48:23 +00:00
|
|
|
|
|
|
|
Dictionary d = p_data;
|
|
|
|
|
|
|
|
if (!d.has("type"))
|
|
|
|
return false;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (d.has("from") && (Object *)(d["from"]) == tree)
|
2016-05-15 02:48:23 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (String(d["type"]) == "resource" && d.has("resource")) {
|
|
|
|
RES r = d["resource"];
|
2016-05-15 02:48:23 +00:00
|
|
|
|
|
|
|
Ref<Sample> sample = r;
|
|
|
|
|
|
|
|
if (sample.is_valid()) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (String(d["type"]) == "files") {
|
2016-05-15 02:48:23 +00:00
|
|
|
|
|
|
|
Vector<String> files = d["files"];
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (files.size() == 0)
|
2016-05-15 02:48:23 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
2016-05-15 02:48:23 +00:00
|
|
|
String file = files[0];
|
|
|
|
String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ftype != "Sample") {
|
2016-05-15 02:48:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SampleLibraryEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
|
2016-05-15 02:48:23 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!can_drop_data_fw(p_point, p_data, p_from))
|
2016-05-15 02:48:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Dictionary d = p_data;
|
|
|
|
|
|
|
|
if (!d.has("type"))
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (String(d["type"]) == "resource" && d.has("resource")) {
|
|
|
|
RES r = d["resource"];
|
2016-05-15 02:48:23 +00:00
|
|
|
|
|
|
|
Ref<Sample> sample = r;
|
|
|
|
|
|
|
|
if (sample.is_valid()) {
|
|
|
|
|
|
|
|
String basename;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (sample->get_name() != "") {
|
|
|
|
basename = sample->get_name();
|
2016-05-15 02:48:23 +00:00
|
|
|
} else if (sample->get_path().is_resource_file()) {
|
|
|
|
basename = sample->get_path().basename();
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
basename = "Sample";
|
2016-05-15 02:48:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String name = basename;
|
|
|
|
int counter = 0;
|
|
|
|
while (sample_library->has_sample(name)) {
|
2016-05-15 02:48:23 +00:00
|
|
|
counter++;
|
2017-03-18 23:36:26 +00:00
|
|
|
name = basename + "_" + itos(counter);
|
2016-05-15 02:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Add Sample"));
|
2017-03-18 23:36:26 +00:00
|
|
|
undo_redo->add_do_method(sample_library.operator->(), "add_sample", name, sample);
|
|
|
|
undo_redo->add_undo_method(sample_library.operator->(), "remove_sample", name);
|
|
|
|
undo_redo->add_do_method(this, "_update_library");
|
|
|
|
undo_redo->add_undo_method(this, "_update_library");
|
2016-05-15 02:48:23 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (String(d["type"]) == "files") {
|
2016-05-15 02:48:23 +00:00
|
|
|
|
|
|
|
DVector<String> files = d["files"];
|
|
|
|
|
|
|
|
_file_load_request(files);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void SampleLibraryEditor::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("_input_event"), &SampleLibraryEditor::_input_event);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_load_pressed"), &SampleLibraryEditor::_load_pressed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_item_edited"), &SampleLibraryEditor::_item_edited);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_delete_pressed"), &SampleLibraryEditor::_delete_pressed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_file_load_request"), &SampleLibraryEditor::_file_load_request);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_update_library"), &SampleLibraryEditor::_update_library);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_button_pressed"), &SampleLibraryEditor::_button_pressed);
|
2016-05-15 02:48:23 +00:00
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &SampleLibraryEditor::get_drag_data_fw);
|
|
|
|
ObjectTypeDB::bind_method(_MD("can_drop_data_fw"), &SampleLibraryEditor::can_drop_data_fw);
|
|
|
|
ObjectTypeDB::bind_method(_MD("drop_data_fw"), &SampleLibraryEditor::drop_data_fw);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SampleLibraryEditor::SampleLibraryEditor() {
|
|
|
|
|
|
|
|
player = memnew(SamplePlayer);
|
|
|
|
add_child(player);
|
2017-03-18 23:36:26 +00:00
|
|
|
add_style_override("panel", get_stylebox("panel", "Panel"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
load = memnew(Button);
|
|
|
|
load->set_pos(Point2(5, 5));
|
|
|
|
load->set_size(Size2(1, 1));
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(load);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
file = memnew(EditorFileDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(file);
|
|
|
|
List<String> extensions;
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type("Sample", &extensions);
|
|
|
|
for (int i = 0; i < extensions.size(); i++)
|
|
|
|
file->add_filter("*." + extensions[i]);
|
2015-06-06 12:44:38 +00:00
|
|
|
file->set_mode(EditorFileDialog::MODE_OPEN_FILES);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tree = memnew(Tree);
|
2017-04-06 17:00:19 +00:00
|
|
|
tree->set_columns(7);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(tree);
|
2017-03-18 23:36:26 +00:00
|
|
|
tree->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 5);
|
|
|
|
tree->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 5);
|
|
|
|
tree->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 30);
|
|
|
|
tree->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 5);
|
2014-02-10 01:10:30 +00:00
|
|
|
tree->set_column_titles_visible(true);
|
2017-03-18 23:36:26 +00:00
|
|
|
tree->set_column_title(0, TTR("Name"));
|
|
|
|
tree->set_column_title(1, TTR("Preview"));
|
|
|
|
tree->set_column_title(2, TTR("Format"));
|
|
|
|
tree->set_column_title(3, "dB");
|
|
|
|
tree->set_column_title(4, TTR("Pitch"));
|
2017-04-06 17:00:19 +00:00
|
|
|
tree->set_column_title(5, TTR("Priority"));
|
|
|
|
tree->set_column_title(6, "");
|
2017-03-18 23:36:26 +00:00
|
|
|
|
|
|
|
tree->set_column_min_width(1, 150);
|
|
|
|
tree->set_column_min_width(2, 100);
|
|
|
|
tree->set_column_min_width(3, 50);
|
|
|
|
tree->set_column_min_width(4, 50);
|
2017-04-06 17:00:19 +00:00
|
|
|
tree->set_column_min_width(5, 60);
|
|
|
|
tree->set_column_min_width(6, 32);
|
2017-03-18 23:36:26 +00:00
|
|
|
tree->set_column_expand(1, false);
|
|
|
|
tree->set_column_expand(2, false);
|
|
|
|
tree->set_column_expand(3, false);
|
|
|
|
tree->set_column_expand(4, false);
|
|
|
|
tree->set_column_expand(5, false);
|
2017-04-06 17:00:19 +00:00
|
|
|
tree->set_column_expand(6, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-15 02:48:23 +00:00
|
|
|
tree->set_drag_forwarding(this);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
dialog = memnew(ConfirmationDialog);
|
|
|
|
add_child(dialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tree->connect("button_pressed", this, "_button_pressed");
|
|
|
|
load->connect("pressed", this, "_load_pressed");
|
|
|
|
file->connect("files_selected", this, "_file_load_request");
|
|
|
|
tree->connect("item_edited", this, "_item_edited");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-03 17:52:07 +00:00
|
|
|
is_playing = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SampleLibraryEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
|
|
|
sample_library_editor->set_undo_redo(&get_undo_redo());
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleLibrary *s = p_object->cast_to<SampleLibrary>();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sample_library_editor->edit(Ref<SampleLibrary>(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleLibraryEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
|
|
|
return p_object->is_type("SampleLibrary");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleLibraryEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
2016-01-17 23:03:57 +00:00
|
|
|
//sample_library_editor->show();
|
|
|
|
button->show();
|
|
|
|
editor->make_bottom_panel_item_visible(sample_library_editor);
|
2017-03-18 23:36:26 +00:00
|
|
|
// sample_library_editor->set_process(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2016-01-17 23:03:57 +00:00
|
|
|
if (sample_library_editor->is_visible())
|
|
|
|
editor->hide_bottom_panel();
|
|
|
|
button->hide();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// sample_library_editor->set_process(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SampleLibraryEditorPlugin::SampleLibraryEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor = p_node;
|
|
|
|
sample_library_editor = memnew(SampleLibraryEditor);
|
2016-01-17 23:03:57 +00:00
|
|
|
|
|
|
|
//editor->get_viewport()->add_child(sample_library_editor);
|
2017-03-18 23:36:26 +00:00
|
|
|
sample_library_editor->set_custom_minimum_size(Size2(0, 250));
|
|
|
|
button = p_node->add_bottom_panel_item("SampleLibrary", sample_library_editor);
|
2016-01-17 23:03:57 +00:00
|
|
|
button->hide();
|
|
|
|
|
|
|
|
//sample_library_editor->set_area_as_parent_rect();
|
2017-03-18 23:36:26 +00:00
|
|
|
// sample_library_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END);
|
|
|
|
// sample_library_editor->set_margin( MARGIN_TOP, 120 );
|
2016-01-17 23:03:57 +00:00
|
|
|
//sample_library_editor->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SampleLibraryEditorPlugin::~SampleLibraryEditorPlugin() {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|