--- gigedit/trunk/src/gigedit/mainwindow.cpp 2014/06/08 19:09:26 2610
+++ gigedit/trunk/src/gigedit/mainwindow.cpp 2014/07/05 19:43:14 2664
@@ -47,11 +47,13 @@
#include "CombineInstrumentsDialog.h"
#include "scripteditor.h"
#include "scriptslots.h"
+#include "ReferencesView.h"
#include "../../gfx/status_attached.xpm"
#include "../../gfx/status_detached.xpm"
MainWindow::MainWindow() :
+ m_DimRegionChooser(*this),
dimreg_label(_("Changes apply to:")),
dimreg_all_regions(_("all regions")),
dimreg_all_dimregs(_("all dimension splits")),
@@ -145,8 +147,19 @@
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")));
@@ -236,6 +249,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)
@@ -282,7 +299,33 @@
" "
" "
" "
+ "
"
" "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
" "
" "
" "
@@ -311,6 +354,7 @@
" "
" "
" "
+ " "
" "
" "
" "
@@ -364,7 +408,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);
@@ -404,8 +448,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());
+ 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());
+ 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)
);
@@ -417,6 +478,8 @@
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
m_TreeViewScripts.set_model(m_refScriptsTreeModel);
m_TreeViewScripts.set_tooltip_text(_(
+ "Use CTRL + double click for editing a script."
+ "\n\n"
"Note: instrument scripts are a LinuxSampler extension of the gig "
"format. This feature will not work with the GigaStudio software!"
));
@@ -426,6 +489,10 @@
m_TreeViewScripts.signal_button_press_event().connect_notify(
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
);
+ //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?
+ m_TreeViewScripts.signal_row_activated().connect(
+ sigc::mem_fun(*this, &MainWindow::script_double_clicked)
+ );
m_refScriptsTreeModel->signal_row_changed().connect(
sigc::mem_fun(*this, &MainWindow::script_name_changed)
);
@@ -474,6 +541,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(
@@ -599,7 +672,7 @@
void MainWindow::dimreg_changed()
{
update_dimregs();
- dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());
+ dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
}
void MainWindow::on_sel_change()
@@ -697,6 +770,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);
@@ -711,6 +785,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);
@@ -827,7 +902,28 @@
// load the instrument
gig::File* pFile = (gig::File*) instr->GetParent();
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
- //TODO: automatically select the given instrument
+ // automatically select the given instrument
+ int i = 0;
+ for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
+ instrument = pFile->GetNextInstrument(), ++i)
+ {
+ if (instrument == instr) {
+ // select item in "instruments" tree view
+ m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
+ // make sure the selected item in the "instruments" tree view is
+ // visible (scroll to it)
+ m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
+ // select item in instrument menu
+ {
+ const std::vector children =
+ instrument_menu->get_children();
+ static_cast(children[i])->set_active();
+ }
+ // update region chooser and dimension region chooser
+ m_RegionChooser.set_instrument(instr);
+ break;
+ }
+ }
}
void MainWindow::on_loader_progress()
@@ -1108,8 +1204,8 @@
_(
"Gigedit is released under the GNU General Public License.\n"
"\n"
- "Please notice that this is still a very young instrument editor. "
- "So better backup your Gigasampler files before editing them with "
+ "This program is distributed WITHOUT ANY WARRANTY; So better "
+ "backup your Gigasampler/GigaStudio files before editing them with "
"this application.\n"
"\n"
"Please report bugs to: http://bugs.linuxsampler.org"
@@ -1358,6 +1454,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;
@@ -1384,7 +1501,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 != "") {
@@ -1402,6 +1521,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";
}
}
}
@@ -1425,7 +1547,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;
@@ -1558,9 +1681,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);
}
}
@@ -1594,16 +1723,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);
}
}
@@ -1631,6 +1775,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);
}
}
@@ -2438,6 +2591,21 @@
}
}
+void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
+ Gtk::TreeViewColumn* column)
+{
+ Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
+ if (!iter) return;
+ Gtk::TreeModel::Row row = *iter;
+ gig::Script* script = row[m_ScriptsModel.m_col_script];
+ if (!script) return;
+
+ ScriptEditor* editor = new ScriptEditor;
+ editor->setScript(script);
+ //editor->reparent(*this);
+ editor->show();
+}
+
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
const Gtk::TreeModel::iterator& iter) {
if (!iter) return;
@@ -2484,6 +2652,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;
@@ -2644,6 +2828,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;
}