--- gigedit/trunk/src/gigedit/mainwindow.cpp 2019/10/24 12:06:18 3636 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2019/10/24 13:12:52 3637 @@ -1484,6 +1484,8 @@ sigc::mem_fun(*this, &MainWindow::file_changed)); instrumentProps.signal_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); + sampleProps.signal_changed().connect( + sigc::mem_fun(*this, &MainWindow::file_changed)); fileProps.signal_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); midiRules.signal_changed().connect( @@ -3064,6 +3066,294 @@ } +SampleProps::SampleProps() : +#if HAS_GTKMM_STOCK + quitButton(Gtk::Stock::CLOSE), +#else + quitButton(_("_Close")), +#endif + table(2,1), + eName(_("Name")), + eUnityNote(_("Unity Note")), + eSampleGroup(_("Sample Group")), + eSampleFormatInfo(_("Sample Format")), + eSampleID("Sample ID"), + eChecksum("Wave Data CRC-32"), + eLoopsCount(_("Loops"), 0, 1), // we might support more than 1 loop in future + eLoopStart(_("Loop start position"), 0, 9999999), + eLoopLength(_("Loop size"), 0, 9999999), + eLoopType(_("Loop type")), + eLoopPlayCount(_("Playback count")), + table2(2,1), + eName2(_("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")) +{ + if (!Settings::singleton()->autoRestoreWindowDimension) { + //set_default_size(470, 390); + set_position(Gtk::WIN_POS_MOUSE); + } + + set_title(_("Sample Properties")); + + tabs.append_page(vbox[1], _("Settings")); + tabs.append_page(vbox[2], _("Info")); + + connect(eName, &SampleProps::set_Name); + connect(eUnityNote, &gig::Sample::MIDIUnityNote); + connect(eLoopsCount, &gig::Sample::Loops); + connectLambda(eLoopStart, [this](uint32_t start){ + m->LoopStart = start; + m->LoopEnd = start + m->LoopSize; + }); + connectLambda(eLoopLength, [this](uint32_t length){ + m->LoopSize = length; + m->LoopEnd = m->LoopStart + length; + }); + { + const char* choices[] = { _("normal"), _("bidirectional"), _("backward"), 0 }; + static const gig::loop_type_t values[] = { + gig::loop_type_normal, + gig::loop_type_bidirectional, + gig::loop_type_backward + }; + eLoopType.set_choices(choices, values); + } + connect(eLoopType, &gig::Sample::LoopType); + connect(eLoopPlayCount, &gig::Sample::LoopPlayCount); + + eName.signal_value_changed().connect(sig_name_changed.make_slot()); + + connect(eName2, &SampleProps::set_Name); + connectLambda(eCreationDate, [this](gig::String s) { + m->pInfo->CreationDate = s; + }); + connectLambda(eComments, [this](gig::String s) { + m->pInfo->Comments = s; + }); + connectLambda(eProduct, [this](gig::String s) { + m->pInfo->Product = s; + }); + connectLambda(eCopyright, [this](gig::String s) { + m->pInfo->Copyright = s; + }); + connectLambda(eArtists, [this](gig::String s) { + m->pInfo->Artists = s; + }); + connectLambda(eGenre, [this](gig::String s) { + m->pInfo->Genre = s; + }); + connectLambda(eKeywords, [this](gig::String s) { + m->pInfo->Keywords = s; + }); + connectLambda(eEngineer, [this](gig::String s) { + m->pInfo->Engineer = s; + }); + connectLambda(eTechnician, [this](gig::String s) { + m->pInfo->Technician = s; + }); + connectLambda(eSoftware, [this](gig::String s) { + m->pInfo->Software = s; + }); + connectLambda(eMedium, [this](gig::String s) { + m->pInfo->Medium = s; + }); + connectLambda(eSource, [this](gig::String s) { + m->pInfo->Source = s; + }); + connectLambda(eSourceForm, [this](gig::String s) { + m->pInfo->SourceForm = s; + }); + connectLambda(eCommissioned, [this](gig::String s) { + m->pInfo->Commissioned = s; + }); + connectLambda(eSubject, [this](gig::String s) { + m->pInfo->Subject = s; + }); + + // tab 1 +#if USE_GTKMM_GRID + table.set_column_spacing(5); +#else + table.set_col_spacings(5); +#endif + table.add(eName); + table.add(eUnityNote); + table.add(eSampleGroup); + table.add(eSampleFormatInfo); + table.add(eSampleID); + table.add(eChecksum); + table.add(eLoopsCount); + table.add(eLoopStart); + table.add(eLoopLength); + table.add(eLoopType); + table.add(eLoopPlayCount); + + // tab 2 +#if USE_GTKMM_GRID + table2.set_column_spacing(5); +#else + table2.set_col_spacings(5); +#endif + table2.add(eName2); + table2.add(eCreationDate); + table2.add(eComments); + table2.add(eProduct); + table2.add(eCopyright); + table2.add(eArtists); + table2.add(eGenre); + table2.add(eKeywords); + table2.add(eEngineer); + table2.add(eTechnician); + table2.add(eSoftware); + table2.add(eMedium); + table2.add(eSource); + table2.add(eSourceForm); + table2.add(eCommissioned); + table2.add(eSubject); + + add(vbox[0]); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) + table.set_margin(5); +#else + table.set_border_width(5); +#endif + vbox[1].pack_start(table); + vbox[2].pack_start(table2); + table.show(); + table2.show(); + vbox[0].pack_start(tabs); + vbox[0].pack_start(buttonBox, Gtk::PACK_SHRINK); + buttonBox.set_layout(Gtk::BUTTONBOX_END); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) + buttonBox.set_margin(5); +#else + buttonBox.set_border_width(5); +#endif + buttonBox.show(); + buttonBox.pack_start(quitButton); + quitButton.set_can_default(); + quitButton.grab_focus(); + + quitButton.signal_clicked().connect( + sigc::mem_fun(*this, &SampleProps::hide)); + + quitButton.show(); + vbox[0].show(); +#if HAS_GTKMM_SHOW_ALL_CHILDREN + show_all_children(); +#endif +} + +void SampleProps::set_sample(gig::Sample* sample) +{ + update(sample); + + update_model++; + + // tab 1 + eName.set_value(sample->pInfo->Name); + eUnityNote.set_value(sample->MIDIUnityNote); + // show sample group name + { + Glib::ustring s = "---"; + if (sample && sample->GetGroup()) + s = sample->GetGroup()->Name; + eSampleGroup.text.set_text(s); + } + // assemble sample format info string + { + Glib::ustring s; + if (sample) { + switch (sample->Channels) { + case 1: s = _("Mono"); break; + case 2: s = _("Stereo"); break; + default: + s = ToString(sample->Channels) + _(" audio channels"); + break; + } + s += " " + ToString(sample->BitDepth) + " Bits"; + s += " " + ToString(sample->SamplesPerSecond/1000) + "." + + ToString((sample->SamplesPerSecond%1000)/100) + " kHz"; + } else { + s = _("No sample assigned to this dimension region."); + } + eSampleFormatInfo.text.set_text(s); + } + // generate sample's memory address pointer string + { + Glib::ustring s; + if (sample) { + char buf[64] = {}; + snprintf(buf, sizeof(buf), "%p", sample); + s = buf; + } else { + s = "---"; + } + eSampleID.text.set_text(s); + } + // generate raw wave form data CRC-32 checksum string + { + Glib::ustring s = "---"; + if (sample) { + char buf[64] = {}; + snprintf(buf, sizeof(buf), "%x", sample->GetWaveDataCRC32Checksum()); + s = buf; + } + eChecksum.text.set_text(s); + } + eLoopsCount.set_value(sample->Loops); + eLoopStart.set_value(sample->LoopStart); + eLoopLength.set_value(sample->LoopSize); + eLoopType.set_value(sample->LoopType); + eLoopPlayCount.set_value(sample->LoopPlayCount); + // tab 2 + eName2.set_value(sample->pInfo->Name); + eCreationDate.set_value(sample->pInfo->CreationDate); + eComments.set_value(sample->pInfo->Comments); + eProduct.set_value(sample->pInfo->Product); + eCopyright.set_value(sample->pInfo->Copyright); + eArtists.set_value(sample->pInfo->Artists); + eGenre.set_value(sample->pInfo->Genre); + eKeywords.set_value(sample->pInfo->Keywords); + eEngineer.set_value(sample->pInfo->Engineer); + eTechnician.set_value(sample->pInfo->Technician); + eSoftware.set_value(sample->pInfo->Software); + eMedium.set_value(sample->pInfo->Medium); + eSource.set_value(sample->pInfo->Source); + eSourceForm.set_value(sample->pInfo->SourceForm); + eCommissioned.set_value(sample->pInfo->Commissioned); + eSubject.set_value(sample->pInfo->Subject); + + update_model--; +} + +void SampleProps::set_Name(const gig::String& name) +{ + m->pInfo->Name = name; +} + +void SampleProps::update_name() +{ + update_model++; + eName.set_value(m->pInfo->Name); + update_model--; +} + + void MainWindow::file_changed() { if (file && !file_is_changed) { @@ -3295,6 +3585,60 @@ } } +bool MainWindow::sample_props_set_sample() +{ + sampleProps.signal_name_changed().clear(); + + std::vector rows = m_TreeViewSamples.get_selection()->get_selected_rows(); + if (rows.empty()) { + sampleProps.hide(); + return false; + } + //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though. + Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); + if (it) { + Gtk::TreeModel::Row row = *it; + gig::Sample* sample = row[m_SamplesModel.m_col_sample]; + + sampleProps.set_sample(sample); + + // make sure sample tree is updated when user changes the + // sample name in sample properties window + sampleProps.signal_name_changed().connect( + sigc::bind( + sigc::mem_fun(*this, + &MainWindow::sample_name_changed_by_sample_props + ), it + ) + ); + } else { + sampleProps.hide(); + } + //NOTE: explicit boolean cast required for GTKMM4 development branch here + return it ? true : false; +} + +void MainWindow::show_sample_props() +{ + if (sample_props_set_sample()) { + sampleProps.show(); + sampleProps.deiconify(); + } +} + +void MainWindow::sample_name_changed_by_sample_props(Gtk::TreeModel::iterator& it) +{ + Gtk::TreeModel::Row row = *it; + Glib::ustring name = row[m_SamplesModel.m_col_name]; + + gig::Sample* sample = row[m_SamplesModel.m_col_sample]; + Glib::ustring gigname(gig_to_utf8(sample->pInfo->Name)); + if (gigname != name) { + Gtk::TreeModel::Path path(*it); + row[m_SamplesModel.m_col_name] = gigname; + } +} + void MainWindow::show_midi_rules() { if (gig::Instrument* instrument = get_instrument()) @@ -4001,11 +4345,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 - ); - msg.run(); + show_sample_props(); } void MainWindow::on_action_add_script_group() { @@ -4804,6 +5144,10 @@ file_changed(); } } + // change name in the sample properties window + if (sampleProps.get_sample() == sample && sample) { + sampleProps.set_sample(sample); + } } void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,