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 |
217 |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
218 |
); |
); |
219 |
|
|
220 |
|
toggle_action = |
221 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
222 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
223 |
|
actionGroup->add( |
224 |
|
toggle_action, |
225 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
226 |
|
); |
227 |
|
|
228 |
|
|
229 |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
230 |
|
|
344 |
" </menu>" |
" </menu>" |
345 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
346 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
347 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
348 |
" </menu>" |
" </menu>" |
349 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
350 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
406 |
} |
} |
407 |
{ |
{ |
408 |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
409 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
410 |
|
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).")); |
411 |
|
} |
412 |
|
{ |
413 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
414 |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
415 |
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.")); |
416 |
} |
} |
448 |
// Create the Tree model: |
// Create the Tree model: |
449 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
450 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
451 |
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.")); |
452 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
453 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
454 |
); |
); |
456 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
457 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
458 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
459 |
|
|
460 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
461 |
|
// the sequence of instruments within the gig file |
462 |
|
{ |
463 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
464 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
465 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
466 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
467 |
|
m_TreeView.signal_drag_begin().connect( |
468 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
469 |
|
); |
470 |
|
m_TreeView.signal_drag_data_get().connect( |
471 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
472 |
|
); |
473 |
|
m_TreeView.signal_drag_data_received().connect( |
474 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
475 |
|
); |
476 |
|
} |
477 |
|
|
478 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
479 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
485 |
{ |
{ |
486 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
487 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
488 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
489 |
column->add_attribute( |
column->add_attribute( |
490 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
491 |
); |
); |
493 |
{ |
{ |
494 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
495 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
496 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
497 |
column->add_attribute( |
column->add_attribute( |
498 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
499 |
); |
); |
510 |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
511 |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
512 |
m_TreeViewScripts.set_tooltip_text(_( |
m_TreeViewScripts.set_tooltip_text(_( |
513 |
|
"Use CTRL + double click for editing a script." |
514 |
|
"\n\n" |
515 |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
516 |
"format. This feature will not work with the GigaStudio software!" |
"format. This feature will not work with the GigaStudio software!" |
517 |
)); |
)); |
521 |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
522 |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
523 |
); |
); |
524 |
|
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
525 |
|
m_TreeViewScripts.signal_row_activated().connect( |
526 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
527 |
|
); |
528 |
m_refScriptsTreeModel->signal_row_changed().connect( |
m_refScriptsTreeModel->signal_row_changed().connect( |
529 |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
530 |
); |
); |
580 |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
581 |
); |
); |
582 |
|
|
583 |
|
dimreg_edit.signal_select_sample().connect( |
584 |
|
sigc::mem_fun(*this, &MainWindow::select_sample) |
585 |
|
); |
586 |
|
|
587 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
588 |
sigc::hide( |
sigc::hide( |
589 |
sigc::bind( |
sigc::bind( |
724 |
} |
} |
725 |
|
|
726 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
727 |
|
|
728 |
|
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
729 |
|
switch_sampler_instrument_signal.emit(get_instrument()); |
730 |
|
} |
731 |
} |
} |
732 |
|
|
733 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
748 |
void Loader::thread_function() |
void Loader::thread_function() |
749 |
{ |
{ |
750 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
751 |
printf("Start %s\n", filename); |
printf("Start %s\n", filename.c_str()); |
752 |
RIFF::File* riff = new RIFF::File(filename); |
try { |
753 |
gig = new gig::File(riff); |
RIFF::File* riff = new RIFF::File(filename); |
754 |
gig::progress_t progress; |
gig = new gig::File(riff); |
755 |
progress.callback = loader_progress_callback; |
gig::progress_t progress; |
756 |
progress.custom = this; |
progress.callback = loader_progress_callback; |
757 |
|
progress.custom = this; |
758 |
gig->GetInstrument(0, &progress); |
|
759 |
printf("End\n"); |
gig->GetInstrument(0, &progress); |
760 |
finished_dispatcher(); |
printf("End\n"); |
761 |
|
finished_dispatcher(); |
762 |
|
} catch (RIFF::Exception e) { |
763 |
|
error_message = e.Message; |
764 |
|
error_dispatcher.emit(); |
765 |
|
} catch (...) { |
766 |
|
error_message = _("Unknown exception occurred"); |
767 |
|
error_dispatcher.emit(); |
768 |
|
} |
769 |
} |
} |
770 |
|
|
771 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
772 |
: filename(filename), thread(0) |
: filename(filename), thread(0), progress(0.f) |
773 |
{ |
{ |
774 |
} |
} |
775 |
|
|
803 |
return finished_dispatcher; |
return finished_dispatcher; |
804 |
} |
} |
805 |
|
|
806 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
807 |
|
{ |
808 |
|
return error_dispatcher; |
809 |
|
} |
810 |
|
|
811 |
|
void saver_progress_callback(gig::progress_t* progress) |
812 |
|
{ |
813 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
814 |
|
saver->progress_callback(progress->factor); |
815 |
|
} |
816 |
|
|
817 |
|
void Saver::progress_callback(float fraction) |
818 |
|
{ |
819 |
|
{ |
820 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
821 |
|
progress = fraction; |
822 |
|
} |
823 |
|
progress_dispatcher.emit(); |
824 |
|
} |
825 |
|
|
826 |
|
void Saver::thread_function() |
827 |
|
{ |
828 |
|
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
829 |
|
printf("Start %s\n", filename.c_str()); |
830 |
|
try { |
831 |
|
gig::progress_t progress; |
832 |
|
progress.callback = saver_progress_callback; |
833 |
|
progress.custom = this; |
834 |
|
|
835 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
836 |
|
if (filename.empty()) { |
837 |
|
gig->Save(&progress); |
838 |
|
} else { |
839 |
|
gig->Save(filename, &progress); |
840 |
|
} |
841 |
|
|
842 |
|
printf("End\n"); |
843 |
|
finished_dispatcher.emit(); |
844 |
|
} catch (RIFF::Exception e) { |
845 |
|
error_message = e.Message; |
846 |
|
error_dispatcher.emit(); |
847 |
|
} catch (...) { |
848 |
|
error_message = _("Unknown exception occurred"); |
849 |
|
error_dispatcher.emit(); |
850 |
|
} |
851 |
|
} |
852 |
|
|
853 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
854 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
855 |
|
{ |
856 |
|
} |
857 |
|
|
858 |
|
void Saver::launch() |
859 |
|
{ |
860 |
|
#ifdef OLD_THREADS |
861 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
862 |
|
#else |
863 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
864 |
|
#endif |
865 |
|
printf("launch thread=%x\n", thread); |
866 |
|
} |
867 |
|
|
868 |
|
float Saver::get_progress() |
869 |
|
{ |
870 |
|
float res; |
871 |
|
{ |
872 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
873 |
|
res = progress; |
874 |
|
} |
875 |
|
return res; |
876 |
|
} |
877 |
|
|
878 |
|
Glib::Dispatcher& Saver::signal_progress() |
879 |
|
{ |
880 |
|
return progress_dispatcher; |
881 |
|
} |
882 |
|
|
883 |
|
Glib::Dispatcher& Saver::signal_finished() |
884 |
|
{ |
885 |
|
return finished_dispatcher; |
886 |
|
} |
887 |
|
|
888 |
|
Glib::Dispatcher& Saver::signal_error() |
889 |
|
{ |
890 |
|
return error_dispatcher; |
891 |
|
} |
892 |
|
|
893 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
894 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
895 |
{ |
{ |
896 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
897 |
show_all_children(); |
show_all_children(); |
898 |
|
resize(600,50); |
899 |
} |
} |
900 |
|
|
901 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
964 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
965 |
int response = dialog.run(); |
int response = dialog.run(); |
966 |
dialog.hide(); |
dialog.hide(); |
967 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
968 |
return response != Gtk::RESPONSE_CANCEL; |
// user decided to exit app without saving |
969 |
|
if (response == Gtk::RESPONSE_NO) return true; |
970 |
|
|
971 |
|
// user cancelled dialog, thus don't close app |
972 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
973 |
|
|
974 |
|
// TODO: the following return valid is disabled and hard coded instead for |
975 |
|
// now, due to the fact that saving with progress bar is now implemented |
976 |
|
// asynchronously, as a result the app does not close automatically anymore |
977 |
|
// after saving the file has completed |
978 |
|
// |
979 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
980 |
|
// return response != Gtk::RESPONSE_CANCEL; |
981 |
|
// |
982 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
983 |
|
return false; // always prevent closing the app for now (see comment above) |
984 |
} |
} |
985 |
|
|
986 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
1031 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1032 |
{ |
{ |
1033 |
__clear(); |
__clear(); |
1034 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
1035 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1036 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
1037 |
|
Glib::filename_display_basename(name) + "' ...", |
1038 |
|
*this |
1039 |
|
); |
1040 |
|
progress_dialog->show_all(); |
1041 |
|
loader = new Loader(name); //FIXME: memory leak! |
1042 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1043 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1044 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1045 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1046 |
|
loader->signal_error().connect( |
1047 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1048 |
loader->launch(); |
loader->launch(); |
1049 |
} |
} |
1050 |
|
|
1060 |
// load the instrument |
// load the instrument |
1061 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1062 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1063 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1064 |
|
int i = 0; |
1065 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1066 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1067 |
|
{ |
1068 |
|
if (instrument == instr) { |
1069 |
|
// select item in "instruments" tree view |
1070 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1071 |
|
// make sure the selected item in the "instruments" tree view is |
1072 |
|
// visible (scroll to it) |
1073 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1074 |
|
// select item in instrument menu |
1075 |
|
{ |
1076 |
|
const std::vector<Gtk::Widget*> children = |
1077 |
|
instrument_menu->get_children(); |
1078 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1079 |
|
} |
1080 |
|
// update region chooser and dimension region chooser |
1081 |
|
m_RegionChooser.set_instrument(instr); |
1082 |
|
break; |
1083 |
|
} |
1084 |
|
} |
1085 |
} |
} |
1086 |
|
|
1087 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1088 |
{ |
{ |
1089 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1090 |
} |
} |
1091 |
|
|
1092 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1093 |
{ |
{ |
1094 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1095 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
1096 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename.c_str()); |
1097 |
load_dialog->hide(); |
progress_dialog->hide(); |
1098 |
|
} |
1099 |
|
|
1100 |
|
void MainWindow::on_loader_error() |
1101 |
|
{ |
1102 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1103 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1104 |
|
msg.run(); |
1105 |
|
progress_dialog->hide(); |
1106 |
} |
} |
1107 |
|
|
1108 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1141 |
|
|
1142 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1143 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1144 |
try { |
|
1145 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1146 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1147 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1148 |
file_is_changed = false; |
*this |
1149 |
} |
); |
1150 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1151 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1152 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1153 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1154 |
msg.run(); |
saver->signal_finished().connect( |
1155 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1156 |
} |
saver->signal_error().connect( |
1157 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1158 |
|
saver->launch(); |
1159 |
|
|
1160 |
|
return true; |
1161 |
|
} |
1162 |
|
|
1163 |
|
void MainWindow::on_saver_progress() |
1164 |
|
{ |
1165 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1166 |
|
} |
1167 |
|
|
1168 |
|
void MainWindow::on_saver_error() |
1169 |
|
{ |
1170 |
|
file_structure_changed_signal.emit(this->file); |
1171 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1172 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1173 |
|
msg.run(); |
1174 |
|
} |
1175 |
|
|
1176 |
|
void MainWindow::on_saver_finished() |
1177 |
|
{ |
1178 |
|
this->file = saver->gig; |
1179 |
|
this->filename = saver->filename; |
1180 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1181 |
|
set_title(Glib::filename_display_basename(filename)); |
1182 |
|
file_has_name = true; |
1183 |
|
file_is_changed = false; |
1184 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1185 |
__import_queued_samples(); |
__import_queued_samples(); |
1186 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1187 |
|
|
1188 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1189 |
return true; |
|
1190 |
|
__refreshEntireGUI(); |
1191 |
|
progress_dialog->hide(); |
1192 |
} |
} |
1193 |
|
|
1194 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1253 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1254 |
|
|
1255 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1256 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1257 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1258 |
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; |
|
1259 |
} |
} |
1260 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1261 |
file_structure_changed_signal.emit(this->file); |
|
1262 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1263 |
|
_("Saving") + Glib::ustring(" '") + |
1264 |
|
Glib::filename_display_basename(filename) + "' ...", |
1265 |
|
*this |
1266 |
|
); |
1267 |
|
progress_dialog->show_all(); |
1268 |
|
|
1269 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1270 |
|
saver->signal_progress().connect( |
1271 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1272 |
|
saver->signal_finished().connect( |
1273 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1274 |
|
saver->signal_error().connect( |
1275 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1276 |
|
saver->launch(); |
1277 |
|
|
1278 |
return true; |
return true; |
1279 |
} |
} |
1280 |
return false; |
return false; |
1385 |
!Settings::singleton()->warnUserOnExtensions; |
!Settings::singleton()->warnUserOnExtensions; |
1386 |
} |
} |
1387 |
|
|
1388 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1389 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1390 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1391 |
|
} |
1392 |
|
|
1393 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1394 |
{ |
{ |
1395 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1399 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1400 |
#endif |
#endif |
1401 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1402 |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson"); |
1403 |
const std::string sComment = |
const std::string sComment = |
1404 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1405 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1406 |
_( |
_( |
1407 |
"Gigedit is released under the GNU General Public License.\n" |
"Gigedit is released under the GNU General Public License.\n" |
1408 |
"\n" |
"\n" |
1409 |
"Please notice that this is still a very young instrument editor. " |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1410 |
"So better backup your Gigasampler files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
1411 |
"this application.\n" |
"this application.\n" |
1412 |
"\n" |
"\n" |
1413 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: http://bugs.linuxsampler.org" |
1911 |
} |
} |
1912 |
} |
} |
1913 |
|
|
1914 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
1915 |
|
if (!instrument) return; |
1916 |
|
|
1917 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1918 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1919 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1920 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
1921 |
|
// select and show the respective instrument in the list view |
1922 |
|
show_intruments_tab(); |
1923 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1924 |
|
Gtk::TreePath path( |
1925 |
|
m_TreeView.get_selection()->get_selected() |
1926 |
|
); |
1927 |
|
m_TreeView.scroll_to_row(path); |
1928 |
|
on_sel_change(); // the regular instrument selection change callback |
1929 |
|
} |
1930 |
|
} |
1931 |
|
} |
1932 |
|
|
1933 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
1934 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
1935 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
1936 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
1937 |
|
|
1938 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1939 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1940 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1941 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
1942 |
|
// select and show the respective instrument in the list view |
1943 |
|
show_intruments_tab(); |
1944 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1945 |
|
Gtk::TreePath path( |
1946 |
|
m_TreeView.get_selection()->get_selected() |
1947 |
|
); |
1948 |
|
m_TreeView.scroll_to_row(path); |
1949 |
|
on_sel_change(); // the regular instrument selection change callback |
1950 |
|
|
1951 |
|
// select respective region in the region selector |
1952 |
|
m_RegionChooser.set_region(pRegion); |
1953 |
|
|
1954 |
|
// select and show the respective dimension region in the editor |
1955 |
|
//update_dimregs(); |
1956 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
1957 |
|
//dimreg_edit.set_dim_region(dimRgn); |
1958 |
|
|
1959 |
|
return true; |
1960 |
|
} |
1961 |
|
} |
1962 |
|
|
1963 |
|
return false; |
1964 |
|
} |
1965 |
|
|
1966 |
|
void MainWindow::select_sample(gig::Sample* sample) { |
1967 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
1968 |
|
for (int g = 0; g < model->children().size(); ++g) { |
1969 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
1970 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
1971 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
1972 |
|
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
1973 |
|
show_samples_tab(); |
1974 |
|
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
1975 |
|
Gtk::TreePath path( |
1976 |
|
m_TreeViewSamples.get_selection()->get_selected() |
1977 |
|
); |
1978 |
|
m_TreeViewSamples.scroll_to_row(path); |
1979 |
|
return; |
1980 |
|
} |
1981 |
|
} |
1982 |
|
} |
1983 |
|
} |
1984 |
|
|
1985 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
1986 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1987 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
2713 |
sizeof(script)/*length of data in bytes*/); |
sizeof(script)/*length of data in bytes*/); |
2714 |
} |
} |
2715 |
|
|
2716 |
|
// see comment on on_sample_treeview_drag_begin() |
2717 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2718 |
|
{ |
2719 |
|
first_call_to_drag_data_get = true; |
2720 |
|
} |
2721 |
|
|
2722 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2723 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2724 |
|
{ |
2725 |
|
if (!first_call_to_drag_data_get) return; |
2726 |
|
first_call_to_drag_data_get = false; |
2727 |
|
|
2728 |
|
// get selected source instrument |
2729 |
|
gig::Instrument* src = NULL; |
2730 |
|
{ |
2731 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2732 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2733 |
|
if (it) { |
2734 |
|
Gtk::TreeModel::Row row = *it; |
2735 |
|
src = row[m_Columns.m_col_instr]; |
2736 |
|
} |
2737 |
|
} |
2738 |
|
if (!src) return; |
2739 |
|
|
2740 |
|
// pass the source gig::Instrument as pointer |
2741 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
2742 |
|
sizeof(src)/*length of data in bytes*/); |
2743 |
|
} |
2744 |
|
|
2745 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
2746 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
2747 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
2748 |
|
{ |
2749 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
2750 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
2751 |
|
return; |
2752 |
|
|
2753 |
|
gig::Instrument* dst = NULL; |
2754 |
|
{ |
2755 |
|
Gtk::TreeModel::Path path; |
2756 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
2757 |
|
if (!found) return; |
2758 |
|
|
2759 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
2760 |
|
if (!iter) return; |
2761 |
|
Gtk::TreeModel::Row row = *iter; |
2762 |
|
dst = row[m_Columns.m_col_instr]; |
2763 |
|
} |
2764 |
|
if (!dst) return; |
2765 |
|
|
2766 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
2767 |
|
src->MoveTo(dst); |
2768 |
|
__refreshEntireGUI(); |
2769 |
|
select_instrument(src); |
2770 |
|
} |
2771 |
|
|
2772 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2773 |
// 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 |
2774 |
// 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 |
2920 |
} |
} |
2921 |
} |
} |
2922 |
|
|
2923 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
2924 |
|
Gtk::TreeViewColumn* column) |
2925 |
|
{ |
2926 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
2927 |
|
if (!iter) return; |
2928 |
|
Gtk::TreeModel::Row row = *iter; |
2929 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2930 |
|
if (!script) return; |
2931 |
|
|
2932 |
|
ScriptEditor* editor = new ScriptEditor; |
2933 |
|
editor->setScript(script); |
2934 |
|
//editor->reparent(*this); |
2935 |
|
editor->show(); |
2936 |
|
} |
2937 |
|
|
2938 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
2939 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
2940 |
if (!iter) return; |
if (!iter) return; |
2991 |
|
|
2992 |
ReferencesView* d = new ReferencesView(*this); |
ReferencesView* d = new ReferencesView(*this); |
2993 |
d->setSample(sample); |
d->setSample(sample); |
2994 |
|
d->dimension_region_selected.connect( |
2995 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
2996 |
|
); |
2997 |
d->show_all(); |
d->show_all(); |
2998 |
d->resize(500, 400); |
d->resize(500, 400); |
2999 |
d->run(); |
d->run(); |
3067 |
); |
); |
3068 |
} |
} |
3069 |
|
|
3070 |
// Note: requires that this file already has a filename ! |
// Finally save gig file persistently to disk ... |
3071 |
this->file->Save(); |
//NOTE: requires that this gig file already has a filename ! |
3072 |
|
{ |
3073 |
|
std::cout << "Saving file\n" << std::flush; |
3074 |
|
file_structure_to_be_changed_signal.emit(this->file); |
3075 |
|
|
3076 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
3077 |
|
_("Saving") + Glib::ustring(" '") + |
3078 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
3079 |
|
*this |
3080 |
|
); |
3081 |
|
progress_dialog->show_all(); |
3082 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
3083 |
|
saver->signal_progress().connect( |
3084 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
3085 |
|
saver->signal_finished().connect( |
3086 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
3087 |
|
saver->signal_error().connect( |
3088 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
3089 |
|
saver->launch(); |
3090 |
|
} |
3091 |
} |
} |
3092 |
|
|
3093 |
void MainWindow::on_action_merge_files() { |
void MainWindow::on_action_merge_files() { |
3177 |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
3178 |
); |
); |
3179 |
} |
} |
3180 |
|
|
3181 |
|
{ |
3182 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
3183 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
3184 |
|
if (item) item->set_sensitive(b); |
3185 |
|
} |
3186 |
} |
} |
3187 |
|
|
3188 |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3211 |
// 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 |
3212 |
// address, which would lead to incorrect refcount if not deleted here |
// address, which would lead to incorrect refcount if not deleted here |
3213 |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3214 |
it != samples.end(); it != samples.end()) |
it != samples.end(); ++it) |
3215 |
{ |
{ |
3216 |
sample_ref_count.erase(*it); |
sample_ref_count.erase(*it); |
3217 |
} |
} |
3284 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
3285 |
return m_RegionChooser.signal_keyboard_key_released(); |
return m_RegionChooser.signal_keyboard_key_released(); |
3286 |
} |
} |
3287 |
|
|
3288 |
|
sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() { |
3289 |
|
return switch_sampler_instrument_signal; |
3290 |
|
} |