@@ -599,7 +599,14 @@ void Transpose::transposeFretDiagram(FretDiagram* diagram, Score* score, Interva
599599 return ;
600600 }
601601
602- String name = names.front ();
602+ Fraction tick = Fraction (0 , 1 );
603+ Segment* seg = diagram->segment ();
604+ if (seg) {
605+ tick = seg->tick ();
606+ }
607+ Key key = !diagram->staff () ? Key::C : diagram->staff ()->key (tick);
608+
609+ String name = findBestEnharmonicFit (names, key, score->style ());
603610
604611 diagram->setHarmony (name);
605612 harmony = diagram->harmony ();
@@ -608,17 +615,10 @@ void Transpose::transposeFretDiagram(FretDiagram* diagram, Score* score, Interva
608615 }
609616
610617 // Transpose harmony without undo
611- Fraction tick = Fraction (0 , 1 );
612- Segment* seg = harmony->getParentSeg ();
613- if (seg) {
614- tick = seg->tick ();
615- }
616-
617618 Interval kv = harmony->staff ()->transpose (harmony->tick ());
618619 Interval iv = harmony->part ()->instrument (harmony->tick ())->transpose ();
619620 Interval hInterval ((interval.diatonic - kv.diatonic + iv.diatonic ), (interval.chromatic - kv.chromatic + iv.chromatic ));
620621
621- Key key = !harmony->staff () ? Key::C : harmony->staff ()->key (tick);
622622 for (HarmonyInfo* info : harmony->chords ()) {
623623 if (mode == TransposeMode::DIATONICALLY) {
624624 info->setRootTpc (Transpose::transposeTpcDiatonicByKey (info->rootTpc (), transposeInterval, key, trKeys, useDoubleSharpsFlats));
@@ -646,6 +646,28 @@ void Transpose::transposeFretDiagram(FretDiagram* diagram, Score* score, Interva
646646 return ;
647647}
648648
649+ String Transpose::findBestEnharmonicFit (const std::vector<String>& notes, Key key, const MStyle& style)
650+ {
651+ std::vector<int > tpcs;
652+ NoteSpellingType harmonySpelling = style.styleV (Sid::chordSymbolSpelling).value <NoteSpellingType>();
653+ NoteCaseType harmonyCase = NoteCaseType::AUTO;
654+ size_t idx = 0 ;
655+ for (const String& note : notes) {
656+ int tpc = convertNote (note, harmonySpelling, harmonyCase, idx);
657+ tpcs.push_back (tpc);
658+ }
659+
660+ int tpc = bestEnharmonicFit (tpcs, key);
661+
662+ if (tpc == Tpc::TPC_INVALID) {
663+ return notes.front ();
664+ }
665+
666+ String note = tpc2name (tpc, harmonySpelling, harmonyCase);
667+
668+ return note;
669+ }
670+
649671// ---------------------------------------------------------
650672// transposeTpcDiatonicByKey
651673//
0 commit comments