1 |
/* |
/* |
2 |
* Copyright (C) 2006-2014 Andreas Persson |
* Copyright (C) 2006-2015 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
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", |
221 |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
222 |
); |
); |
223 |
|
|
224 |
|
toggle_action = |
225 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
226 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
227 |
|
actionGroup->add( |
228 |
|
toggle_action, |
229 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
230 |
|
); |
231 |
|
|
232 |
|
|
233 |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
234 |
|
|
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'/>" |
361 |
" </menu>" |
" </menu>" |
362 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
363 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
364 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
365 |
" </menu>" |
" </menu>" |
366 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
367 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
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'/>" |
425 |
} |
} |
426 |
{ |
{ |
427 |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
428 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
429 |
|
item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode).")); |
430 |
|
} |
431 |
|
{ |
432 |
|
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 |
} |
} |
481 |
// Create the Tree model: |
// Create the Tree model: |
482 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
483 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
484 |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules.")); |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); |
485 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
486 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
487 |
); |
); |
489 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
490 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
491 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
492 |
|
|
493 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
494 |
|
// the sequence of instruments within the gig file |
495 |
|
{ |
496 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
497 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
498 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
499 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
500 |
|
m_TreeView.signal_drag_begin().connect( |
501 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
502 |
|
); |
503 |
|
m_TreeView.signal_drag_data_get().connect( |
504 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
505 |
|
); |
506 |
|
m_TreeView.signal_drag_data_received().connect( |
507 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
508 |
|
); |
509 |
|
} |
510 |
|
|
511 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
512 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
518 |
{ |
{ |
519 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
520 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
521 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
522 |
column->add_attribute( |
column->add_attribute( |
523 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
524 |
); |
); |
526 |
{ |
{ |
527 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
528 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
529 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
530 |
column->add_attribute( |
column->add_attribute( |
531 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
532 |
); |
); |
543 |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
544 |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
545 |
m_TreeViewScripts.set_tooltip_text(_( |
m_TreeViewScripts.set_tooltip_text(_( |
546 |
|
"Use CTRL + double click for editing a script." |
547 |
|
"\n\n" |
548 |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
549 |
"format. This feature will not work with the GigaStudio software!" |
"format. This feature will not work with the GigaStudio software!" |
550 |
)); |
)); |
554 |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
555 |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
556 |
); |
); |
557 |
|
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
558 |
|
m_TreeViewScripts.signal_row_activated().connect( |
559 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
560 |
|
); |
561 |
m_refScriptsTreeModel->signal_row_changed().connect( |
m_refScriptsTreeModel->signal_row_changed().connect( |
562 |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
563 |
); |
); |
613 |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
614 |
); |
); |
615 |
|
|
616 |
|
dimreg_edit.signal_select_sample().connect( |
617 |
|
sigc::mem_fun(*this, &MainWindow::select_sample) |
618 |
|
); |
619 |
|
|
620 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
621 |
sigc::hide( |
sigc::hide( |
622 |
sigc::bind( |
sigc::bind( |
757 |
} |
} |
758 |
|
|
759 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
760 |
|
|
761 |
|
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
762 |
|
switch_sampler_instrument_signal.emit(get_instrument()); |
763 |
|
} |
764 |
} |
} |
765 |
|
|
766 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
781 |
void Loader::thread_function() |
void Loader::thread_function() |
782 |
{ |
{ |
783 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
784 |
printf("Start %s\n", filename); |
printf("Start %s\n", filename.c_str()); |
785 |
RIFF::File* riff = new RIFF::File(filename); |
try { |
786 |
gig = new gig::File(riff); |
RIFF::File* riff = new RIFF::File(filename); |
787 |
gig::progress_t progress; |
gig = new gig::File(riff); |
788 |
progress.callback = loader_progress_callback; |
gig::progress_t progress; |
789 |
progress.custom = this; |
progress.callback = loader_progress_callback; |
790 |
|
progress.custom = this; |
791 |
gig->GetInstrument(0, &progress); |
|
792 |
printf("End\n"); |
gig->GetInstrument(0, &progress); |
793 |
finished_dispatcher(); |
printf("End\n"); |
794 |
|
finished_dispatcher(); |
795 |
|
} catch (RIFF::Exception e) { |
796 |
|
error_message = e.Message; |
797 |
|
error_dispatcher.emit(); |
798 |
|
} catch (...) { |
799 |
|
error_message = _("Unknown exception occurred"); |
800 |
|
error_dispatcher.emit(); |
801 |
|
} |
802 |
} |
} |
803 |
|
|
804 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
805 |
: filename(filename), thread(0) |
: filename(filename), thread(0), progress(0.f) |
806 |
{ |
{ |
807 |
} |
} |
808 |
|
|
836 |
return finished_dispatcher; |
return finished_dispatcher; |
837 |
} |
} |
838 |
|
|
839 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
840 |
|
{ |
841 |
|
return error_dispatcher; |
842 |
|
} |
843 |
|
|
844 |
|
void saver_progress_callback(gig::progress_t* progress) |
845 |
|
{ |
846 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
847 |
|
saver->progress_callback(progress->factor); |
848 |
|
} |
849 |
|
|
850 |
|
void Saver::progress_callback(float fraction) |
851 |
|
{ |
852 |
|
{ |
853 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
854 |
|
progress = fraction; |
855 |
|
} |
856 |
|
progress_dispatcher.emit(); |
857 |
|
} |
858 |
|
|
859 |
|
void Saver::thread_function() |
860 |
|
{ |
861 |
|
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
862 |
|
printf("Start %s\n", filename.c_str()); |
863 |
|
try { |
864 |
|
gig::progress_t progress; |
865 |
|
progress.callback = saver_progress_callback; |
866 |
|
progress.custom = this; |
867 |
|
|
868 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
869 |
|
if (filename.empty()) { |
870 |
|
gig->Save(&progress); |
871 |
|
} else { |
872 |
|
gig->Save(filename, &progress); |
873 |
|
} |
874 |
|
|
875 |
|
printf("End\n"); |
876 |
|
finished_dispatcher.emit(); |
877 |
|
} catch (RIFF::Exception e) { |
878 |
|
error_message = e.Message; |
879 |
|
error_dispatcher.emit(); |
880 |
|
} catch (...) { |
881 |
|
error_message = _("Unknown exception occurred"); |
882 |
|
error_dispatcher.emit(); |
883 |
|
} |
884 |
|
} |
885 |
|
|
886 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
887 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
888 |
|
{ |
889 |
|
} |
890 |
|
|
891 |
|
void Saver::launch() |
892 |
|
{ |
893 |
|
#ifdef OLD_THREADS |
894 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
895 |
|
#else |
896 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
897 |
|
#endif |
898 |
|
printf("launch thread=%x\n", thread); |
899 |
|
} |
900 |
|
|
901 |
|
float Saver::get_progress() |
902 |
|
{ |
903 |
|
float res; |
904 |
|
{ |
905 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
906 |
|
res = progress; |
907 |
|
} |
908 |
|
return res; |
909 |
|
} |
910 |
|
|
911 |
|
Glib::Dispatcher& Saver::signal_progress() |
912 |
|
{ |
913 |
|
return progress_dispatcher; |
914 |
|
} |
915 |
|
|
916 |
|
Glib::Dispatcher& Saver::signal_finished() |
917 |
|
{ |
918 |
|
return finished_dispatcher; |
919 |
|
} |
920 |
|
|
921 |
|
Glib::Dispatcher& Saver::signal_error() |
922 |
|
{ |
923 |
|
return error_dispatcher; |
924 |
|
} |
925 |
|
|
926 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
927 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
928 |
{ |
{ |
929 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
930 |
show_all_children(); |
show_all_children(); |
931 |
|
resize(600,50); |
932 |
} |
} |
933 |
|
|
934 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
997 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
998 |
int response = dialog.run(); |
int response = dialog.run(); |
999 |
dialog.hide(); |
dialog.hide(); |
1000 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
1001 |
return response != Gtk::RESPONSE_CANCEL; |
// user decided to exit app without saving |
1002 |
|
if (response == Gtk::RESPONSE_NO) return true; |
1003 |
|
|
1004 |
|
// user cancelled dialog, thus don't close app |
1005 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
1006 |
|
|
1007 |
|
// TODO: the following return valid is disabled and hard coded instead for |
1008 |
|
// now, due to the fact that saving with progress bar is now implemented |
1009 |
|
// asynchronously, as a result the app does not close automatically anymore |
1010 |
|
// after saving the file has completed |
1011 |
|
// |
1012 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
1013 |
|
// return response != Gtk::RESPONSE_CANCEL; |
1014 |
|
// |
1015 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
1016 |
|
return false; // always prevent closing the app for now (see comment above) |
1017 |
} |
} |
1018 |
|
|
1019 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
1064 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1065 |
{ |
{ |
1066 |
__clear(); |
__clear(); |
1067 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
1068 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1069 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
1070 |
|
Glib::filename_display_basename(name) + "' ...", |
1071 |
|
*this |
1072 |
|
); |
1073 |
|
progress_dialog->show_all(); |
1074 |
|
loader = new Loader(name); //FIXME: memory leak! |
1075 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1076 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1077 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1078 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1079 |
|
loader->signal_error().connect( |
1080 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1081 |
loader->launch(); |
loader->launch(); |
1082 |
} |
} |
1083 |
|
|
1093 |
// load the instrument |
// load the instrument |
1094 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1095 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1096 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1097 |
|
int i = 0; |
1098 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1099 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1100 |
|
{ |
1101 |
|
if (instrument == instr) { |
1102 |
|
// select item in "instruments" tree view |
1103 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1104 |
|
// make sure the selected item in the "instruments" tree view is |
1105 |
|
// visible (scroll to it) |
1106 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1107 |
|
// select item in instrument menu |
1108 |
|
{ |
1109 |
|
const std::vector<Gtk::Widget*> children = |
1110 |
|
instrument_menu->get_children(); |
1111 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1112 |
|
} |
1113 |
|
// update region chooser and dimension region chooser |
1114 |
|
m_RegionChooser.set_instrument(instr); |
1115 |
|
break; |
1116 |
|
} |
1117 |
|
} |
1118 |
} |
} |
1119 |
|
|
1120 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1121 |
{ |
{ |
1122 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1123 |
} |
} |
1124 |
|
|
1125 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1126 |
{ |
{ |
1127 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1128 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
1129 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename.c_str()); |
1130 |
load_dialog->hide(); |
progress_dialog->hide(); |
1131 |
|
} |
1132 |
|
|
1133 |
|
void MainWindow::on_loader_error() |
1134 |
|
{ |
1135 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1136 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1137 |
|
msg.run(); |
1138 |
|
progress_dialog->hide(); |
1139 |
} |
} |
1140 |
|
|
1141 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1174 |
|
|
1175 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1176 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1177 |
try { |
|
1178 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1179 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1180 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1181 |
file_is_changed = false; |
*this |
1182 |
} |
); |
1183 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1184 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1185 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1186 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1187 |
msg.run(); |
saver->signal_finished().connect( |
1188 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1189 |
} |
saver->signal_error().connect( |
1190 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1191 |
|
saver->launch(); |
1192 |
|
|
1193 |
|
return true; |
1194 |
|
} |
1195 |
|
|
1196 |
|
void MainWindow::on_saver_progress() |
1197 |
|
{ |
1198 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1199 |
|
} |
1200 |
|
|
1201 |
|
void MainWindow::on_saver_error() |
1202 |
|
{ |
1203 |
|
file_structure_changed_signal.emit(this->file); |
1204 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1205 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1206 |
|
msg.run(); |
1207 |
|
} |
1208 |
|
|
1209 |
|
void MainWindow::on_saver_finished() |
1210 |
|
{ |
1211 |
|
this->file = saver->gig; |
1212 |
|
this->filename = saver->filename; |
1213 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1214 |
|
set_title(Glib::filename_display_basename(filename)); |
1215 |
|
file_has_name = true; |
1216 |
|
file_is_changed = false; |
1217 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1218 |
__import_queued_samples(); |
__import_queued_samples(); |
1219 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1220 |
|
|
1221 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1222 |
return true; |
|
1223 |
|
__refreshEntireGUI(); |
1224 |
|
progress_dialog->hide(); |
1225 |
} |
} |
1226 |
|
|
1227 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1286 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1287 |
|
|
1288 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1289 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1290 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1291 |
std::string filename = dialog.get_filename(); |
filename += ".gig"; |
|
if (!Glib::str_has_suffix(filename, ".gig")) { |
|
|
filename += ".gig"; |
|
|
} |
|
|
printf("filename=%s\n", filename.c_str()); |
|
|
file->Save(filename); |
|
|
this->filename = filename; |
|
|
current_gig_dir = Glib::path_get_dirname(filename); |
|
|
set_title(Glib::filename_display_basename(filename)); |
|
|
file_has_name = true; |
|
|
file_is_changed = false; |
|
|
} catch (RIFF::Exception e) { |
|
|
file_structure_changed_signal.emit(this->file); |
|
|
Glib::ustring txt = _("Could not save file: ") + e.Message; |
|
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
|
|
msg.run(); |
|
|
return false; |
|
1292 |
} |
} |
1293 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1294 |
file_structure_changed_signal.emit(this->file); |
|
1295 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1296 |
|
_("Saving") + Glib::ustring(" '") + |
1297 |
|
Glib::filename_display_basename(filename) + "' ...", |
1298 |
|
*this |
1299 |
|
); |
1300 |
|
progress_dialog->show_all(); |
1301 |
|
|
1302 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1303 |
|
saver->signal_progress().connect( |
1304 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1305 |
|
saver->signal_finished().connect( |
1306 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1307 |
|
saver->signal_error().connect( |
1308 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1309 |
|
saver->launch(); |
1310 |
|
|
1311 |
return true; |
return true; |
1312 |
} |
} |
1313 |
return false; |
return false; |
1418 |
!Settings::singleton()->warnUserOnExtensions; |
!Settings::singleton()->warnUserOnExtensions; |
1419 |
} |
} |
1420 |
|
|
1421 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1422 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1423 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1424 |
|
} |
1425 |
|
|
1426 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1427 |
{ |
{ |
1428 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1432 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1433 |
#endif |
#endif |
1434 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1435 |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson"); |
1436 |
const std::string sComment = |
const std::string sComment = |
1437 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1438 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1439 |
_( |
_( |
1440 |
"Gigedit is released under the GNU General Public License.\n" |
"Gigedit is released under the GNU General Public License.\n" |
1441 |
"\n" |
"\n" |
1442 |
"Please notice that this is still a very young instrument editor. " |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1443 |
"So better backup your Gigasampler files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
1444 |
"this application.\n" |
"this application.\n" |
1445 |
"\n" |
"\n" |
1446 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: http://bugs.linuxsampler.org" |
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")); |
1951 |
} |
} |
1952 |
} |
} |
1953 |
|
|
1954 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
1955 |
|
if (!instrument) return; |
1956 |
|
|
1957 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1958 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1959 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1960 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
1961 |
|
// select and show the respective instrument in the list view |
1962 |
|
show_intruments_tab(); |
1963 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1964 |
|
Gtk::TreePath path( |
1965 |
|
m_TreeView.get_selection()->get_selected() |
1966 |
|
); |
1967 |
|
m_TreeView.scroll_to_row(path); |
1968 |
|
on_sel_change(); // the regular instrument selection change callback |
1969 |
|
} |
1970 |
|
} |
1971 |
|
} |
1972 |
|
|
1973 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
1974 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
1975 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
1976 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
1977 |
|
|
1978 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1979 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1980 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1981 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
1982 |
|
// select and show the respective instrument in the list view |
1983 |
|
show_intruments_tab(); |
1984 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1985 |
|
Gtk::TreePath path( |
1986 |
|
m_TreeView.get_selection()->get_selected() |
1987 |
|
); |
1988 |
|
m_TreeView.scroll_to_row(path); |
1989 |
|
on_sel_change(); // the regular instrument selection change callback |
1990 |
|
|
1991 |
|
// select respective region in the region selector |
1992 |
|
m_RegionChooser.set_region(pRegion); |
1993 |
|
|
1994 |
|
// select and show the respective dimension region in the editor |
1995 |
|
//update_dimregs(); |
1996 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
1997 |
|
//dimreg_edit.set_dim_region(dimRgn); |
1998 |
|
|
1999 |
|
return true; |
2000 |
|
} |
2001 |
|
} |
2002 |
|
|
2003 |
|
return false; |
2004 |
|
} |
2005 |
|
|
2006 |
|
void MainWindow::select_sample(gig::Sample* sample) { |
2007 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2008 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2009 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2010 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2011 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2012 |
|
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
2013 |
|
show_samples_tab(); |
2014 |
|
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
2015 |
|
Gtk::TreePath path( |
2016 |
|
m_TreeViewSamples.get_selection()->get_selected() |
2017 |
|
); |
2018 |
|
m_TreeViewSamples.scroll_to_row(path); |
2019 |
|
return; |
2020 |
|
} |
2021 |
|
} |
2022 |
|
} |
2023 |
|
} |
2024 |
|
|
2025 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
2026 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2027 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
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 |
{ |
{ |
2838 |
sizeof(script)/*length of data in bytes*/); |
sizeof(script)/*length of data in bytes*/); |
2839 |
} |
} |
2840 |
|
|
2841 |
|
// see comment on on_sample_treeview_drag_begin() |
2842 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2843 |
|
{ |
2844 |
|
first_call_to_drag_data_get = true; |
2845 |
|
} |
2846 |
|
|
2847 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2848 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2849 |
|
{ |
2850 |
|
if (!first_call_to_drag_data_get) return; |
2851 |
|
first_call_to_drag_data_get = false; |
2852 |
|
|
2853 |
|
// get selected source instrument |
2854 |
|
gig::Instrument* src = NULL; |
2855 |
|
{ |
2856 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2857 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2858 |
|
if (it) { |
2859 |
|
Gtk::TreeModel::Row row = *it; |
2860 |
|
src = row[m_Columns.m_col_instr]; |
2861 |
|
} |
2862 |
|
} |
2863 |
|
if (!src) return; |
2864 |
|
|
2865 |
|
// pass the source gig::Instrument as pointer |
2866 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
2867 |
|
sizeof(src)/*length of data in bytes*/); |
2868 |
|
} |
2869 |
|
|
2870 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
2871 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
2872 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
2873 |
|
{ |
2874 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
2875 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
2876 |
|
return; |
2877 |
|
|
2878 |
|
gig::Instrument* dst = NULL; |
2879 |
|
{ |
2880 |
|
Gtk::TreeModel::Path path; |
2881 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
2882 |
|
if (!found) return; |
2883 |
|
|
2884 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
2885 |
|
if (!iter) return; |
2886 |
|
Gtk::TreeModel::Row row = *iter; |
2887 |
|
dst = row[m_Columns.m_col_instr]; |
2888 |
|
} |
2889 |
|
if (!dst) return; |
2890 |
|
|
2891 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
2892 |
|
src->MoveTo(dst); |
2893 |
|
__refreshEntireGUI(); |
2894 |
|
select_instrument(src); |
2895 |
|
} |
2896 |
|
|
2897 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2898 |
// drag'n'drop (at least when target is an Entry). This work-around |
// drag'n'drop (at least when target is an Entry). This work-around |
2899 |
// makes sure the code in drag_data_get and drop_drag_data_received is |
// makes sure the code in drag_data_get and drop_drag_data_received is |
3045 |
} |
} |
3046 |
} |
} |
3047 |
|
|
3048 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
3049 |
|
Gtk::TreeViewColumn* column) |
3050 |
|
{ |
3051 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
3052 |
|
if (!iter) return; |
3053 |
|
Gtk::TreeModel::Row row = *iter; |
3054 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
3055 |
|
if (!script) return; |
3056 |
|
|
3057 |
|
ScriptEditor* editor = new ScriptEditor; |
3058 |
|
editor->setScript(script); |
3059 |
|
//editor->reparent(*this); |
3060 |
|
editor->show(); |
3061 |
|
} |
3062 |
|
|
3063 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
3064 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
3065 |
if (!iter) return; |
if (!iter) return; |
3116 |
|
|
3117 |
ReferencesView* d = new ReferencesView(*this); |
ReferencesView* d = new ReferencesView(*this); |
3118 |
d->setSample(sample); |
d->setSample(sample); |
3119 |
|
d->dimension_region_selected.connect( |
3120 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
3121 |
|
); |
3122 |
d->show_all(); |
d->show_all(); |
3123 |
d->resize(500, 400); |
d->resize(500, 400); |
3124 |
d->run(); |
d->run(); |
3192 |
); |
); |
3193 |
} |
} |
3194 |
|
|
3195 |
// Note: requires that this file already has a filename ! |
// Finally save gig file persistently to disk ... |
3196 |
this->file->Save(); |
//NOTE: requires that this gig file already has a filename ! |
3197 |
|
{ |
3198 |
|
std::cout << "Saving file\n" << std::flush; |
3199 |
|
file_structure_to_be_changed_signal.emit(this->file); |
3200 |
|
|
3201 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
3202 |
|
_("Saving") + Glib::ustring(" '") + |
3203 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
3204 |
|
*this |
3205 |
|
); |
3206 |
|
progress_dialog->show_all(); |
3207 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
3208 |
|
saver->signal_progress().connect( |
3209 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
3210 |
|
saver->signal_finished().connect( |
3211 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
3212 |
|
saver->signal_error().connect( |
3213 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
3214 |
|
saver->launch(); |
3215 |
|
} |
3216 |
} |
} |
3217 |
|
|
3218 |
void MainWindow::on_action_merge_files() { |
void MainWindow::on_action_merge_files() { |
3284 |
} |
} |
3285 |
|
|
3286 |
// update GUI |
// update GUI |
3287 |
__refreshEntireGUI(); |
__refreshEntireGUI(); |
3288 |
} |
} |
3289 |
} |
} |
3290 |
|
|
3302 |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
3303 |
); |
); |
3304 |
} |
} |
3305 |
|
|
3306 |
|
{ |
3307 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
3308 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
3309 |
|
if (item) item->set_sensitive(b); |
3310 |
|
} |
3311 |
} |
} |
3312 |
|
|
3313 |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3336 |
// just in case a new sample is added later with exactly the same memory |
// just in case a new sample is added later with exactly the same memory |
3337 |
// address, which would lead to incorrect refcount if not deleted here |
// address, which would lead to incorrect refcount if not deleted here |
3338 |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3339 |
it != samples.end(); it != samples.end()) |
it != samples.end(); ++it) |
3340 |
{ |
{ |
3341 |
sample_ref_count.erase(*it); |
sample_ref_count.erase(*it); |
3342 |
} |
} |
3409 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
3410 |
return m_RegionChooser.signal_keyboard_key_released(); |
return m_RegionChooser.signal_keyboard_key_released(); |
3411 |
} |
} |
3412 |
|
|
3413 |
|
sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() { |
3414 |
|
return switch_sampler_instrument_signal; |
3415 |
|
} |