--- gigedit/trunk/src/gigedit/mainwindow.cpp 2013/04/14 07:29:59 2442 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2013/04/28 15:40:43 2446 @@ -545,7 +545,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*/); } @@ -1003,6 +1003,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 +1057,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 +1070,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 +1112,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 +1143,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 +1159,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 +1167,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 +1180,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")); @@ -1276,7 +1324,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 +1346,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 +1367,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 +1415,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 +1435,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 +1550,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; @@ -1557,7 +1601,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 +1673,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 +1709,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 +1735,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(); @@ -1857,15 +1904,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 +1941,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(); } }