Skip to content

Commit

Permalink
allow melisma to be deleted on chordrest duration change
Browse files Browse the repository at this point in the history
  • Loading branch information
asattely committed Jul 5, 2023
1 parent 719ecf5 commit a107c90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/engraving/layout/v0/lyricslayout.cpp
Expand Up @@ -279,13 +279,15 @@ void LyricsLayout::layout(LyricsLine* item, LayoutContext& ctx)
ps = ps->prev1(SegmentType::ChordRest);
}
if (!ps || ps == lyricsSegment) {
// no valid previous CR, so try to lengthen melisma instead
// either there is no valid previous CR, or the previous CR is the one the lyric starts on
// we don't want to make the melisma longer arbitrarily, but there is a possibility that the next
// CR won't extend the melisma, so let's check it
ps = ns;
s = ps->nextCR(lyricsTrack, true);
EngravingItem* e = s ? s->element(lyricsTrack) : nullptr;
// check to make sure we have a chord
if (!e || e->type() != ElementType::CHORD) {
// nothing to do but set ticks to 0
if (!e || e->type() != ElementType::CHORD || ps->tick() > item->tick() + item->ticks()) {
// nope, nothing to do but set ticks to 0
// this will result in melisma being deleted later
item->lyrics()->undoChangeProperty(Pid::LYRIC_TICKS, Fraction::fromTicks(0));
item->setTicks(Fraction(0, 1));
Expand Down
12 changes: 8 additions & 4 deletions src/engraving/libmscore/lyrics.cpp
Expand Up @@ -373,6 +373,9 @@ PropertyValue Lyrics::getProperty(Pid propertyId) const

bool Lyrics::setProperty(Pid propertyId, const PropertyValue& v)
{
ChordRest* scr = nullptr;
ChordRest* ecr = nullptr;

switch (propertyId) {
case Pid::PLACEMENT:
setPlacement(v.value<PlacementV>());
Expand All @@ -389,14 +392,14 @@ bool Lyrics::setProperty(Pid propertyId, const PropertyValue& v)
// endTick info is wrong.
// Somehow we need to fix this.
// See https://musescore.org/en/node/285304 and https://musescore.org/en/node/311289
ChordRest* ecr = score()->findCR(endTick(), track());
ecr = score()->findCR(endTick(), track());
if (ecr) {
ecr->setMelismaEnd(false);
}
}

scr = score()->findCR(tick(), track());
_ticks = v.value<Fraction>();
if (_ticks <= Fraction(0, 1)) {
if (scr && _ticks <= scr->ticks()) {
// if no ticks, we have to relayout in order to remove invalid melisma segments
setRemoveInvalidSegments();
layout()->layoutItem(this);
Expand Down Expand Up @@ -518,8 +521,9 @@ 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;
Expand Down

0 comments on commit a107c90

Please sign in to comment.