Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial ties refinements #26048

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/engraving/dom/dom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ set(DOM_SRC
${CMAKE_CURRENT_LIST_DIR}/textlinebase.h
${CMAKE_CURRENT_LIST_DIR}/tie.cpp
${CMAKE_CURRENT_LIST_DIR}/tie.h
${CMAKE_CURRENT_LIST_DIR}/tiejumppointlist.cpp
${CMAKE_CURRENT_LIST_DIR}/tiejumppointlist.h
${CMAKE_CURRENT_LIST_DIR}/tiemap.h
${CMAKE_CURRENT_LIST_DIR}/timesig.cpp
${CMAKE_CURRENT_LIST_DIR}/timesig.h
Expand Down
3 changes: 3 additions & 0 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,9 @@ static Tie* createAndAddTie(Note* startNote, Note* endNote)
tie->setTrack(startNote->track());
tie->setTick(startNote->chord()->segment()->tick());
if (endNote) {
if (endNote->tieBack()) {
score->undoRemoveElement(endNote->tieBack());
}
tie->setEndNote(endNote);
tie->setTicks(endNote->chord()->segment()->tick() - startNote->chord()->segment()->tick());
}
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/dom/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ NoteHeadGroup NoteHead::headGroup() const
//---------------------------------------------------------

Note::Note(Chord* ch)
: EngravingItem(ElementType::NOTE, ch, ElementFlag::MOVABLE)
: EngravingItem(ElementType::NOTE, ch, ElementFlag::MOVABLE), m_jumpPoints(this)
{
m_playEvents.push_back(NoteEvent()); // add default play event
}
Expand Down Expand Up @@ -599,7 +599,7 @@ std::vector<const Note*> Note::compoundNotes() const
}

Note::Note(const Note& n, bool link)
: EngravingItem(n)
: EngravingItem(n), m_jumpPoints(this)
{
if (link) {
score()->undo(new Link(this, const_cast<Note*>(&n)));
Expand Down Expand Up @@ -2509,13 +2509,13 @@ PartialTie* Note::outgoingPartialTie() const
void Note::setTieFor(Tie* t)
{
m_tieFor = t;
m_jumpPoints.setStartTie(m_tieFor);
}

void Note::setTieBack(Tie* t)
{
if (m_tieBack && t && m_tieBack->jumpPoint()) {
t->setJumpPoint(m_tieBack->jumpPoint());
m_tieBack->setJumpPoint(nullptr);
}
m_tieBack = t;
}
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "pitchspelling.h"
#include "symbol.h"
#include "tie.h"
#include "tiejumppointlist.h"
#include "types.h"

namespace mu::engraving {
Expand Down
272 changes: 22 additions & 250 deletions src/engraving/dom/tie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "factory.h"
#include "hook.h"
#include "ledgerline.h"
#include "marker.h"
#include "masterscore.h"
#include "measure.h"
#include "mscoreview.h"
Expand All @@ -45,7 +44,7 @@
#include "stafftype.h"
#include "stem.h"
#include "system.h"
#include "types/typesconv.h"
#include "tiejumppointlist.h"
#include "undo.h"
#include "utils.h"
#include "volta.h"
Expand Down Expand Up @@ -215,19 +214,25 @@ Tie::Tie(const ElementType& type, EngravingItem* parent)
setAnchor(Anchor::NOTE);
}

TieJumpPointList* Tie::startTieJumpPoints() const
{
return m_jumpPoint ? m_jumpPoint->jumpPointList() : nullptr;
}

void Tie::updatePossibleJumpPoints()
{
if (!tieJumpPoints()) {
return;
}

tieJumpPoints()->clear();

MasterScore* master = masterScore();
const Note* note = toNote(parentItem());
const Chord* chord = note->chord();
const Measure* measure = chord->measure();
const MeasureBase* masterMeasureBase = master->measure(measure->index());
const Measure* masterMeasure = masterMeasureBase && masterMeasureBase->isMeasure() ? toMeasure(masterMeasureBase) : nullptr;
if (!tieJumpPoints()) {
return;
}

tieJumpPoints()->clear();

if (!chord->hasFollowingJumpItem()) {
return;
Expand Down Expand Up @@ -293,7 +298,7 @@ void Tie::addTiesToJumpPoints()
jumpPoint->undoSetActive(true);
continue;
}
jumpPoints->addTieToScore(jumpPoint);
jumpPoints->undoAddTieToScore(jumpPoint);
}
}

Expand Down Expand Up @@ -468,254 +473,18 @@ bool Tie::isCrossStaff() const
|| (endChord && (endChord->staffMove() != 0 || endChord->vStaffIdx() != staff));
}

