Skip to content

Commit

Permalink
Add verse property to partial lyrics line
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Jan 7, 2025
1 parent 70d476b commit de6b2a8
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/engraving/dom/lyrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ class PartialLyricsLine final : public LyricsLine
PropertyValue getProperty(Pid propertyId) const override;
bool setProperty(Pid propertyId, const PropertyValue&) override;
PropertyValue propertyDefault(Pid propertyId) const override;
Sid getPropertyStyle(Pid propertyId) const override;

Lyrics* findLyricsInPreviousRepeatSeg();
Lyrics* findLyricsInPreviousRepeatSeg() const;
Lyrics* findAdjacentLyricsOrDefault() const;

protected:
void doComputeEndElement() override;
Expand Down Expand Up @@ -246,5 +248,7 @@ class PartialLyricsLineSegment final : public LyricsLineSegment
bool lyricsAddToSkyline() const override { return lyricsLine()->addToSkyline(); }
Color color() const override { return lyricsLine()->color(); }
double baseLineShift() const override;

EngravingItem* propertyDelegate(Pid) override;
};
} // namespace mu::engraving
73 changes: 59 additions & 14 deletions src/engraving/dom/lyricsline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

#include "lyrics.h"

#include "chord.h"
#include "chordrest.h"
#include "factory.h"
#include "measure.h"
#include "navigate.h"
#include "note.h"
Expand Down Expand Up @@ -209,6 +211,8 @@ bool PartialLyricsLine::setProperty(Pid propertyId, const PropertyValue& val)
return LyricsLine::setProperty(propertyId, val);
}

triggerLayout();

return true;
}

Expand All @@ -222,6 +226,16 @@ PropertyValue PartialLyricsLine::propertyDefault(Pid propertyId) const
}
}

Sid PartialLyricsLine::getPropertyStyle(Pid propertyId) const
{
switch (propertyId) {
case Pid::PLACEMENT:
return Sid::lyricsPlacement;
default:
return LyricsLine::getPropertyStyle(propertyId);
}
}

