186 |
actionGroup->add(toggle_action, |
actionGroup->add(toggle_action, |
187 |
sigc::mem_fun( |
sigc::mem_fun( |
188 |
*this, &MainWindow::on_action_view_status_bar)); |
*this, &MainWindow::on_action_view_status_bar)); |
189 |
|
actionGroup->add( |
190 |
|
Gtk::Action::create("RefreshAll", _("_Refresh All")), |
191 |
|
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
192 |
|
); |
193 |
|
|
194 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
195 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
actionGroup->add(Gtk::Action::create("MenuHelp", |
261 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
262 |
); |
); |
263 |
actionGroup->add( |
actionGroup->add( |
264 |
|
Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")), |
265 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) |
266 |
|
); |
267 |
|
actionGroup->add( |
268 |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
269 |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
270 |
); |
); |
271 |
actionGroup->add( |
actionGroup->add( |
272 |
|
Gtk::Action::create("ReplaceSample", |
273 |
|
_("Replace Sample...")), |
274 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_sample) |
275 |
|
); |
276 |
|
actionGroup->add( |
277 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
278 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
279 |
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
325 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
326 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
327 |
" <menuitem action='ShowSampleRefs'/>" |
" <menuitem action='ShowSampleRefs'/>" |
328 |
|
" <menuitem action='ReplaceSample' />" |
329 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
330 |
" <separator/>" |
" <separator/>" |
331 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
332 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
333 |
" </menu>" |
" </menu>" |
334 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
335 |
" <menu action='AllInstruments'>" |
" <menu action='AllInstruments'>" |
352 |
" </menu>" |
" </menu>" |
353 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
354 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
355 |
|
" <separator/>" |
356 |
|
" <menuitem action='RefreshAll'/>" |
357 |
" </menu>" |
" </menu>" |
358 |
" <menu action='MenuTools'>" |
" <menu action='MenuTools'>" |
359 |
" <menuitem action='CombineInstruments'/>" |
" <menuitem action='CombineInstruments'/>" |
381 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
382 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
383 |
" <menuitem action='ShowSampleRefs'/>" |
" <menuitem action='ShowSampleRefs'/>" |
384 |
|
" <menuitem action='ReplaceSample' />" |
385 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
386 |
" <separator/>" |
" <separator/>" |
387 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
388 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
389 |
" </popup>" |
" </popup>" |
390 |
" <popup name='ScriptPopupMenu'>" |
" <popup name='ScriptPopupMenu'>" |
391 |
" <menuitem action='AddScriptGroup'/>" |
" <menuitem action='AddScriptGroup'/>" |
430 |
} |
} |
431 |
{ |
{ |
432 |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
433 |
|
uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples")); |
434 |
|
item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones).")); |
435 |
|
// copy tooltip to popup menu |
436 |
|
Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>( |
437 |
|
uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples")); |
438 |
|
item2->set_tooltip_text(item->get_tooltip_text()); |
439 |
|
} |
440 |
|
{ |
441 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
442 |
|
uiManager->get_widget("/MenuBar/MenuView/RefreshAll")); |
443 |
|
item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface.")); |
444 |
|
} |
445 |
|
{ |
446 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
447 |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
448 |
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
449 |
} |
} |
1715 |
file = 0; |
file = 0; |
1716 |
set_file_is_shared(isSharedInstrument); |
set_file_is_shared(isSharedInstrument); |
1717 |
|
|
1718 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = |
1719 |
|
(filename && strlen(filename) > 0) ? |
1720 |
|
filename : (!gig->GetFileName().empty()) ? |
1721 |
|
gig->GetFileName() : _("Unsaved Gig File"); |
1722 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1723 |
file_has_name = filename; |
file_has_name = filename; |
1724 |
file_is_changed = false; |
file_is_changed = false; |
1872 |
window->show(); |
window->show(); |
1873 |
} |
} |
1874 |
|
|
1875 |
|
void MainWindow::on_action_refresh_all() { |
1876 |
|
__refreshEntireGUI(); |
1877 |
|
} |
1878 |
|
|
1879 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1880 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1881 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
2374 |
file_changed(); |
file_changed(); |
2375 |
} |
} |
2376 |
|
|
2377 |
|
void MainWindow::on_action_replace_sample() { |
2378 |
|
add_or_replace_sample(true); |
2379 |
|
} |
2380 |
|
|
2381 |
void MainWindow::on_action_add_sample() { |
void MainWindow::on_action_add_sample() { |
2382 |
|
add_or_replace_sample(false); |
2383 |
|
} |
2384 |
|
|
2385 |
|
void MainWindow::add_or_replace_sample(bool replace) { |
2386 |
if (!file) return; |
if (!file) return; |
2387 |
// get selected group |
|
2388 |
|
// get selected group (and probably selected sample) |
2389 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2390 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
2391 |
if (!it) return; |
if (!it) return; |
2392 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2393 |
|
gig::Sample* sample = NULL; |
2394 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2395 |
if (!group) { // not a group, but a sample is selected (probably) |
if (!group) { // not a group, but a sample is selected (probably) |
2396 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
if (replace) sample = row[m_SamplesModel.m_col_sample]; |
2397 |
if (!sample) return; |
if (!row[m_SamplesModel.m_col_sample]) return; |
2398 |
it = row.parent(); // resolve parent (that is the sample's group) |
it = row.parent(); // resolve parent (that is the sample's group) |
2399 |
if (!it) return; |
if (!it) return; |
2400 |
row = *it; |
if (!replace) row = *it; |
2401 |
group = row[m_SamplesModel.m_col_group]; |
group = (*it)[m_SamplesModel.m_col_group]; |
2402 |
if (!group) return; |
if (!group) return; |
2403 |
} |
} |
2404 |
|
if (replace && !sample) return; |
2405 |
|
|
2406 |
// show 'browse for file' dialog |
// show 'browse for file' dialog |
2407 |
Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)")); |
Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); |
2408 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
2409 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
2410 |
dialog.set_select_multiple(true); |
dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample |
2411 |
|
|
2412 |
// matches all file types supported by libsndfile |
// matches all file types supported by libsndfile |
2413 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
2478 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
2479 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
2480 |
} |
} |
2481 |
// add a new sample to the .gig file |
// add a new sample to the .gig file (if adding is requested actually) |
2482 |
gig::Sample* sample = file->AddSample(); |
if (!replace) sample = file->AddSample(); |
2483 |
// file name without path |
// file name without path |
2484 |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
2485 |
// remove file extension if there is one |
// remove file extension if there is one |
2530 |
// physically when File::Save() is called) |
// physically when File::Save() is called) |
2531 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
2532 |
// make sure sample is part of the selected group |
// make sure sample is part of the selected group |
2533 |
group->AddSample(sample); |
if (!replace) group->AddSample(sample); |
2534 |
// schedule that physical resize and sample import |
// schedule that physical resize and sample import |
2535 |
// (data copying), performed when "Save" is requested |
// (data copying), performed when "Save" is requested |
2536 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2538 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2539 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue.push_back(sched_item); |
2540 |
// add sample to the tree view |
// add sample to the tree view |
2541 |
Gtk::TreeModel::iterator iterSample = |
if (replace) { |
2542 |
m_refSamplesTreeModel->append(row.children()); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
2543 |
Gtk::TreeModel::Row rowSample = *iterSample; |
} else { |
2544 |
rowSample[m_SamplesModel.m_col_name] = |
Gtk::TreeModel::iterator iterSample = |
2545 |
gig_to_utf8(sample->pInfo->Name); |
m_refSamplesTreeModel->append(row.children()); |
2546 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
2547 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_name] = |
2548 |
|
gig_to_utf8(sample->pInfo->Name); |
2549 |
|
rowSample[m_SamplesModel.m_col_sample] = sample; |
2550 |
|
rowSample[m_SamplesModel.m_col_group] = NULL; |
2551 |
|
} |
2552 |
// close sound file |
// close sound file |
2553 |
sf_close(hFile); |
sf_close(hFile); |
2554 |
file_changed(); |
file_changed(); |
2559 |
} |
} |
2560 |
// show error message box when some file(s) could not be opened / added |
// show error message box when some file(s) could not be opened / added |
2561 |
if (!error_files.empty()) { |
if (!error_files.empty()) { |
2562 |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
Glib::ustring txt = |
2563 |
|
(replace |
2564 |
|
? _("Failed to replace sample with:\n") |
2565 |
|
: _("Could not add the following sample(s):\n")) |
2566 |
|
+ error_files; |
2567 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2568 |
msg.run(); |
msg.run(); |
2569 |
} |
} |
2747 |
} |
} |
2748 |
} |
} |
2749 |
|
|
2750 |
|
void MainWindow::on_action_remove_unused_samples() { |
2751 |
|
if (!file) return; |
2752 |
|
|
2753 |
|
// collect all samples that are not referenced by any instrument |
2754 |
|
std::list<gig::Sample*> lsamples; |
2755 |
|
for (int iSample = 0; file->GetSample(iSample); ++iSample) { |
2756 |
|
gig::Sample* sample = file->GetSample(iSample); |
2757 |
|
bool isUsed = false; |
2758 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; |
2759 |
|
instrument = file->GetNextInstrument()) |
2760 |
|
{ |
2761 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
2762 |
|
rgn = instrument->GetNextRegion()) |
2763 |
|
{ |
2764 |
|
for (int i = 0; i < 256; ++i) { |
2765 |
|
if (!rgn->pDimensionRegions[i]) continue; |
2766 |
|
if (rgn->pDimensionRegions[i]->pSample != sample) continue; |
2767 |
|
isUsed = true; |
2768 |
|
goto endOfRefSearch; |
2769 |
|
} |
2770 |
|
} |
2771 |
|
} |
2772 |
|
endOfRefSearch: |
2773 |
|
if (!isUsed) lsamples.push_back(sample); |
2774 |
|
} |
2775 |
|
|
2776 |
|
if (lsamples.empty()) return; |
2777 |
|
|
2778 |
|
// notify everybody that we're going to remove these samples |
2779 |
|
samples_to_be_removed_signal.emit(lsamples); |
2780 |
|
|
2781 |
|
// remove collected samples |
2782 |
|
try { |
2783 |
|
for (std::list<gig::Sample*>::iterator itSample = lsamples.begin(); |
2784 |
|
itSample != lsamples.end(); ++itSample) |
2785 |
|
{ |
2786 |
|
gig::Sample* sample = *itSample; |
2787 |
|
// remove sample from the .gig file |
2788 |
|
file->DeleteSample(sample); |
2789 |
|
// if sample was just previously added, remove it fro the import queue |
2790 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
2791 |
|
iter != m_SampleImportQueue.end(); ++iter) |
2792 |
|
{ |
2793 |
|
if ((*iter).gig_sample == sample) { |
2794 |
|
printf("Removing previously added sample '%s'\n", |
2795 |
|
(*iter).sample_path.c_str()); |
2796 |
|
m_SampleImportQueue.erase(iter); |
2797 |
|
break; |
2798 |
|
} |
2799 |
|
} |
2800 |
|
} |
2801 |
|
} catch (RIFF::Exception e) { |
2802 |
|
// show error message |
2803 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2804 |
|
msg.run(); |
2805 |
|
} |
2806 |
|
|
2807 |
|
// notify everybody that we're done with removal |
2808 |
|
samples_removed_signal.emit(); |
2809 |
|
|
2810 |
|
dimreg_changed(); |
2811 |
|
file_changed(); |
2812 |
|
__refreshEntireGUI(); |
2813 |
|
} |
2814 |
|
|
2815 |
// see comment on on_sample_treeview_drag_begin() |
// see comment on on_sample_treeview_drag_begin() |
2816 |
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2817 |
{ |
{ |
3284 |
} |
} |
3285 |
|
|
3286 |
// update GUI |
// update GUI |
3287 |
__refreshEntireGUI(); |
__refreshEntireGUI(); |
3288 |
} |
} |
3289 |
} |
} |
3290 |
|
|