--- gigedit/trunk/src/gigedit/mainwindow.cpp 2008/12/06 13:49:26 1799 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2012/03/14 05:22:26 2332 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 - 2008 Andreas Persson + * Copyright (C) 2006-2012 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 @@ -20,32 +20,22 @@ #include #include +#include +#include +#include +#include +#include #include #include #include #include #include +#include #include #include "wrapLabel.hh" #include "global.h" - -#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 -#define ABOUT_DIALOG -#include -#endif - -#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2 -namespace Glib { -Glib::ustring filename_display_basename(const std::string& filename) -{ - gchar* gstr = g_path_get_basename(filename.c_str()); - Glib::ustring str(gstr); - g_free(gstr); - return Glib::filename_to_utf8(str); -} -} -#endif +#include "compat.h" #include #include @@ -130,8 +120,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(); @@ -179,11 +169,9 @@ action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); actionGroup->add(Gtk::Action::create("MenuHelp", action->property_label())); -#ifdef ABOUT_DIALOG actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), sigc::mem_fun( *this, &MainWindow::on_action_help_about)); -#endif actionGroup->add( Gtk::Action::create("AddInstrument", _("Add _Instrument")), sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) @@ -239,11 +227,9 @@ " " " " " " -#ifdef ABOUT_DIALOG " " " " " " -#endif " " " " " " @@ -272,6 +258,8 @@ m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK); + set_file_is_shared(false); + // Status Bar: m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); @@ -308,8 +296,8 @@ ); // establish drag&drop between samples tree view and dimension region 'Sample' text entry - std::list drag_target_gig_sample; - drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); + std::vector drag_target_gig_sample; + drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); m_TreeViewSamples.drag_source_set(drag_target_gig_sample); m_TreeViewSamples.signal_drag_begin().connect( sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin) @@ -374,7 +362,6 @@ file = 0; file_is_changed = false; - set_file_is_shared(false); show_all_children(); @@ -478,7 +465,7 @@ void Loader::progress_callback(float fraction) { { - Glib::Mutex::Lock lock(progressMutex); + Glib::Threads::Mutex::Lock lock(progressMutex); progress = fraction; } progress_dispatcher(); @@ -486,7 +473,7 @@ void Loader::thread_function() { - printf("thread_function self=%x\n", Glib::Thread::self()); + printf("thread_function self=%x\n", Glib::Threads::Thread::self()); printf("Start %s\n", filename); RIFF::File* riff = new RIFF::File(filename); gig = new gig::File(riff); @@ -500,13 +487,17 @@ } Loader::Loader(const char* filename) - : thread(0), filename(filename) + : filename(filename), thread(0) { } void Loader::launch() { +#ifdef OLD_THREADS thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); +#else + thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); +#endif printf("launch thread=%x\n", thread); } @@ -514,7 +505,7 @@ { float res; { - Glib::Mutex::Lock lock(progressMutex); + Glib::Threads::Mutex::Lock lock(progressMutex); res = progress; } return res; @@ -544,10 +535,12 @@ Gtk::MenuItem* instrument_menu = dynamic_cast(uiManager->get_widget("/MenuBar/MenuInstrument")); instrument_menu->hide(); - for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) { - delete &instrument_menu->get_submenu()->items()[i]; + Gtk::Menu* menu = instrument_menu->get_submenu(); + while (menu->get_children().size()) { + Gtk::Widget* child = *menu->get_children().begin(); + menu->remove(*child); + delete child; } - instrument_menu->get_submenu()->items().clear(); // forget all samples that ought to be imported m_SampleImportQueue.clear(); // clear the samples and instruments tree views @@ -571,7 +564,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*/); } @@ -582,9 +575,7 @@ Glib::filename_display_basename(filename).c_str()); Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); g_free(msg); -#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); -#endif dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); @@ -598,13 +589,10 @@ bool MainWindow::leaving_shared_mode_dialog() { Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); -#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 dialog.set_secondary_text( _("If you proceed to work on another instrument file, it won't be " "used by the sampler until you tell the sampler explicitly to " - "load it.") - ); -#endif + "load it.")); dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.set_default_response(Gtk::RESPONSE_CANCEL); @@ -623,8 +611,13 @@ dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); dialog.set_default_response(Gtk::RESPONSE_OK); +#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 Gtk::FileFilter filter; filter.add_pattern("*.gig"); +#else + Glib::RefPtr filter = Gtk::FileFilter::create(); + filter->add_pattern("*.gig"); +#endif dialog.set_filter(filter); if (current_gig_dir != "") { dialog.set_current_folder(current_gig_dir); @@ -632,7 +625,7 @@ 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()); + printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); load_file(filename.c_str()); current_gig_dir = Glib::path_get_dirname(filename); } @@ -641,7 +634,7 @@ 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( @@ -674,7 +667,7 @@ void MainWindow::on_loader_finished() { printf("Loader finished!\n"); - printf("on_loader_finished self=%x\n", Glib::Thread::self()); + printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); load_gig(loader->gig, loader->filename); load_dialog->hide(); } @@ -746,13 +739,15 @@ dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); dialog.set_default_response(Gtk::RESPONSE_OK); - -#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2 dialog.set_do_overwrite_confirmation(); - // TODO: an overwrite dialog for gtkmm < 2.8 -#endif + +#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 Gtk::FileFilter filter; filter.add_pattern("*.gig"); +#else + Glib::RefPtr filter = Gtk::FileFilter::create(); + filter->add_pattern("*.gig"); +#endif dialog.set_filter(filter); // set initial dir and filename of the Save As dialog @@ -760,7 +755,7 @@ { std::string basename = Glib::path_get_basename(filename); std::string dir = Glib::path_get_dirname(filename); - basename = std::string("copy_of_") + basename; + basename = std::string(_("copy_of_")) + basename; Glib::ustring copyFileName = Glib::build_filename(dir, basename); if (Glib::path_is_absolute(filename)) { dialog.set_filename(copyFileName); @@ -828,7 +823,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) { @@ -845,7 +840,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; @@ -887,6 +882,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; @@ -915,47 +912,50 @@ void MainWindow::on_action_help_about() { -#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-2012 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"); dialog.run(); -#endif } 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), + table(2, 1), update_model(0) { - set_title("File Properties"); + set_title(_("File Properties")); eName.set_width_chars(50); connect(eName, &DLS::Info::Name); @@ -1001,7 +1001,7 @@ buttonBox.set_border_width(5); buttonBox.show(); buttonBox.pack_start(quitButton); - quitButton.set_flags(Gtk::CAN_DEFAULT); + quitButton.set_can_default(); quitButton.grab_focus(); quitButton.signal_clicked().connect( sigc::mem_fun(*this, &PropDialog::hide)); @@ -1071,23 +1071,23 @@ } InstrumentProps::InstrumentProps() - : table(2,1), + : update_model(0), 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"), - update_model(0) + table(2,1), + 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")) { - set_title("Instrument Properties"); + set_title(_("Instrument Properties")); eDimensionKeyRangeLow.set_tip( _("start of the keyboard area which should switch the " @@ -1136,7 +1136,7 @@ buttonBox.set_border_width(5); buttonBox.show(); buttonBox.pack_start(quitButton); - quitButton.set_flags(Gtk::CAN_DEFAULT); + quitButton.set_can_default(); quitButton.grab_focus(); quitButton.signal_clicked().connect( @@ -1312,7 +1312,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; @@ -1355,7 +1355,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(); } @@ -1364,7 +1364,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 @@ -1398,7 +1398,13 @@ dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); dialog.set_select_multiple(true); - Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile + + // matches all file types supported by libsndfile +#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 + Gtk::FileFilter soundfilter; +#else + Glib::RefPtr soundfilter = Gtk::FileFilter::create(); +#endif const char* const supportedFileTypes[] = { "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", @@ -1406,12 +1412,27 @@ "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", "*.caf", "*.CAF", NULL }; + const char* soundfiles = _("Sound Files"); + const char* allfiles = _("All Files"); +#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 for (int i = 0; supportedFileTypes[i]; i++) soundfilter.add_pattern(supportedFileTypes[i]); - soundfilter.set_name("Sound Files"); - Gtk::FileFilter allpassfilter; // matches every file + soundfilter.set_name(soundfiles); + + // matches every file + Gtk::FileFilter allpassfilter; allpassfilter.add_pattern("*.*"); - allpassfilter.set_name("All Files"); + allpassfilter.set_name(allfiles); +#else + for (int i = 0; supportedFileTypes[i]; i++) + soundfilter->add_pattern(supportedFileTypes[i]); + soundfilter->set_name(soundfiles); + + // matches every file + Glib::RefPtr allpassfilter = Gtk::FileFilter::create(); + allpassfilter->add_pattern("*.*"); + allpassfilter->set_name(allfiles); +#endif dialog.add_filter(soundfilter); dialog.add_filter(allpassfilter); if (current_sample_dir != "") { @@ -1420,8 +1441,8 @@ 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(); + std::vector filenames = dialog.get_filenames(); + for (std::vector::iterator iter = filenames.begin(); iter != filenames.end(); ++iter) { printf("Adding sample %s\n",(*iter).c_str()); // use libsndfile to retrieve file informations @@ -1429,7 +1450,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: @@ -1445,7 +1466,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(); @@ -1553,7 +1574,7 @@ "untouched.\n") ); Gtk::HBox entryArea; - Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_RIGHT); + Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START); Gtk::Entry postfixEntryBox; postfixEntryBox.set_text(".wav"); entryArea.pack_start(entryLabel); @@ -1572,7 +1593,7 @@ { current_sample_dir = dialog.get_current_folder(); Glib::ustring error_files; - Glib::ustring folder = dialog.get_filename(); + std::string folder = dialog.get_filename(); for (gig::Sample* sample = file->GetFirstSample(); sample; sample = file->GetNextSample()) { @@ -1584,7 +1605,7 @@ SNDFILE* hFile = sf_open(filename.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: @@ -1600,7 +1621,7 @@ break; default: sf_close(hFile); - throw std::string("format not supported"); + throw std::string(_("format not supported")); } SampleImportItem sched_item; sched_item.gig_sample = sample; @@ -1873,6 +1894,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; }