17 |
* 02110-1301 USA. |
* 02110-1301 USA. |
18 |
*/ |
*/ |
19 |
|
|
|
#include <libintl.h> |
|
20 |
#include <iostream> |
#include <iostream> |
21 |
|
|
22 |
#include <gtkmm/filechooserdialog.h> |
#include <gtkmm/filechooserdialog.h> |
25 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
26 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
27 |
|
|
28 |
|
#include "global.h" |
29 |
|
|
30 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
31 |
#define ABOUT_DIALOG |
#define ABOUT_DIALOG |
32 |
#include <gtkmm/aboutdialog.h> |
#include <gtkmm/aboutdialog.h> |
49 |
|
|
50 |
#include "mainwindow.h" |
#include "mainwindow.h" |
51 |
|
|
|
#define _(String) gettext(String) |
|
|
|
|
52 |
template<class T> inline std::string ToString(T o) { |
template<class T> inline std::string ToString(T o) { |
53 |
std::stringstream ss; |
std::stringstream ss; |
54 |
ss << o; |
ss << o; |
294 |
|
|
295 |
file = 0; |
file = 0; |
296 |
file_is_changed = false; |
file_is_changed = false; |
297 |
|
file_is_shared = false; |
298 |
|
|
299 |
show_all_children(); |
show_all_children(); |
300 |
|
|
308 |
|
|
309 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
bool MainWindow::on_delete_event(GdkEventAny* event) |
310 |
{ |
{ |
311 |
return file_is_changed && !close_confirmation_dialog(); |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
312 |
} |
} |
313 |
|
|
314 |
void MainWindow::on_action_quit() |
void MainWindow::on_action_quit() |
315 |
{ |
{ |
316 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
317 |
hide(); |
hide(); |
318 |
} |
} |
319 |
|
|
427 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
428 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
429 |
// free libgig's gig::File instance |
// free libgig's gig::File instance |
430 |
if (file) { |
if (file && !file_is_shared) delete file; |
431 |
delete file; |
file = NULL; |
432 |
file = NULL; |
file_is_shared = false; |
|
} |
|
433 |
} |
} |
434 |
|
|
435 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
436 |
{ |
{ |
437 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
438 |
|
|
439 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
440 |
|
|
441 |
// clear all GUI elements |
// clear all GUI elements |
442 |
__clear(); |
__clear(); |
468 |
return response != Gtk::RESPONSE_CANCEL; |
return response != Gtk::RESPONSE_CANCEL; |
469 |
} |
} |
470 |
|
|
471 |
|
bool MainWindow::leaving_shared_mode_dialog() { |
472 |
|
Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); |
473 |
|
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
474 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
475 |
|
dialog.set_secondary_text( |
476 |
|
_("If you proceed to work on another instrument file, it won't be " |
477 |
|
"used by the sampler until you tell the sampler explicitly to " |
478 |
|
"load it.") |
479 |
|
); |
480 |
|
#endif |
481 |
|
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
482 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
483 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
484 |
|
int response = dialog.run(); |
485 |
|
dialog.hide(); |
486 |
|
return response == Gtk::RESPONSE_YES; |
487 |
|
} |
488 |
|
|
489 |
void MainWindow::on_action_file_open() |
void MainWindow::on_action_file_open() |
490 |
{ |
{ |
491 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
492 |
|
|
493 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
494 |
|
|
495 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
496 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
531 |
msg.run(); |
msg.run(); |
532 |
Gtk::Main::quit(); |
Gtk::Main::quit(); |
533 |
} |
} |
534 |
|
// clear all GUI elements |
535 |
|
__clear(); |
536 |
|
// load the instrument |
537 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
538 |
load_gig(pFile, 0 /*file name*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
539 |
//TODO: automatically select the given instrument |
//TODO: automatically select the given instrument |
540 |
} |
} |
541 |
|
|
584 |
bool MainWindow::file_save() |
bool MainWindow::file_save() |
585 |
{ |
{ |
586 |
if (!check_if_savable()) return false; |
if (!check_if_savable()) return false; |
587 |
if (!file_has_name) return file_save_as(); |
if (!file_is_shared && !file_has_name) return file_save_as(); |
588 |
|
|
589 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
590 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
596 |
} |
} |
597 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
598 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
599 |
Glib::ustring txt = "Could not save file: " + e.Message; |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
600 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
601 |
msg.run(); |
msg.run(); |
602 |
return false; |
return false; |
651 |
file_is_changed = false; |
file_is_changed = false; |
652 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
653 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
654 |
Glib::ustring txt = "Could not save file: " + e.Message; |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
655 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
656 |
msg.run(); |
msg.run(); |
657 |
return false; |
return false; |
748 |
} |
} |
749 |
// show error message box when some sample(s) could not be imported |
// show error message box when some sample(s) could not be imported |
750 |
if (error_files.size()) { |
if (error_files.size()) { |
751 |
Glib::ustring txt = "Could not import the following sample(s):\n" + error_files; |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
752 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
753 |
msg.run(); |
msg.run(); |
754 |
} |
} |
942 |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
943 |
} |
} |
944 |
|
|
945 |
sigc::signal<void> InstrumentProps::signal_instrument_changed() |
sigc::signal<void>& InstrumentProps::signal_instrument_changed() |
946 |
{ |
{ |
947 |
return instrument_changed; |
return instrument_changed; |
948 |
} |
} |
955 |
} |
} |
956 |
} |
} |
957 |
|
|
958 |
void MainWindow::load_gig(gig::File* gig, const char* filename) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
959 |
{ |
{ |
960 |
file = 0; |
file = 0; |
961 |
|
file_is_shared = isSharedInstrument; |
962 |
|
|
963 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = filename ? filename : _("Unsaved Gig File"); |
964 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1092 |
|
|
1093 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
1094 |
if (!file) return; |
if (!file) return; |
1095 |
|
if (file_is_shared) { |
1096 |
|
Gtk::MessageDialog msg( |
1097 |
|
*this, |
1098 |
|
_("You cannot delete an instrument from this file, since it's " |
1099 |
|
"currently used by the sampler."), |
1100 |
|
false, Gtk::MESSAGE_INFO |
1101 |
|
); |
1102 |
|
msg.run(); |
1103 |
|
return; |
1104 |
|
} |
1105 |
|
|
1106 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1107 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1108 |
if (it) { |
if (it) { |
1289 |
} |
} |
1290 |
// 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 |
1291 |
if (error_files.size()) { |
if (error_files.size()) { |
1292 |
Glib::ustring txt = "Could not add the following sample(s):\n" + error_files; |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
1293 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1294 |
msg.run(); |
msg.run(); |
1295 |
} |
} |
1502 |
} |
} |
1503 |
} |
} |
1504 |
|
|
1505 |
sigc::signal<void, gig::File*> MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
1506 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
1507 |
} |
} |
1508 |
|
|
1509 |
sigc::signal<void, gig::File*> MainWindow::signal_file_structure_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() { |
1510 |
return file_structure_changed_signal; |
return file_structure_changed_signal; |
1511 |
} |
} |
1512 |
|
|
1513 |
sigc::signal<void, std::list<gig::Sample*> > MainWindow::signal_samples_to_be_removed() { |
sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() { |
1514 |
return samples_to_be_removed_signal; |
return samples_to_be_removed_signal; |
1515 |
} |
} |
1516 |
|
|
1517 |
sigc::signal<void> MainWindow::signal_samples_removed() { |
sigc::signal<void>& MainWindow::signal_samples_removed() { |
1518 |
return samples_removed_signal; |
return samples_removed_signal; |
1519 |
} |
} |
1520 |
|
|
1521 |
sigc::signal<void, gig::Region*> MainWindow::signal_region_to_be_changed() { |
sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() { |
1522 |
return region_to_be_changed_signal; |
return region_to_be_changed_signal; |
1523 |
} |
} |
1524 |
|
|
1525 |
sigc::signal<void, gig::Region*> MainWindow::signal_region_changed() { |
sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() { |
1526 |
return region_changed_signal; |
return region_changed_signal; |
1527 |
} |
} |
1528 |
|
|
1529 |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/> MainWindow::signal_sample_ref_changed() { |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() { |
1530 |
return sample_ref_changed_signal; |
return sample_ref_changed_signal; |
1531 |
} |
} |
1532 |
|
|
1533 |
sigc::signal<void, gig::DimensionRegion*> MainWindow::signal_dimreg_to_be_changed() { |
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() { |
1534 |
return dimreg_to_be_changed_signal; |
return dimreg_to_be_changed_signal; |
1535 |
} |
} |
1536 |
|
|
1537 |
sigc::signal<void, gig::DimensionRegion*> MainWindow::signal_dimreg_changed() { |
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() { |
1538 |
return dimreg_changed_signal; |
return dimreg_changed_signal; |
1539 |
} |
} |