//---------------------------------------------------------
// PartialTieJumpPoint
//---------------------------------------------------------

TieJumpPoint::TieJumpPoint(Note* note, bool active, int idx, bool followingNote)
: m_note(note), m_active(active), m_followingNote(followingNote)
{
m_id = u"jumpPoint" + String::fromStdString(std::to_string(idx));
if (active && endTie()) {
endTie()->setJumpPoint(this);
}
}

Tie* TieJumpPoint::endTie() const
{
return m_note ? m_note->tieBack() : nullptr;
}

void TieJumpPoint::undoSetActive(bool v)
{
Score* score = m_note ? m_note->score() : nullptr;
if (!score || m_active == v) {
return;
}
score->undo(new ChangeTieJumpPointActive(m_jumpPointList, m_id, v));
}

const String TieJumpPoint::menuTitle() const
{
const Measure* measure = m_note->findMeasure();
const int measureNo = measure ? measure->no() + 1 : 0;
const TranslatableString tieTo("engraving", "Tie to ");
const String title = tieTo.str + precedingJumpItemName() + u" " + muse::mtrc("engraving", "(m. %1)").arg(measureNo);

return title;
}

String TieJumpPoint::precedingJumpItemName() const
{
const Chord* startChord = m_note->chord();
const Segment* seg = startChord->segment();
const Measure* measure = seg->measure();

if (seg->score()->firstSegment(SegmentType::ChordRest) == seg) {
return muse::mtrc("engraving", "start of score");
}

// Markers
for (const EngravingItem* e : measure->el()) {
if (!e->isMarker()) {
continue;
}

const Marker* marker = toMarker(e);
if (muse::contains(Marker::RIGHT_MARKERS, marker->markerType())) {
continue;
}

if (marker->markerType() == MarkerType::CODA || marker->markerType() == MarkerType::VARCODA) {
return muse::mtrc("engraving", "coda");
} else {
return muse::mtrc("engraving", "segno");
}
}

// Voltas
auto spanners = m_note->score()->spannerMap().findOverlapping(measure->tick().ticks(), measure->tick().ticks());
for (auto& spanner : spanners) {
if (!spanner.value->isVolta() || Fraction::fromTicks(spanner.start) != startChord->tick()) {
continue;
}

Volta* volta = toVolta(spanner.value);

return muse::mtrc("engraving", "“%1” volta").arg(volta->beginText());
}

// Repeat barlines
if (measure->repeatStart()) {
return muse::mtrc("engraving", "start repeat");
}

for (Segment* prevSeg = seg->prev(SegmentType::BarLineType); prevSeg && prevSeg->tick() == seg->tick();
prevSeg = prevSeg->prev(SegmentType::BarLineType)) {
EngravingItem* el = prevSeg->element(startChord->track());
if (!el || !el->isBarLine()) {
continue;
}

BarLine* bl = toBarLine(el);
if (bl->barLineType() & (BarLineType::START_REPEAT | BarLineType::END_START_REPEAT)) {
return muse::mtrc("engraving", "start repeat");
}
}

if (m_note->tieBack() && m_note->tieBack()->startNote()) {
return muse::mtrc("engraving", "next note");
}

return muse::mtrc("engraving", "invalid");
}

//---------------------------------------------------------
// PartialTieJumpPointList
//---------------------------------------------------------

TieJumpPointList::~TieJumpPointList()
{
muse::DeleteAll(m_jumpPoints);
m_jumpPoints.clear();
}

void TieJumpPointList::add(TieJumpPoint* item)
{
item->setJumpPointList(this);
m_jumpPoints.push_back(item);
}

void TieJumpPointList::clear()
{
for (const TieJumpPoint* jumpPoint : m_jumpPoints) {
Tie* endTie = jumpPoint->endTie();
if (!endTie) {
continue;
}
endTie->setJumpPoint(nullptr);
}
muse::DeleteAll(m_jumpPoints);
m_jumpPoints.clear();
}

