Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Jan 8, 2025
1 parent de6b2a8 commit 84ef19f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 30 deletions.
10 changes: 10 additions & 0 deletions src/engraving/dom/lyrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "system.h"
#include "textedit.h"
#include "undo.h"
#include "utils.h"

#include "log.h"

Expand Down Expand Up @@ -325,6 +326,15 @@ void Lyrics::adjustPrevious()
}
}

void Lyrics::setNeedRemoveInvalidSegments()
{
// Allow "invalid" segments when there is a partial lyric line in a following repeat segment
if (chordRest()->hasFollowingJumpItem() && repeatHasPartialLyricLine(measure())) {
return;
}
m_needRemoveInvalidSegments = true;
}

//---------------------------------------------------------
// endEdit
//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/lyrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Lyrics final : public TextBase
void adjustPrevious();

bool needRemoveInvalidSegments() const { return m_needRemoveInvalidSegments; }
void setNeedRemoveInvalidSegments() { m_needRemoveInvalidSegments = true; }
void setNeedRemoveInvalidSegments();
void removeInvalidSegments();

LyricsLine* separator() const { return m_separator; }
Expand Down
18 changes: 18 additions & 0 deletions src/engraving/dom/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,4 +1484,22 @@ std::vector<Measure*> findPreviousRepeatMeasures(const Measure* measure)

return measures;
}

bool repeatHasPartialLyricLine(const Measure* endRepeatMeasure)
{
const std::vector<Measure*> measures = findFollowingRepeatMeasures(endRepeatMeasure);
const Score* score = endRepeatMeasure->score();

for (const Measure* measure : measures) {
const SpannerMap::IntervalList& spanners = score->spannerMap().findOverlapping(measure->tick().ticks(), measure->endTick().ticks());

for (auto& spanner : spanners) {
if (spanner.value->isPartialLyricsLine() && spanner.start == measure->tick().ticks()) {
return true;
}
}
}

return false;
}
}
1 change: 1 addition & 0 deletions src/engraving/dom/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ extern InstrumentTrackId makeInstrumentTrackId(const EngravingItem* item);

extern std::vector<Measure*> findFollowingRepeatMeasures(const Measure* measure);
extern std::vector<Measure*> findPreviousRepeatMeasures(const Measure* measure);
extern bool repeatHasPartialLyricLine(const Measure* endRepeatMeasure);
} // namespace mu::engraving
20 changes: 1 addition & 19 deletions src/engraving/rendering/score/lyricslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ double LyricsLayout::lyricsLineEndX(const LyricsLineSegment* item, const Lyrics*
}

