Skip to content

Commit bdccb18

Browse files
Merge pull request #26953 from RomanPudashkin/450_port_fixes
Porting some PRs to 4.5.0 (3)
2 parents 72a410f + 2beb04e commit bdccb18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+609
-311
lines changed

src/engraving/dom/dynamic.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,15 @@ void Dynamic::drawEditMode(Painter* p, EditData& ed, double currentViewScaling)
764764
}
765765
}
766766

767+
bool Dynamic::isTextualEditAllowed(EditData& ed) const
768+
{
769+
if (ed.key == Key_Tab) {
770+
return false;
771+
}
772+
773+
return TextBase::isTextualEditAllowed(ed);
774+
}
775+
767776
//---------------------------------------------------------
768777
// hasLeftHairpin
769778
//---------------------------------------------------------

src/engraving/dom/dynamic.h

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class Dynamic final : public TextBase
124124
void endEditDrag(EditData&) override;
125125
void drawEditMode(muse::draw::Painter* painter, EditData& editData, double currentViewScaling) override;
126126

127+
bool isTextualEditAllowed(EditData&) const override;
128+
127129
Hairpin* leftHairpin() const { return m_leftHairpin; }
128130
Hairpin* rightHairpin() const { return m_rightHairpin; }
129131

src/engraving/dom/score.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -3666,10 +3666,10 @@ void Score::selectRange(EngravingItem* e, staff_idx_t staffIdx)
36663666
if (startSegment) {
36673667
Segment* endSegment = findElementEndSegment(this, e, m_selection.endSegment());
36683668
staff_idx_t elementStaffIdx = e->staffIdx();
3669-
Fraction tick = startSegment->tick();
3670-
Fraction etick = endSegment->tick();
3671-
36723669
if (endSegment && elementStaffIdx != muse::nidx) {
3670+
Fraction tick = startSegment->tick();
3671+
Fraction etick = endSegment->tick();
3672+
36733673
m_selection.extendRangeSelection(startSegment, endSegment, elementStaffIdx, tick, etick);
36743674
m_selection.updateSelectedElements();
36753675

@@ -3770,13 +3770,15 @@ bool Score::tryExtendSingleSelectionToRange(EngravingItem* newElement, staff_idx
37703770
staff_idx_t endStaffIdx = startStaffIdx + 1;
37713771

37723772
track_idx_t activeTrack = newElement->track();
3773+
bool activeSegmentIsStart = false;
37733774

37743775
if (newElement->isMeasure()) {
37753776
Measure* m = toMeasure(newElement);
37763777
const Fraction tick = m->tick();
37773778

37783779
if (tick < startSegment->tick()) {
37793780
startSegment = m->first(SegmentType::ChordRest);
3781+
activeSegmentIsStart = true;
37803782
}
37813783
if (m == lastMeasure()) {
37823784
endSegment = nullptr;
@@ -3792,6 +3794,7 @@ bool Score::tryExtendSingleSelectionToRange(EngravingItem* newElement, staff_idx
37923794
Segment* newStartSegment = findElementStartSegment(this, newElement);
37933795
if (newStartSegment && newStartSegment->tick() < startSegment->tick()) {
37943796
startSegment = newStartSegment;
3797+
activeSegmentIsStart = true;
37953798
}
37963799

37973800
Segment* newEndSegment = findElementEndSegment(this, newElement, newStartSegment);
@@ -3810,6 +3813,7 @@ bool Score::tryExtendSingleSelectionToRange(EngravingItem* newElement, staff_idx
38103813
m_selection.updateSelectedElements();
38113814

38123815
m_selection.setActiveTrack(activeTrack);
3816+
m_selection.setActiveSegment(activeSegmentIsStart ? startSegment : endSegment);
38133817

38143818
return true;
38153819
}

src/engraving/dom/select.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ void Selection::extendRangeSelection(ChordRest* cr)
15451545

15461546
void Selection::extendRangeSelection(Segment* seg, Segment* segAfter, staff_idx_t staffIdx, const Fraction& tick, const Fraction& etick)
15471547
{
1548-
bool activeIsFirst = false;
1548+
bool activeSegmentIsStart = false;
15491549
staff_idx_t activeStaff = m_activeTrack / VOICES;
15501550

15511551
if (staffIdx < m_staffStart) {
@@ -1562,18 +1562,18 @@ void Selection::extendRangeSelection(Segment* seg, Segment* segAfter, staff_idx_
15621562

15631563
if (tick < tickStart()) {
15641564
m_startSegment = seg;
1565-
activeIsFirst = true;
1566-
} else if (etick >= tickEnd()) {
1565+
activeSegmentIsStart = true;
1566+
} else if (etick > tickEnd()) {
15671567
m_endSegment = segAfter;
15681568
} else {
15691569
if (m_activeSegment == m_startSegment) {
15701570
m_startSegment = seg;
1571-
activeIsFirst = true;
1571+
activeSegmentIsStart = true;
15721572
} else {
15731573
m_endSegment = segAfter;
15741574
}
15751575
}
1576-
activeIsFirst ? m_activeSegment = m_startSegment : m_activeSegment = m_endSegment;
1576+
m_activeSegment = activeSegmentIsStart ? m_startSegment : m_endSegment;
15771577
m_score->setSelectionChanged(true);
15781578
assert(!(m_endSegment && !m_startSegment));
15791579
}

src/engraving/dom/stringdata.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ bool StringData::convertPitch(int pitch, int pitchOffset, int* string, int* fret
364364
for (int i = strings - 1; i >= 0; i--) {
365365
instrString strg = m_stringTable.at(i);
366366
if (pitch >= strg.pitch) {
367-
if (pitch == strg.pitch || !strg.open) {
368-
*string = strings - i - 1;
369-
}
367+
*string = strings - i - 1;
370368
*fret = pitch - strg.pitch;
371369
return true;
372370
}

src/engraving/dom/textbase.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3364,7 +3364,7 @@ bool TextBase::isNonTextualEditAllowed(EditData& ed) const
33643364
Key_Down
33653365
};
33663366

3367-
return muse::contains(ARROW_KEYS, static_cast<KeyboardKey>(ed.key));
3367+
return muse::contains(ARROW_KEYS, static_cast<KeyboardKey>(ed.key)) && !(ed.modifiers & AltModifier);
33683368
}
33693369

33703370
void TextBase::checkMeasureBoundariesAndMoveIfNeed()

src/engraving/dom/volta.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ PointF Volta::linePos(Grip grip, System** system) const
360360
x += (isAtSystemStart ? 0.5 : -0.5) * absoluteFromSpatium(lineWidth());
361361
} else {
362362
if ((*system) && segment->tick() == (*system)->endTick()) {
363-
x += segment->staffShape(backSegment()->effectiveStaffIdx()).right();
363+
staff_idx_t si = backSegment()->effectiveStaffIdx();
364+
if (si == muse::nidx) {
365+
return PointF(x, 0.0);
366+
}
367+
x += segment->staffShape(si).right();
364368
x -= 0.5 * absoluteFromSpatium(lineWidth());
365369
} else if (segment->segmentType() & SegmentType::BarLineType) {
366370
BarLine* barLine = toBarLine(segment->elementAt(track()));

src/engraving/rendering/score/horizontalspacing.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ double HorizontalSpacing::computeSpacingForFullSystem(System* system, double str
7878
return ctx.xCur;
7979
}
8080

81-
double HorizontalSpacing::updateSpacingForLastAddedMeasure(System* system)
81+
double HorizontalSpacing::updateSpacingForLastAddedMeasure(System* system, bool startOfContinuousLayoutRegion)
8282
{
8383
HorizontalSpacingContext ctx;
8484
ctx.system = system;
@@ -95,7 +95,7 @@ double HorizontalSpacing::updateSpacingForLastAddedMeasure(System* system)
9595

9696
if (secondToLast) {
9797
ctx.xCur = secondToLast->x();
98-
if (secondToLast->isHBox() || last->isHBox()) {
98+
if (secondToLast->isHBox() || last->isHBox() || startOfContinuousLayoutRegion) {
9999
ctx.xCur += secondToLast->width();
100100
}
101101
} else {
@@ -106,7 +106,7 @@ double HorizontalSpacing::updateSpacingForLastAddedMeasure(System* system)
106106
last->mutldata()->setPosX(ctx.xCur);
107107
last->computeMinWidth();
108108
ctx.xCur += last->width();
109-
} else if (!secondToLast || secondToLast->isHBox()) {
109+
} else if (!secondToLast || secondToLast->isHBox() || startOfContinuousLayoutRegion) {
110110
spaceMeasureGroup({ toMeasure(last) }, ctx);
111111
} else {
112112
ctx.startMeas = toMeasure(last);

src/engraving/rendering/score/horizontalspacing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class HorizontalSpacing
4747

4848
static double computeSpacingForFullSystem(System* system, double stretchReduction = 1.0, double squeezeFactor = 1.0,
4949
bool overrideMinMeasureWidth = false);
50-
static double updateSpacingForLastAddedMeasure(System* system);
50+
static double updateSpacingForLastAddedMeasure(System* system, bool startOfContinuousLayoutRegion = false);
5151
static void squeezeSystemToFit(System* system, double& curSysWidth, double targetSysWidth);
5252
static void justifySystem(System* system, double curSysWidth, double targetSystemWidth);
5353

src/engraving/rendering/score/layoutcontext.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ size_t DomAccessor::ntracks() const
236236
return score()->ntracks();
237237
}
238238

239+
size_t DomAccessor::nmeasures() const
240+
{
241+
IF_ASSERT_FAILED(score()) {
242+
return 0;
243+
}
244+
return score()->nmeasures();
245+
}
246+
239247
const Measure* DomAccessor::tick2measure(const Fraction& tick) const
240248
{
241249
IF_ASSERT_FAILED(score()) {

src/engraving/rendering/score/layoutcontext.h

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class DomAccessor
167167

168168
size_t ntracks() const;
169169

170+
size_t nmeasures() const;
171+
170172
const Measure* tick2measure(const Fraction& tick) const;
171173
const Measure* firstMeasure() const;
172174
const Measure* lastMeasure() const;

src/engraving/rendering/score/scorehorizontalviewlayout.cpp

+51-30
Original file line numberDiff line numberDiff line change
@@ -278,39 +278,48 @@ void ScoreHorizontalViewLayout::collectLinearSystem(LayoutContext& ctx)
278278
System* system = ctx.mutDom().systems().front();
279279
SystemLayout::setInstrumentNames(system, ctx, /* longNames */ true);
280280

281-
PointF pos;
282-
bool firstMeasure = true; //lc.startTick.isZero();
281+
double targetSystemWidth = ctx.dom().nmeasures() * ctx.conf().styleMM(Sid::minMeasureWidth).val();
282+
system->setWidth(targetSystemWidth);
283+
284+
double curSystemWidth = 0.0;
285+
bool firstMeasureInScore = true; //lc.startTick.isZero();
286+
bool firstMeasureInLayout = true;
283287

284288
//set first measure to lc.nextMeasures for following
285289
//utilizing in getNextMeasure()
286290
ctx.mutState().setNextMeasure(ctx.mutDom().first());
287291
ctx.mutState().setTick(Fraction(0, 1));
288292
MeasureLayout::getNextMeasure(ctx);
289293

294+
std::set<Measure*> measuresToLayout;
295+
290296
while (ctx.state().curMeasure()) {
291-
double ww = 0.0;
292297
if (ctx.state().curMeasure()->isVBox() || ctx.state().curMeasure()->isTBox()) {
293298
ctx.mutState().curMeasure()->resetExplicitParent();
294299
MeasureLayout::getNextMeasure(ctx);
295300
continue;
296301
}
297302
system->appendMeasure(ctx.mutState().curMeasure());
303+
bool createHeader = ctx.state().prevMeasure() && ctx.state().prevMeasure()->isHBox()
304+
&& toHBox(ctx.state().prevMeasure())->createSystemHeader();
298305
if (ctx.state().curMeasure()->isMeasure()) {
299306
Measure* m = toMeasure(ctx.mutState().curMeasure());
300307
if (m->mmRest()) {
301308
m->mmRest()->resetExplicitParent();
302309
}
303-
if (firstMeasure) {
304-
SystemLayout::layoutSystem(system, ctx, pos.rx());
310+
if (firstMeasureInScore) {
311+
SystemLayout::layoutSystem(system, ctx, curSystemWidth, true);
305312
if (m->repeatStart()) {
306313
Segment* s = m->findSegmentR(SegmentType::StartRepeatBarLine, Fraction(0, 1));
307314
if (!s->enabled()) {
308315
s->setEnabled(true);
309316
}
310317
}
311318
MeasureLayout::addSystemHeader(m, true, ctx);
312-
pos.rx() += system->leftMargin();
313-
firstMeasure = false;
319+
curSystemWidth += system->leftMargin();
320+
firstMeasureInScore = false;
321+
} else if (createHeader) {
322+
MeasureLayout::addSystemHeader(m, false, ctx);
314323
} else if (m->header()) {
315324
MeasureLayout::removeSystemHeader(m);
316325
}
@@ -325,56 +334,68 @@ void ScoreHorizontalViewLayout::collectLinearSystem(LayoutContext& ctx)
325334
if (ctx.conf().isMode(LayoutMode::HORIZONTAL_FIXED)) {
326335
MeasureLayout::createEndBarLines(m, true, ctx);
327336
layoutSegmentsWithDuration(m, visibleParts);
328-
ww = m->width();
329-
MeasureLayout::stretchMeasureInPracticeMode(m, ww, ctx);
337+
double measureWidth = m->width();
338+
MeasureLayout::stretchMeasureInPracticeMode(m, measureWidth, ctx);
339+
m->setPos(curSystemWidth, m->y());
340+
curSystemWidth += measureWidth;
330341
} else {
331-
MeasureLayout::createEndBarLines(m, false, ctx);
332342
MeasureLayout::computePreSpacingItems(m, ctx);
333-
HorizontalSpacing::updateSpacingForLastAddedMeasure(system);
334-
ww = m->width();
335-
MeasureLayout::layoutMeasureElements(m, ctx);
343+
MeasureLayout::createEndBarLines(m, false, ctx);
344+
MeasureLayout::setRepeatCourtesiesAndParens(m, ctx);
345+
curSystemWidth = HorizontalSpacing::updateSpacingForLastAddedMeasure(system, firstMeasureInLayout);
346+
measuresToLayout.insert(m);
347+
if (firstMeasureInLayout) {
348+
firstMeasureInLayout = false;
349+
}
336350
}
337351
} else {
338352
// for measures not in range, use existing layout
339-
ww = m->width();
340-
if (m->pos() != pos) {
353+
double measureWidth = m->width();
354+
if (!muse::RealIsEqual(m->x(), curSystemWidth)) {
341355
// fix beam positions
342356
// other elements with system as parent are processed in layoutSystemElements()
343357
// but full beam processing is expensive and not needed if we adjust position here
344-
PointF p = pos - m->pos();
358+
PointF p = PointF(curSystemWidth, 0.0) - m->pos();
345359
for (const Segment& s : m->segments()) {
346360
if (!s.isChordRestType()) {
347361
continue;
348362
}
349363
for (size_t track = 0; track < ctx.dom().ntracks(); ++track) {
350364
EngravingItem* e = s.element(static_cast<track_idx_t>(track));
351-
if (e) {
352-
ChordRest* cr = toChordRest(e);
353-
if (cr->beam() && cr->beam()->elements().front() == cr) {
354-
cr->beam()->mutldata()->move(p);
355-
}
365+
if (!e) {
366+
continue;
367+
}
368+
ChordRest* cr = toChordRest(e);
369+
if (cr->beam() && cr->beam()->elements().front() == cr) {
370+
cr->beam()->mutldata()->move(p);
356371
}
357372
}
358373
}
359374
}
375+
m->setPos(curSystemWidth, m->y());
376+
curSystemWidth += measureWidth;
360377
}
361-
m->setPos(pos);
362-
MeasureLayout::layoutStaffLines(m, ctx);
363378
} else if (ctx.state().curMeasure()->isHBox()) {
364-
MeasureBase* curM = ctx.mutState().curMeasure();
365-
HBox* curHBox = toHBox(curM);
366-
curHBox->setPos(pos + PointF(curHBox->absoluteFromSpatium(curHBox->topGap()), 0.0));
367-
TLayout::layoutBaseMeasureBase(curHBox, curHBox->mutldata(), ctx);
368-
ww = curHBox->width();
379+
curSystemWidth = HorizontalSpacing::updateSpacingForLastAddedMeasure(system);
369380
}
370-
pos.rx() += ww;
371381

372382
MeasureLayout::getNextMeasure(ctx);
373383
}
374384

385+
for (Measure* m : measuresToLayout) {
386+
MeasureLayout::layoutMeasureElements(m, ctx);
387+
}
388+
389+
for (MeasureBase* m : system->measures()) {
390+
if (!m->isMeasure()) {
391+
continue;
392+
}
393+
MeasureLayout::layoutStaffLines(toMeasure(m), ctx);
394+
}
395+
375396
SystemLayout::hideEmptyStaves(system, ctx, true);
376397

377-
system->setWidth(pos.x());
398+
system->setWidth(curSystemWidth);
378399
}
379400

380401
static Segment* findFirstEnabledSegment(Measure* measure)

src/engraving/rendering/score/slurtielayout.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "dom/measure.h"
4343
#include "dom/guitarbend.h"
4444
#include "dom/laissezvib.h"
45+
#include "dom/parenthesis.h"
4546
#include "dom/partialtie.h"
4647

4748
#include "tlayout.h"
@@ -1859,16 +1860,26 @@ void SlurTieLayout::setPartialTieEndPos(PartialTie* item, SlurTiePos& sPos)
18591860
}
18601861

18611862
const Segment* adjSeg = outgoing ? seg->next1() : seg->prev1();
1862-
while (adjSeg && (!adjSeg->isActive() || !adjSeg->enabled())) {
1863+
while (adjSeg && (!adjSeg->isActive() || !adjSeg->enabled() || adjSeg->allElementsInvisible())) {
18631864
adjSeg = outgoing ? adjSeg->next1() : adjSeg->prev1();
18641865
}
18651866

18661867
double widthToSegment = 0.0;
18671868
if (adjSeg) {
18681869
EngravingItem* element = adjSeg->element(staff2track(item->vStaffIdx()));
1870+
track_idx_t strack = track2staff(item->track());
1871+
track_idx_t etrack = strack + VOICES - 1;
1872+
for (EngravingItem* paren : adjSeg->findAnnotations(ElementType::PARENTHESIS, strack, etrack)) {
1873+
if ((outgoing && toParenthesis(paren)->direction() == DirectionH::LEFT)
1874+
|| (!outgoing && toParenthesis(paren)->direction() == DirectionH::RIGHT)) {
1875+
element = paren;
1876+
break;
1877+
}
1878+
}
1879+
18691880
const double elementWidth = element ? element->width() : 0.0;
1870-
widthToSegment = outgoing ? adjSeg->xPosInSystemCoords() - sPos.p1.x() : sPos.p2.x()
1871-
- (adjSeg->xPosInSystemCoords() + elementWidth);
1881+
const double elPos = adjSeg->xPosInSystemCoords() + (element ? element->pos().x() + element->shape().bbox().x() : 0.0);
1882+
widthToSegment = outgoing ? elPos - sPos.p1.x() : sPos.p2.x() - (elPos + elementWidth);
18721883
widthToSegment -= 0.25 * item->spatium();
18731884
}
18741885

src/engraving/rw/read400/read400.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ bool Read400::pasteStaff(XmlReader& e, Segment* dst, staff_idx_t dstStaff, Fract
711711
}
712712

713713
if (score->cmdState().layoutRange()) {
714-
score->cmdState().reset();
715714
score->setLayout(dstTick, dstTick + tickLen, dstStaff, endStaff, dst);
716715
}
717716

0 commit comments

Comments
 (0)