TieJumpPoint* TieJumpPointList::findJumpPoint(const String& id)
{
for (TieJumpPoint* jumpPoint : m_jumpPoints) {
if (jumpPoint->id() != id) {
continue;
}

return jumpPoint;
}
return nullptr;
}

void TieJumpPointList::toggleJumpPoint(const String& id)
{
TieJumpPoint* end = findJumpPoint(id);

if (!end) {
LOGE() << "No partial tie end point found with id: " << id;
return;
}

Score* score = end->note() ? end->note()->score() : nullptr;
if (!score) {
return;
}

score->startCmd(TranslatableString("engraving", "Toggle partial tie"));
const bool checked = end->active();
if (checked) {
undoRemoveTieFromScore(end);
} else {
addTieToScore(end);
}
score->endCmd();
}

void TieJumpPointList::addTieToScore(TieJumpPoint* jumpPoint)
{
Note* note = jumpPoint->note();
Score* score = note ? note->score() : nullptr;
if (!m_startTie || !score) {
return;
}

if (jumpPoint->followingNote()) {
// Remove partial tie and add full tie
if (!m_startTie->isPartialTie() || !toPartialTie(m_startTie)->isOutgoing()) {
return;
}
jumpPoint->undoSetActive(true);
m_startTie = Tie::changeTieType(m_startTie, note);
return;
}

jumpPoint->undoSetActive(true);

// Check if there is already a tie. If so, add partial tie info to it
Tie* tieBack = note->tieBack();
if (tieBack && !tieBack->isPartialTie()) {
tieBack->setJumpPoint(jumpPoint);
return;
}
// Otherwise create incoming partial tie on note
PartialTie* pt = Factory::createPartialTie(note);
pt->setParent(note);
pt->setEndNote(note);
pt->setJumpPoint(jumpPoint);
score->undoAddElement(pt);
}

void TieJumpPointList::undoRemoveTieFromScore(TieJumpPoint* jumpPoint)
{
Note* note = jumpPoint->note();
Score* score = note ? note->score() : nullptr;
if (!m_startTie || !score) {
return;
}

if (jumpPoint->followingNote()) {
// Remove full tie and add partial tie
if (m_startTie->isPartialTie()) {
return;
}
jumpPoint->undoSetActive(false);

m_startTie = Tie::changeTieType(m_startTie);
return;
}

jumpPoint->undoSetActive(false);

// Check if there is a full tie. If so, remove partial tie info from it
Tie* tieBack = note->tieBack();
if (tieBack && !tieBack->isPartialTie()) {
tieBack->setJumpPoint(nullptr);
return;
}
// Otherwise remove incoming partial tie on note
PartialTie* pt = note->incomingPartialTie();
if (!pt) {
return;
}
score->undoRemoveElement(pt);
}

Tie* Tie::changeTieType(Tie* oldTie, Note* endNote)
void Tie::changeTieType(Tie* oldTie, Note* endNote)
{
// Replaces oldTie with an outgoing partial tie if no endNote is specified. Otherwise replaces oldTie with a regular tie
Note* startNote = oldTie->startNote();
bool addPartialTie = !endNote;
Score* score = startNote ? startNote->score() : nullptr;
if (!score) {
return nullptr;
return;
}

TranslatableString undoCmd = addPartialTie ? TranslatableString("engraving", "Replace full tie with partial tie") : TranslatableString(
"engraving", "Replace partial tie with full tie");
TranslatableString undoCmd = addPartialTie ? TranslatableString("engraving", "Replace full tie with partial tie")
: TranslatableString("engraving", "Replace partial tie with full tie");
Tie* newTie = addPartialTie ? Factory::createPartialTie(score->dummy()->note()) : Factory::createTie(score->dummy()->note());

score->undoRemoveElement(oldTie);
Expand All @@ -741,8 +510,6 @@ Tie* Tie::changeTieType(Tie* oldTie, Note* endNote)
score->undoAddElement(newTie);

score->endCmd();

return newTie;
}

void Tie::updateStartTieOnRemoval()
Expand All @@ -756,4 +523,9 @@ void Tie::updateStartTieOnRemoval()
score()->undoRemoveElement(_startTie);
}
}

Tie* Tie::startTie() const
{
return startTieJumpPoints() ? startTieJumpPoints()->startTie() : nullptr;
}
}
Loading
Loading