Skip to content

Commit

Permalink
[engraving] added LD_CONDITIONS to MeasureRepeat layout
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Sep 18, 2023
1 parent 10ac45a commit b4af7bd
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 28 deletions.
7 changes: 3 additions & 4 deletions src/engraving/dom/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "part.h"
#include "score.h"
#include "segment.h"
#include "slur.h"
#include "staff.h"
#include "stafftype.h"
#include "stem.h"
Expand Down Expand Up @@ -691,7 +690,7 @@ void Chord::add(EngravingItem* e)
case ElementType::STRETCHED_BEND:
case ElementType::CHORDLINE:
case ElementType::FRET_CIRCLE:
el().push_back(e);
addEl(e);
break;
case ElementType::STEM_SLASH:
assert(!m_stemSlash);
Expand Down Expand Up @@ -762,7 +761,7 @@ void Chord::remove(EngravingItem* e)
note->removeSpannerFor(s);
}
if (StretchedBend* stretchedBend = note->stretchedBend()) {
el().remove(stretchedBend);
removeEl(stretchedBend);
}
} else {
LOGD("Chord::remove() note %p not found!", e);
Expand Down Expand Up @@ -809,7 +808,7 @@ void Chord::remove(EngravingItem* e)
// fallthrough
case ElementType::CHORDLINE:
case ElementType::FRET_CIRCLE:
el().remove(e);
removeEl(e);
break;
case ElementType::CHORD:
{
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ int ChordRest::lastVerse(PlacementV p) const
void ChordRest::removeMarkings(bool /* keepTremolo */)
{
DeleteAll(el());
el().clear();
clearEls();
DeleteAll(lyrics());
lyrics().clear();
}
Expand Down
12 changes: 11 additions & 1 deletion src/engraving/dom/chordrest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "durationelement.h"
#include "types/types.h"

#include "fermata.h"

namespace mu::engraving {
enum class CrossMeasure : signed char {
UNKNOWN = -1,
Expand Down Expand Up @@ -147,9 +149,13 @@ class ChordRest : public DurationElement
void removeDeleteBeam(bool beamed);
void replaceBeam(Beam* newBeam);

ElementList& el() { return m_el; }
const ElementList& el() const { return m_el; }

//! TODO Look like a hack, see using
void addFermata(Fermata* f) { addEl(f); }
void removeFermata(Fermata* f) { removeEl(f); }
//! --------------------------------

Slur* slur(const ChordRest* secondChordRest = nullptr) const;

CrossMeasure crossMeasure() const { return m_crossMeasure; }
Expand Down Expand Up @@ -197,6 +203,10 @@ class ChordRest : public DurationElement

protected:

void addEl(EngravingItem* e) { m_el.push_back(e); }
bool removeEl(EngravingItem* e) { return m_el.remove(e); }
void clearEls() { m_el.clear(); }

std::vector<Lyrics*> m_lyrics;
TabDurationSymbol* m_tabDur = nullptr; // stores a duration symbol in tablature staves

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ void Rest::add(EngravingItem* e)
// fallthrough
case ElementType::SYMBOL:
case ElementType::IMAGE:
el().push_back(e);
addEl(e);
e->added();
break;
default:
Expand All @@ -798,7 +798,7 @@ void Rest::remove(EngravingItem* e)
// fallthrough
case ElementType::SYMBOL:
case ElementType::IMAGE:
if (!el().remove(e)) {
if (!removeEl(e)) {
LOGD("Rest::remove(): cannot find %s", e->typeName());
} else {
e->removed();
Expand Down
49 changes: 33 additions & 16 deletions src/engraving/rendering/dev/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ void TLayout::layoutItem(EngravingItem* item, LayoutContext& ctx)
case ElementType::MEASURE_NUMBER:
layout(item_cast<const MeasureNumber*>(item), static_cast<MeasureNumber::LayoutData*>(ldata));
break;
case ElementType::MEASURE_REPEAT: layout(item_cast<MeasureRepeat*>(item), ctx);
case ElementType::MEASURE_REPEAT:
layout(item_cast<const MeasureRepeat*>(item), static_cast<MeasureRepeat::LayoutData*>(ldata), ctx);
break;
case ElementType::MMREST: layout(item_cast<MMRest*>(item), ctx);
break;
Expand Down Expand Up @@ -3100,7 +3101,7 @@ void TLayout::layout(const Harmony* item, Harmony::LayoutData* ldata, LayoutCont
if (fd) {
newPosY = ldata->pos().y();
} else {
newPosY = ypos - ((item->align() == AlignV::BOTTOM) ? item->harmonyHeight() - ldata->bbox().height() : 0.0);
newPosY = ypos - ((item->align() == AlignV::BOTTOM) ? -ldata->bbox().height() : 0.0);
}
} else {
RectF bb;
Expand Down Expand Up @@ -3194,8 +3195,6 @@ void TLayout::layout(const Image* item, Image::LayoutData* ldata)
return;
}

LD_CONDITION(item->parentItem()->layoutData()->isSetBbox());

ldata->setPos(0.0, 0.0);
const_cast<Image*>(item)->init();

Expand All @@ -3205,6 +3204,9 @@ void TLayout::layout(const Image* item, Image::LayoutData* ldata)
if (item->autoScale()
&& ((item->explicitParent()->isHBox() || item->explicitParent()->isVBox()))) {
const EngravingItem::LayoutData* parentLD = item->parentItem()->layoutData();

LD_CONDITION(parentLD->isSetBbox());

if (item->lockAspectRatio()) {
double f = item->sizeIsSpatium() ? item->spatium() : DPMM;
SizeF size(item->imageSize());
Expand Down Expand Up @@ -3676,7 +3678,7 @@ void TLayout::layoutMeasureBase(const MeasureBase* item, MeasureBase::LayoutData

void TLayout::layout(const MeasureNumber* item, MeasureNumber::LayoutData* ldata)
{
LD_CONDITION(item->measure()->layoutData()->isSetBbox());
LD_CONDITION(item->measure()->layoutData()->isSetBbox()); // layoutMeasureNumberBase

layoutMeasureNumberBase(item, ldata);
}
Expand Down Expand Up @@ -3761,16 +3763,40 @@ void TLayout::layoutMeasureNumberBase(const MeasureNumberBase* item, MeasureNumb
}
}

static void layoutMeasureRepeat(const MeasureRepeat* item, const LayoutContext& ctx, MeasureRepeat::LayoutData* ldata)
void TLayout::layout(const MeasureRepeat* item, MeasureRepeat::LayoutData* ldata, const LayoutContext& ctx)
{
//! NOTE The types are listed here explicitly to show what types there are (see Rest::add method)
//! and accordingly show what depends on.
for (EngravingItem* e : item->el()) {
switch (e->type()) {
case ElementType::DEAD_SLAPPED: {
DeadSlapped* ds = item_cast<DeadSlapped*>(e);
LD_INDEPENDENT;
layout(ds, ds->mutLayoutData());
} break;
case ElementType::SYMBOL: {
Symbol* s = item_cast<Symbol*>(e);
// not clear yet
layoutSymbol(s, const_cast<LayoutContext&>(ctx));
} break;
case ElementType::IMAGE: {
Image* im = item_cast<Image*>(e);
LD_INDEPENDENT;
layout(im, im->mutLayoutData());
} break;
default:
UNREACHABLE;
}
}

switch (item->numMeasures()) {
case 1:
{
ldata->setSymId(SymId::repeat1Bar);
if (ctx.conf().styleB(Sid::mrNumberSeries) && item->track() != mu::nidx) {
int placeInSeries = 2; // "1" would be the measure actually being repeated
staff_idx_t staffIdx = item->staffIdx();
Measure* m = item->measure();
const Measure* m = item->measure();
while (m && m->isOneMeasureRepeat(staffIdx) && m->prevIsOneMeasureRepeat(staffIdx)) {
placeInSeries++;
m = m->prevMeasure();
Expand Down Expand Up @@ -3825,15 +3851,6 @@ static void layoutMeasureRepeat(const MeasureRepeat* item, const LayoutContext&
}
}

void TLayout::layout(MeasureRepeat* item, LayoutContext& ctx)
{
for (EngravingItem* e : item->el()) {
layoutItem(e, ctx);
}

layoutMeasureRepeat(item, ctx, item->mutLayoutData());
}

static void layoutMMRest(const MMRest* item, const LayoutContext& ctx, MMRest::LayoutData* ldata)
{
//! NOTE This is not look like layout data, perhaps this is should be set not here
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/rendering/dev/tlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "../../dom/measurebase.h"
#include "../../dom/measurenumber.h"
#include "../../dom/measurenumberbase.h"
#include "../../dom/measurerepeat.h"

#include "../../dom/textbase.h"

Expand Down Expand Up @@ -99,7 +100,6 @@ class Lyrics;
class LyricsLine;
class LyricsLineSegment;

class MeasureRepeat;
class MMRest;
class MMRestRange;

Expand Down Expand Up @@ -246,7 +246,7 @@ class TLayout
static void layoutMeasureBase(const MeasureBase* item, MeasureBase::LayoutData* ldata, const LayoutContext& ctx); // base class
static void layout(const MeasureNumber* item, MeasureNumber::LayoutData* ldata);
static void layoutMeasureNumberBase(const MeasureNumberBase* item, MeasureNumberBase::LayoutData* ldata); // base class
static void layout(MeasureRepeat* item, LayoutContext& ctx);
static void layout(const MeasureRepeat* item, MeasureRepeat::LayoutData* ldata, const LayoutContext& ctx);
static void layout(MMRest* item, LayoutContext& ctx);
static void layout(MMRestRange* item, LayoutContext& ctx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ static void addFermataToChord(const Notation& notation, ChordRest* cr)
}
setElementPropertyFlags(na, Pid::PLACEMENT, direction);
if (cr->segment() == nullptr && cr->isGrace()) {
cr->el().push_back(na); // store for later move to segment
cr->addFermata(na); // store for later move to segment
} else {
cr->segment()->add(na);
}
Expand Down Expand Up @@ -2101,7 +2101,7 @@ static void addGraceChordsBefore(Chord* c, GraceChordList& gcl)
for (EngravingItem* e : gc->el()) {
if (e->isFermata()) {
c->segment()->add(e);
gc->el().remove(e);
gc->removeFermata(toFermata(e));
break; // out of the door, line on the left, one cross each
}
}
Expand Down

0 comments on commit b4af7bd

Please sign in to comment.