--- gigedit/trunk/src/gigedit/mainwindow.cpp 2014/06/07 22:34:31 2604
+++ gigedit/trunk/src/gigedit/mainwindow.cpp 2014/06/11 21:22:24 2625
@@ -46,6 +46,8 @@
#include "Settings.h"
#include "CombineInstrumentsDialog.h"
#include "scripteditor.h"
+#include "scriptslots.h"
+#include "ReferencesView.h"
#include "../../gfx/status_attached.xpm"
#include "../../gfx/status_detached.xpm"
@@ -134,14 +136,29 @@
sigc::mem_fun(
*this, &MainWindow::show_instr_props));
actionGroup->add(Gtk::Action::create("MidiRules",
- _("_Midi Rules")),
+ _("_Midi Rules...")),
sigc::mem_fun(
*this, &MainWindow::show_midi_rules));
+ actionGroup->add(Gtk::Action::create("ScriptSlots",
+ _("_Script Slots...")),
+ sigc::mem_fun(
+ *this, &MainWindow::show_script_slots));
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
sigc::mem_fun(
*this, &MainWindow::on_action_quit));
- actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
-
+ actionGroup->add(
+ Gtk::Action::create("MenuSample", _("_Sample")),
+ sigc::mem_fun(*this, &MainWindow::show_samples_tab)
+ );
+ actionGroup->add(
+ Gtk::Action::create("MenuInstrument", _("_Instrument")),
+ sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
+ );
+ actionGroup->add(
+ Gtk::Action::create("MenuScript", _("S_cript")),
+ sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
+ );
+ actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
@@ -231,6 +248,10 @@
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
);
actionGroup->add(
+ Gtk::Action::create("ShowSampleRefs", _("Show References...")),
+ sigc::mem_fun(*this, &MainWindow::on_action_view_references)
+ );
+ actionGroup->add(
Gtk::Action::create("ReplaceAllSamplesInAllGroups",
_("Replace All Samples in All Groups...")),
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
@@ -277,7 +298,33 @@
" "
" "
" "
+ "
"
" "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
" "
" "
" "
@@ -296,6 +343,7 @@
" "
" "
" "
+ " "
" "
" "
" "
@@ -305,6 +353,7 @@
" "
" "
" "
+ " "
" "
" "
" "
@@ -358,7 +407,7 @@
instrument_menu = static_cast(
- uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
+ uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
@@ -398,8 +447,25 @@
m_TreeViewSamples.set_model(m_refSamplesTreeModel);
m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
// m_TreeViewSamples.set_reorderable();
- m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
- m_TreeViewSamples.set_headers_visible(false);
+ m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
+ m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
+ {
+ Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
+ Gtk::CellRendererText* cellrenderer =
+ dynamic_cast(column->get_first_cell_renderer());
+ column->add_attribute(
+ cellrenderer->property_foreground(), m_SamplesModel.m_color
+ );
+ }
+ {
+ Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
+ Gtk::CellRendererText* cellrenderer =
+ dynamic_cast(column->get_first_cell_renderer());
+ column->add_attribute(
+ cellrenderer->property_foreground(), m_SamplesModel.m_color
+ );
+ }
+ m_TreeViewSamples.set_headers_visible(true);
m_TreeViewSamples.signal_button_press_event().connect_notify(
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
);
@@ -424,6 +490,17 @@
sigc::mem_fun(*this, &MainWindow::script_name_changed)
);
+ // establish drag&drop between scripts tree view and ScriptSlots window
+ std::vector drag_target_gig_script;
+ drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
+ m_TreeViewScripts.drag_source_set(drag_target_gig_script);
+ m_TreeViewScripts.signal_drag_begin().connect(
+ sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
+ );
+ m_TreeViewScripts.signal_drag_data_get().connect(
+ sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
+ );
+
// establish drag&drop between samples tree view and dimension region 'Sample' text entry
std::vector drag_target_gig_sample;
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
@@ -457,6 +534,12 @@
dimreg_changed_signal.make_slot());
dimreg_edit.signal_sample_ref_changed().connect(
sample_ref_changed_signal.make_slot());
+ sample_ref_changed_signal.connect(
+ sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
+ );
+ samples_to_be_removed_signal.connect(
+ sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
+ );
m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
sigc::hide(
@@ -680,6 +763,7 @@
// clear the samples and instruments tree views
m_refTreeModel->clear();
m_refSamplesTreeModel->clear();
+ m_refScriptsTreeModel->clear();
// remove all entries from "Instrument" menu
while (!instrument_menu->get_children().empty()) {
remove_instrument_from_menu(0);
@@ -694,6 +778,7 @@
// clear the samples and instruments tree views
m_refTreeModel->clear();
m_refSamplesTreeModel->clear();
+ m_refScriptsTreeModel->clear();
// remove all entries from "Instrument" menu
while (!instrument_menu->get_children().empty()) {
remove_instrument_from_menu(0);
@@ -1341,6 +1426,27 @@
}
}
+void MainWindow::updateSampleRefCountMap(gig::File* gig) {
+ sample_ref_count.clear();
+
+ if (!gig) return;
+
+ for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
+ instrument = gig->GetNextInstrument())
+ {
+ for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
+ rgn = instrument->GetNextRegion())
+ {
+ for (int i = 0; i < 256; ++i) {
+ if (!rgn->pDimensionRegions[i]) continue;
+ if (rgn->pDimensionRegions[i]->pSample) {
+ sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
+ }
+ }
+ }
+ }
+}
+
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
{
file = 0;
@@ -1367,7 +1473,9 @@
add_instrument_to_menu(name);
}
instrument_name_connection.unblock();
- uiManager->get_widget("/MenuBar/MenuInstrument")->show();
+ uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
+
+ updateSampleRefCountMap(gig);
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
if (group->Name != "") {
@@ -1385,6 +1493,9 @@
gig_to_utf8(sample->pInfo->Name);
rowSample[m_SamplesModel.m_col_sample] = sample;
rowSample[m_SamplesModel.m_col_group] = NULL;
+ int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
+ rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
+ rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
}
}
}
@@ -1408,7 +1519,8 @@
rowScript[m_ScriptsModel.m_col_group] = NULL;
}
}
- // unfold all script groups by default
+ // unfold all sample groups & script groups by default
+ m_TreeViewSamples.expand_all();
m_TreeViewScripts.expand_all();
file = gig;
@@ -1478,6 +1590,22 @@
}
}
+void MainWindow::show_script_slots() {
+ if (!file) return;
+ // get selected instrument
+ Glib::RefPtr sel = m_TreeView.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (!it) return;
+ Gtk::TreeModel::Row row = *it;
+ gig::Instrument* instrument = row[m_Columns.m_col_instr];
+ if (!instrument) return;
+
+ ScriptSlots* window = new ScriptSlots;
+ window->setInstrument(instrument);
+ //window->reparent(*this);
+ window->show();
+}
+
void MainWindow::on_action_view_status_bar() {
Gtk::CheckMenuItem* item =
dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
@@ -1525,9 +1653,15 @@
show_instr_props();
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
// gig v2 files have no midi rules
+ const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
+ static_cast(
+ uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
+ bEnabled
+ );
static_cast(
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
- !(file->pVersion && file->pVersion->major == 2));
+ bEnabled
+ );
popup_menu->popup(button->button, button->time);
}
}
@@ -1561,16 +1695,31 @@
group_selected = row[m_SamplesModel.m_col_group];
sample_selected = row[m_SamplesModel.m_col_sample];
}
+
+
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
set_sensitive(group_selected || sample_selected);
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
set_sensitive(group_selected || sample_selected);
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
set_sensitive(file);
+ dynamic_cast(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
+ set_sensitive(sample_selected);
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
set_sensitive(group_selected || sample_selected);
// show sample popup
sample_popup->popup(button->button, button->time);
+
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
+ set_sensitive(group_selected || sample_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
+ set_sensitive(group_selected || sample_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
+ set_sensitive(file);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
+ set_sensitive(sample_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
+ set_sensitive(group_selected || sample_selected);
}
}
@@ -1598,6 +1747,15 @@
set_sensitive(group_selected || script_selected);
// show sample popup
script_popup->popup(button->button, button->time);
+
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
+ set_sensitive(group_selected || script_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
+ set_sensitive(file);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
+ set_sensitive(script_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
+ set_sensitive(group_selected || script_selected);
}
}
@@ -2228,6 +2386,32 @@
}
}
+// see comment on on_sample_treeview_drag_begin()
+void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr& context)
+{
+ first_call_to_drag_data_get = true;
+}
+
+void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr&,
+ Gtk::SelectionData& selection_data, guint, guint)
+{
+ if (!first_call_to_drag_data_get) return;
+ first_call_to_drag_data_get = false;
+
+ // get selected script
+ gig::Script* script = NULL;
+ Glib::RefPtr sel = m_TreeViewScripts.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (it) {
+ Gtk::TreeModel::Row row = *it;
+ script = row[m_ScriptsModel.m_col_script];
+ }
+ // pass the gig::Script as pointer
+ selection_data.set(selection_data.get_target(), 0/*unused*/,
+ (const guchar*)&script,
+ sizeof(script)/*length of data in bytes*/);
+}
+
// For some reason drag_data_get gets called two times for each
// drag'n'drop (at least when target is an Entry). This work-around
// makes sure the code in drag_data_get and drop_drag_data_received is
@@ -2425,6 +2609,22 @@
delete d;
}
+void MainWindow::on_action_view_references() {
+ Glib::RefPtr sel = m_TreeViewSamples.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (!it) return;
+ Gtk::TreeModel::Row row = *it;
+ gig::Sample* sample = row[m_SamplesModel.m_col_sample];
+ if (!sample) return;
+
+ ReferencesView* d = new ReferencesView(*this);
+ d->setSample(sample);
+ d->show_all();
+ d->resize(500, 400);
+ d->run();
+ delete d;
+}
+
void MainWindow::mergeFiles(const std::vector& filenames) {
struct _Source {
std::vector riffs;
@@ -2585,6 +2785,50 @@
}
}
+void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
+ if (!sample) return;
+ sample_ref_count[sample] += offset;
+ const int refcount = sample_ref_count[sample];
+
+ Glib::RefPtr model = m_TreeViewSamples.get_model();
+ for (int g = 0; g < model->children().size(); ++g) {
+ Gtk::TreeModel::Row rowGroup = model->children()[g];
+ for (int s = 0; s < rowGroup.children().size(); ++s) {
+ Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
+ if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
+ rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
+ rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
+ }
+ }
+}
+
+void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
+ on_sample_ref_count_incremented(oldSample, -1);
+ on_sample_ref_count_incremented(newSample, +1);
+}
+
+void MainWindow::on_samples_to_be_removed(std::list samples) {
+ // just in case a new sample is added later with exactly the same memory
+ // address, which would lead to incorrect refcount if not deleted here
+ for (std::list::const_iterator it = samples.begin();
+ it != samples.end(); it != samples.end())
+ {
+ sample_ref_count.erase(*it);
+ }
+}
+
+void MainWindow::show_samples_tab() {
+ m_TreeViewNotebook.set_current_page(0);
+}
+
+void MainWindow::show_intruments_tab() {
+ m_TreeViewNotebook.set_current_page(1);
+}
+
+void MainWindow::show_scripts_tab() {
+ m_TreeViewNotebook.set_current_page(2);
+}
+
sigc::signal& MainWindow::signal_file_structure_to_be_changed() {
return file_structure_to_be_changed_signal;
}