// Full dashes or melisma before a repeat - possibly with a partial dash/repeat on the other side of the repeat
if (endChordRest && hasFollowingJump) {
if (endChordRest && hasFollowingJump && !lyricsLine->nextLyrics()) {
Measure* endMeasure = lyricsLine->findEndMeasure();
// check if there is a partial lyrics line in a following measure
if (repeatHasPartialLyricLine(endMeasure) || endChordRest == lyricsLine->startElement()) {
Expand Down Expand Up @@ -857,21 +857,3 @@ void LyricsLayout::adjustLyricsLineYOffset(LyricsLineSegment* item, const Lyrics

item->ryoffset() = endLyrics->offset().y();
}

bool LyricsLayout::repeatHasPartialLyricLine(const Measure* endRepeatMeasure)
{
const std::vector<Measure*> measures = findFollowingRepeatMeasures(endRepeatMeasure);
const Score* score = endRepeatMeasure->score();

for (const Measure* measure : measures) {
const SpannerMap::IntervalList& spanners = score->spannerMap().findOverlapping(measure->tick().ticks(), measure->endTick().ticks());

for (auto& spanner : spanners) {
if (spanner.value->isPartialLyricsLine() && spanner.start == measure->tick().ticks()) {
return true;
}
}
}

return false;
}
2 changes: 0 additions & 2 deletions src/engraving/rendering/score/lyricslayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class LyricsLayout
static double lyricsLineStartX(const LyricsLineSegment* item);
static double lyricsLineEndX(const LyricsLineSegment* item, const Lyrics* endLyrics = nullptr);
static void adjustLyricsLineYOffset(LyricsLineSegment* item, const Lyrics* endLyrics = nullptr);

static bool repeatHasPartialLyricLine(const Measure* endRepeatMeasure);
};
}
#endif // MU_ENGRAVING_LYRICSLAYOUT_DEV_H
50 changes: 42 additions & 8 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "engraving/dom/textedit.h"
#include "engraving/dom/tuplet.h"
#include "engraving/dom/undo.h"
#include "engraving/dom/utils.h"
#include "engraving/compat/dummyelement.h"

#include "engraving/rw/xmlreader.h"
Expand Down Expand Up @@ -6162,7 +6163,6 @@ void NotationInteraction::addMelisma()
FontStyle fStyle = lyrics->fontStyle();
PropertyFlags fFlags = lyrics->propertyFlags(Pid::FONT_STYLE);
Fraction endTick = segment->tick(); // a previous melisma cannot extend beyond this point

endEditText();

// search next chord
Expand All @@ -6176,14 +6176,29 @@ void NotationInteraction::addMelisma()

// look for the lyrics we are moving from; may be the current lyrics or a previous one
// we are extending with several underscores
Lyrics* fromLyrics = 0;
Lyrics* fromLyrics = nullptr;
PartialLyricsLine* prevPartialLyricsLine = nullptr;
while (segment) {
ChordRest* cr = toChordRest(segment->element(track));
if (cr) {
fromLyrics = cr->lyrics(verse, placement);
if (fromLyrics) {
break;
}
// Check if there is a partial melisma to extend
auto spanners = score()->spannerMap().findOverlapping(cr->tick().ticks(), cr->endTick().ticks());
for (auto& spanner : spanners) {
if (!spanner.value->isPartialLyricsLine() || spanner.value->staffIdx() != cr->staffIdx()) {
continue;
}
PartialLyricsLine* lyricsLine = toPartialLyricsLine(spanner.value);
if (lyricsLine->no() != verse || lyricsLine->placement() != placement || !lyricsLine->isEndMelisma()) {
continue;
}

prevPartialLyricsLine = lyricsLine;
break;
}
}
segment = segment->prev1(SegmentType::ChordRest);
// if the segment has a rest in this track, stop going back
Expand Down Expand Up @@ -6228,15 +6243,29 @@ void NotationInteraction::addMelisma()
}

// if a place for a new lyrics has been found, create a lyrics there
ChordRest* nextCR = toChordRest(nextSegment->element(track));

// Disallow melisma lines between non-adjacent repeat sections eg. 1st volta -> 2nd volta
if (nextCR && fromLyrics) {
Measure* toLyricsMeasure = nextCR->measure();
Measure* fromLyricsMeasure = fromLyrics->measure();

if (toLyricsMeasure != fromLyricsMeasure && fromLyricsMeasure->lastChordRest(track)->hasFollowingJumpItem()) {
const std::vector<Measure*> previousRepeats = findPreviousRepeatMeasures(toLyricsMeasure);
const bool inPrecedingRepeatSeg = muse::contains(previousRepeats, fromLyricsMeasure);
if (!previousRepeats.empty() && !inPrecedingRepeatSeg) {
return;
}
}
}

score()->startCmd(TranslatableString("undoableAction", "Enter lyrics extension line"));
ChordRest* cr = toChordRest(nextSegment->element(track));
Lyrics* toLyrics = cr->lyrics(verse, placement);
bool newLyrics = (toLyrics == 0);
Lyrics* toLyrics = nextCR->lyrics(verse, placement);
bool newLyrics = (toLyrics == nullptr);
if (!toLyrics) {
toLyrics = Factory::createLyrics(cr);
toLyrics = Factory::createLyrics(nextCR);
toLyrics->setTrack(track);
toLyrics->setParent(cr);
toLyrics->setParent(nextCR);

toLyrics->setNo(verse);
const TextStyleType styleType(toLyrics->isEven() ? TextStyleType::LYRICS_EVEN : TextStyleType::LYRICS_ODD);
Expand All @@ -6254,6 +6283,7 @@ void NotationInteraction::addMelisma()
} else if (toLyrics->syllabic() == LyricsSyllabic::END) {
toLyrics->undoChangeProperty(Pid::SYLLABIC, int(LyricsSyllabic::SINGLE));
}

if (fromLyrics) {
// as we moved away from fromLyrics by an underscore,
// it can be isolated or terminal but cannot have dashes after
Expand All @@ -6269,7 +6299,7 @@ void NotationInteraction::addMelisma()
if (fromLyrics->segment()->tick() < endTick) {
fromLyrics->undoChangeProperty(Pid::LYRIC_TICKS, endTick - fromLyrics->segment()->tick());
}
} else if (hasPrecedingRepeat) {
} else if (hasPrecedingRepeat && !prevPartialLyricsLine) {
// No from lyrics - create incoming partial melisma
PartialLyricsLine* melisma = Factory::createPartialLyricsLine(score()->dummy());
melisma->setIsEndMelisma(true);
Expand All @@ -6281,6 +6311,10 @@ void NotationInteraction::addMelisma()
melisma->setTrack2(initialCR->track());

score()->undoAddElement(melisma);
} else if (prevPartialLyricsLine) {
const Fraction tickDiff = nextCR->tick() - prevPartialLyricsLine->tick2();
prevPartialLyricsLine->undoMoveEnd(tickDiff);
prevPartialLyricsLine->triggerLayout();
}
if (newLyrics) {
score()->undoAddElement(toLyrics);
Expand Down

0 comments on commit 84ef19f

Please sign in to comment.