Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MU3 Backend] ENG-56: Default-y order for other elements #8311

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 47 additions & 21 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ void MusicXMLParserPass2::measure(const QString& partId,
fbl.append(fb);
}
else if (_e.name() == "harmony")
harmony(partId, measure, time + mTime);
harmony(partId, measure, time + mTime, delayedDirections);
else if (_e.name() == "note") {
Fraction missingPrev;
Fraction dura;
Expand Down Expand Up @@ -2509,15 +2509,12 @@ void MusicXMLParserDirection::direction(const QString& partId,

if (placement == "" && hasTotalY())
placement = totalY() < 0 ? "above" : "below";
if (hasTotalY()) {
// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(totalY(), t, track, placement, measure, tick + _offset);
delayedDirections.push_back(delayedDirection);
}
else {
addElemOffset(t, track, placement, measure, tick + _offset);
}

// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(hasTotalY() ? totalY() : 100, t, track, placement, measure, tick + _offset);
delayedDirections.push_back(delayedDirection);

}
}
else if (_tpoSound > 0) {
Expand Down Expand Up @@ -2554,14 +2551,19 @@ void MusicXMLParserDirection::direction(const QString& partId,
dynaValue = 0;
dyn->setVelocity( dynaValue );
}
//TODO:ws if (_hasDefaultY) dyn->textStyle().setYoff(_defaultY);
addElemOffset(dyn, track, placement, measure, tick + _offset);

// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(hasTotalY() ? totalY() : 100, dyn, track, placement, measure, tick + _offset);
delayedDirections.push_back(delayedDirection);
}

// handle the elems
foreach( auto elem, _elems) {
// TODO (?) if (_hasDefaultY) elem->setYoff(_defaultY);
addElemOffset(elem, track, placement, measure, tick + _offset);
// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(hasTotalY() ? totalY() : 100, elem, track, placement, measure, tick + _offset);
delayedDirections.push_back(delayedDirection);
}

// handle the spanner stops first
Expand Down Expand Up @@ -4973,14 +4975,19 @@ FiguredBass* MusicXMLParserPass2::figuredBass()
which affects both single strings and barres
*/

FretDiagram* MusicXMLParserPass2::frame()
FretDiagram* MusicXMLParserPass2::frame(qreal& defaultY, qreal& relativeY, bool& hasTotalY)
{
Q_ASSERT(_e.isStartElement() && _e.name() == "frame");

FretDiagram* fd = new FretDiagram(_score);

int fretOffset = 0;

bool tempHasY = false;
defaultY += _e.attributes().value("default-y").toDouble(&tempHasY) * -0.1;
hasTotalY |= tempHasY;
relativeY += _e.attributes().value("relative-y").toDouble(&tempHasY) * -0.1;
hasTotalY |= tempHasY;

// Format: fret: string
std::map<int, int> bStarts;
std::map<int, int> bEnds;
Expand Down Expand Up @@ -5097,7 +5104,7 @@ FretDiagram* MusicXMLParserPass2::frame()
Parse the /score-partwise/part/measure/harmony node.
*/

void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const Fraction sTime)
void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const Fraction sTime, DelayedDirectionsList& delayedDirections)
{
Q_ASSERT(_e.isStartElement() && _e.name() == "harmony");

Expand All @@ -5121,6 +5128,16 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const
// previous code: double dy = -0.1 * e.attribute("default-y", QString::number(styleYOff* -10)).toDouble();
double dy = -0.1 * _e.attributes().value("default-y").toDouble();
#endif
QString placement = _e.attributes().value("placement").toString();
qreal defaultY = 0;
qreal relativeY = 0;
bool hasTotalY = false;
bool tempHasY = false;
defaultY += _e.attributes().value("default-y").toDouble(&tempHasY) * -0.1;
hasTotalY |= tempHasY;
relativeY += _e.attributes().value("relative-y").toDouble(&tempHasY) * -0.1;
hasTotalY |= tempHasY;

bool printObject = _e.attributes().value("print-object") != "no";
//QString printFrame = _e.attributes().value("print-frame").toString();
//QString printStyle = _e.attributes().value("print-style").toString();
Expand Down Expand Up @@ -5242,7 +5259,7 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const
}
}
else if (_e.name() == "frame")
fd = frame();
fd = frame(defaultY, relativeY, hasTotalY);
else if (_e.name() == "level")
skipLogCurrElem();
else if (_e.name() == "offset")
Expand Down Expand Up @@ -5279,17 +5296,26 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const
// TODO-LV: do this only if ha points to a valid harmony
// harmony = ha;
ha->setTrack(track);
Segment* s = measure->getSegment(SegmentType::ChordRest, sTime + offset);

// Add harmony to FretDiagram if present, otherwise add directly to Segment
Element* se;
if (fd) {
fd->setTrack(track);
s->add(fd);
fd->add(ha);
se = fd;
}
else {
s->add(ha);
se = ha;
}

qreal totalY = defaultY + relativeY;
if (placement == "") {
placement = totalY > 0 ? "below" : "above";
}
// Add element to score later, after collecting all the others and sorting by default-y
// This allows default-y to be at least respected by the order of elements
MusicXMLDelayedDirectionElement* delayedDirection = new MusicXMLDelayedDirectionElement(hasTotalY ? totalY : 100, se, track, placement, measure, sTime + offset);
delayedDirections.push_back(delayedDirection);
}

//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ class MusicXMLParserPass2 {
void notePrintSpacingNo(Fraction& dura);
FiguredBassItem* figure(const int idx, const bool paren);
FiguredBass* figuredBass();
FretDiagram* frame();
void harmony(const QString& partId, Measure* measure, const Fraction sTime);
FretDiagram* frame(qreal& defaultY, qreal& relativeY, bool& hasTotalY);
void harmony(const QString& partId, Measure* measure, const Fraction sTime, DelayedDirectionsList& delayedDirections);
Accidental* accidental();
void beam(Beam::Mode& beamMode);
void duration(Fraction& dura);
Expand Down
44 changes: 22 additions & 22 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4520,6 +4520,28 @@ void Score::layoutSystemElements(System* system, LayoutContext& lc)
}
}

//-------------------------------------------------------------
// FretDiagram
//-------------------------------------------------------------

if (hasFretDiagram) {
for (const Segment* s : sl) {
for (Element* e : s->annotations()) {
if (e->isFretDiagram())
e->layout();
}
}

//-------------------------------------------------------------
// Harmony, 2nd place
// We have FretDiagrams, we want the Harmony above this and
// above the volta.
//-------------------------------------------------------------

layoutHarmonies(sl);
alignHarmonies(system, sl, false, styleP(Sid::maxFretShiftAbove), styleP(Sid::maxFretShiftBelow));
}

//-------------------------------------------------------------
// TempoText
//-------------------------------------------------------------
Expand Down Expand Up @@ -4575,28 +4597,6 @@ void Score::layoutSystemElements(System* system, LayoutContext& lc)
}
}

//-------------------------------------------------------------
// FretDiagram
//-------------------------------------------------------------

if (hasFretDiagram) {
for (const Segment* s : sl) {
for (Element* e : s->annotations()) {
if (e->isFretDiagram())
e->layout();
}
}

//-------------------------------------------------------------
// Harmony, 2nd place
// We have FretDiagrams, we want the Harmony above this and
// above the volta.
//-------------------------------------------------------------

layoutHarmonies(sl);
alignHarmonies(system, sl, false, styleP(Sid::maxFretShiftAbove), styleP(Sid::maxFretShiftBelow));
}

//-------------------------------------------------------------
// RehearsalMark
//-------------------------------------------------------------
Expand Down
Loading