20 |
#include <iostream> |
#include <iostream> |
21 |
#include <cstring> |
#include <cstring> |
22 |
|
|
23 |
|
#include <glibmmconfig.h> |
24 |
|
// threads.h must be included first to be able to build with |
25 |
|
// G_DISABLE_DEPRECATED |
26 |
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ |
27 |
|
(GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 |
28 |
|
#include <glibmm/threads.h> |
29 |
|
#endif |
30 |
|
|
31 |
#include <glibmm/convert.h> |
#include <glibmm/convert.h> |
32 |
#include <glibmm/dispatcher.h> |
#include <glibmm/dispatcher.h> |
33 |
#include <glibmm/miscutils.h> |
#include <glibmm/miscutils.h> |
194 |
actionGroup->add(toggle_action, |
actionGroup->add(toggle_action, |
195 |
sigc::mem_fun( |
sigc::mem_fun( |
196 |
*this, &MainWindow::on_action_view_status_bar)); |
*this, &MainWindow::on_action_view_status_bar)); |
197 |
|
actionGroup->add( |
198 |
|
Gtk::Action::create("RefreshAll", _("_Refresh All")), |
199 |
|
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
200 |
|
); |
201 |
|
|
202 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
203 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
actionGroup->add(Gtk::Action::create("MenuHelp", |
237 |
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
238 |
); |
); |
239 |
|
|
240 |
|
toggle_action = |
241 |
|
Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved")); |
242 |
|
toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved); |
243 |
|
actionGroup->add( |
244 |
|
toggle_action, |
245 |
|
sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved) |
246 |
|
); |
247 |
|
|
248 |
|
|
249 |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
250 |
|
|
277 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
278 |
); |
); |
279 |
actionGroup->add( |
actionGroup->add( |
280 |
|
Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")), |
281 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) |
282 |
|
); |
283 |
|
actionGroup->add( |
284 |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
285 |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
286 |
); |
); |
345 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
346 |
" <separator/>" |
" <separator/>" |
347 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
348 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
349 |
" </menu>" |
" </menu>" |
350 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
351 |
" <menu action='AllInstruments'>" |
" <menu action='AllInstruments'>" |
368 |
" </menu>" |
" </menu>" |
369 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
370 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
371 |
|
" <separator/>" |
372 |
|
" <menuitem action='RefreshAll'/>" |
373 |
" </menu>" |
" </menu>" |
374 |
" <menu action='MenuTools'>" |
" <menu action='MenuTools'>" |
375 |
" <menuitem action='CombineInstruments'/>" |
" <menuitem action='CombineInstruments'/>" |
378 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
379 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
380 |
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
381 |
|
" <menuitem action='MoveRootNoteWithRegionMoved'/>" |
382 |
" </menu>" |
" </menu>" |
383 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
384 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
402 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
403 |
" <separator/>" |
" <separator/>" |
404 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
405 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
406 |
" </popup>" |
" </popup>" |
407 |
" <popup name='ScriptPopupMenu'>" |
" <popup name='ScriptPopupMenu'>" |
408 |
" <menuitem action='AddScriptGroup'/>" |
" <menuitem action='AddScriptGroup'/>" |
447 |
} |
} |
448 |
{ |
{ |
449 |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
450 |
|
uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved")); |
451 |
|
item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around.")); |
452 |
|
} |
453 |
|
{ |
454 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
455 |
|
uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples")); |
456 |
|
item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones).")); |
457 |
|
// copy tooltip to popup menu |
458 |
|
Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>( |
459 |
|
uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples")); |
460 |
|
item2->set_tooltip_text(item->get_tooltip_text()); |
461 |
|
} |
462 |
|
{ |
463 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
464 |
|
uiManager->get_widget("/MenuBar/MenuView/RefreshAll")); |
465 |
|
item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface.")); |
466 |
|
} |
467 |
|
{ |
468 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
469 |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
470 |
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.")); |
471 |
} |
} |
613 |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
614 |
m_RegionChooser.signal_instrument_changed().connect( |
m_RegionChooser.signal_instrument_changed().connect( |
615 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
616 |
|
m_RegionChooser.signal_instrument_changed().connect( |
617 |
|
sigc::mem_fun(*this, &MainWindow::region_changed)); |
618 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
619 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
620 |
instrumentProps.signal_changed().connect( |
instrumentProps.signal_changed().connect( |
804 |
|
|
805 |
void Loader::thread_function() |
void Loader::thread_function() |
806 |
{ |
{ |
807 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%p\n", |
808 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
809 |
printf("Start %s\n", filename.c_str()); |
printf("Start %s\n", filename.c_str()); |
810 |
try { |
try { |
811 |
RIFF::File* riff = new RIFF::File(filename); |
RIFF::File* riff = new RIFF::File(filename); |
827 |
} |
} |
828 |
|
|
829 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
830 |
: filename(filename), thread(0), progress(0.f) |
: filename(filename), gig(0), thread(0), progress(0.f) |
831 |
{ |
{ |
832 |
} |
} |
833 |
|
|
838 |
#else |
#else |
839 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
840 |
#endif |
#endif |
841 |
printf("launch thread=%x\n", thread); |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
842 |
} |
} |
843 |
|
|
844 |
float Loader::get_progress() |
float Loader::get_progress() |
883 |
|
|
884 |
void Saver::thread_function() |
void Saver::thread_function() |
885 |
{ |
{ |
886 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%p\n", |
887 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
888 |
printf("Start %s\n", filename.c_str()); |
printf("Start %s\n", filename.c_str()); |
889 |
try { |
try { |
890 |
gig::progress_t progress; |
gig::progress_t progress; |
921 |
#else |
#else |
922 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
923 |
#endif |
#endif |
924 |
printf("launch thread=%x\n", thread); |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
925 |
} |
} |
926 |
|
|
927 |
float Saver::get_progress() |
float Saver::get_progress() |
1081 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1082 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
1083 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
1084 |
printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); |
printf("on_action_file_open self=%p\n", |
1085 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
1086 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
1087 |
current_gig_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
1088 |
} |
} |
1152 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1153 |
{ |
{ |
1154 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1155 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%p\n", |
1156 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
1157 |
load_gig(loader->gig, loader->filename.c_str()); |
load_gig(loader->gig, loader->filename.c_str()); |
1158 |
progress_dialog->hide(); |
progress_dialog->hide(); |
1159 |
} |
} |
1345 |
void MainWindow::__import_queued_samples() { |
void MainWindow::__import_queued_samples() { |
1346 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1347 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1348 |
printf("Samples to import: %d\n", m_SampleImportQueue.size()); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1349 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1350 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1351 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1451 |
!Settings::singleton()->syncSamplerInstrumentSelection; |
!Settings::singleton()->syncSamplerInstrumentSelection; |
1452 |
} |
} |
1453 |
|
|
1454 |
|
void MainWindow::on_action_move_root_note_with_region_moved() { |
1455 |
|
Settings::singleton()->moveRootNoteWithRegionMoved = |
1456 |
|
!Settings::singleton()->moveRootNoteWithRegionMoved; |
1457 |
|
} |
1458 |
|
|
1459 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1460 |
{ |
{ |
1461 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1748 |
file = 0; |
file = 0; |
1749 |
set_file_is_shared(isSharedInstrument); |
set_file_is_shared(isSharedInstrument); |
1750 |
|
|
1751 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = |
1752 |
|
(filename && strlen(filename) > 0) ? |
1753 |
|
filename : (!gig->GetFileName().empty()) ? |
1754 |
|
gig->GetFileName() : _("Unsaved Gig File"); |
1755 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1756 |
file_has_name = filename; |
file_has_name = filename; |
1757 |
file_is_changed = false; |
file_is_changed = false; |
1905 |
window->show(); |
window->show(); |
1906 |
} |
} |
1907 |
|
|
1908 |
|
void MainWindow::on_action_refresh_all() { |
1909 |
|
__refreshEntireGUI(); |
1910 |
|
} |
1911 |
|
|
1912 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1913 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1914 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
2663 |
try |
try |
2664 |
{ |
{ |
2665 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
|
int bitdepth; |
|
2666 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
2667 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
2668 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
2669 |
case SF_FORMAT_PCM_U8: |
case SF_FORMAT_PCM_U8: |
|
bitdepth = 16; |
|
|
break; |
|
2670 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
2671 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
2672 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
2673 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
|
bitdepth = 24; |
|
2674 |
break; |
break; |
2675 |
default: |
default: |
2676 |
sf_close(hFile); |
sf_close(hFile); |
2776 |
} |
} |
2777 |
} |
} |
2778 |
|
|
2779 |
|
void MainWindow::on_action_remove_unused_samples() { |
2780 |
|
if (!file) return; |
2781 |
|
|
2782 |
|
// collect all samples that are not referenced by any instrument |
2783 |
|
std::list<gig::Sample*> lsamples; |
2784 |
|
for (int iSample = 0; file->GetSample(iSample); ++iSample) { |
2785 |
|
gig::Sample* sample = file->GetSample(iSample); |
2786 |
|
bool isUsed = false; |
2787 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; |
2788 |
|
instrument = file->GetNextInstrument()) |
2789 |
|
{ |
2790 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
2791 |
|
rgn = instrument->GetNextRegion()) |
2792 |
|
{ |
2793 |
|
for (int i = 0; i < 256; ++i) { |
2794 |
|
if (!rgn->pDimensionRegions[i]) continue; |
2795 |
|
if (rgn->pDimensionRegions[i]->pSample != sample) continue; |
2796 |
|
isUsed = true; |
2797 |
|
goto endOfRefSearch; |
2798 |
|
} |
2799 |
|
} |
2800 |
|
} |
2801 |
|
endOfRefSearch: |
2802 |
|
if (!isUsed) lsamples.push_back(sample); |
2803 |
|
} |
2804 |
|
|
2805 |
|
if (lsamples.empty()) return; |
2806 |
|
|
2807 |
|
// notify everybody that we're going to remove these samples |
2808 |
|
samples_to_be_removed_signal.emit(lsamples); |
2809 |
|
|
2810 |
|
// remove collected samples |
2811 |
|
try { |
2812 |
|
for (std::list<gig::Sample*>::iterator itSample = lsamples.begin(); |
2813 |
|
itSample != lsamples.end(); ++itSample) |
2814 |
|
{ |
2815 |
|
gig::Sample* sample = *itSample; |
2816 |
|
// remove sample from the .gig file |
2817 |
|
file->DeleteSample(sample); |
2818 |
|
// if sample was just previously added, remove it fro the import queue |
2819 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
2820 |
|
iter != m_SampleImportQueue.end(); ++iter) |
2821 |
|
{ |
2822 |
|
if ((*iter).gig_sample == sample) { |
2823 |
|
printf("Removing previously added sample '%s'\n", |
2824 |
|
(*iter).sample_path.c_str()); |
2825 |
|
m_SampleImportQueue.erase(iter); |
2826 |
|
break; |
2827 |
|
} |
2828 |
|
} |
2829 |
|
} |
2830 |
|
} catch (RIFF::Exception e) { |
2831 |
|
// show error message |
2832 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2833 |
|
msg.run(); |
2834 |
|
} |
2835 |
|
|
2836 |
|
// notify everybody that we're done with removal |
2837 |
|
samples_removed_signal.emit(); |
2838 |
|
|
2839 |
|
dimreg_changed(); |
2840 |
|
file_changed(); |
2841 |
|
__refreshEntireGUI(); |
2842 |
|
} |
2843 |
|
|
2844 |
// see comment on on_sample_treeview_drag_begin() |
// see comment on on_sample_treeview_drag_begin() |
2845 |
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) |
2846 |
{ |
{ |
3301 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
3302 |
|
|
3303 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
3304 |
printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); |
printf("on_action_merge_files self=%p\n", |
3305 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
3306 |
std::vector<std::string> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
3307 |
|
|
3308 |
// merge the selected files to the currently open .gig file |
// merge the selected files to the currently open .gig file |
3314 |
} |
} |
3315 |
|
|
3316 |
// update GUI |
// update GUI |
3317 |
__refreshEntireGUI(); |
__refreshEntireGUI(); |
3318 |
} |
} |
3319 |
} |
} |
3320 |
|
|