@@ -96,12 +96,6 @@ struct HarmonyMapKey
9696 }
9797};
9898
99- struct DiagramInfo {
100- String harmonyName;
101- String diagramXml;
102- String diagramPattern;
103- };
104-
10599static std::map<HarmonyMapKey /* key*/ , std::vector<DiagramInfo> > s_harmonyToDiagramMap;
106100static std::unordered_map<String /* pattern*/ , std::vector<String /* harmonyName*/ > > s_diagramPatternToHarmoniesMap;
107101
@@ -244,16 +238,7 @@ Segment* FretDiagram::segment() const
244238
245239void FretDiagram::updateDiagram (const String& harmonyName)
246240{
247- if (s_harmonyToDiagramMap.empty ()) {
248- readHarmonyToDiagramFile (HARMONY_TO_DIAGRAM_FILE_PATH);
249- }
250-
251- String _harmonyName = harmonyName;
252-
253- NoteSpellingType spellingType = style ().styleV (Sid::chordSymbolSpelling).value <NoteSpellingType>();
254- HarmonyMapKey key = createHarmonyMapKey (_harmonyName, spellingType, score ()->chordList ());
255-
256- std::vector<DiagramInfo> availableDiagrams = muse::value (s_harmonyToDiagramMap, key);
241+ std::vector<DiagramInfo> availableDiagrams = patternsFromHarmony (harmonyName);
257242 if (availableDiagrams.empty ()) {
258243 return ;
259244 }
@@ -272,6 +257,7 @@ void FretDiagram::updateDiagram(const String& harmonyName)
272257 read460::TRead::read (this , reader, ctx);
273258
274259 triggerLayout ();
260+ return ;
275261}
276262
277263// ---------------------------------------------------------
@@ -761,21 +747,21 @@ void FretDiagram::applyDiagramPattern(FretDiagram* diagram, const String& patter
761747 }
762748}
763749
764- String FretDiagram::patternFromDiagram (const FretDiagram* diagram)
750+ String FretDiagram::patternFromDiagram () const
765751{
766- const int strings = diagram-> strings ();
767- const int offset = diagram-> fretOffset ();
752+ const int diagramStrings = strings ();
753+ const int offset = fretOffset ();
768754
769755 StringList patternParts;
770- const DotMap& dotsMap = diagram-> dots ();
756+ const DotMap& dotsMap = dots ();
771757
772- for (int i = 0 ; i < strings ; ++i) {
773- const FretItem::Marker marker = diagram-> marker (i);
758+ for (int i = 0 ; i < diagramStrings ; ++i) {
759+ const FretItem::Marker fretMarker = marker (i);
774760
775- if (marker .mtype == FretMarkerType::CROSS) {
761+ if (fretMarker .mtype == FretMarkerType::CROSS) {
776762 patternParts.push_back (u" X" );
777763 continue ;
778- } else if (marker .mtype == FretMarkerType::CIRCLE) {
764+ } else if (fretMarker .mtype == FretMarkerType::CIRCLE) {
779765 patternParts.push_back (u" O" );
780766 continue ;
781767 }
@@ -825,16 +811,16 @@ String FretDiagram::patternFromDiagram(const FretDiagram* diagram)
825811
826812 String pattern = patternParts.join (u" " );
827813
828- const BarreMap& barres = diagram-> barres ();
814+ const BarreMap& _barres = barres ();
829815 StringList barreParts;
830- for (const auto & [fret, b] : barres ) {
816+ for (const auto & [fret, b] : _barres ) {
831817 if (!b.exists ()) {
832818 continue ;
833819 }
834820
835821 int adjustedFret = fret + offset;
836822 int start = b.startString ;
837- int end = (b.endString != -1 ) ? b.endString : strings - 1 ;
823+ int end = (b.endString != -1 ) ? b.endString : diagramStrings - 1 ;
838824
839825 barreParts.push_back (u' B' + String::number (adjustedFret)
840826 + u' [' + String::number (start)
@@ -848,11 +834,28 @@ String FretDiagram::patternFromDiagram(const FretDiagram* diagram)
848834 return pattern;
849835}
850836
851- std::vector<String> FretDiagram::patternHarmonies (const String& pattern)
837+ std::vector<String> FretDiagram::harmoniesFromPattern (const String& pattern) const
852838{
839+ if (s_diagramPatternToHarmoniesMap.empty ()) {
840+ readHarmonyToDiagramFile (HARMONY_TO_DIAGRAM_FILE_PATH);
841+ }
853842 return muse::value (s_diagramPatternToHarmoniesMap, pattern);
854843}
855844
845+ std::vector<DiagramInfo> FretDiagram::patternsFromHarmony (const String& harmonyName)
846+ {
847+ if (s_harmonyToDiagramMap.empty ()) {
848+ readHarmonyToDiagramFile (HARMONY_TO_DIAGRAM_FILE_PATH);
849+ }
850+
851+ String _harmonyName = harmonyName;
852+
853+ NoteSpellingType spellingType = style ().styleV (Sid::chordSymbolSpelling).value <NoteSpellingType>();
854+ HarmonyMapKey key = createHarmonyMapKey (_harmonyName, spellingType, score ()->chordList ());
855+
856+ return muse::value (s_harmonyToDiagramMap, key);
857+ }
858+
856859// ---------------------------------------------------------
857860// clear
858861// ---------------------------------------------------------
@@ -1002,7 +1005,7 @@ void FretDiagram::add(EngravingItem* e)
10021005 readHarmonyToDiagramFile (HARMONY_TO_DIAGRAM_FILE_PATH);
10031006 }
10041007
1005- String pattern = patternFromDiagram (this );
1008+ String pattern = patternFromDiagram ();
10061009 if (!pattern.empty ()) {
10071010 std::vector<String> matchedHarmonies = muse::value (s_diagramPatternToHarmoniesMap, pattern);
10081011 if (!matchedHarmonies.empty ()) {
@@ -1415,7 +1418,7 @@ bool FretDiagram::isCustom(const String& harmonyNameForCompare) const
14151418 return true ;
14161419 }
14171420
1418- String currentPattern = patternFromDiagram (this );
1421+ String currentPattern = patternFromDiagram ();
14191422
14201423 for (const DiagramInfo& diagram : availableDiagrams) {
14211424 if (diagram.diagramPattern == currentPattern) {
0 commit comments