404 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
405 |
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_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.")); |
406 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
407 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
408 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); |
409 |
|
{ |
410 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
411 |
|
Gtk::CellRendererText* cellrenderer = |
412 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
413 |
|
column->add_attribute( |
414 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
415 |
|
); |
416 |
|
} |
417 |
|
{ |
418 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
419 |
|
Gtk::CellRendererText* cellrenderer = |
420 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
421 |
|
column->add_attribute( |
422 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
423 |
|
); |
424 |
|
} |
425 |
|
m_TreeViewSamples.set_headers_visible(true); |
426 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
427 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
428 |
); |
); |
491 |
dimreg_changed_signal.make_slot()); |
dimreg_changed_signal.make_slot()); |
492 |
dimreg_edit.signal_sample_ref_changed().connect( |
dimreg_edit.signal_sample_ref_changed().connect( |
493 |
sample_ref_changed_signal.make_slot()); |
sample_ref_changed_signal.make_slot()); |
494 |
|
sample_ref_changed_signal.connect( |
495 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) |
496 |
|
); |
497 |
|
samples_to_be_removed_signal.connect( |
498 |
|
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
499 |
|
); |
500 |
|
|
501 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
502 |
sigc::hide( |
sigc::hide( |
1383 |
} |
} |
1384 |
} |
} |
1385 |
|
|
1386 |
|
void MainWindow::updateSampleRefCountMap(gig::File* gig) { |
1387 |
|
sample_ref_count.clear(); |
1388 |
|
|
1389 |
|
if (!gig) return; |
1390 |
|
|
1391 |
|
for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; |
1392 |
|
instrument = gig->GetNextInstrument()) |
1393 |
|
{ |
1394 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
1395 |
|
rgn = instrument->GetNextRegion()) |
1396 |
|
{ |
1397 |
|
for (int i = 0; i < 256; ++i) { |
1398 |
|
if (!rgn->pDimensionRegions[i]) continue; |
1399 |
|
if (rgn->pDimensionRegions[i]->pSample) { |
1400 |
|
sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; |
1401 |
|
} |
1402 |
|
} |
1403 |
|
} |
1404 |
|
} |
1405 |
|
} |
1406 |
|
|
1407 |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1408 |
{ |
{ |
1409 |
file = 0; |
file = 0; |
1432 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1433 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
1434 |
|
|
1435 |
|
updateSampleRefCountMap(gig); |
1436 |
|
|
1437 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1438 |
if (group->Name != "") { |
if (group->Name != "") { |
1439 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1450 |
gig_to_utf8(sample->pInfo->Name); |
gig_to_utf8(sample->pInfo->Name); |
1451 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1452 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1453 |
|
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1454 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1455 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; |
1456 |
} |
} |
1457 |
} |
} |
1458 |
} |
} |
2695 |
} |
} |
2696 |
} |
} |
2697 |
|
|
2698 |
|
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
2699 |
|
if (!sample) return; |
2700 |
|
sample_ref_count[sample] += offset; |
2701 |
|
const int refcount = sample_ref_count[sample]; |
2702 |
|
|
2703 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2704 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2705 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2706 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2707 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2708 |
|
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
2709 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
2710 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; |
2711 |
|
} |
2712 |
|
} |
2713 |
|
} |
2714 |
|
|
2715 |
|
void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { |
2716 |
|
on_sample_ref_count_incremented(oldSample, -1); |
2717 |
|
on_sample_ref_count_incremented(newSample, +1); |
2718 |
|
} |
2719 |
|
|
2720 |
|
void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) { |
2721 |
|
// just in case a new sample is added later with exactly the same memory |
2722 |
|
// address, which would lead to incorrect refcount if not deleted here |
2723 |
|
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
2724 |
|
it != samples.end(); it != samples.end()) |
2725 |
|
{ |
2726 |
|
sample_ref_count.erase(*it); |
2727 |
|
} |
2728 |
|
} |
2729 |
|
|
2730 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
2731 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
2732 |
} |
} |