--- gigedit/trunk/src/gigedit/mainwindow.cpp 2008/02/03 14:10:47 1661 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2009/07/31 10:15:27 1959 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 - 2008 Andreas Persson + * Copyright (C) 2006-2009 Andreas Persson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -25,6 +26,7 @@ #include #include #include +#include "wrapLabel.hh" #include "global.h" @@ -128,8 +130,8 @@ m_HPaned.add2(dimreg_vbox); - m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples"); - m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments"); + m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); + m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); actionGroup = Gtk::ActionGroup::create(); @@ -201,13 +203,18 @@ sigc::mem_fun(*this, &MainWindow::on_action_add_group) ); actionGroup->add( - Gtk::Action::create("AddSample", _("Add _Sample(s)")), + Gtk::Action::create("AddSample", _("Add _Sample(s)...")), sigc::mem_fun(*this, &MainWindow::on_action_add_sample) ); actionGroup->add( Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) ); + actionGroup->add( + Gtk::Action::create("ReplaceAllSamplesInAllGroups", + _("Replace All Samples in All Groups...")), + sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) + ); uiManager = Gtk::UIManager::create(); uiManager->insert_action_group(actionGroup); @@ -248,6 +255,7 @@ " " " " " " + " " " " " " " " @@ -563,7 +571,7 @@ gig::File* pFile = new gig::File; // already add one new instrument by default gig::Instrument* pInstrument = pFile->AddInstrument(); - pInstrument->pInfo->Name = "Unnamed Instrument"; + pInstrument->pInfo->Name = _("Unnamed Instrument"); // update GUI with that new gig::File load_gig(pFile, 0 /*no file name yet*/); } @@ -618,22 +626,22 @@ Gtk::FileFilter filter; filter.add_pattern("*.gig"); dialog.set_filter(filter); - if (current_dir != "") { - dialog.set_current_folder(current_dir); + if (current_gig_dir != "") { + dialog.set_current_folder(current_gig_dir); } if (dialog.run() == Gtk::RESPONSE_OK) { std::string filename = dialog.get_filename(); printf("filename=%s\n", filename.c_str()); printf("on_action_file_open self=%x\n", Glib::Thread::self()); load_file(filename.c_str()); - current_dir = Glib::path_get_dirname(filename); + current_gig_dir = Glib::path_get_dirname(filename); } } void MainWindow::load_file(const char* name) { __clear(); - load_dialog = new LoadDialog("Loading...", *this); + load_dialog = new LoadDialog(_("Loading..."), *this); load_dialog->show_all(); loader = new Loader(strdup(name)); loader->signal_progress().connect( @@ -747,12 +755,38 @@ filter.add_pattern("*.gig"); dialog.set_filter(filter); - if (Glib::path_is_absolute(filename)) { - dialog.set_filename(filename); - } else if (current_dir != "") { - dialog.set_current_folder(current_dir); + // set initial dir and filename of the Save As dialog + // and prepare that initial filename as a copy of the gig + { + std::string basename = Glib::path_get_basename(filename); + std::string dir = Glib::path_get_dirname(filename); + basename = std::string(_("copy_of_")) + basename; + Glib::ustring copyFileName = Glib::build_filename(dir, basename); + if (Glib::path_is_absolute(filename)) { + dialog.set_filename(copyFileName); + } else { + if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir); + } + dialog.set_current_name(Glib::filename_display_basename(copyFileName)); } - dialog.set_current_name(Glib::filename_display_basename(filename)); + + // show warning in the dialog + Gtk::HBox descriptionArea; + descriptionArea.set_spacing(15); + Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); + descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); + view::WrapLabel description; + description.set_markup( + _("\nCAUTION: You MUST use the " + "\"Save\" dialog instead of " + "\"Save As...\" if you want to save " + "to the same .gig file. Using " + "\"Save As...\" for writing to the " + "same .gig file will end up in corrupted sample wave data!\n") + ); + descriptionArea.pack_start(description); + dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); + descriptionArea.show_all(); if (dialog.run() == Gtk::RESPONSE_OK) { file_structure_to_be_changed_signal.emit(this->file); @@ -764,7 +798,7 @@ printf("filename=%s\n", filename.c_str()); file->Save(filename); this->filename = filename; - current_dir = Glib::path_get_dirname(filename); + current_gig_dir = Glib::path_get_dirname(filename); set_title(Glib::filename_display_basename(filename)); file_has_name = true; file_is_changed = false; @@ -794,7 +828,7 @@ info.format = 0; SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); try { - if (!hFile) throw std::string("could not open file"); + if (!hFile) throw std::string(_("could not open file")); // determine sample's bit depth int bitdepth; switch (info.format & 0xff) { @@ -811,7 +845,7 @@ break; default: sf_close(hFile); // close sound file - throw std::string("format not supported"); // unsupported subformat (yet?) + throw std::string(_("format not supported")); // unsupported subformat (yet?) } const int bufsize = 10000; @@ -853,6 +887,8 @@ } // cleanup sf_close(hFile); + // let the sampler re-cache the sample if needed + sample_changed_signal.emit(iter->gig_sample); // on success we remove the sample from the import queue, // otherwise keep it, maybe it works the next time ? std::list::iterator cur = iter; @@ -883,16 +919,21 @@ { #ifdef ABOUT_DIALOG Gtk::AboutDialog dialog; +#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2 + dialog.set_program_name("Gigedit"); +#else + dialog.set_name("Gigedit"); +#endif dialog.set_version(VERSION); - dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson"); - dialog.set_comments( + dialog.set_copyright("Copyright (C) 2006-2009 Andreas Persson"); + dialog.set_comments(_( "Released under the GNU General Public License.\n" "\n" "Please notice that this is still a very young instrument editor. " "So better backup your Gigasampler files before editing them with " "this application.\n" "\n" - "Please report bugs to: http://bugs.linuxsampler.org" + "Please report bugs to: http://bugs.linuxsampler.org") ); dialog.set_website("http://www.linuxsampler.org"); dialog.set_website_label("http://www.linuxsampler.org"); @@ -902,26 +943,26 @@ PropDialog::PropDialog() : table(2,1), - eName("Name"), - eCreationDate("Creation date"), - eComments("Comments"), - eProduct("Product"), - eCopyright("Copyright"), - eArtists("Artists"), - eGenre("Genre"), - eKeywords("Keywords"), - eEngineer("Engineer"), - eTechnician("Technician"), - eSoftware("Software"), - eMedium("Medium"), - eSource("Source"), - eSourceForm("Source form"), - eCommissioned("Commissioned"), - eSubject("Subject"), + eName(_("Name")), + eCreationDate(_("Creation date")), + eComments(_("Comments")), + eProduct(_("Product")), + eCopyright(_("Copyright")), + eArtists(_("Artists")), + eGenre(_("Genre")), + eKeywords(_("Keywords")), + eEngineer(_("Engineer")), + eTechnician(_("Technician")), + eSoftware(_("Software")), + eMedium(_("Medium")), + eSource(_("Source")), + eSourceForm(_("Source form")), + eCommissioned(_("Commissioned")), + eSubject(_("Subject")), quitButton(Gtk::Stock::CLOSE), update_model(0) { - set_title("File Properties"); + set_title(_("File Properties")); eName.set_width_chars(50); connect(eName, &DLS::Info::Name); @@ -1039,21 +1080,21 @@ InstrumentProps::InstrumentProps() : table(2,1), quitButton(Gtk::Stock::CLOSE), - eName("Name"), - eIsDrum("Is drum"), - eMIDIBank("MIDI bank", 0, 16383), - eMIDIProgram("MIDI program"), - eAttenuation("Attenuation", 0, 96, 0, 1), - eGainPlus6("Gain +6dB", eAttenuation, -6), - eEffectSend("Effect send", 0, 65535), - eFineTune("Fine tune", -8400, 8400), - ePitchbendRange("Pitchbend range", 0, 12), - ePianoReleaseMode("Piano release mode"), - eDimensionKeyRangeLow("Keyswitching range low"), - eDimensionKeyRangeHigh("Keyswitching range high"), + eName(_("Name")), + eIsDrum(_("Is drum")), + eMIDIBank(_("MIDI bank"), 0, 16383), + eMIDIProgram(_("MIDI program")), + eAttenuation(_("Attenuation"), 0, 96, 0, 1), + eGainPlus6(_("Gain +6dB"), eAttenuation, -6), + eEffectSend(_("Effect send"), 0, 65535), + eFineTune(_("Fine tune"), -8400, 8400), + ePitchbendRange(_("Pitchbend range"), 0, 12), + ePianoReleaseMode(_("Piano release mode")), + eDimensionKeyRangeLow(_("Keyswitching range low")), + eDimensionKeyRangeHigh(_("Keyswitching range high")), update_model(0) { - set_title("Instrument Properties"); + set_title(_("Instrument Properties")); eDimensionKeyRangeLow.set_tip( _("start of the keyboard area which should switch the " @@ -1278,7 +1319,7 @@ gig::Instrument* instrument = file->AddInstrument(); __instrument_indexer++; instrument->pInfo->Name = - "Unnamed Instrument " + ToString(__instrument_indexer); + _("Unnamed Instrument ") + ToString(__instrument_indexer); // update instrument tree view Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); Gtk::TreeModel::Row rowInstr = *iterInstr; @@ -1321,7 +1362,7 @@ void MainWindow::on_action_sample_properties() { //TODO: show a dialog where the selected sample's properties can be edited Gtk::MessageDialog msg( - *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO + *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO ); msg.run(); } @@ -1330,7 +1371,7 @@ static int __sample_indexer = 0; if (!file) return; gig::Group* group = file->AddGroup(); - group->Name = "Unnamed Group"; + group->Name = _("Unnamed Group"); if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); __sample_indexer++; // update sample tree view @@ -1374,13 +1415,17 @@ }; for (int i = 0; supportedFileTypes[i]; i++) soundfilter.add_pattern(supportedFileTypes[i]); - soundfilter.set_name("Sound Files"); + soundfilter.set_name(_("Sound Files")); Gtk::FileFilter allpassfilter; // matches every file allpassfilter.add_pattern("*.*"); - allpassfilter.set_name("All Files"); + allpassfilter.set_name(_("All Files")); dialog.add_filter(soundfilter); dialog.add_filter(allpassfilter); + if (current_sample_dir != "") { + dialog.set_current_folder(current_sample_dir); + } if (dialog.run() == Gtk::RESPONSE_OK) { + current_sample_dir = dialog.get_current_folder(); Glib::ustring error_files; Glib::SListHandle filenames = dialog.get_filenames(); for (Glib::SListHandle::iterator iter = filenames.begin(); @@ -1391,7 +1436,7 @@ info.format = 0; SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); try { - if (!hFile) throw std::string("could not open file"); + if (!hFile) throw std::string(_("could not open file")); int bitdepth; switch (info.format & 0xff) { case SF_FORMAT_PCM_S8: @@ -1407,7 +1452,7 @@ break; default: sf_close(hFile); // close sound file - throw std::string("format not supported"); // unsupported subformat (yet?) + throw std::string(_("format not supported")); // unsupported subformat (yet?) } // add a new sample to the .gig file gig::Sample* sample = file->AddSample(); @@ -1493,6 +1538,100 @@ } } +void MainWindow::on_action_replace_all_samples_in_all_groups() +{ + if (!file) return; + Gtk::FileChooserDialog dialog(*this, _("Select Folder"), + Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); + view::WrapLabel description( + _("This is a very specific function. It tries to replace all samples " + "in the current gig file by samples located in the chosen " + "directory.\n\n" + "It works like this: For each sample in the gig file, it tries to " + "find a sample file in the selected directory with the same name as " + "the sample in the gig file. Optionally, you can add a filename " + "extension below, which will be added to the filename expected to be " + "found. That is, assume you have a gig file with a sample called " + "'Snare', if you enter '.wav' below (like it's done by default), it " + "expects to find a sample file called 'Snare.wav' and will replace " + "the sample in the gig file accordingly. If you don't need an " + "extension, blank the field below. Any gig sample where no " + "appropriate sample file could be found will be reported and left " + "untouched.\n") + ); + Gtk::HBox entryArea; + Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_RIGHT); + Gtk::Entry postfixEntryBox; + postfixEntryBox.set_text(".wav"); + entryArea.pack_start(entryLabel); + entryArea.pack_start(postfixEntryBox); + dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK); + dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); + description.show(); + entryArea.show_all(); + dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + dialog.add_button(_("Select"), Gtk::RESPONSE_OK); + dialog.set_select_multiple(false); + if (current_sample_dir != "") { + dialog.set_current_folder(current_sample_dir); + } + if (dialog.run() == Gtk::RESPONSE_OK) + { + current_sample_dir = dialog.get_current_folder(); + Glib::ustring error_files; + Glib::ustring folder = dialog.get_filename(); + for (gig::Sample* sample = file->GetFirstSample(); + sample; sample = file->GetNextSample()) + { + std::string filename = + folder + G_DIR_SEPARATOR_S + sample->pInfo->Name + + postfixEntryBox.get_text().raw(); + SF_INFO info; + info.format = 0; + SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); + try + { + if (!hFile) throw std::string(_("could not open file")); + int bitdepth; + switch (info.format & 0xff) { + case SF_FORMAT_PCM_S8: + case SF_FORMAT_PCM_16: + case SF_FORMAT_PCM_U8: + bitdepth = 16; + break; + case SF_FORMAT_PCM_24: + case SF_FORMAT_PCM_32: + case SF_FORMAT_FLOAT: + case SF_FORMAT_DOUBLE: + bitdepth = 24; + break; + default: + sf_close(hFile); + throw std::string(_("format not supported")); + } + SampleImportItem sched_item; + sched_item.gig_sample = sample; + sched_item.sample_path = filename; + m_SampleImportQueue.push_back(sched_item); + sf_close(hFile); + file_changed(); + } + catch (std::string what) + { + if (error_files.size()) error_files += "\n"; + error_files += filename += " (" + what + ")"; + } + } + // show error message box when some file(s) could not be opened / added + if (error_files.size()) { + Glib::ustring txt = + _("Could not replace the following sample(s):\n") + error_files; + Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); + msg.run(); + } + } +} + void MainWindow::on_action_remove_sample() { if (!file) return; Glib::RefPtr sel = m_TreeViewSamples.get_selection(); @@ -1741,6 +1880,10 @@ return region_changed_signal; } +sigc::signal& MainWindow::signal_sample_changed() { + return sample_changed_signal; +} + sigc::signal& MainWindow::signal_sample_ref_changed() { return sample_ref_changed_signal; }