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 1 commit
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
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
257 changes: 11 additions & 246 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,6 +214,11 @@ 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()) {
Expand Down Expand Up @@ -469,250 +473,6 @@ 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 String measureStr = String::fromStdString(std::to_string(measureNo));

//: %1 represents the preceding jump item eg. coda. %2 represents the measure number
return muse::mtrc("engraving", "Tie to %1 (m. %2)").arg(precedingJumpItemName(), measureStr);
}

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) {
//: Used at %1 in the string "Tie to %1 (m. %2)"
return muse::mtrc("engraving", "start of score", "partial tie menu");
}

// 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) {
//: Used at %1 in the string "Tie to %1 (m. %2)"
return muse::mtrc("engraving", "coda", "partial tie menu");
} else {
//: Used at %1 in the string "Tie to %1 (m. %2)"
return muse::mtrc("engraving", "segno", "partial tie menu");
}
}

// 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);

//: Used at %1 in the string "Tie to %1 (m. %2)". %1 in this string represents the volta's text set by the user
return muse::mtrc("engraving", "“%1” volta", "partial tie menu").arg(volta->beginText());
}

// Repeat barlines
if (measure->repeatStart()) {
//: Used at %1 in the string "Tie to %1 (m. %2)"
return muse::mtrc("engraving", "start repeat", "partial tie menu");
}

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)) {
//: Used at %1 in the string "Tie to %1 (m. %2)"
return muse::mtrc("engraving", "start repeat", "partial tie menu");
}
}

if (m_note->tieBack() && m_note->tieBack()->startNote()) {
//: Used at %1 in the string "Tie to %1 (m. %2)"
return muse::mtrc("engraving", "next note", "partial tie menu");
}

//: Used at %1 in the string "Tie to %1 (m. %2)"
return muse::mtrc("engraving", "invalid", "partial tie menu");
}

//---------------------------------------------------------
// 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 {
undoAddTieToScore(end);
}
score->endCmd();
}

void TieJumpPointList::undoAddTieToScore(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)
{
// Replaces oldTie with an outgoing partial tie if no endNote is specified. Otherwise replaces oldTie with a regular tie
Expand Down Expand Up @@ -765,4 +525,9 @@ void Tie::updateStartTieOnRemoval()
score()->undoRemoveElement(_startTie);
}
}

Tie* Tie::startTie() const
{
return startTieJumpPoints() ? startTieJumpPoints()->startTie() : nullptr;
}
}
62 changes: 3 additions & 59 deletions src/engraving/dom/tie.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,63 +26,7 @@

namespace mu::engraving {
class TieJumpPointList;
class TieJumpPoint
{
public:
TieJumpPoint(Note* note, bool active, int idx, bool followingNote);
TieJumpPoint() {}

Note* note() const { return m_note; }
Tie* endTie() const;
bool followingNote() const { return m_followingNote; }
const String& id() const { return m_id; }
bool active() const { return m_active; }
void setActive(bool v) { m_active = v; }
void undoSetActive(bool v);
void setJumpPointList(TieJumpPointList* jumpPointList) { m_jumpPointList = jumpPointList; }
TieJumpPointList* jumpPointList() { return m_jumpPointList; }

const String menuTitle() const;

private:
String precedingJumpItemName() const;
Note* m_note = nullptr;
bool m_active = false;
String m_id;
TieJumpPointList* m_jumpPointList = nullptr;
bool m_followingNote = false;
};

class TieJumpPointList
{
public:
TieJumpPointList() = default;
~TieJumpPointList();

void add(TieJumpPoint* item);
void clear();
size_t size() const { return m_jumpPoints.size(); }
bool empty() const { return m_jumpPoints.empty(); }

void setStartTie(Tie* startTie) { m_startTie = startTie; }
Tie* startTie() const { return m_startTie; }

TieJumpPoint* findJumpPoint(const String& id);
void toggleJumpPoint(const String& id);

void undoAddTieToScore(TieJumpPoint* jumpPoint);
void undoRemoveTieFromScore(TieJumpPoint* jumpPoint);

std::vector<TieJumpPoint*>::iterator begin() { return m_jumpPoints.begin(); }
std::vector<TieJumpPoint*>::const_iterator begin() const { return m_jumpPoints.begin(); }
std::vector<TieJumpPoint*>::iterator end() { return m_jumpPoints.end(); }
std::vector<TieJumpPoint*>::const_iterator end() const { return m_jumpPoints.end(); }

private:
std::vector<TieJumpPoint*> m_jumpPoints;
Tie* m_startTie = nullptr;
};

class TieJumpPoint;
//---------------------------------------------------------
// @@ TieSegment
/// a single segment of a tie
Expand Down Expand Up @@ -189,7 +133,7 @@ class Tie : public SlurTie
void setJumpPoint(TieJumpPoint* jumpPoint) { m_jumpPoint = jumpPoint; }
void updateStartTieOnRemoval();
TieJumpPoint* jumpPoint() const { return m_jumpPoint; }
Tie* startTie() const { return startTieJumpPoints() ? startTieJumpPoints()->startTie() : nullptr; }
Tie* startTie() const;

static Tie* changeTieType(Tie* oldTie, Note* endNote = nullptr);

Expand All @@ -201,6 +145,6 @@ class Tie : public SlurTie

// Jump point information for incoming ties after repeats
TieJumpPoint* m_jumpPoint = nullptr;
TieJumpPointList* startTieJumpPoints() const { return m_jumpPoint ? m_jumpPoint->jumpPointList() : nullptr; }
TieJumpPointList* startTieJumpPoints() const;
};
} // namespace mu::engraving
Loading