--- gigedit/trunk/src/gigedit/mainwindow.cpp 2013/04/14 07:29:59 2442 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2013/09/16 13:20:46 2476 @@ -128,8 +128,33 @@ *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"), "ffaga"); + toggle_action->set_active(true); + //FIXME: doesn't work, why? + toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); + actionGroup->add(toggle_action); + + toggle_action = + Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); + toggle_action->set_active(true); + //FIXME: doesn't work, why? + toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); + actionGroup->add(toggle_action); + + toggle_action = + Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); + toggle_action->set_active(true); + //FIXME: doesn't work, why? + toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field.")); + 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, @@ -196,6 +221,11 @@ " " " " " " + " " + " " + " " + " " + " " " " " " " " @@ -545,7 +575,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*/); } @@ -907,15 +937,19 @@ #endif dialog.set_version(VERSION); dialog.set_copyright("Copyright (C) 2006-2013 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") - ); + 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(); @@ -1003,6 +1037,18 @@ } +void InstrumentProps::set_Name(const gig::String& name) +{ + m->pInfo->Name = name; +} + +void InstrumentProps::update_name() +{ + update_model++; + eName.set_value(m->pInfo->Name); + update_model--; +} + void InstrumentProps::set_IsDrum(bool value) { m->IsDrum = value; @@ -1045,6 +1091,7 @@ "\"keyswitching\" dimension") ); + connect(eName, &InstrumentProps::set_Name); connect(eIsDrum, &InstrumentProps::set_IsDrum); connect(eMIDIBank, &InstrumentProps::set_MIDIBank); connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); @@ -1057,6 +1104,8 @@ connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, &gig::Instrument::DimensionKeyRange); + eName.signal_value_changed().connect(sig_name_changed.make_slot()); + table.set_col_spacings(5); table.add(eName); @@ -1097,6 +1146,7 @@ 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); @@ -1127,7 +1177,7 @@ instrument_name_connection.block(); for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; instrument = gig->GetNextInstrument()) { - Glib::ustring name(instrument->pInfo->Name); + Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); Gtk::TreeModel::iterator iter = m_refTreeModel->append(); Gtk::TreeModel::Row row = *iter; @@ -1143,7 +1193,7 @@ 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(); @@ -1151,7 +1201,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; } @@ -1163,23 +1214,54 @@ // select the first instrument m_TreeView.get_selection()->select(Gtk::TreePath("0")); - gig::Instrument* instrument = get_instrument(); - if (instrument) { + instr_props_set_instrument(); +} + +bool MainWindow::instr_props_set_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() { - gig::Instrument* instrument = get_instrument(); - if (instrument) - { - instrumentProps.set_instrument(instrument); + 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::on_action_view_status_bar() { Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); @@ -1191,6 +1273,36 @@ 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) { @@ -1276,7 +1388,7 @@ } void MainWindow::add_instrument(gig::Instrument* instrument) { - const char* name = instrument->pInfo->Name.c_str(); + const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); // update instrument tree view instrument_name_connection.block(); @@ -1298,8 +1410,8 @@ if (!file) return; gig::Instrument* instrument = file->AddInstrument(); __instrument_indexer++; - instrument->pInfo->Name = - _("Unnamed Instrument ") + ToString(__instrument_indexer); + instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") + + ToString(__instrument_indexer)); add_instrument(instrument); } @@ -1319,7 +1431,8 @@ // duplicate the orginal instrument gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); instrNew->pInfo->Name = - instrOrig->pInfo->Name + " (" + _("Copy") + ")"; + instrOrig->pInfo->Name + + gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); add_instrument(instrNew); } @@ -1366,12 +1479,7 @@ Gtk::TreePath(ToString(index))); } #endif - instr = get_instrument(); - if (instr) { - instrumentProps.set_instrument(instr); - } else { - instrumentProps.hide(); - } + instr_props_set_instrument(); } catch (RIFF::Exception e) { Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); msg.run(); @@ -1391,13 +1499,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(); @@ -1506,7 +1614,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; @@ -1520,6 +1628,7 @@ &instrument, sizeof(instrument)) != SF_FALSE) { sample->MIDIUnityNote = instrument.basenote; + sample->FineTune = instrument.detune; if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { sample->Loops = 1; @@ -1557,7 +1666,8 @@ 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 @@ -1628,8 +1738,9 @@ 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); @@ -1663,7 +1774,8 @@ catch (std::string what) { if (!error_files.empty()) error_files += "\n"; - error_files += filename += " (" + what + ")"; + error_files += Glib::filename_to_utf8(filename) + + " (" + what + ")"; } } // show error message box when some file(s) could not be opened / added @@ -1688,7 +1800,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(); @@ -1814,7 +1926,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 @@ -1857,15 +1974,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(); } @@ -1893,8 +2011,15 @@ // 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(); } }