Skip to content

Commit ba3d32c

Browse files
committed
More accurate segment start pos
1 parent 4f952bf commit ba3d32c

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

src/importexport/finale/internal/importfinaleparser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ class FinaleParser : public muse::Injectable
375375
std::vector<std::pair<engraving::staff_idx_t, musx::dom::StaffCmper> >& links);
376376
musx::dom::MusxInstance<musx::dom::others::LayerAttributes> layerAttributes(const engraving::Fraction& tick,
377377
engraving::track_idx_t track);
378+
double musicStartPosForMeasure(const engraving::Measure* m) const;
378379

379380
IFinaleConfiguration::ImportPositionsType importPositionsType() const { return m_importPositionsType; }
380381
bool importCustomPositions() const { return m_importPositionsType != IFinaleConfiguration::ImportPositionsType::None; }

src/importexport/finale/internal/importfinalesmartshapes.cpp

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,55 @@ static char32_t usedOttavaSymbol(const FinaleParser& ctx, OttavaType ottavaType)
359359
return ctx.score()->engravingFont()->symCode(SymId::ottavaAlta);
360360
}
361361

362+
double FinaleParser::musicStartPosForMeasure(const Measure* m) const
363+
{
364+
double pos = 0.0;
365+
for (Segment* s = m->first(SegmentType::ChordRest)->prevActive(); s;
366+
s = s->prevActive(SegmentType::TimeSig | SegmentType::KeySig | SegmentType::HeaderClef
367+
| SegmentType::StartRepeatBarLine | SegmentType::BeginBarLine)) {
368+
if (s->allElementsInvisible() || s->hasTimeSigAboveStaves()) {
369+
continue;
370+
}
371+
if (s->isTimeSigType()) {
372+
for (staff_idx_t i = 0; i < score()->nstaves(); ++i) {
373+
if (!m->system()->staff(i)->show()) {
374+
continue;
375+
}
376+
pos = std::max(pos, score()->staff(i)->spatium(m->tick()));
377+
}
378+
pos *= evpuToSp(partScore() ? musxOptions().timeOptions->timeBackParts : musxOptions().timeOptions->timeBack);
379+
} else if (s->isKeySigType()) {
380+
for (staff_idx_t i = 0; i < score()->nstaves(); ++i) {
381+
if (!m->system()->staff(i)->show()) {
382+
continue;
383+
}
384+
pos = std::max(pos, score()->staff(i)->spatium(m->tick()));
385+
}
386+
pos *= evpuToSp(musxOptions().keyOptions->keyBack);
387+
} else if (s->isHeaderClefType()) {
388+
for (staff_idx_t i = 0; i < score()->nstaves(); ++i) {
389+
if (!m->system()->staff(i)->show()) {
390+
continue;
391+
}
392+
pos = std::max(pos, score()->staff(i)->spatium(m->tick()));
393+
}
394+
pos *= evpuToSp(musxOptions().clefOptions->clefBackSepar);
395+
}
396+
pos += s->x() + s->minRight();
397+
if (m->isFirstInSystem()) {
398+
MeasCmper measId = muse::value(m_tick2Meas, m->tick(), MeasCmper());
399+
if (const auto staffSystem = musxDocument()->calcSystemFromMeasure(currentMusxPartId(), measId)) {
400+
if (!staffSystem->placeEndSpaceBeforeBarline || !s->isStartRepeatBarLineType()) {
401+
pos += evpuToSp(staffSystem->extraStartSystemSpace)
402+
* staffSystem->calcEffectiveScaling().toDouble() * FINALE_DEFAULT_SPATIUM;
403+
}
404+
}
405+
}
406+
break;
407+
}
408+
return pos;
409+
}
410+
362411
void FinaleParser::importSmartShapes()
363412
{
364413
const MusxInstanceList<others::SmartShape> smartShapes = m_doc->getOthers()->getArray<others::SmartShape>(m_currentMusxPartId);
@@ -834,16 +883,8 @@ void FinaleParser::importSmartShapes()
834883
System* s;
835884
ss->rxoffset() += startSeg->x() + startSeg->measure()->x() - toSLine(newSpanner)->linePos(Grip::START, &s).x();
836885
} else {
837-
ss->rxoffset() += firstMeasureOfSystem->x() - ss->system()->firstNoteRestSegmentX(true);
838-
for (Segment* s = firstMeasureOfSystem->first(SegmentType::ChordRest)->prevActive(); s;
839-
s = s->prev(SegmentType::TimeSig | SegmentType::KeySig | SegmentType::HeaderClef
840-
| SegmentType::StartRepeatBarLine | SegmentType::BeginBarLine)) {
841-
if (s->allElementsInvisible() || s->hasTimeSigAboveStaves()) {
842-
continue;
843-
}
844-
ss->rxoffset() += s->x() + s->minRight();
845-
break;
846-
}
886+
ss->rxoffset() += firstMeasureOfSystem->x() + musicStartPosForMeasure(firstMeasureOfSystem)
887+
- ss->system()->firstNoteRestSegmentX(true);
847888
}
848889

849890
// In MuseScore, userOff2 is relative/added to offset

src/importexport/finale/internal/importfinaletext.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,13 +874,10 @@ void FinaleParser::importTextExpressions()
874874
staffShape.remove_if([](ShapeElement& el) { return el.height() == 0; });
875875
p.rx() = staffShape.right() + s->pageX();
876876
} else if (expressionDef->horzMeasExprAlign == others::HorizontalMeasExprAlign::StartTimeSig) {
877-
// Observed: Elements placed .45sp too far left when there is a custom offset
878877
Segment* seg = measure->findSegmentR(SegmentType::TimeSig, rTick);
879878
p.rx() = seg ? seg->pageX() : s->pageX();
880879
} else if (expressionDef->horzMeasExprAlign == others::HorizontalMeasExprAlign::AfterClefKeyTime) {
881-
Segment* seg = s->prev(SegmentType::TimeSig | SegmentType::KeySig | SegmentType::HeaderClef
882-
| SegmentType::StartRepeatBarLine | SegmentType::BeginBarLine);
883-
p.rx() = seg ? seg->pageX() + seg->minRight() : s->pageX();
880+
p.rx() = s->measure()->pageX() + musicStartPosForMeasure(s->measure());
884881
} else if (expressionDef->horzMeasExprAlign == others::HorizontalMeasExprAlign::CenterOverMusic
885882
|| expressionDef->horzMeasExprAlign == others::HorizontalMeasExprAlign::CenterOverBarlines) {
886883
p.rx() = measure->findSegmentR(SegmentType::ChordRest, Fraction(0, 1))->x() / 2;

0 commit comments

Comments
 (0)