--- gigedit/trunk/src/gigedit/mainwindow.cpp 2009/02/03 19:38:19 1831 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2014/04/23 16:49:05 2541 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2009 Andreas Persson + * Copyright (C) 2006-2014 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,71 +20,32 @@ #include #include +#include +#include +#include +#include +#include #include #include #include #include #include #include +#if GTKMM_MAJOR_VERSION < 3 #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 "global.h" +#include "compat.h" #include #include #include "mainwindow.h" - +#include "Settings.h" #include "../../gfx/status_attached.xpm" #include "../../gfx/status_detached.xpm" -template inline std::string ToString(T o) { - std::stringstream ss; - ss << o; - return ss.str(); -} - -Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) { } - -void Table::add(BoolEntry& boolentry) -{ - attach(boolentry.widget, 0, 2, rowno, rowno + 1, - Gtk::FILL, Gtk::SHRINK); - rowno++; -} - -void Table::add(BoolEntryPlus6& boolentry) -{ - attach(boolentry.widget, 0, 2, rowno, rowno + 1, - Gtk::FILL, Gtk::SHRINK); - rowno++; -} - -void Table::add(LabelWidget& prop) -{ - attach(prop.label, 1, 2, rowno, rowno + 1, - Gtk::FILL, Gtk::SHRINK); - attach(prop.widget, 2, 3, rowno, rowno + 1, - Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK); - rowno++; -} MainWindow::MainWindow() : dimreg_label(_("Changes apply to:")), @@ -99,8 +60,7 @@ add(m_VBox); // Handle selection - Glib::RefPtr tree_sel_ref = m_TreeView.get_selection(); - tree_sel_ref->signal_changed().connect( + m_TreeView.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &MainWindow::on_sel_change)); // m_TreeView.set_reorderable(); @@ -129,6 +89,10 @@ dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); m_HPaned.add2(dimreg_vbox); + dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); + dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well.")); + dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below.")); + dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below).")); m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); @@ -163,13 +127,36 @@ Gtk::Stock::PROPERTIES), sigc::mem_fun( *this, &MainWindow::show_instr_props)); + actionGroup->add(Gtk::Action::create("MidiRules", + _("_Midi Rules")), + sigc::mem_fun( + *this, &MainWindow::show_midi_rules)); actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), sigc::mem_fun( *this, &MainWindow::on_action_quit)); actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); - actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); + + actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); + Glib::RefPtr toggle_action = + Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); + toggle_action->set_active(true); + actionGroup->add(toggle_action); + + toggle_action = + Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); + toggle_action->set_active(true); + actionGroup->add(toggle_action); + + toggle_action = + Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); + toggle_action->set_active(true); + actionGroup->add(toggle_action); + + + actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); + toggle_action = Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); toggle_action->set_active(true); actionGroup->add(toggle_action, @@ -179,20 +166,34 @@ 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) ); actionGroup->add( + Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")), + sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) + ); + actionGroup->add( Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) ); + + actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings"))); + + toggle_action = + Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions")); + toggle_action->set_active(Settings::singleton()->warnUserOnExtensions); + actionGroup->add( + toggle_action, + sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) + ); + + // sample right-click popup actions actionGroup->add( Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), @@ -234,20 +235,28 @@ " " " " " " + " " + " " + " " + " " + " " " " " " " " " " " " -#ifdef ABOUT_DIALOG + " " + " " + " " " " " " " " -#endif " " " " " " + " " " " + " " " " " " " " @@ -255,7 +264,7 @@ " " " " " " - " " + " " " " " " " " @@ -263,6 +272,34 @@ uiManager->add_ui_from_string(ui_info); popup_menu = dynamic_cast(uiManager->get_widget("/PopupMenu")); + + // Set tooltips for menu items (for some reason, setting a tooltip on the + // respective Gtk::Action objects above will simply be ignored, no matter + // if using Gtk::Action::set_tooltip() or passing the tooltip string on + // Gtk::Action::create()). + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); + item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action.")); + } + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); + item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action.")); + } + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); + item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action.")); + } + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); + item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application.")); + } + + instrument_menu = static_cast( + uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); @@ -272,6 +309,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); @@ -286,7 +325,8 @@ // Create the Tree model: m_refTreeModel = Gtk::ListStore::create(m_Columns); m_TreeView.set_model(m_refTreeModel); - m_refTreeModel->signal_row_changed().connect( + m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules.")); + instrument_name_connection = m_refTreeModel->signal_row_changed().connect( sigc::mem_fun(*this, &MainWindow::instrument_name_changed) ); @@ -297,6 +337,7 @@ // create samples treeview (including its data model) m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); m_TreeViewSamples.set_model(m_refSamplesTreeModel); + m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples.")); // m_TreeViewSamples.set_reorderable(); m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); m_TreeViewSamples.set_headers_visible(false); @@ -308,8 +349,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) @@ -327,9 +368,11 @@ sigc::mem_fun(*this, &MainWindow::file_changed)); m_DimRegionChooser.signal_region_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); - instrumentProps.signal_instrument_changed().connect( + instrumentProps.signal_changed().connect( + sigc::mem_fun(*this, &MainWindow::file_changed)); + propDialog.signal_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); - propDialog.signal_info_changed().connect( + midiRules.signal_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); dimreg_edit.signal_dimreg_to_be_changed().connect( @@ -374,7 +417,6 @@ file = 0; file_is_changed = false; - set_file_is_shared(false); show_all_children(); @@ -405,9 +447,8 @@ gig::Instrument* MainWindow::get_instrument() { gig::Instrument* instrument = 0; - Glib::RefPtr tree_sel_ref = m_TreeView.get_selection(); - - Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); + Gtk::TreeModel::const_iterator it = + m_TreeView.get_selection()->get_selected(); if (it) { Gtk::TreeModel::Row row = *it; instrument = row[m_Columns.m_col_instr]; @@ -466,6 +507,16 @@ void MainWindow::on_sel_change() { + // select item in instrument menu + Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected(); + if (it) { + Gtk::TreePath path(it); + int index = path[0]; + const std::vector children = + instrument_menu->get_children(); + static_cast(children[index])->set_active(); + } + m_RegionChooser.set_instrument(get_instrument()); } @@ -478,7 +529,7 @@ void Loader::progress_callback(float fraction) { { - Glib::Mutex::Lock lock(progressMutex); + Glib::Threads::Mutex::Lock lock(progressMutex); progress = fraction; } progress_dispatcher(); @@ -486,7 +537,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 +551,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 +569,7 @@ { float res; { - Glib::Mutex::Lock lock(progressMutex); + Glib::Threads::Mutex::Lock lock(progressMutex); res = progress; } return res; @@ -540,19 +595,15 @@ // Clear all GUI elements / controls. This method is typically called // before a new .gig file is to be created or to be loaded. void MainWindow::__clear() { - // remove all entries from "Instrument" menu - 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]; - } - instrument_menu->get_submenu()->items().clear(); // forget all samples that ought to be imported m_SampleImportQueue.clear(); // clear the samples and instruments tree views m_refTreeModel->clear(); m_refSamplesTreeModel->clear(); + // remove all entries from "Instrument" menu + while (!instrument_menu->get_children().empty()) { + remove_instrument_from_menu(0); + } // free libgig's gig::File instance if (file && !file_is_shared) delete file; file = NULL; @@ -571,7 +622,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 = gig_from_utf8(_("Unnamed Instrument")); // update GUI with that new gig::File load_gig(pFile, 0 /*no file name yet*/); } @@ -582,9 +633,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 +647,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 +669,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 +683,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); } @@ -674,7 +725,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 +797,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 @@ -775,7 +828,12 @@ descriptionArea.set_spacing(15); Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); +#if GTKMM_MAJOR_VERSION < 3 view::WrapLabel description; +#else + Gtk::Label description; + description.set_line_wrap(); +#endif description.set_markup( _("\nCAUTION: You MUST use the " "\"Save\" dialog instead of " @@ -827,6 +885,7 @@ SF_INFO info; info.format = 0; SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); + sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); try { if (!hFile) throw std::string(_("could not open file")); // determine sample's bit depth @@ -887,6 +946,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; @@ -894,13 +955,13 @@ m_SampleImportQueue.erase(cur); } catch (std::string what) { // remember the files that made trouble (and their cause) - if (error_files.size()) error_files += "\n"; + if (!error_files.empty()) error_files += "\n"; error_files += (*iter).sample_path += " (" + what + ")"; ++iter; } } // show error message box when some sample(s) could not be imported - if (error_files.size()) { + if (!error_files.empty()) { Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); @@ -913,30 +974,41 @@ propDialog.deiconify(); } +void MainWindow::on_action_warn_user_on_extensions() { + Settings::singleton()->warnUserOnExtensions = + !Settings::singleton()->warnUserOnExtensions; +} + 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-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") - ); + dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); + const std::string sComment = + _("Built " __DATE__ "\nUsing ") + + ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + + _( + "Gigedit is 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" + ); + dialog.set_comments(sComment.c_str()); 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")), + : eName(_("Name")), eCreationDate(_("Creation date")), eComments(_("Comments")), eProduct(_("Product")), @@ -953,7 +1025,7 @@ eCommissioned(_("Commissioned")), eSubject(_("Subject")), quitButton(Gtk::Stock::CLOSE), - update_model(0) + table(2, 1) { set_title(_("File Properties")); eName.set_width_chars(50); @@ -1001,7 +1073,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)); @@ -1013,79 +1085,52 @@ void PropDialog::set_info(DLS::Info* info) { - this->info = info; - update_model++; - eName.set_value(info->Name); - eCreationDate.set_value(info->CreationDate); - eComments.set_value(info->Comments); - eProduct.set_value(info->Product); - eCopyright.set_value(info->Copyright); - eArtists.set_value(info->Artists); - eGenre.set_value(info->Genre); - eKeywords.set_value(info->Keywords); - eEngineer.set_value(info->Engineer); - eTechnician.set_value(info->Technician); - eSoftware.set_value(info->Software); - eMedium.set_value(info->Medium); - eSource.set_value(info->Source); - eSourceForm.set_value(info->SourceForm); - eCommissioned.set_value(info->Commissioned); - eSubject.set_value(info->Subject); - update_model--; + update(info); } -sigc::signal& PropDialog::signal_info_changed() -{ - return info_changed; -} -void InstrumentProps::set_IsDrum(bool value) +void InstrumentProps::set_Name(const gig::String& name) { - instrument->IsDrum = value; + m->pInfo->Name = name; } -void InstrumentProps::set_MIDIBank(uint16_t value) +void InstrumentProps::update_name() { - instrument->MIDIBank = value; + update_model++; + eName.set_value(m->pInfo->Name); + update_model--; } -void InstrumentProps::set_MIDIProgram(uint32_t value) +void InstrumentProps::set_IsDrum(bool value) { - instrument->MIDIProgram = value; + m->IsDrum = value; } -void InstrumentProps::set_DimensionKeyRange_low(uint8_t value) +void InstrumentProps::set_MIDIBank(uint16_t value) { - instrument->DimensionKeyRange.low = value; - if (value > instrument->DimensionKeyRange.high) { - eDimensionKeyRangeHigh.set_value(value); - } + m->MIDIBank = value; } -void InstrumentProps::set_DimensionKeyRange_high(uint8_t value) +void InstrumentProps::set_MIDIProgram(uint32_t value) { - instrument->DimensionKeyRange.high = value; - if (value < instrument->DimensionKeyRange.low) { - eDimensionKeyRangeLow.set_value(value); - } + m->MIDIProgram = value; } -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")), - update_model(0) +InstrumentProps::InstrumentProps() : + quitButton(Gtk::Stock::CLOSE), + 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")); @@ -1098,6 +1143,7 @@ "\"keyswitching\" dimension") ); + connect(eName, &InstrumentProps::set_Name); connect(eIsDrum, &InstrumentProps::set_IsDrum); connect(eMIDIBank, &InstrumentProps::set_MIDIBank); connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); @@ -1107,10 +1153,10 @@ connect(eFineTune, &gig::Instrument::FineTune); connect(ePitchbendRange, &gig::Instrument::PitchbendRange); connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode); - connect(eDimensionKeyRangeLow, - &InstrumentProps::set_DimensionKeyRange_low); - connect(eDimensionKeyRangeHigh, - &InstrumentProps::set_DimensionKeyRange_high); + connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, + &gig::Instrument::DimensionKeyRange); + + eName.signal_value_changed().connect(sig_name_changed.make_slot()); table.set_col_spacings(5); @@ -1136,7 +1182,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( @@ -1149,28 +1195,16 @@ void InstrumentProps::set_instrument(gig::Instrument* instrument) { - this->instrument = instrument; + update(instrument); update_model++; eName.set_value(instrument->pInfo->Name); eIsDrum.set_value(instrument->IsDrum); eMIDIBank.set_value(instrument->MIDIBank); eMIDIProgram.set_value(instrument->MIDIProgram); - eAttenuation.set_value(instrument->Attenuation); - eGainPlus6.set_value(instrument->Attenuation); - eEffectSend.set_value(instrument->EffectSend); - eFineTune.set_value(instrument->FineTune); - ePitchbendRange.set_value(instrument->PitchbendRange); - ePianoReleaseMode.set_value(instrument->PianoReleaseMode); - eDimensionKeyRangeLow.set_value(instrument->DimensionKeyRange.low); - eDimensionKeyRangeHigh.set_value(instrument->DimensionKeyRange.high); update_model--; } -sigc::signal& InstrumentProps::signal_instrument_changed() -{ - return instrument_changed; -} void MainWindow::file_changed() { @@ -1192,37 +1226,26 @@ propDialog.set_info(gig->pInfo); - Gtk::MenuItem* instrument_menu = - dynamic_cast(uiManager->get_widget("/MenuBar/MenuInstrument")); - - int instrument_index = 0; - Gtk::RadioMenuItem::Group instrument_group; + instrument_name_connection.block(); for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; instrument = gig->GetNextInstrument()) { + Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); + Gtk::TreeModel::iterator iter = m_refTreeModel->append(); Gtk::TreeModel::Row row = *iter; - row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); + row[m_Columns.m_col_name] = name; row[m_Columns.m_col_instr] = instrument; - // create a menu item for this instrument - Gtk::RadioMenuItem* item = - new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str()); - instrument_menu->get_submenu()->append(*item); - item->signal_activate().connect( - sigc::bind( - sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), - instrument_index - ) - ); - instrument_index++; + + add_instrument_to_menu(name); } - instrument_menu->show(); - instrument_menu->get_submenu()->show_all_children(); + instrument_name_connection.unblock(); + uiManager->get_widget("/MenuBar/MenuInstrument")->show(); for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { if (group->Name != "") { Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); Gtk::TreeModel::Row rowGroup = *iterGroup; - rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); + rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); rowGroup[m_SamplesModel.m_col_group] = group; rowGroup[m_SamplesModel.m_col_sample] = NULL; for (gig::Sample* sample = group->GetFirstSample(); @@ -1230,7 +1253,8 @@ Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children()); Gtk::TreeModel::Row rowSample = *iterSample; - rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); + rowSample[m_SamplesModel.m_col_name] = + gig_to_utf8(sample->pInfo->Name); rowSample[m_SamplesModel.m_col_sample] = sample; rowSample[m_SamplesModel.m_col_group] = NULL; } @@ -1240,21 +1264,70 @@ file = gig; // select the first instrument - Glib::RefPtr tree_sel_ref = m_TreeView.get_selection(); - tree_sel_ref->select(Gtk::TreePath("0")); + m_TreeView.get_selection()->select(Gtk::TreePath("0")); + + instr_props_set_instrument(); + gig::Instrument* instrument = get_instrument(); + if (instrument) { + midiRules.set_instrument(instrument); + } } -void MainWindow::show_instr_props() +bool MainWindow::instr_props_set_instrument() { - gig::Instrument* instrument = get_instrument(); - if (instrument) - { + instrumentProps.signal_name_changed().clear(); + + Gtk::TreeModel::const_iterator it = + m_TreeView.get_selection()->get_selected(); + if (it) { + Gtk::TreeModel::Row row = *it; + gig::Instrument* instrument = row[m_Columns.m_col_instr]; + instrumentProps.set_instrument(instrument); + + // make sure instrument tree is updated when user changes the + // instrument name in instrument properties window + instrumentProps.signal_name_changed().connect( + sigc::bind( + sigc::mem_fun(*this, + &MainWindow::instr_name_changed_by_instr_props), + it)); + } else { + instrumentProps.hide(); + } + return it; +} + +void MainWindow::show_instr_props() +{ + if (instr_props_set_instrument()) { instrumentProps.show(); instrumentProps.deiconify(); } } +void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it) +{ + Gtk::TreeModel::Row row = *it; + Glib::ustring name = row[m_Columns.m_col_name]; + + gig::Instrument* instrument = row[m_Columns.m_col_instr]; + Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name)); + if (gigname != name) { + row[m_Columns.m_col_name] = gigname; + } +} + +void MainWindow::show_midi_rules() +{ + if (gig::Instrument* instrument = get_instrument()) + { + midiRules.set_instrument(instrument); + midiRules.show(); + midiRules.deiconify(); + } +} + void MainWindow::on_action_view_status_bar() { Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); @@ -1266,17 +1339,62 @@ else m_StatusBar.hide(); } +bool MainWindow::is_copy_samples_unity_note_enabled() const { + Gtk::CheckMenuItem* item = + dynamic_cast(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); + if (!item) { + std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n"; + return true; + } + return item->get_active(); +} + +bool MainWindow::is_copy_samples_fine_tune_enabled() const { + Gtk::CheckMenuItem* item = + dynamic_cast(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); + if (!item) { + std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n"; + return true; + } + return item->get_active(); +} + +bool MainWindow::is_copy_samples_loop_enabled() const { + Gtk::CheckMenuItem* item = + dynamic_cast(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); + if (!item) { + std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n"; + return true; + } + return item->get_active(); +} + void MainWindow::on_button_release(GdkEventButton* button) { if (button->type == GDK_2BUTTON_PRESS) { show_instr_props(); } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { + // gig v2 files have no midi rules + static_cast( + uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( + !(file->pVersion && file->pVersion->major == 2)); popup_menu->popup(button->button, button->time); } } -void MainWindow::on_instrument_selection_change(int index) { - m_RegionChooser.set_instrument(file->GetInstrument(index)); +void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) { + if (item->get_active()) { + const std::vector children = + instrument_menu->get_children(); + std::vector::const_iterator it = + find(children.begin(), children.end(), item); + if (it != children.end()) { + int index = it - children.begin(); + m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index))); + + m_RegionChooser.set_instrument(file->GetInstrument(index)); + } + } } void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { @@ -1306,21 +1424,89 @@ } } -void MainWindow::on_action_add_instrument() { - static int __instrument_indexer = 0; - if (!file) return; - gig::Instrument* instrument = file->AddInstrument(); - __instrument_indexer++; - instrument->pInfo->Name = - _("Unnamed Instrument ") + ToString(__instrument_indexer); + +Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( + const Glib::ustring& name, int position) { + + Gtk::RadioMenuItem::Group instrument_group; + const std::vector children = instrument_menu->get_children(); + if (!children.empty()) { + instrument_group = + static_cast(children[0])->get_group(); + } + Gtk::RadioMenuItem* item = + new Gtk::RadioMenuItem(instrument_group, name); + if (position < 0) { + instrument_menu->append(*item); + } else { + instrument_menu->insert(*item, position); + } + item->show(); + item->signal_activate().connect( + sigc::bind( + sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), + item)); + return item; +} + +void MainWindow::remove_instrument_from_menu(int index) { + const std::vector children = + instrument_menu->get_children(); + Gtk::Widget* child = children[index]; + instrument_menu->remove(*child); + delete child; +} + +void MainWindow::add_instrument(gig::Instrument* instrument) { + const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); + // update instrument tree view + instrument_name_connection.block(); Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); Gtk::TreeModel::Row rowInstr = *iterInstr; - rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); + rowInstr[m_Columns.m_col_name] = name; rowInstr[m_Columns.m_col_instr] = instrument; + instrument_name_connection.unblock(); + + add_instrument_to_menu(name); + + m_TreeView.get_selection()->select(iterInstr); + file_changed(); } +void MainWindow::on_action_add_instrument() { + static int __instrument_indexer = 0; + if (!file) return; + gig::Instrument* instrument = file->AddInstrument(); + __instrument_indexer++; + instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") + + ToString(__instrument_indexer)); + + add_instrument(instrument); +} + +void MainWindow::on_action_duplicate_instrument() { + if (!file) return; + + // retrieve the currently selected instrument + // (being the original instrument to be duplicated) + Glib::RefPtr sel = m_TreeView.get_selection(); + Gtk::TreeModel::iterator itSelection = sel->get_selected(); + if (!itSelection) return; + Gtk::TreeModel::Row row = *itSelection; + gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; + if (!instrOrig) return; + + // duplicate the orginal instrument + gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); + instrNew->pInfo->Name = + instrOrig->pInfo->Name + + gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); + + add_instrument(instrNew); +} + void MainWindow::on_action_remove_instrument() { if (!file) return; if (file_is_shared) { @@ -1340,11 +1526,36 @@ Gtk::TreeModel::Row row = *it; gig::Instrument* instr = row[m_Columns.m_col_instr]; try { + Gtk::TreePath path(it); + int index = path[0]; + // remove instrument from the gig file if (instr) file->DeleteInstrument(instr); - // remove respective row from instruments tree view - m_refTreeModel->erase(it); file_changed(); + + remove_instrument_from_menu(index); + + // remove row from instruments tree view + m_refTreeModel->erase(it); + +#if GTKMM_MAJOR_VERSION < 3 + // select another instrument (in gtk3 this is done + // automatically) + if (!m_refTreeModel->children().empty()) { + if (index == m_refTreeModel->children().size()) { + index--; + } + m_TreeView.get_selection()->select( + Gtk::TreePath(ToString(index))); + } +#endif + instr_props_set_instrument(); + instr = get_instrument(); + if (instr) { + midiRules.set_instrument(instr); + } else { + midiRules.hide(); + } } catch (RIFF::Exception e) { Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); msg.run(); @@ -1364,13 +1575,13 @@ static int __sample_indexer = 0; if (!file) return; gig::Group* group = file->AddGroup(); - group->Name = _("Unnamed Group"); + group->Name = gig_from_utf8(_("Unnamed Group")); if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); __sample_indexer++; // update sample tree view Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); Gtk::TreeModel::Row rowGroup = *iterGroup; - rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); + rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); rowGroup[m_SamplesModel.m_col_sample] = NULL; rowGroup[m_SamplesModel.m_col_group] = group; file_changed(); @@ -1398,7 +1609,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 +1623,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 +1652,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 @@ -1458,7 +1690,7 @@ break; } } - sample->pInfo->Name = filename; + sample->pInfo->Name = gig_from_utf8(filename); sample->Channels = info.channels; sample->BitDepth = bitdepth; sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; @@ -1472,8 +1704,8 @@ &instrument, sizeof(instrument)) != SF_FALSE) { sample->MIDIUnityNote = instrument.basenote; + sample->FineTune = instrument.detune; -#if HAVE_SF_INSTRUMENT_LOOPS if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { sample->Loops = 1; @@ -1493,7 +1725,6 @@ sample->LoopPlayCount = instrument.loops[0].count; sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; } -#endif } // schedule resizing the sample (which will be done @@ -1511,19 +1742,20 @@ Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(row.children()); Gtk::TreeModel::Row rowSample = *iterSample; - rowSample[m_SamplesModel.m_col_name] = filename; + rowSample[m_SamplesModel.m_col_name] = + gig_to_utf8(sample->pInfo->Name); rowSample[m_SamplesModel.m_col_sample] = sample; rowSample[m_SamplesModel.m_col_group] = NULL; // close sound file sf_close(hFile); file_changed(); } catch (std::string what) { // remember the files that made trouble (and their cause) - if (error_files.size()) error_files += "\n"; + if (!error_files.empty()) error_files += "\n"; error_files += *iter += " (" + what + ")"; } } // show error message box when some file(s) could not be opened / added - if (error_files.size()) { + if (!error_files.empty()) { Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); @@ -1536,7 +1768,7 @@ if (!file) return; Gtk::FileChooserDialog dialog(*this, _("Select Folder"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); - view::WrapLabel description( + const char* str = _("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" @@ -1550,10 +1782,15 @@ "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") - ); + "untouched.\n"); +#if GTKMM_MAJOR_VERSION < 3 + view::WrapLabel description(str); +#else + Gtk::Label description(str); + description.set_line_wrap(); +#endif 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,13 +1809,14 @@ { 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()) { std::string filename = - folder + G_DIR_SEPARATOR_S + sample->pInfo->Name + - postfixEntryBox.get_text().raw(); + folder + G_DIR_SEPARATOR_S + + Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) + + postfixEntryBox.get_text()); SF_INFO info; info.format = 0; SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); @@ -1611,12 +1849,13 @@ } catch (std::string what) { - if (error_files.size()) error_files += "\n"; - error_files += filename += " (" + what + ")"; + if (!error_files.empty()) error_files += "\n"; + error_files += Glib::filename_to_utf8(filename) + + " (" + what + ")"; } } // show error message box when some file(s) could not be opened / added - if (error_files.size()) { + if (!error_files.empty()) { Glib::ustring txt = _("Could not replace the following sample(s):\n") + error_files; Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); @@ -1637,7 +1876,7 @@ try { // remove group or sample from the gig file if (group) { - // temporarily remember the samples that bolong to + // temporarily remember the samples that belong to // that group (we need that to clean the queue) std::list members; for (gig::Sample* pSample = group->GetFirstSample(); @@ -1763,7 +2002,12 @@ channels_changed = true; region_changed(); } - dimreg_edit.set_sample(sample); + dimreg_edit.set_sample( + sample, + is_copy_samples_unity_note_enabled(), + is_copy_samples_fine_tune_enabled(), + is_copy_samples_loop_enabled() + ); if (sample->Channels == 2 && !stereo_dimension) { // add samplechannel dimension @@ -1806,15 +2050,16 @@ Glib::ustring name = row[m_SamplesModel.m_col_name]; gig::Group* group = row[m_SamplesModel.m_col_group]; gig::Sample* sample = row[m_SamplesModel.m_col_sample]; + gig::String gigname(gig_from_utf8(name)); if (group) { - if (group->Name != name) { - group->Name = name; + if (group->Name != gigname) { + group->Name = gigname; printf("group name changed\n"); file_changed(); } } else if (sample) { - if (sample->pInfo->Name != name.raw()) { - sample->pInfo->Name = name.raw(); + if (sample->pInfo->Name != gigname) { + sample->pInfo->Name = gigname; printf("sample name changed\n"); file_changed(); } @@ -1826,9 +2071,31 @@ if (!iter) return; Gtk::TreeModel::Row row = *iter; Glib::ustring name = row[m_Columns.m_col_name]; + + // change name in instrument menu + int index = path[0]; + const std::vector children = instrument_menu->get_children(); + if (index < children.size()) { +#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2 + static_cast(children[index])->set_label(name); +#else + remove_instrument_from_menu(index); + Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index); + item->set_active(); +#endif + } + + // change name in gig gig::Instrument* instrument = row[m_Columns.m_col_instr]; - if (instrument && instrument->pInfo->Name != name.raw()) { - instrument->pInfo->Name = name.raw(); + gig::String gigname(gig_from_utf8(name)); + if (instrument && instrument->pInfo->Name != gigname) { + instrument->pInfo->Name = gigname; + + // change name in the instrument properties window + if (instrumentProps.get_instrument() == instrument) { + instrumentProps.update_name(); + } + file_changed(); } } @@ -1873,6 +2140,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; }