void PartialLyricsLine::doComputeEndElement()
{
LyricsLine::doComputeEndElement();
Expand All @@ -235,25 +249,28 @@ void PartialLyricsLine::doComputeEndElement()
// PartialLyricsLineSegment
//=========================================================

static const ElementStyle partialLyricsLineSegmentElementStyle {
{ Sid::lyricsPlacement, Pid::PLACEMENT },
{ Sid::lyricsPosBelow, Pid::OFFSET },
{ Sid::lyricsMinTopDistance, Pid::MIN_DISTANCE },
};

PartialLyricsLineSegment::PartialLyricsLineSegment(PartialLyricsLine* line, System* parent)
: LyricsLineSegment(ElementType::PARTIAL_LYRICSLINE_SEGMENT, line, parent, ElementFlag::ON_STAFF)
{
setGenerated(false);
initElementStyle(&partialLyricsLineSegmentElementStyle);
}

double PartialLyricsLineSegment::lineSpacing() const
{
const Lyrics* prevLyrics = lyricsLine()->findLyricsInPreviousRepeatSeg();
if (prevLyrics) {
return prevLyrics->lineSpacing();
}
const Lyrics* lyrics = lyricsLine()->findAdjacentLyricsOrDefault();

const Lyrics* nextLyrics = lyricsLine()->nextLyrics();
if (nextLyrics) {
return lyricsLine()->nextLyrics()->lineSpacing();
if (!lyrics) {
return 0.0;
}

return 0.0;
return lyrics->lineSpacing();
}

double PartialLyricsLineSegment::baseLineShift() const
Expand All @@ -262,20 +279,30 @@ double PartialLyricsLineSegment::baseLineShift() const
return -0.5 * absoluteFromSpatium(lineWidth());
}

const Lyrics* prevLyrics = lyricsLine()->findLyricsInPreviousRepeatSeg();
if (prevLyrics) {
return -style().styleD(Sid::lyricsDashYposRatio) * prevLyrics->fontMetrics().xHeight();
const Lyrics* lyrics = lyricsLine()->findAdjacentLyricsOrDefault();
if (!lyrics) {
return 0.0;
}

return 0.0;
return -style().styleD(Sid::lyricsDashYposRatio) * lyrics->fontMetrics().xHeight();
}

EngravingItem* PartialLyricsLineSegment::propertyDelegate(Pid pid)
{
switch (pid) {
case Pid::VERSE:
return lyricsLine();
default:
return LyricsLineSegment::propertyDelegate(pid);
}
}

Lyrics* PartialLyricsLine::findLyricsInPreviousRepeatSeg()
Lyrics* PartialLyricsLine::findLyricsInPreviousRepeatSeg() const
{
const std::vector<Measure*> measures = findPreviousRepeatMeasures(findStartMeasure());

for (const Measure* measure : measures) {
Lyrics* prev = prevLyrics(measure->last(SegmentType::ChordRest), staffIdx(), no(), placement());
Lyrics* prev = lastLyricsInMeasure(measure->last(SegmentType::ChordRest), staffIdx(), no(), placement());

if (!prev) {
continue;
Expand All @@ -286,4 +313,22 @@ Lyrics* PartialLyricsLine::findLyricsInPreviousRepeatSeg()

return nullptr;
}

Lyrics* PartialLyricsLine::findAdjacentLyricsOrDefault() const
{
Lyrics* prev = findLyricsInPreviousRepeatSeg();
if (prev) {
return prev;
}

Lyrics* next = nextLyrics();
if (next) {
return next;
}

// If there are no adjacent lyrics, create dummy lyrics using the odd lyrics text style to get font information
Lyrics* dummyLyr = Factory::createLyrics(toChordRest(score()->dummy()->chord()));
dummyLyr->setTextStyleType(TextStyleType::LYRICS_ODD);
return dummyLyr;
}
}
21 changes: 16 additions & 5 deletions src/engraving/dom/navigate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,19 +1055,19 @@ EngravingItem* Score::prevElement()
// - currently used to determine the first lyric of a melisma
//---------------------------------------------------------

Lyrics* prevLyrics(const Segment* seg, const staff_idx_t staffIdx, const int no, const PlacementV& placement)
Lyrics* lastLyricsInMeasure(const Segment* seg, const staff_idx_t staffIdx, const int no, const PlacementV& placement)
{
const Segment* prevSegment = seg;
while ((prevSegment = prevSegment->prev1(mu::engraving::SegmentType::ChordRest))) {
while (seg) {
const track_idx_t strack = staffIdx * VOICES;
const track_idx_t etrack = strack + VOICES;
for (track_idx_t track = strack; track < etrack; ++track) {
EngravingItem* el = prevSegment->element(track);
EngravingItem* el = seg->element(track);
Lyrics* prevLyrics = el && el->isChord() ? toChordRest(el)->lyrics(no, placement) : nullptr;
if (prevLyrics) {
return prevLyrics;
}
}
seg = seg->prev1(mu::engraving::SegmentType::ChordRest);
}
return nullptr;
}
Expand All @@ -1078,7 +1078,18 @@ Lyrics* prevLyrics(const Lyrics* lyrics)
if (!seg) {
return nullptr;
}
return prevLyrics(seg, lyrics->staffIdx(), lyrics->no(), lyrics->placement());
while ((seg = seg->prev1(mu::engraving::SegmentType::ChordRest))) {
const track_idx_t strack = lyrics->staffIdx() * VOICES;
const track_idx_t etrack = strack + VOICES;
for (track_idx_t track = strack; track < etrack; ++track) {
EngravingItem* el = seg->element(track);
Lyrics* prevLyrics = el && el->isChord() ? toChordRest(el)->lyrics(lyrics->no(), lyrics->placement()) : nullptr;
if (prevLyrics) {
return prevLyrics;
}
}
}
return nullptr;
}

Lyrics* nextLyrics(const Lyrics* lyrics)
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/navigate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Segment;
extern int pitch2y(int pitch, int enh, int clefOffset, int key, int& prefix, const char* tversatz);
extern ChordRest* nextChordRest(const ChordRest* cr, bool skipGrace = false, bool skipMeasureRepeatRests = true);
extern ChordRest* prevChordRest(const ChordRest* cr, bool skipGrace = false, bool skipMeasureRepeatRests = true);
extern Lyrics* prevLyrics(const Segment* seg, const staff_idx_t staffIdx, const int no, const PlacementV& placement);
extern Lyrics* lastLyricsInMeasure(const Segment* seg, const staff_idx_t staffIdx, const int no, const PlacementV& placement);
extern Lyrics* prevLyrics(const Lyrics* lyrics);
extern Lyrics* nextLyrics(const Lyrics* lyrics);
} // namespace mu::engraving
7 changes: 5 additions & 2 deletions src/engraving/rendering/score/lyricslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ void LyricsLayout::layout(LyricsLineSegment* item, LayoutContext& ctx)
UNUSED(ctx);

assert(item->isPartialLyricsLineSegment() || item->lyrics());
item->ryoffset() = 0.0;

if (!item->isPartialLyricsLineSegment()) {
item->ryoffset() = 0.0;
}

LyricsLineSegment::LayoutData* ldata = item->mutldata();
ldata->clearDashes();
Expand Down Expand Up @@ -837,7 +840,7 @@ void LyricsLayout::adjustLyricsLineYOffset(LyricsLineSegment* item, const Lyrics
// Partial melisma or dashes
if (lyricsLine->isPartialLyricsLine()) {
Lyrics* nextLyrics = findNextLyrics(endChordRest, item->no());
item->ryoffset() = nextLyrics ? nextLyrics->offset().y() : 0.0;
item->ryoffset() = nextLyrics ? nextLyrics->offset().y() : item->offset().y();
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/tests/parts_data/part-image-parts.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<linkedMain/>
<Image>
<Image>
<z>9199</z>
<z>9299</z>
<path>71b2e9f575296b78c22ba721cd71f6e5.png</path>
<linkPath>schnee.png</linkPath>
</Image>
Expand Down Expand Up @@ -874,7 +874,7 @@
</linked>
<Image>
<Image>
<z>9199</z>
<z>9299</z>
<path>71b2e9f575296b78c22ba721cd71f6e5.png</path>
<linkPath>schnee.png</linkPath>
</Image>
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/tests/parts_data/part-image-udel.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<linkedMain/>
<Image>
<Image>
<z>9199</z>
<z>9299</z>
<path>71b2e9f575296b78c22ba721cd71f6e5.png</path>
<linkPath>schnee.png</linkPath>
</Image>
Expand Down Expand Up @@ -876,7 +876,7 @@
</linked>
<Image>
<Image>
<z>9199</z>
<z>9299</z>
<path>71b2e9f575296b78c22ba721cd71f6e5.png</path>
<linkPath>schnee.png</linkPath>
</Image>
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/tests/parts_data/part-image.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<Note>
<Image>
<Image>
<z>9199</z>
<z>9299</z>
<path>71b2e9f575296b78c22ba721cd71f6e5.png</path>
<linkPath>schnee.png</linkPath>
</Image>
Expand Down
18 changes: 18 additions & 0 deletions src/inspector/internal/services/elementrepositoryservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "engraving/dom/trill.h"
#include "engraving/dom/volta.h"
#include "engraving/dom/note.h"
#include "engraving/dom/lyrics.h"

#include "log.h"

Expand Down Expand Up @@ -92,6 +93,7 @@ QList<mu::engraving::EngravingItem*> ElementRepositoryService::findElementsByTyp
case mu::engraving::ElementType::BRACKET: return findBrackets();
case mu::engraving::ElementType::REST: return findRests();
case mu::engraving::ElementType::ORNAMENT: return findOrnaments();
case mu::engraving::ElementType::LYRICS: return findLyrics();
case mu::engraving::ElementType::PEDAL:
case mu::engraving::ElementType::GLISSANDO:
case mu::engraving::ElementType::VIBRATO:
Expand Down Expand Up @@ -448,3 +450,19 @@ QList<mu::engraving::EngravingItem*> ElementRepositoryService::findOrnaments() c

return resultList;
}

QList<EngravingItem*> ElementRepositoryService::findLyrics() const
{
QList<mu::engraving::EngravingItem*> resultList;
for (mu::engraving::EngravingItem* element : m_exposedElementList) {
if (element->isLyrics()) {
resultList << element;
} else if (element->isPartialLyricsLine()) {
resultList << element;
} else if (element->isPartialLyricsLineSegment()) {
resultList << toPartialLyricsLineSegment(element)->lyricsLine();
}
}

return resultList;
}
1 change: 1 addition & 0 deletions src/inspector/internal/services/elementrepositoryservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ElementRepositoryService : public QObject, public IElementRepositoryServic
QList<mu::engraving::EngravingItem*> findLines(mu::engraving::ElementType lineType) const;
QList<mu::engraving::EngravingItem*> findRests() const;
QList<mu::engraving::EngravingItem*> findOrnaments() const;
QList<mu::engraving::EngravingItem*> findLyrics() const;

QList<mu::engraving::EngravingItem*> m_exposedElementList;
QList<mu::engraving::EngravingItem*> m_rawElementList;
Expand Down
2 changes: 2 additions & 0 deletions src/inspector/models/abstractinspectormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ static const QMap<mu::engraving::ElementType, InspectorModelType> NOTATION_ELEME
{ mu::engraving::ElementType::GRADUAL_TEMPO_CHANGE_SEGMENT, InspectorModelType::TYPE_GRADUAL_TEMPO_CHANGE },
{ mu::engraving::ElementType::INSTRUMENT_NAME, InspectorModelType::TYPE_INSTRUMENT_NAME },
{ mu::engraving::ElementType::LYRICS, InspectorModelType::TYPE_LYRICS },
{ mu::engraving::ElementType::PARTIAL_LYRICSLINE, InspectorModelType::TYPE_LYRICS },
{ mu::engraving::ElementType::PARTIAL_LYRICSLINE_SEGMENT, InspectorModelType::TYPE_LYRICS },
{ mu::engraving::ElementType::REST, InspectorModelType::TYPE_REST },
{ mu::engraving::ElementType::DYNAMIC, InspectorModelType::TYPE_DYNAMIC },
{ mu::engraving::ElementType::EXPRESSION, InspectorModelType::TYPE_EXPRESSION },
Expand Down

0 comments on commit de6b2a8

Please sign in to comment.