From c2d06bce4589182f92a0a083ebc4df0998dbb829 Mon Sep 17 00:00:00 2001
From: SeeLook <seelook@gmail.com>
Date: Mon, 10 Feb 2025 09:47:03 +0100
Subject: [PATCH] Tmelody: do not refer to measure notes by pointers

- it fixes melody
---
 src/libs/core/music/tmelody.cpp | 10 +++++-----
 src/libs/core/music/tmelody.h   |  6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/libs/core/music/tmelody.cpp b/src/libs/core/music/tmelody.cpp
index 8b5b2638..3d1c8a4e 100644
--- a/src/libs/core/music/tmelody.cpp
+++ b/src/libs/core/music/tmelody.cpp
@@ -104,7 +104,7 @@ void Tmelody::addNote(const Tchunk &n)
         p_measures << Tmeasure(p_measures.count() + 1, m_meter->meter());
 
     lastMeasure().addNote(n);
-    m_notes << &lastMeasure().lastNote();
+    m_notes << lastMeasure().lastNote();
 }
 
 void Tmelody::clear(bool withCredits, bool withKey)
@@ -142,7 +142,7 @@ void Tmelody::swapWithNotes(int noteNr, const QList<Tchunk> &notes)
     if (barToSwapIn)
         barToSwapIn->swapWithNotes(noteIdInBar, notes);
     for (int n = 1; n < notes.count(); ++n) {
-        m_notes.insert(noteNr + n, &barToSwapIn->note(noteIdInBar + n));
+        m_notes.insert(noteNr + n, barToSwapIn->note(noteIdInBar + n));
     }
 }
 
@@ -333,7 +333,7 @@ bool Tmelody::fromXml(QXmlStreamReader &xml, bool madeWithNootka, int partId)
                             if (prevTie > -1) {
                                 // check and fix tie, Nootka supports them only between the same notes
                                 // scoring app may set tie between different ones, but seems like in such case there is no 'stop' tag used (musescore)
-                                Tnote &prevNote = m_notes[prevTie]->p();
+                                Tnote &prevNote = m_notes[prevTie].p();
                                 short prevChromatic = prevNote.chromatic(), currChromatic = ch.p().chromatic();
                                 if ((prevChromatic == currChromatic && ch.p().rtm.tie() == Trhythm::e_noTie) || prevChromatic != currChromatic) {
                                     if (prevNote.rtm.tie() == Trhythm::e_tieCont)
@@ -686,7 +686,7 @@ void Tmelody::transpose(int semis, bool outScaleToRest, const Tnote &loNote, con
     auto hi = doInScaleCheck ? hiNote.chromatic() : 0;
 
     for (int n = 0; n < length(); ++n) {
-        Tnote &noteSeg = m_notes[n]->p();
+        Tnote &noteSeg = m_notes[n].p();
         int transOff = 0;
         Trhythm transRtm(noteSeg.rtm);
         auto transChrom = noteSeg.chromatic() + semis;
@@ -810,5 +810,5 @@ bool Tmelody::processXMLData(QXmlStreamReader &xml)
 void Tmelody::prepend(const Tchunk &n)
 {
     p_measures.first().prepend(n);
-    m_notes.prepend(&p_measures.first().note(0));
+    m_notes.prepend(p_measures.first().note(0));
 }
diff --git a/src/libs/core/music/tmelody.h b/src/libs/core/music/tmelody.h
index 3c62041f..7290ee3e 100644
--- a/src/libs/core/music/tmelody.h
+++ b/src/libs/core/music/tmelody.h
@@ -75,8 +75,8 @@ public:
     /**
      * A pointer to note @p index
      */
-    Tchunk *note(int index) { return m_notes[index]; }
-    Tchunk chunk(int index) const { return *m_notes[index]; }
+    Tchunk *note(int index) { return &m_notes[index]; }
+    Tchunk chunk(int index) const { return m_notes[index]; }
 
     Tmeasure &measure(int nr) { return p_measures[nr]; }
     Tmeasure &lastMeasure() { return p_measures.last(); }
@@ -178,7 +178,7 @@ protected:
 private:
     QString m_title;
     QString m_composer;
-    QList<Tchunk *> m_notes; /**< List of pointers to ordered notes */
+    QVector<Tchunk> m_notes; /**< List of pointers to ordered notes */
     int m_tempo;
     Tmeter::EbeatUnit m_beat = Tmeter::BeatQuarter;
     TkeySignature m_key;
-- 
GitLab