Add stop and delete buttons to sample library
Based on the work by @rdcklinux in #3339. The play button becomes a stop button while playing. A delete button is added in the last column.
This commit is contained in:
parent
be4d58e120
commit
533b9b7342
|
@ -35,7 +35,6 @@
|
||||||
#include "sample_editor_plugin.h"
|
#include "sample_editor_plugin.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SampleLibraryEditor::_input_event(InputEvent p_event) {
|
void SampleLibraryEditor::_input_event(InputEvent p_event) {
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,8 +42,13 @@ void SampleLibraryEditor::_input_event(InputEvent p_event) {
|
||||||
|
|
||||||
void SampleLibraryEditor::_notification(int p_what) {
|
void SampleLibraryEditor::_notification(int p_what) {
|
||||||
|
|
||||||
if (p_what==NOTIFICATION_FIXED_PROCESS) {
|
if (p_what==NOTIFICATION_PROCESS) {
|
||||||
|
if (is_playing && !player->is_active()) {
|
||||||
|
TreeItem *tl=last_sample_playing->cast_to<TreeItem>();
|
||||||
|
tl->set_button(0,0,get_icon("Play","EditorIcons"));
|
||||||
|
is_playing = false;
|
||||||
|
set_process(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||||
|
@ -128,13 +132,36 @@ void SampleLibraryEditor::_button_pressed(Object *p_item,int p_column, int p_id)
|
||||||
TreeItem *ti=p_item->cast_to<TreeItem>();
|
TreeItem *ti=p_item->cast_to<TreeItem>();
|
||||||
String name = ti->get_text(0);
|
String name = ti->get_text(0);
|
||||||
|
|
||||||
if (p_column==0) {
|
if (p_column==0) { // Play/Stop
|
||||||
|
|
||||||
player->play(name,true);
|
String btn_type;
|
||||||
} else if (p_column==1) {
|
if(!is_playing) {
|
||||||
|
is_playing = true;
|
||||||
|
btn_type = "Stop";
|
||||||
|
player->play(name,true);
|
||||||
|
last_sample_playing = p_item;
|
||||||
|
set_process(true);
|
||||||
|
} else {
|
||||||
|
_stop_pressed();
|
||||||
|
if(last_sample_playing != p_item){
|
||||||
|
TreeItem *tl=last_sample_playing->cast_to<TreeItem>();
|
||||||
|
tl->set_button(p_column,0,get_icon("Play","EditorIcons"));
|
||||||
|
btn_type = "Stop";
|
||||||
|
player->play(name,true);
|
||||||
|
last_sample_playing = p_item;
|
||||||
|
} else {
|
||||||
|
btn_type = "Play";
|
||||||
|
is_playing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ti->set_button(p_column,0,get_icon(btn_type,"EditorIcons"));
|
||||||
|
} else if (p_column==1) { // Edit
|
||||||
|
|
||||||
get_tree()->get_root()->get_child(0)->call("_resource_selected",sample_library->get_sample(name));
|
get_tree()->get_root()->get_child(0)->call("_resource_selected",sample_library->get_sample(name));
|
||||||
|
} else if (p_column==5) { // Delete
|
||||||
|
|
||||||
|
ti->select(0);
|
||||||
|
_delete_pressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,7 +178,7 @@ void SampleLibraryEditor::_item_edited() {
|
||||||
|
|
||||||
TreeItem *s = tree->get_selected();
|
TreeItem *s = tree->get_selected();
|
||||||
|
|
||||||
if (tree->get_selected_column()==0) {
|
if (tree->get_selected_column()==0) { // Name
|
||||||
// renamed
|
// renamed
|
||||||
String old_name=s->get_metadata(0);
|
String old_name=s->get_metadata(0);
|
||||||
String new_name=s->get_text(0);
|
String new_name=s->get_text(0);
|
||||||
|
@ -174,23 +201,16 @@ void SampleLibraryEditor::_item_edited() {
|
||||||
undo_redo->add_undo_method(this,"_update_library");
|
undo_redo->add_undo_method(this,"_update_library");
|
||||||
undo_redo->commit_action();
|
undo_redo->commit_action();
|
||||||
|
|
||||||
} else if (tree->get_selected_column()==3) {
|
} else if (tree->get_selected_column()==3) { // Volume dB
|
||||||
|
|
||||||
StringName n = s->get_text(0);
|
StringName n = s->get_text(0);
|
||||||
sample_library->sample_set_volume_db(n,s->get_range(3));
|
sample_library->sample_set_volume_db(n,s->get_range(3));
|
||||||
|
|
||||||
} else if (tree->get_selected_column()==4) {
|
} else if (tree->get_selected_column()==4) { // Pitch scale
|
||||||
|
|
||||||
StringName n = s->get_text(0);
|
StringName n = s->get_text(0);
|
||||||
sample_library->sample_set_pitch_scale(n,s->get_range(4));
|
sample_library->sample_set_pitch_scale(n,s->get_range(4));
|
||||||
|
|
||||||
} else if (tree->get_selected_column()==5) {
|
|
||||||
|
|
||||||
//edit
|
|
||||||
|
|
||||||
Ref<Sample> samp = sample_library->get_sample(tree->get_selected()->get_metadata(0));
|
|
||||||
|
|
||||||
get_tree()->get_root()->get_child(0)->call("_resource_selected",samp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,16 +264,18 @@ void SampleLibraryEditor::_update_library() {
|
||||||
for(List<StringName>::Element *E=names.front();E;E=E->next()) {
|
for(List<StringName>::Element *E=names.front();E;E=E->next()) {
|
||||||
|
|
||||||
TreeItem *ti = tree->create_item(root);
|
TreeItem *ti = tree->create_item(root);
|
||||||
|
|
||||||
|
// Name + Play/Stop
|
||||||
ti->set_cell_mode(0,TreeItem::CELL_MODE_STRING);
|
ti->set_cell_mode(0,TreeItem::CELL_MODE_STRING);
|
||||||
ti->set_editable(0,true);
|
ti->set_editable(0,true);
|
||||||
ti->set_selectable(0,true);
|
ti->set_selectable(0,true);
|
||||||
ti->set_text(0,E->get());
|
ti->set_text(0,E->get());
|
||||||
ti->set_metadata(0,E->get());
|
ti->set_metadata(0,E->get());
|
||||||
ti->add_button(0,get_icon("Play","EditorIcons"),0);
|
ti->add_button(0,get_icon("Play","EditorIcons"));
|
||||||
ti->add_button(1,get_icon("Edit","EditorIcons"),1);
|
|
||||||
|
|
||||||
Ref<Sample> smp = sample_library->get_sample(E->get());
|
Ref<Sample> smp = sample_library->get_sample(E->get());
|
||||||
|
|
||||||
|
// Preview/edit
|
||||||
Ref<ImageTexture> preview( memnew( ImageTexture ));
|
Ref<ImageTexture> preview( memnew( ImageTexture ));
|
||||||
preview->create(128,16,Image::FORMAT_RGB);
|
preview->create(128,16,Image::FORMAT_RGB);
|
||||||
SampleEditor::generate_preview_texture(smp,preview);
|
SampleEditor::generate_preview_texture(smp,preview);
|
||||||
|
@ -261,30 +283,32 @@ void SampleLibraryEditor::_update_library() {
|
||||||
ti->set_selectable(1,false);
|
ti->set_selectable(1,false);
|
||||||
ti->set_editable(1,false);
|
ti->set_editable(1,false);
|
||||||
ti->set_icon(1,preview);
|
ti->set_icon(1,preview);
|
||||||
|
ti->add_button(1,get_icon("Edit","EditorIcons"));
|
||||||
|
|
||||||
|
// Format
|
||||||
ti->set_cell_mode(2,TreeItem::CELL_MODE_STRING);
|
ti->set_cell_mode(2,TreeItem::CELL_MODE_STRING);
|
||||||
ti->set_editable(2,false);
|
ti->set_editable(2,false);
|
||||||
ti->set_selectable(2,false);
|
ti->set_selectable(2,false);
|
||||||
Ref<Sample> s = sample_library->get_sample(E->get());
|
ti->set_text(2,String()+/*itos(smp->get_length())+" frames ("+String::num(smp->get_length()/(float)smp->get_mix_rate(),2)+" smp), "+*/(smp->get_format()==Sample::FORMAT_PCM16?"16 Bits, ":(smp->get_format()==Sample::FORMAT_PCM8?"8 bits, ":"IMA-ADPCM,"))+(smp->is_stereo()?"Stereo":"Mono"));
|
||||||
ti->set_text(2,String()+/*itos(s->get_length())+" frames ("+String::num(s->get_length()/(float)s->get_mix_rate(),2)+" s), "+*/(s->get_format()==Sample::FORMAT_PCM16?"16 Bits, ":(s->get_format()==Sample::FORMAT_PCM8?"8 bits, ":"IMA-ADPCM,"))+(s->is_stereo()?"Stereo":"Mono"));
|
|
||||||
|
|
||||||
|
// Volume dB
|
||||||
ti->set_cell_mode(3,TreeItem::CELL_MODE_RANGE);
|
ti->set_cell_mode(3,TreeItem::CELL_MODE_RANGE);
|
||||||
ti->set_range_config(3,-60,24,0.01);
|
ti->set_range_config(3,-60,24,0.01);
|
||||||
ti->set_selectable(3,true);
|
ti->set_selectable(3,true);
|
||||||
ti->set_editable(3,true);
|
ti->set_editable(3,true);
|
||||||
ti->set_range(3,sample_library->sample_get_volume_db(E->get()));
|
ti->set_range(3,sample_library->sample_get_volume_db(E->get()));
|
||||||
|
|
||||||
|
// Pitch scale
|
||||||
ti->set_cell_mode(4,TreeItem::CELL_MODE_RANGE);
|
ti->set_cell_mode(4,TreeItem::CELL_MODE_RANGE);
|
||||||
ti->set_range_config(4,0.01,100,0.01);
|
ti->set_range_config(4,0.01,100,0.01);
|
||||||
ti->set_selectable(4,true);
|
ti->set_selectable(4,true);
|
||||||
ti->set_editable(4,true);
|
ti->set_editable(4,true);
|
||||||
ti->set_range(4,sample_library->sample_get_pitch_scale(E->get()));
|
ti->set_range(4,sample_library->sample_get_pitch_scale(E->get()));
|
||||||
|
|
||||||
//ti->set_cell_mode(5,TreeItem::CELL_MODE_CUSTOM);
|
// Delete
|
||||||
//ti->set_text(5,"Edit..");
|
ti->set_cell_mode(5,TreeItem::CELL_MODE_STRING);
|
||||||
//ti->set_selectable(5,true);
|
ti->add_button(5,get_icon("Remove","EditorIcons"));
|
||||||
//ti->set_editable(5,true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//player->add_sample("default",sample);
|
//player->add_sample("default",sample);
|
||||||
|
@ -303,7 +327,6 @@ void SampleLibraryEditor::edit(Ref<SampleLibrary> p_sample_library) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
hide();
|
hide();
|
||||||
set_fixed_process(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -367,7 +390,7 @@ SampleLibraryEditor::SampleLibraryEditor() {
|
||||||
add_child(_delete);
|
add_child(_delete);
|
||||||
|
|
||||||
tree = memnew( Tree );
|
tree = memnew( Tree );
|
||||||
tree->set_columns(5);
|
tree->set_columns(6);
|
||||||
add_child(tree);
|
add_child(tree);
|
||||||
tree->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5);
|
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_RIGHT,ANCHOR_END,5);
|
||||||
|
@ -375,19 +398,22 @@ SampleLibraryEditor::SampleLibraryEditor() {
|
||||||
tree->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,5);
|
tree->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,5);
|
||||||
tree->set_column_titles_visible(true);
|
tree->set_column_titles_visible(true);
|
||||||
tree->set_column_title(0,"Name");
|
tree->set_column_title(0,"Name");
|
||||||
|
|
||||||
tree->set_column_title(1,"Preview");
|
tree->set_column_title(1,"Preview");
|
||||||
tree->set_column_title(2,"Format");
|
tree->set_column_title(2,"Format");
|
||||||
tree->set_column_title(3,"dB");
|
tree->set_column_title(3,"dB");
|
||||||
tree->set_column_title(4,"PScale");
|
tree->set_column_title(4,"Pitch");
|
||||||
|
tree->set_column_title(5,"");
|
||||||
|
|
||||||
tree->set_column_min_width(1,150);
|
tree->set_column_min_width(1,150);
|
||||||
tree->set_column_min_width(2,100);
|
tree->set_column_min_width(2,100);
|
||||||
tree->set_column_min_width(3,50);
|
tree->set_column_min_width(3,50);
|
||||||
tree->set_column_min_width(4,50);
|
tree->set_column_min_width(4,50);
|
||||||
|
tree->set_column_min_width(5,32);
|
||||||
tree->set_column_expand(1,false);
|
tree->set_column_expand(1,false);
|
||||||
tree->set_column_expand(2,false);
|
tree->set_column_expand(2,false);
|
||||||
tree->set_column_expand(3,false);
|
tree->set_column_expand(3,false);
|
||||||
tree->set_column_expand(4,false);
|
tree->set_column_expand(4,false);
|
||||||
|
tree->set_column_expand(5,false);
|
||||||
|
|
||||||
dialog = memnew( ConfirmationDialog );
|
dialog = memnew( ConfirmationDialog );
|
||||||
add_child( dialog );
|
add_child( dialog );
|
||||||
|
@ -461,5 +487,3 @@ SampleLibraryEditorPlugin::SampleLibraryEditorPlugin(EditorNode *p_node) {
|
||||||
SampleLibraryEditorPlugin::~SampleLibraryEditorPlugin()
|
SampleLibraryEditorPlugin::~SampleLibraryEditorPlugin()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ class SampleLibraryEditor : public Panel {
|
||||||
Button *load;
|
Button *load;
|
||||||
Button *_delete;
|
Button *_delete;
|
||||||
Tree *tree;
|
Tree *tree;
|
||||||
|
bool is_playing;
|
||||||
|
Object *last_sample_playing;
|
||||||
|
|
||||||
EditorFileDialog *file;
|
EditorFileDialog *file;
|
||||||
|
|
||||||
|
@ -79,7 +81,6 @@ protected:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; }
|
void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; }
|
||||||
|
|
||||||
void edit(Ref<SampleLibrary> p_sample);
|
void edit(Ref<SampleLibrary> p_sample);
|
||||||
SampleLibraryEditor();
|
SampleLibraryEditor();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue