From 9b08337ada6dfca3767869a148087c6d0413c3d0 Mon Sep 17 00:00:00 2001 From: SeeLook <seelook@gmail.com> Date: Mon, 10 Feb 2025 09:10:50 +0100 Subject: [PATCH] Change Tnote from pointer to value, rename methods - use const when possible --- src/libs/core/score/tbeamobject.cpp | 5 +- src/libs/core/score/tmeasureobject.cpp | 10 +-- src/libs/core/score/tnoteitem.cpp | 111 ++++++++++++------------- src/libs/core/score/tnoteitem.h | 6 +- src/libs/core/score/tnotepair.cpp | 30 +++++-- src/libs/core/score/tnotepair.h | 20 ++--- src/libs/core/score/tscoreobject.cpp | 40 ++++----- src/libs/core/score/tscoreobject.h | 2 +- 8 files changed, 118 insertions(+), 106 deletions(-) diff --git a/src/libs/core/score/tbeamobject.cpp b/src/libs/core/score/tbeamobject.cpp index afb55ac9..139be2a9 100644 --- a/src/libs/core/score/tbeamobject.cpp +++ b/src/libs/core/score/tbeamobject.cpp @@ -89,8 +89,9 @@ void TbeamObject::addNote(TnotePair *np) else qDebug() << " [BEAM] note" << np->index() << "has already a beam"; - if (m_notes.count() > 1) + if (m_notes.count() > 1) { m_notes.last()->note()->rtm.setBeam(Trhythm::e_beamCont); // no need to be updated + } if (m_notes.isEmpty()) np->note()->rtm.setBeam(Trhythm::e_beamStart); else @@ -100,7 +101,7 @@ void TbeamObject::addNote(TnotePair *np) m_notes << np; if (np->note()->rhythm() == Trhythm::Sixteenth) { - Tnote *beforeLastNote = m_notes.count() > 1 ? m_notes[m_notes.count() - 2]->note() : nullptr; + const Tnote *beforeLastNote = m_notes.count() > 1 ? m_notes[m_notes.count() - 2]->note() : nullptr; if (m_16beams.isEmpty() || (beforeLastNote && beforeLastNote->rhythm() != Trhythm::Sixteenth)) { // is first in beam or previous note was not a sixteenth m_16beams << T16beam(m_notes.count() - 1); // then create new beam segment diff --git a/src/libs/core/score/tmeasureobject.cpp b/src/libs/core/score/tmeasureobject.cpp index c906a9d5..be272ea3 100644 --- a/src/libs/core/score/tmeasureobject.cpp +++ b/src/libs/core/score/tmeasureobject.cpp @@ -109,7 +109,7 @@ void TmeasureObject::appendNewNotes(int segmentId, int count) for (int n = segmentId; n < segmentId + count; ++n) m_notes.append(m_score->noteSegment(n)); updateRhythmicGroups(); - int grWithBeam = beamGroup(segmentId); + const int grWithBeam = beamGroup(segmentId); for (int n = segmentId; n < segmentId + count; ++n) { auto np = m_score->noteSegment(n); if (np->item() == nullptr) @@ -436,13 +436,13 @@ void TmeasureObject::changeNoteDuration(TnotePair *np, const Tnote &newNote) m_score->insertSilently(np->index() + r, Tnote(newNote, thisBarRtms[r]), this); } } - np->setNote(nn); + np->setPairNotes(nn); update(np->rhythmGroup()); checkBarLine(); } else { // measure duration is less than meter - take notes from the next measure m_free += prevDur - newDur; - np->setNote(nn); + np->setPairNotes(nn); fill(); // it updates measure } shiftReleased(notesToOut); @@ -523,7 +523,7 @@ int TmeasureObject::releaseAtEnd(int dur, Tpairs ¬esToOut, int endNote) rList[r].setTie(Trhythm::e_tieCont); m_score->insertSilently(lastNote->index() + r, Tnote(*lastNote->note(), rList[r]), this); } - lastNote->setNote(Tnote(*lastNote->note(), rList.first())); + lastNote->setPairNotes(Tnote(*lastNote->note(), rList.first())); // remaining part of the note that goes to next measure auto rtmToNext = Trhythm::resolve(dur); int indexToInsert = rtmToNext.count() > 1 ? 0 : notesToOut.count(); @@ -563,7 +563,7 @@ void TmeasureObject::releaseAtStart(int dur, Tpairs ¬esToOut) firstTie = firstNote->note()->rtm.tie(); if (!firstNote->note()->isRest()) rList.first().setTie(firstTie > Trhythm::e_tieStart ? Trhythm::e_tieCont : Trhythm::e_tieEnd); - firstNote->setNote(Tnote(*firstNote->note(), rList.first())); + firstNote->setPairNotes(Tnote(*firstNote->note(), rList.first())); for (int r = 1; r < rList.count(); ++r) { if (!firstNote->note()->isRest()) rList[r].setTie(Trhythm::e_tieCont); diff --git a/src/libs/core/score/tnoteitem.cpp b/src/libs/core/score/tnoteitem.cpp index a5906282..f1feca4c 100644 --- a/src/libs/core/score/tnoteitem.cpp +++ b/src/libs/core/score/tnoteitem.cpp @@ -17,7 +17,6 @@ ***************************************************************************/ #include "tnoteitem.h" -#include "music/tnote.h" #include "tbeamobject.h" #include "tmeasureobject.h" #include "tnotepair.h" @@ -65,7 +64,6 @@ TnoteItem::TnoteItem(TstaffItem *staffObj, TnotePair *wrapper) , m_stemHeight(STEM_HEIGHT) { setParent(m_staff->score()); // to avoid deleting with parent staff - m_note = new Tnote(); m_staff->score()->component()->setData("import QtQuick 2.9; Rectangle {}", QUrl()); m_stem = qobject_cast<QQuickItem *>(m_staff->score()->component()->create()); @@ -108,7 +106,6 @@ TnoteItem::TnoteItem(TstaffItem *staffObj, TnotePair *wrapper) TnoteItem::~TnoteItem() { // qDebug() << debug() << "is going deleted"; - delete m_note; } int TnoteItem::index() const @@ -189,20 +186,20 @@ void TnoteItem::setColor(const QColor &c) */ void TnoteItem::setNote(const Tnote &n) { - bool updateHead = n.rhythm() != m_note->rhythm() || n.isRest() != m_note->isRest() || n.hasDot() != m_note->hasDot(); - bool fixBeam = n.isRest() != m_note->isRest(); - bool updateStem = updateHead || fixBeam || ((n.rtm.beam() != Trhythm::e_noBeam) != (m_note->rtm.beam() != Trhythm::e_noBeam)) - || (n.rtm.stemDown() != m_note->rtm.stemDown() || m_stem->height() != m_stemHeight) || n.onUpperStaff() != m_note->onUpperStaff(); - bool updateTie = n.rtm.tie() != m_note->rtm.tie(); + bool updateHead = n.rhythm() != m_note.rhythm() || n.isRest() != m_note.isRest() || n.hasDot() != m_note.hasDot(); + bool fixBeam = n.isRest() != m_note.isRest(); + bool updateStem = updateHead || fixBeam || ((n.rtm.beam() != Trhythm::e_noBeam) != (m_note.rtm.beam() != Trhythm::e_noBeam)) + || (n.rtm.stemDown() != m_note.rtm.stemDown() || m_stem->height() != m_stemHeight) || n.onUpperStaff() != m_note.onUpperStaff(); + bool updateTie = n.rtm.tie() != m_note.rtm.tie(); - *m_note = n; + m_note = n; if (fixBeam) { - if (m_note->isRest()) { + if (m_note.isRest()) { if (m_wrapper->beam()) m_measure->noteGoingRest(m_wrapper); } else { - if (m_note->rhythm() > Trhythm::Quarter) + if (m_note.rhythm() > Trhythm::Quarter) m_measure->restGoingNote(m_wrapper); } } @@ -211,10 +208,10 @@ void TnoteItem::setNote(const Tnote &n) updateNoteHead(); int oldNotePos = static_cast<int>(m_notePosY); - if (m_note->isRest()) - m_notePosY = staff()->upperLine() + (m_note->onUpperStaff() ? 0.0 : 22.0) + (m_note->rhythm() == Trhythm::Whole ? 2.0 : 4.0); + if (m_note.isRest()) + m_notePosY = staff()->upperLine() + (m_note.onUpperStaff() ? 0.0 : 22.0) + (m_note.rhythm() == Trhythm::Whole ? 2.0 : 4.0); else { - if (m_note->isValid()) { + if (m_note.isValid()) { m_notePosY = getHeadY(n); } else { if (staff()->score()->singleNote()) { @@ -287,7 +284,7 @@ void TnoteItem::setX(qreal xx) Trhythm TnoteItem::rhythm() const { - return m_note->rtm; + return m_note.rtm; } qreal TnoteItem::rightX() const @@ -297,7 +294,7 @@ qreal TnoteItem::rightX() const bool TnoteItem::hasTie() const { - return m_note->rtm.tie() > Trhythm::e_tieStart; + return m_note.rtm.tie() > Trhythm::e_tieStart; } void TnoteItem::setHeight(qreal hh) @@ -325,7 +322,7 @@ void TnoteItem::setHeight(qreal hh) qreal TnoteItem::rhythmFactor() const { - if (m_note->rhythm() == Trhythm::NoRhythm) + if (m_note.rhythm() == Trhythm::NoRhythm) return 0.75; /** @@ -340,8 +337,8 @@ qreal TnoteItem::rhythmFactor() const {0.15, 0.5, 0.0} // sixteenth note }; - int add = m_note->hasDot() ? 1 : (m_note->isTriplet() ? 2 : 0); - return rtmGapArray[static_cast<int>(m_note->rhythm()) - 1][add]; + int add = m_note.hasDot() ? 1 : (m_note.isTriplet() ? 2 : 0); + return rtmGapArray[static_cast<int>(m_note.rhythm()) - 1][add]; } char TnoteItem::debug() @@ -366,10 +363,10 @@ void TnoteItem::shiftHead(qreal shift) void TnoteItem::checkTie() { - if (m_tie && (m_note->rtm.tie() == Trhythm::e_noTie || m_note->rtm.tie() == Trhythm::e_tieEnd)) { + if (m_tie && (m_note.rtm.tie() == Trhythm::e_noTie || m_note.rtm.tie() == Trhythm::e_tieEnd)) { delete m_tie; m_tie = nullptr; - } else if (m_tie == nullptr && (m_note->rtm.tie() == Trhythm::e_tieStart || m_note->rtm.tie() == Trhythm::e_tieCont)) { + } else if (m_tie == nullptr && (m_note.rtm.tie() == Trhythm::e_tieStart || m_note.rtm.tie() == Trhythm::e_tieCont)) { QQmlComponent comp(m_staff->score()->qmlEngine(), QUrl(QStringLiteral("qrc:/score/Tie.qml"))); m_tie = qobject_cast<QQuickItem *>(comp.create()); m_tie->setParentItem(m_head); @@ -393,12 +390,12 @@ qreal TnoteItem::tieWidth() { return qMax(1.5, staff()->gapFactor() * rhythmFactor() + (this == m_measure->last()->item() ? 1.5 : 0.0) - + (m_note->rtm.stemDown() ? 1.5 : m_flag->width() + 1.3)); + + (m_note.rtm.stemDown() ? 1.5 : m_flag->width() + 1.3)); } QPointF TnoteItem::stemTop() { - return mapToItem(parentItem(), QPointF(m_stem->x(), m_stem->y() + (m_note->rtm.stemDown() ? m_stem->height() : 0.0))); + return mapToItem(parentItem(), QPointF(m_stem->x(), m_stem->y() + (m_note.rtm.stemDown() ? m_stem->height() : 0.0))); } /** @@ -511,7 +508,7 @@ void TnoteItem::setBowing(EbowDirection bowDir) } if (bowDir != BowUndefined) { qreal bowY = 0.0; - if (m_note->onUpperStaff()) { + if (m_note.onUpperStaff()) { if (m_notePosY < m_staff->upperLine() - 2.0) // high pitch notes, above staff bowY = m_staff->upperLine(); // bow below staff else if (m_notePosY < m_staff->upperLine() + 1.0) // not that high but still above staff @@ -609,51 +606,51 @@ qreal TnoteItem::getHeadY(const Tnote &n) QString TnoteItem::getAccidText() { - if (!m_note->isValid()) + if (!m_note.isValid()) return QString(); - QString a = unicodeGlyphArray(m_note->alter()); - qint8 accidInKey = m_staff->score()->accidInKey(m_note->note() - 1); + QString a = unicodeGlyphArray(m_note.alter()); + qint8 accidInKey = m_staff->score()->accidInKey(m_note.note() - 1); bool extraAccid = false; if (accidInKey) { // key signature has an accidental on this note - if (m_note->alter() == 0) // show neutral if note has not any accidental + if (m_note.alter() == 0) // show neutral if note has not any accidental a = unicodeGlyphArray(3); // neutral else { - if (accidInKey == m_note->alter()) { // accidental in key, do not show + if (accidInKey == m_note.alter()) { // accidental in key, do not show if (m_staff->score()->showExtraAccids() && accidInKey) { // or user wants it at any cost extraAccid = true; - a = extraAccidString(m_note->alter()); + a = extraAccidString(m_note.alter()); } else a.clear(); } } } - if (m_note->rtm.tie() > Trhythm::e_tieStart) { + if (m_note.rtm.tie() > Trhythm::e_tieStart) { a.clear(); // do not display accidental of first note in measure if it has tie } else if (!extraAccid) { int id = index() - 1; // check the previous notes for accidentals - Tnote *checkNote; + const Tnote *checkNote; while (id > -1 && m_staff->score()->noteSegment(id)->item()->measure() == measure()) { checkNote = m_staff->score()->noteSegment(id)->note(); - if (checkNote->note() == m_note->note()) { - if (checkNote->rtm.tie() > Trhythm::e_tieStart && checkNote->alter() == m_note->alter()) { + if (checkNote->note() == m_note.note()) { + if (checkNote->rtm.tie() > Trhythm::e_tieStart && checkNote->alter() == m_note.alter()) { // Ignore notes prolonged with ties - they could be continued from the previous measure // and then, the accidental has to be displayed again in current measure id--; continue; } - if (checkNote->alter() != 0 && m_note->alter() == 0) { + if (checkNote->alter() != 0 && m_note.alter() == 0) { if (a.isEmpty()) a = unicodeGlyphArray(3); // and add neutral when some of previous notes with the same step had an accidental - } else if (checkNote->alter() == m_note->alter()) { // do not display it twice + } else if (checkNote->alter() == m_note.alter()) { // do not display it twice if (m_staff->score()->showExtraAccids()) // accidental with parenthesis - a = extraAccidString(m_note->alter()); + a = extraAccidString(m_note.alter()); else // or nothing a.clear(); - } else if (accidInKey == m_note->alter() && checkNote->alter() != m_note->alter()) + } else if (accidInKey == m_note.alter() && checkNote->alter() != m_note.alter()) a = unicodeGlyphArray( - m_note->alter()); // There is already accidental in key signature but some of the previous notes had another one, show it again + m_note.alter()); // There is already accidental in key signature but some of the previous notes had another one, show it again break; } id--; @@ -676,15 +673,15 @@ QString TnoteItem::getAccidText() QString TnoteItem::getHeadText() const { - return getHeadText(m_note->rtm); + return getHeadText(m_note.rtm); } QString TnoteItem::getFlagText() { - if (m_note->rhythm() < Trhythm::Eighth || m_note->isRest() || m_note->rtm.beam() != Trhythm::e_noBeam) + if (m_note.rhythm() < Trhythm::Eighth || m_note.isRest() || m_note.rtm.beam() != Trhythm::e_noBeam) return QString(); // In Scorek font, flag glyphs are placed: flag for stem-up, then flag for stem-down, starting from 0xe240 - return QString(QChar(0xe240 + (static_cast<int>(m_note->rhythm()) - 4) * 2 + (m_note->rtm.stemDown() ? 1 : 0))); + return QString(QChar(0xe240 + (static_cast<int>(m_note.rhythm()) - 4) * 2 + (m_note.rtm.stemDown() ? 1 : 0))); } void TnoteItem::keySignatureChanged() @@ -844,7 +841,7 @@ void TnoteItem::updateWidth() setWidth(5.0); else { qreal w = m_alter->width() + m_head->width(); - if (!m_note->isRest() && !m_note->rtm.stemDown() && m_stem->isVisible() && m_flag->width() > 0.0) + if (!m_note.isRest() && !m_note.rtm.stemDown() && m_stem->isVisible() && m_flag->width() > 0.0) w += m_flag->width() - 0.5; setWidth(w); updateTieScale(); @@ -854,7 +851,7 @@ void TnoteItem::updateWidth() void TnoteItem::updateNoteHead() { QString headText = getHeadText(); - if (m_note->hasDot()) + if (m_note.hasDot()) headText.append(QStringLiteral("\ue1e8")); m_head->setProperty("text", headText); } @@ -863,29 +860,29 @@ void TnoteItem::updateTieScale() { if (m_tie) { m_tie->setProperty("xScale", tieWidth() / 2.90625); - m_tie->setProperty("stemDown", m_note->rtm.stemDown()); + m_tie->setProperty("stemDown", m_note.rtm.stemDown()); } } void TnoteItem::checkStem() { - if (m_notePosY && !m_note->isRest() && m_note->rhythm() > Trhythm::Whole) { - if (m_note->rtm.beam() == Trhythm::e_noBeam) { - m_note->rtm.setStemDown(m_notePosY < staff()->upperLine() + 4.0 - || (staff()->isPianoStaff() && m_notePosY > staff()->upperLine() + 13.0 && m_notePosY < staff()->upperLine() + 26.0)); + if (m_notePosY && !m_note.isRest() && m_note.rhythm() > Trhythm::Whole) { + if (m_note.rtm.beam() == Trhythm::e_noBeam) { + m_note.rtm.setStemDown(m_notePosY < staff()->upperLine() + 4.0 + || (staff()->isPianoStaff() && m_notePosY > staff()->upperLine() + 13.0 && m_notePosY < staff()->upperLine() + 26.0)); m_stem->setHeight( qMax(STEM_HEIGHT, qAbs(m_notePosY - (staff()->upperLine() + (staff()->isPianoStaff() && m_notePosY > staff()->upperLine() + 13.0 ? 26.0 : 4.0))))); QString flagText = getFlagText(); m_flag->setProperty("text", flagText); if (!flagText.isEmpty()) - m_flag->setY((m_note->rtm.stemDown() ? m_stem->height() : 0.0) - 15.0); + m_flag->setY((m_note.rtm.stemDown() ? m_stem->height() : 0.0) - 15.0); } else { if (m_flag->width() > 0.0) m_flag->setProperty("text", QString()); } - m_stem->setX(m_head->x() + (m_note->rtm.stemDown() ? 0.0 : 2.0)); - m_stem->setY(m_notePosY + (m_note->rtm.stemDown() ? 0.0 : -m_stem->height())); + m_stem->setX(m_head->x() + (m_note.rtm.stemDown() ? 0.0 : 2.0)); + m_stem->setY(m_notePosY + (m_note.rtm.stemDown() ? 0.0 : -m_stem->height())); m_stem->setVisible(true); } else m_stem->setVisible(false); @@ -899,15 +896,15 @@ void TnoteItem::checkStem() void TnoteItem::updateNamePos() { if (m_name) { - if (m_note->isValid()) { + if (m_note.isValid()) { m_name->setVisible(true); qreal yOff; - if (m_note->rtm.stemDown()) - yOff = m_notePosY > 6.0 ? (m_bowing && m_note->onUpperStaff() ? m_stemHeight - 4.0 : -9.5) : m_stemHeight - 4.0; + if (m_note.rtm.stemDown()) + yOff = m_notePosY > 6.0 ? (m_bowing && m_note.onUpperStaff() ? m_stemHeight - 4.0 : -9.5) : m_stemHeight - 4.0; else yOff = m_notePosY > height() - 6.0 && height() - m_stemHeight > 8.0 ? -m_stemHeight - 8.0 : -1.8; m_name->setY(m_notePosY + yOff); - m_name->setProperty("text", m_note->isRest() ? QString() : m_note->styledName()); + m_name->setProperty("text", m_note.isRest() ? QString() : m_note.styledName()); m_name->setX(x() - m_alter->width() + (width() - m_name->width()) / 2.0); } else { m_name->setVisible(false); @@ -924,7 +921,7 @@ void TnoteItem::updateNamePos() */ void TnoteItem::checkAddLinesVisibility() { - bool v = m_notePosY != 0.0 && !m_note->isRest(); + bool v = m_notePosY != 0.0 && !m_note.isRest(); bool betweenStaves = staff()->isPianoStaff() && m_notePosY >= staff()->upperLine() + 10.0 && m_notePosY < staff()->upperLine() + 21.0; for (int i = 0; i < 7; ++i) { m_upLines[i]->setVisible(v && m_notePosY > 0.0 && i >= qFloor((m_notePosY - 1.0) / 2.0) && (i != 6 || !staff()->isPianoStaff())); diff --git a/src/libs/core/score/tnoteitem.h b/src/libs/core/score/tnoteitem.h index 400f2b83..f455f1c1 100644 --- a/src/libs/core/score/tnoteitem.h +++ b/src/libs/core/score/tnoteitem.h @@ -19,7 +19,7 @@ #ifndef TNOTEITEM_H #define TNOTEITEM_H -#include "music/trhythm.h" +#include "music/tnote.h" #include "nootkacoreglobal.h" #include <QtCore/qelapsedtimer.h> #include <QtQuick/qquickitem.h> @@ -65,7 +65,7 @@ public: TmeasureObject *measure() { return m_measure; } void setMeasure(TmeasureObject *m); - Tnote *note() { return m_note; } + Tnote *note() { return &m_note; } void setNote(const Tnote &n); quint32 technical() const; @@ -221,7 +221,7 @@ private: TstaffItem *m_staff; TnotePair *m_wrapper; TmeasureObject *m_measure; - Tnote *m_note; + Tnote m_note; qreal m_notePosY; QQuickItem *m_head, *m_alter, *m_stem, *m_flag; QVector<QQuickItem *> m_upLines, m_loLines, m_underLoLines; diff --git a/src/libs/core/score/tnotepair.cpp b/src/libs/core/score/tnotepair.cpp index 1e030be0..c29dacd0 100644 --- a/src/libs/core/score/tnotepair.cpp +++ b/src/libs/core/score/tnotepair.cpp @@ -17,12 +17,11 @@ ***************************************************************************/ #include "tnotepair.h" -#include "music/tnote.h" #include "tbeamobject.h" #include "tnoteitem.h" #include "tstaffitem.h" -TnotePair::TnotePair(int index, Tnote *n, TnoteItem *ob) +TnotePair::TnotePair(int index, const Tnote &n, TnoteItem *ob) : m_note(n) , m_noteItem(ob) , m_index(static_cast<quint16>(index)) @@ -52,12 +51,22 @@ void TnotePair::setNoteItem(TnoteItem *ob) m_noteItem = ob; } -void TnotePair::setNote(const Tnote &n) +void TnotePair::setPairNotes(const Tnote &n) { - *m_note = n; + m_note = n; m_noteItem->setNote(n); } +void TnotePair::setWrapperNote(const Tnote &n) +{ + m_note = n; +} + +void TnotePair::setRhythmGroup(qint8 g) +{ + m_group = g; +} + void TnotePair::setTechnical(quint32 tech) { if (tech != m_technical.data()) { @@ -70,11 +79,16 @@ void TnotePair::setTechnical(quint32 tech) } } +void TnotePair::addChange(Echanges ch) +{ + m_changes |= ch; +} + void TnotePair::approve() { if (m_changes) { if (m_changes & e_beamChanged || m_changes & e_stemDirChanged) - m_noteItem->setNote(*m_note); + m_noteItem->setNote(m_note); m_changes = 0; } } @@ -100,10 +114,10 @@ void TnotePair::disconnectTie(Euntie untie) { Trhythm::Etie t; if (untie == e_untieNext) - t = m_note->rtm.tie() == Trhythm::e_tieCont ? Trhythm::e_tieStart : Trhythm::e_noTie; + t = m_note.rtm.tie() == Trhythm::e_tieCont ? Trhythm::e_tieStart : Trhythm::e_noTie; else // e_untiePrev - t = m_note->rtm.tie() == Trhythm::e_tieCont ? Trhythm::e_tieEnd : Trhythm::e_noTie; - m_note->rtm.setTie(t); + t = m_note.rtm.tie() == Trhythm::e_tieCont ? Trhythm::e_tieEnd : Trhythm::e_noTie; + m_note.rtm.setTie(t); m_noteItem->note()->rtm.setTie(t); m_noteItem->checkTie(); if (this == m_noteItem->staff()->firstNote() && (t == Trhythm::e_noTie || t == Trhythm::e_tieStart)) diff --git a/src/libs/core/score/tnotepair.h b/src/libs/core/score/tnotepair.h index f67f9dd7..73932b3e 100644 --- a/src/libs/core/score/tnotepair.h +++ b/src/libs/core/score/tnotepair.h @@ -19,10 +19,10 @@ #ifndef TNOTEPAIR_H #define TNOTEPAIR_H +#include "music/tnote.h" #include "music/ttechnical.h" #include <QtCore/qobject.h> -class Tnote; class TnoteItem; class TbeamObject; @@ -40,10 +40,10 @@ class TnotePair friend class TnoteItem; public: - TnotePair(int index = -1, Tnote *n = nullptr, TnoteItem *ob = nullptr); + TnotePair(int index = -1, const Tnote &n = Tnote(), TnoteItem *ob = nullptr); ~TnotePair(); - Tnote *note() { return m_note; } + Tnote *note() { return &m_note; } TnoteItem *item() { return m_noteItem; } void setNoteItem(TnoteItem *ob); @@ -51,12 +51,12 @@ public: /** * Sets note to @p n for both @p note() and then @p item()->setNote() */ - void setNote(const Tnote &n); + void setPairNotes(const Tnote &n); /** * Sets note pointer to another @p Tnote, doesn't update note of the @p item() */ - void setNote(Tnote *n) { m_note = n; } + void setWrapperNote(const Tnote &n); /** * Bowing, fingering, string number and etc... @@ -69,8 +69,8 @@ public: /** * Number of rhythmical group in the measure, -1 (undefined) by default */ - qint8 rhythmGroup() { return m_group; } - void setRhythmGroup(qint8 g) { m_group = g; } + qint8 rhythmGroup() const { return m_group; } + void setRhythmGroup(qint8 g); /** * Number of note in the score @@ -87,8 +87,8 @@ public: enum Euntie { e_untieNext, e_untiePrev }; Q_ENUM(Euntie) - int changes() { return m_changes; } - void addChange(Echanges ch) { m_changes |= ch; } + int changes() const { return m_changes; } + void addChange(Echanges ch); /** * Approves @p changes() (if any) to note @p item() @@ -121,7 +121,7 @@ protected: void flush(); private: - Tnote *m_note; + Tnote m_note; TnoteItem *m_noteItem; qint8 m_group = -1; quint16 m_index; diff --git a/src/libs/core/score/tscoreobject.cpp b/src/libs/core/score/tscoreobject.cpp index bc007946..ad9a7dc9 100644 --- a/src/libs/core/score/tscoreobject.cpp +++ b/src/libs/core/score/tscoreobject.cpp @@ -109,7 +109,7 @@ void TscoreObject::setClefType(Tclef::EclefType ct) Tnote newNote(Tnote(), noteSeg->note()->rtm); newNote.rtm.setStemDown(false); noteSeg->item()->setStemHeight(STEM_HEIGHT); - noteSeg->setNote(newNote); + noteSeg->setPairNotes(newNote); } else { Tnote newNote(*noteSeg->note()); if (oldClef == Tclef::NoClef) { @@ -131,7 +131,7 @@ void TscoreObject::setClefType(Tclef::EclefType ct) fixBeam = true; } - noteSeg->setNote(newNote); + noteSeg->setPairNotes(newNote); if (pianoChanged) { int nextRtmGr = (n == notesCount() - 1 ? -1 : m_segments[n + 1]->rhythmGroup()); @@ -241,7 +241,7 @@ void solveList(const Tnote &n, int dur, QList<Tnote> &outList) void TscoreObject::addNote(const Tnote &newNote, bool fromQML) { if (m_singleNote) { - qDebug() << "[TscoreObject] FIXME! Trying to add note in single mode"; + qDebug() << "[TscoreObject]" << "FIXME! Trying to add note in single mode"; return; } @@ -262,7 +262,7 @@ void TscoreObject::addNote(const Tnote &newNote, bool fromQML) QList<Tnote> notesToCurrent; solveList(n, lastMeasure->free(), notesToCurrent); // solve free duration in current measure if (notesToCurrent.isEmpty()) - qDebug() << "[TscoreObject] can't resolve duration of" << lastMeasure->free(); + qDebug() << "[TscoreObject]" << "can't resolve duration of" << lastMeasure->free(); else { if (!n.isRest()) { notesToCurrent.first().rtm.setTie(newNote.rtm.tie() > Trhythm::e_tieStart ? Trhythm::e_tieCont : Trhythm::e_tieStart); @@ -295,8 +295,8 @@ void TscoreObject::addNote(const Tnote &newNote, bool fromQML) } } else { // just add new note to the last measure m_notes << n; - int lastNoteId = m_segments.count(); - m_segments << getSegment(lastNoteId, &m_notes.last()); + const int lastNoteId = m_segments.count(); + m_segments << getSegment(lastNoteId, n); lastMeasure->appendNewNotes(lastNoteId, 1); } emitLastNote(); @@ -352,7 +352,7 @@ void TscoreObject::setNote(TnoteItem *no, const Tnote &n) removeLastMeasure(); adjustScoreWidth(); } else { - no->wrapper()->setNote(newNote); + no->wrapper()->setPairNotes(newNote); // When note or alter are different - check accidentals in whole measure and fit staff if necessary if (!notesForAlterCheck.isNull() || oldNote.note() != newNote.note() || oldNote.alter() != newNote.alter()) { if (notesForAlterCheck.isNull()) @@ -395,13 +395,13 @@ void TscoreObject::setNote(TnoteItem *no, const Tnote &n) ++it; if (it != enharmList.end()) { note(1)->setVisible(true); - m_segments[1]->setNote(*(it)); + m_segments[1]->setPairNotes(*(it)); } else note(1)->setVisible(false); ++it; if (it != enharmList.end()) { note(2)->setVisible(true); - m_segments[2]->setNote(*(it)); + m_segments[2]->setPairNotes(*(it)); } else note(2)->setVisible(false); } @@ -779,7 +779,7 @@ void TscoreObject::transpose(int semis, bool outScaleToRest, const Tnote &loNote } } - noteSeg->setNote(transposed); + noteSeg->setPairNotes(transposed); if (noteSeg->beam() && !transRtm.isRest()) fixBeam = true; @@ -1323,17 +1323,17 @@ void TscoreObject::checkTieOfSelected() if (m_selectedItem->note()->rtm.tie() > Trhythm::e_tieStart) { // disconnect prevNote->disconnectTie(TnotePair::e_untiePrev); n.rtm.setTie(n.rtm.tie() == Trhythm::e_tieEnd ? Trhythm::e_noTie : Trhythm::e_tieStart); - m_selectedItem->wrapper()->setNote(n); + m_selectedItem->wrapper()->setPairNotes(n); emit m_selectedItem->hasTieChanged(); if (m_selectedItem->staff()->firstNote()->item() == m_selectedItem) m_selectedItem->staff()->deleteExtraTie(); } else { if (!m_selectedItem->note()->isRest() && m_selectedItem->note()->chromatic() == prevNote->note()->chromatic()) { n.rtm.setTie(n.rtm.tie() == Trhythm::e_noTie ? Trhythm::e_tieEnd : Trhythm::e_tieCont); - m_selectedItem->wrapper()->setNote(n); + m_selectedItem->wrapper()->setPairNotes(n); auto pn = *prevNote->note(); pn.rtm.setTie(pn.rtm.tie() == Trhythm::e_noTie ? Trhythm::e_tieStart : Trhythm::e_tieCont); - prevNote->setNote(pn); + prevNote->setPairNotes(pn); emit m_selectedItem->hasTieChanged(); if (m_selectedItem->staff()->firstNote()->item() == m_selectedItem) m_selectedItem->staff()->createExtraTie(m_selectedItem); @@ -1499,7 +1499,7 @@ TmeasureObject *TscoreObject::addMeasure() { auto lastM = m_measures.last(); if (lastM->free()) - qDebug() << "[TscoreObject] FIXME!!! Last measure is not full but the new one is going to be added"; + qDebug() << "[TscoreObject]" << "FIXME!!! Last measure is not full but the new one is going to be added"; lastM = getMeasure(m_measures.count()); m_measures << lastM; lastStaff()->appendMeasure(lastM); @@ -1509,7 +1509,7 @@ TmeasureObject *TscoreObject::addMeasure() TnotePair *TscoreObject::insertSilently(int id, const Tnote &n, TmeasureObject *m) { m_notes.insert(id, n); - auto np = getSegment(id, &m_notes[id]); + auto np = getSegment(id, m_notes[id]); m_segments.insert(id, np); for (int s = id + 1; s < m_segments.count(); ++s) m_segments[s]->setIndex(s); @@ -1526,7 +1526,7 @@ void TscoreObject::appendToNoteList(QList<Tnote> &l) { for (Tnote &n : l) { m_notes << n; - m_segments << getSegment(m_segments.count(), &m_notes.last()); + m_segments << getSegment(m_segments.count(), m_notes.last()); } } @@ -1551,13 +1551,13 @@ void TscoreObject::updateClefOffset() } } -TnotePair *TscoreObject::getSegment(int noteNr, Tnote *n) +TnotePair *TscoreObject::getSegment(int noteNr, const Tnote &n) { - if (m_spareSegments.isEmpty()) + if (m_spareSegments.isEmpty()) { return new TnotePair(noteNr, n); - else { + } else { auto np = m_spareSegments.takeLast(); - np->setNote(n); + np->setWrapperNote(n); np->setIndex(noteNr); return np; } diff --git a/src/libs/core/score/tscoreobject.h b/src/libs/core/score/tscoreobject.h index e0e5f90f..3105d11f 100644 --- a/src/libs/core/score/tscoreobject.h +++ b/src/libs/core/score/tscoreobject.h @@ -650,7 +650,7 @@ private: /** * Returns @p TnotePair - a segment that can be either created or taken from @p m_spareSegments */ - TnotePair *getSegment(int noteNr, Tnote *n); + TnotePair *getSegment(int noteNr, const Tnote &n); /** * Returns @p TmeasureObject - a measure that can be either created or taken from @p m_spareMeasures -- GitLab