26 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
27 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
28 |
|
|
29 |
#if GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
30 |
#define ABOUT_DIALOG |
#define ABOUT_DIALOG |
31 |
#include <gtkmm/aboutdialog.h> |
#include <gtkmm/aboutdialog.h> |
32 |
#endif |
#endif |
99 |
action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); |
action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); |
100 |
action->property_label() = action->property_label() + "..."; |
action->property_label() = action->property_label() + "..."; |
101 |
actionGroup->add(action, |
actionGroup->add(action, |
102 |
*(new Gtk::AccelKey("<shift><control>s")), |
Gtk::AccelKey("<shift><control>s"), |
103 |
sigc::mem_fun( |
sigc::mem_fun( |
104 |
*this, &MainWindow::on_action_file_save_as) |
*this, &MainWindow::on_action_file_save_as)); |
|
); |
|
105 |
actionGroup->add(Gtk::Action::create("Properties", |
actionGroup->add(Gtk::Action::create("Properties", |
106 |
Gtk::Stock::PROPERTIES), |
Gtk::Stock::PROPERTIES), |
107 |
sigc::mem_fun( |
sigc::mem_fun( |
112 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
113 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
114 |
sigc::mem_fun( |
sigc::mem_fun( |
115 |
*this, &MainWindow::hide)); |
*this, &MainWindow::on_action_quit)); |
116 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
117 |
|
|
118 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
152 |
|
|
153 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
154 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
155 |
// add_accel_group(uiManager->get_accel_group()); |
add_accel_group(uiManager->get_accel_group()); |
156 |
|
|
157 |
Glib::ustring ui_info = |
Glib::ustring ui_info = |
158 |
"<ui>" |
"<ui>" |
200 |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
201 |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
202 |
|
|
203 |
m_RegionChooser.signal_sel_changed().connect( |
m_RegionChooser.signal_region_selected().connect( |
204 |
sigc::mem_fun(*this, &MainWindow::region_changed) ); |
sigc::mem_fun(*this, &MainWindow::region_changed) ); |
205 |
m_DimRegionChooser.signal_sel_changed().connect( |
m_DimRegionChooser.signal_dimregion_selected().connect( |
206 |
sigc::mem_fun(*this, &MainWindow::dimreg_changed) ); |
sigc::mem_fun(*this, &MainWindow::dimreg_changed) ); |
207 |
|
|
208 |
|
|
241 |
dimreg_edit.wSample->signal_drag_data_received().connect( |
dimreg_edit.wSample->signal_drag_data_received().connect( |
242 |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
243 |
); |
); |
244 |
|
dimreg_edit.signal_dimreg_changed().connect( |
245 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
246 |
|
m_RegionChooser.signal_instrument_changed().connect( |
247 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
248 |
|
m_DimRegionChooser.signal_region_changed().connect( |
249 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
250 |
|
instrumentProps.signal_instrument_changed().connect( |
251 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
252 |
file = 0; |
file = 0; |
253 |
|
file_is_changed = false; |
254 |
|
|
255 |
show_all_children(); |
show_all_children(); |
256 |
} |
} |
259 |
{ |
{ |
260 |
} |
} |
261 |
|
|
262 |
|
bool MainWindow::on_delete_event(GdkEventAny* event) |
263 |
|
{ |
264 |
|
return file_is_changed && !close_confirmation_dialog(); |
265 |
|
} |
266 |
|
|
267 |
|
void MainWindow::on_action_quit() |
268 |
|
{ |
269 |
|
if (file_is_changed && !close_confirmation_dialog()) return; |
270 |
|
hide(); |
271 |
|
} |
272 |
|
|
273 |
void MainWindow::region_changed() |
void MainWindow::region_changed() |
274 |
{ |
{ |
275 |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
388 |
|
|
389 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
390 |
{ |
{ |
391 |
|
if (file_is_changed && !close_confirmation_dialog()) return; |
392 |
|
|
393 |
// clear all GUI elements |
// clear all GUI elements |
394 |
__clear(); |
__clear(); |
395 |
// create a new .gig file (virtually yet) |
// create a new .gig file (virtually yet) |
398 |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
399 |
pInstrument->pInfo->Name = "Unnamed Instrument"; |
pInstrument->pInfo->Name = "Unnamed Instrument"; |
400 |
// update GUI with that new gig::File |
// update GUI with that new gig::File |
401 |
load_gig(pFile, NULL /*no file name yet*/); |
load_gig(pFile, 0 /*no file name yet*/); |
402 |
|
} |
403 |
|
|
404 |
|
bool MainWindow::close_confirmation_dialog() |
405 |
|
{ |
406 |
|
gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"), |
407 |
|
Glib::filename_display_basename(filename).c_str()); |
408 |
|
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
409 |
|
g_free(msg); |
410 |
|
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
411 |
|
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
412 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
413 |
|
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
414 |
|
dialog.set_default_response(Gtk::RESPONSE_YES); |
415 |
|
int response = dialog.run(); |
416 |
|
if (response == Gtk::RESPONSE_YES) return file_save(); |
417 |
|
return response != Gtk::RESPONSE_CANCEL; |
418 |
} |
} |
419 |
|
|
420 |
void MainWindow::on_action_file_open() |
void MainWindow::on_action_file_open() |
421 |
{ |
{ |
422 |
|
if (file_is_changed && !close_confirmation_dialog()) return; |
423 |
|
|
424 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
425 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
426 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
427 |
|
dialog.set_default_response(Gtk::RESPONSE_OK); |
428 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
429 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
430 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
431 |
|
if (current_dir != "") { |
432 |
|
dialog.set_current_folder(current_dir); |
433 |
|
} |
434 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
435 |
printf("filename=%s\n", dialog.get_filename().c_str()); |
std::string filename = dialog.get_filename(); |
436 |
|
printf("filename=%s\n", filename.c_str()); |
437 |
__clear(); |
__clear(); |
438 |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
439 |
load_file(dialog.get_filename().c_str()); |
load_file(filename.c_str()); |
440 |
|
current_dir = Glib::path_get_dirname(filename); |
441 |
} |
} |
442 |
} |
} |
443 |
|
|
461 |
Gtk::Main::quit(); |
Gtk::Main::quit(); |
462 |
} |
} |
463 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
464 |
load_gig(pFile, NULL /*file name*/); |
load_gig(pFile, 0 /*file name*/); |
465 |
//TODO: automatically select the given instrument |
//TODO: automatically select the given instrument |
466 |
} |
} |
467 |
|
|
480 |
|
|
481 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
482 |
{ |
{ |
483 |
if (!file) return; |
file_save(); |
484 |
|
} |
485 |
|
|
486 |
|
bool MainWindow::file_save() |
487 |
|
{ |
488 |
|
if (!file) return false; |
489 |
|
if (!file_has_name) return file_save_as(); |
490 |
|
|
491 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
492 |
try { |
try { |
493 |
file->Save(); |
file->Save(); |
494 |
|
if (file_is_changed) { |
495 |
|
set_title(get_title().substr(1)); |
496 |
|
file_is_changed = false; |
497 |
|
} |
498 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
499 |
Glib::ustring txt = "Could not save file: " + e.Message; |
Glib::ustring txt = "Could not save file: " + e.Message; |
500 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
501 |
msg.run(); |
msg.run(); |
502 |
return; |
return false; |
503 |
} |
} |
504 |
std::cout << "Saving file done\n" << std::flush; |
std::cout << "Saving file done\n" << std::flush; |
505 |
__import_queued_samples(); |
__import_queued_samples(); |
506 |
|
return true; |
507 |
} |
} |
508 |
|
|
509 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
510 |
{ |
{ |
511 |
if (!file) return; |
file_save_as(); |
512 |
Gtk::FileChooserDialog dialog(*this, "Open", Gtk::FILE_CHOOSER_ACTION_SAVE); |
} |
513 |
|
|
514 |
|
bool MainWindow::file_save_as() |
515 |
|
{ |
516 |
|
if (!file) return false; |
517 |
|
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
518 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
519 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
520 |
|
dialog.set_default_response(Gtk::RESPONSE_OK); |
521 |
|
|
522 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2 |
523 |
|
dialog.set_do_overwrite_confirmation(); |
524 |
|
// TODO: an overwrite dialog for gtkmm < 2.8 |
525 |
|
#endif |
526 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
527 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
528 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
529 |
|
|
530 |
|
if (Glib::path_is_absolute(filename)) { |
531 |
|
dialog.set_filename(filename); |
532 |
|
} else if (current_dir != "") { |
533 |
|
dialog.set_current_folder(current_dir); |
534 |
|
} |
535 |
|
dialog.set_current_name(Glib::filename_display_basename(filename)); |
536 |
|
|
537 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
|
printf("filename=%s\n", dialog.get_filename().c_str()); |
|
538 |
try { |
try { |
539 |
file->Save(dialog.get_filename()); |
std::string filename = dialog.get_filename(); |
540 |
|
if (!Glib::str_has_suffix(filename, ".gig")) { |
541 |
|
filename += ".gig"; |
542 |
|
} |
543 |
|
printf("filename=%s\n", filename.c_str()); |
544 |
|
file->Save(filename); |
545 |
|
this->filename = filename; |
546 |
|
current_dir = Glib::path_get_dirname(filename); |
547 |
|
set_title(Glib::filename_display_basename(filename)); |
548 |
|
file_has_name = true; |
549 |
|
file_is_changed = false; |
550 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
551 |
Glib::ustring txt = "Could not save file: " + e.Message; |
Glib::ustring txt = "Could not save file: " + e.Message; |
552 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
553 |
msg.run(); |
msg.run(); |
554 |
return; |
return false; |
555 |
} |
} |
556 |
__import_queued_samples(); |
__import_queued_samples(); |
557 |
|
return true; |
558 |
} |
} |
559 |
|
return false; |
560 |
} |
} |
561 |
|
|
562 |
// actually write the sample(s)' data to the gig file |
// actually write the sample(s)' data to the gig file |
712 |
entry[15].set_text(info->Subject); |
entry[15].set_text(info->Subject); |
713 |
} |
} |
714 |
|
|
715 |
|
void InstrumentProps::add_prop(BoolEntry& boolentry) |
716 |
|
{ |
717 |
|
table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, |
718 |
|
Gtk::FILL, Gtk::SHRINK); |
719 |
|
rowno++; |
720 |
|
boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); |
721 |
|
} |
722 |
|
|
723 |
|
void InstrumentProps::add_prop(BoolEntryPlus6& boolentry) |
724 |
|
{ |
725 |
|
table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, |
726 |
|
Gtk::FILL, Gtk::SHRINK); |
727 |
|
rowno++; |
728 |
|
boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); |
729 |
|
} |
730 |
|
|
731 |
void InstrumentProps::add_prop(LabelWidget& prop) |
void InstrumentProps::add_prop(LabelWidget& prop) |
732 |
{ |
{ |
733 |
table.attach(prop.label, 0, 1, rowno, rowno + 1, |
table.attach(prop.label, 0, 1, rowno, rowno + 1, |
735 |
table.attach(prop.widget, 1, 2, rowno, rowno + 1, |
table.attach(prop.widget, 1, 2, rowno, rowno + 1, |
736 |
Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); |
Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); |
737 |
rowno++; |
rowno++; |
738 |
|
prop.signal_changed_by_user().connect(instrument_changed.make_slot()); |
739 |
} |
} |
740 |
|
|
741 |
InstrumentProps::InstrumentProps() |
InstrumentProps::InstrumentProps() |
742 |
: table(2,1), |
: table(2,1), |
743 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(Gtk::Stock::CLOSE), |
744 |
eName("Name"), |
eName("Name"), |
745 |
eIsDrum("IsDrum"), |
eIsDrum("Is drum"), |
746 |
eMIDIBank("MIDIBank", 0, 16383), |
eMIDIBank("MIDI bank", 0, 16383), |
747 |
eMIDIProgram("MIDIProgram"), |
eMIDIProgram("MIDI program"), |
748 |
eAttenuation("Attenuation", 0, 96, 0, 1), |
eAttenuation("Attenuation", 0, 96, 0, 1), |
749 |
eGainPlus6("Gain +6dB", eAttenuation, -6), |
eGainPlus6("Gain +6dB", eAttenuation, -6), |
750 |
eEffectSend("EffectSend", 0, 65535), |
eEffectSend("Effect send", 0, 65535), |
751 |
eFineTune("FineTune", -8400, 8400), |
eFineTune("Fine tune", -8400, 8400), |
752 |
ePitchbendRange("PitchbendRange", 0, 12), |
ePitchbendRange("Pitchbend range", 0, 12), |
753 |
ePianoReleaseMode("PianoReleaseMode"), |
ePianoReleaseMode("Piano release mode"), |
754 |
eDimensionKeyRangeLow("DimensionKeyRangeLow"), |
eDimensionKeyRangeLow("Dimension key range low"), |
755 |
eDimensionKeyRangeHigh("DimensionKeyRangeHigh") |
eDimensionKeyRangeHigh("Dimension key range high") |
756 |
{ |
{ |
757 |
set_title("Instrument properties"); |
set_title("Instrument properties"); |
758 |
|
|
772 |
add_prop(eDimensionKeyRangeLow); |
add_prop(eDimensionKeyRangeLow); |
773 |
add_prop(eDimensionKeyRangeHigh); |
add_prop(eDimensionKeyRangeHigh); |
774 |
|
|
775 |
eDimensionKeyRangeLow.signal_value_changed().connect( |
eDimensionKeyRangeLow.signal_changed_by_user().connect( |
776 |
sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed)); |
sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed)); |
777 |
eDimensionKeyRangeHigh.signal_value_changed().connect( |
eDimensionKeyRangeHigh.signal_changed_by_user().connect( |
778 |
sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed)); |
sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed)); |
779 |
|
|
780 |
add(vbox); |
add(vbox); |
799 |
|
|
800 |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
801 |
{ |
{ |
|
update_gui = false; |
|
802 |
eName.set_ptr(&instrument->pInfo->Name); |
eName.set_ptr(&instrument->pInfo->Name); |
803 |
eIsDrum.set_ptr(&instrument->IsDrum); |
eIsDrum.set_ptr(&instrument->IsDrum); |
804 |
eMIDIBank.set_ptr(&instrument->MIDIBank); |
eMIDIBank.set_ptr(&instrument->MIDIBank); |
809 |
eFineTune.set_ptr(&instrument->FineTune); |
eFineTune.set_ptr(&instrument->FineTune); |
810 |
ePitchbendRange.set_ptr(&instrument->PitchbendRange); |
ePitchbendRange.set_ptr(&instrument->PitchbendRange); |
811 |
ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode); |
ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode); |
812 |
|
eDimensionKeyRangeLow.set_ptr(0); |
813 |
|
eDimensionKeyRangeHigh.set_ptr(0); |
814 |
eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low); |
eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low); |
815 |
eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high); |
eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high); |
|
update_gui = true; |
|
816 |
} |
} |
817 |
|
|
818 |
void InstrumentProps::key_range_low_changed() |
void InstrumentProps::key_range_low_changed() |
829 |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
830 |
} |
} |
831 |
|
|
832 |
void MainWindow::load_gig(gig::File* gig, const char* filename) |
sigc::signal<void> InstrumentProps::signal_instrument_changed() |
833 |
{ |
{ |
834 |
file = gig; |
return instrument_changed; |
835 |
|
} |
836 |
|
|
837 |
if (filename) { |
void MainWindow::file_changed() |
838 |
const char *basename = strrchr(filename, '/'); |
{ |
839 |
basename = basename ? basename + 1 : filename; |
if (file && !file_is_changed) { |
840 |
set_title(basename); |
set_title("*" + get_title()); |
841 |
} else { |
file_is_changed = true; |
|
set_title("unnamed"); |
|
842 |
} |
} |
843 |
|
} |
844 |
|
|
845 |
|
void MainWindow::load_gig(gig::File* gig, const char* filename) |
846 |
|
{ |
847 |
|
file = 0; |
848 |
|
|
849 |
|
this->filename = filename ? filename : _("Unsaved Gig File"); |
850 |
|
set_title(Glib::filename_display_basename(this->filename)); |
851 |
|
file_has_name = filename; |
852 |
|
file_is_changed = false; |
853 |
|
|
854 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
855 |
|
|
898 |
} |
} |
899 |
} |
} |
900 |
|
|
901 |
|
file = gig; |
902 |
|
|
903 |
// select the first instrument |
// select the first instrument |
904 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
905 |
tree_sel_ref->select(Gtk::TreePath("0")); |
tree_sel_ref->select(Gtk::TreePath("0")); |
973 |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
974 |
rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
975 |
rowInstr[m_Columns.m_col_instr] = instrument; |
rowInstr[m_Columns.m_col_instr] = instrument; |
976 |
|
file_changed(); |
977 |
} |
} |
978 |
|
|
979 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
988 |
if (instr) file->DeleteInstrument(instr); |
if (instr) file->DeleteInstrument(instr); |
989 |
// remove respective row from instruments tree view |
// remove respective row from instruments tree view |
990 |
m_refTreeModel->erase(it); |
m_refTreeModel->erase(it); |
991 |
|
file_changed(); |
992 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
993 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
994 |
msg.run(); |
msg.run(); |
1017 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
1018 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1019 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_group] = group; |
1020 |
|
file_changed(); |
1021 |
} |
} |
1022 |
|
|
1023 |
void MainWindow::on_action_add_sample() { |
void MainWindow::on_action_add_sample() { |
1043 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
1044 |
dialog.set_select_multiple(true); |
dialog.set_select_multiple(true); |
1045 |
Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile |
Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile |
1046 |
const char* supportedFileTypes[] = { |
const char* const supportedFileTypes[] = { |
1047 |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
1048 |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
1049 |
"*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64", |
"*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64", |
1100 |
// add a new sample to the .gig file |
// add a new sample to the .gig file |
1101 |
gig::Sample* sample = file->AddSample(); |
gig::Sample* sample = file->AddSample(); |
1102 |
// file name without path |
// file name without path |
1103 |
sample->pInfo->Name = (*iter).substr((*iter).rfind('/') + 1).raw(); |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
1104 |
|
// remove file extension if there is one |
1105 |
|
for (int i = 0; supportedFileTypes[i]; i++) { |
1106 |
|
if (Glib::str_has_suffix(filename, supportedFileTypes[i] + 1)) { |
1107 |
|
filename.erase(filename.length() - strlen(supportedFileTypes[i] + 1)); |
1108 |
|
break; |
1109 |
|
} |
1110 |
|
} |
1111 |
|
sample->pInfo->Name = filename; |
1112 |
sample->Channels = info.channels; |
sample->Channels = info.channels; |
1113 |
sample->BitDepth = bitdepth; |
sample->BitDepth = bitdepth; |
1114 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
1128 |
Gtk::TreeModel::iterator iterSample = |
Gtk::TreeModel::iterator iterSample = |
1129 |
m_refSamplesTreeModel->append(row.children()); |
m_refSamplesTreeModel->append(row.children()); |
1130 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
1131 |
rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); |
rowSample[m_SamplesModel.m_col_name] = filename; |
1132 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1133 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1134 |
// close sound file |
// close sound file |
1135 |
sf_close(hFile); |
sf_close(hFile); |
1136 |
|
file_changed(); |
1137 |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
1138 |
if (error_files.size()) error_files += "\n"; |
if (error_files.size()) error_files += "\n"; |
1139 |
error_files += *iter += " (" + what + ")"; |
error_files += *iter += " (" + what + ")"; |
1184 |
} |
} |
1185 |
} |
} |
1186 |
} |
} |
1187 |
|
file_changed(); |
1188 |
} else if (sample) { |
} else if (sample) { |
1189 |
// remove sample from the .gig file |
// remove sample from the .gig file |
1190 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
1199 |
break; |
break; |
1200 |
} |
} |
1201 |
} |
} |
1202 |
|
file_changed(); |
1203 |
} |
} |
1204 |
// remove respective row(s) from samples tree view |
// remove respective row(s) from samples tree view |
1205 |
m_refSamplesTreeModel->erase(it); |
m_refSamplesTreeModel->erase(it); |
1241 |
dimregion->pSample->pInfo->Name.c_str() << "\"" << std::endl; |
dimregion->pSample->pInfo->Name.c_str() << "\"" << std::endl; |
1242 |
// drop success |
// drop success |
1243 |
context->drop_reply(true, time); |
context->drop_reply(true, time); |
1244 |
|
file_changed(); |
1245 |
return; |
return; |
1246 |
} |
} |
1247 |
} |
} |
1257 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
1258 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
1259 |
if (group) { |
if (group) { |
1260 |
group->Name = name; |
if (group->Name != name) { |
1261 |
|
group->Name = name; |
1262 |
|
printf("group name changed\n"); |
1263 |
|
file_changed(); |
1264 |
|
} |
1265 |
} else if (sample) { |
} else if (sample) { |
1266 |
sample->pInfo->Name = name.raw(); |
if (sample->pInfo->Name != name.raw()) { |
1267 |
|
sample->pInfo->Name = name.raw(); |
1268 |
|
printf("sample name changed\n"); |
1269 |
|
file_changed(); |
1270 |
|
} |
1271 |
} |
} |
1272 |
} |
} |
1273 |
|
|
1277 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1278 |
Glib::ustring name = row[m_Columns.m_col_name]; |
Glib::ustring name = row[m_Columns.m_col_name]; |
1279 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1280 |
if (instrument) instrument->pInfo->Name = name.raw(); |
if (instrument && instrument->pInfo->Name != name.raw()) { |
1281 |
|
instrument->pInfo->Name = name.raw(); |
1282 |
|
file_changed(); |
1283 |
|
} |
1284 |
} |
} |