Skip to content

Commit

Permalink
allow lyric entry to interrupt melisma
Browse files Browse the repository at this point in the history
  • Loading branch information
asattely committed Jul 5, 2023
1 parent a107c90 commit d8bdda7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/engraving/layout/v0/lyricslayout.cpp
Expand Up @@ -135,7 +135,8 @@ void LyricsLayout::layout(Lyrics* item, LayoutContext& ctx)
ChordRest* cr = item->chordRest();
if (item->_removeInvalidSegments) {
item->removeInvalidSegments();
} else if (item->_ticks > Fraction(0, 1) || item->_syllabic == LyricsSyllabic::BEGIN || item->_syllabic == LyricsSyllabic::MIDDLE) {
}
if (item->_ticks > Fraction(0, 1) || item->_syllabic == LyricsSyllabic::BEGIN || item->_syllabic == LyricsSyllabic::MIDDLE) {
if (!item->_separator) {
item->_separator = new LyricsLine(ctx.mutDom().dummyParent());
item->_separator->setTick(cr->tick());
Expand Down
8 changes: 7 additions & 1 deletion src/engraving/layout/v0/tlayout.cpp
Expand Up @@ -5327,6 +5327,9 @@ SpannerSegment* TLayout::layoutSystemSLine(SLine* line, System* system, LayoutCo

SpannerSegment* TLayout::layoutSystem(LyricsLine* line, System* system, LayoutContext& ctx)
{
if (!line->lyrics()) {
return nullptr; // a lyrics line with no lyrics shouldn't exist
}
Fraction stick = system->firstMeasure()->tick();
Fraction etick = system->lastMeasure()->endTick();

Expand Down Expand Up @@ -5402,7 +5405,10 @@ SpannerSegment* TLayout::layoutSystem(LyricsLine* line, System* system, LayoutCo
}

TLayout::layout(lineSegm, ctx);

if (!line->lyrics()) {
// this line could have been removed in the process of laying out surrounding lyrics
return nullptr;
}
// if temp melisma extend the first line segment to be
// after the lyrics syllable (otherwise the melisma segment
// will be too short).
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/line.cpp
Expand Up @@ -886,7 +886,7 @@ PointF SLine::linePos(Grip grip, System** sys) const
}
}
}
} else if (isLyricsLine() && toLyrics(explicitParent())->ticks() > Fraction(0, 1)) {
} else if (isLyricsLine() && explicitParent() && toLyrics(explicitParent())->ticks() > Fraction(0, 1)) {
// melisma line
// it is possible CR won't be in correct track
// prefer element in current track if available
Expand Down
3 changes: 1 addition & 2 deletions src/engraving/libmscore/lyrics.cpp
Expand Up @@ -521,11 +521,10 @@ void Lyrics::undoChangeProperty(Pid id, const PropertyValue& v, PropertyFlags ps
void Lyrics::removeInvalidSegments()
{
_removeInvalidSegments = false;
if (_separator && isMelisma() && _ticks <= _separator->startCR()->ticks()) {
if (_separator && isMelisma() && _ticks < _separator->startCR()->ticks()) {
setTicks(Fraction(0, 1));
_separator->setTicks(Fraction(0, 1));
_separator->removeUnmanaged();
delete _separator;
_separator = nullptr;
setAlign(propertyDefault(Pid::ALIGN).value<Align>());
if (_syllabic == LyricsSyllabic::BEGIN || _syllabic == LyricsSyllabic::SINGLE) {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/lyrics.h
Expand Up @@ -141,7 +141,7 @@ class LyricsLine final : public SLine

Lyrics* lyrics() const { return toLyrics(explicitParent()); }
Lyrics* nextLyrics() const { return _nextLyrics; }
bool isEndMelisma() const { return lyrics()->ticks().isNotZero(); }
bool isEndMelisma() const { return lyrics() && lyrics()->ticks().isNotZero(); }
bool isDash() const { return !isEndMelisma(); }
bool setProperty(Pid propertyId, const PropertyValue& v) override;

Expand Down
20 changes: 20 additions & 0 deletions src/engraving/libmscore/textedit.cpp
Expand Up @@ -222,6 +222,26 @@ void TextBase::endEdit(EditData& ed)
} else {
triggerLayout();
}
if (isLyrics()) {
Lyrics* prev = prevLyrics(toLyrics(this));
if (prev) {
if (prev->tick() + prev->ticks() >= tick()) {
// the previous lyric has a spanner attached that goes through this one
// we need to shorten it
Segment* s = score()->tick2segment(tick());
if (s) {
s = s->prev1(SegmentType::ChordRest);
if (s->tick() > prev->tick()) {
prev->undoChangeProperty(Pid::LYRIC_TICKS, s->tick() - prev->tick());
} else {
prev->undoChangeProperty(Pid::LYRIC_TICKS, Fraction::fromTicks(1));
}
}
}
prev->setRemoveInvalidSegments();
prev->triggerLayout();
}
}

static const double w = 2.0;
score()->addRefresh(canvasBoundingRect().adjusted(-w, -w, w, w));
Expand Down

0 comments on commit d8bdda7

Please sign in to comment.