Skip to content

Commit

Permalink
Merge pull request #1297 from lvinken/musicxml-fixes
Browse files Browse the repository at this point in the history
Musicxml fixes
  • Loading branch information
lasconic committed Sep 10, 2014
2 parents 42e7816 + aafac2e commit 2b0fda1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
60 changes: 42 additions & 18 deletions mscore/importxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,36 @@ void MusicXml::import(Score* s)
{
tupletAssert();
score = s;

// TODO only if multi-measure rests used ???
// score->style()->set(StyleIdx::createMultiMeasureRests, true);

for (QDomElement e = doc->documentElement(); !e.isNull(); e = e.nextSiblingElement()) {
if (e.tagName() == "score-partwise")
scorePartwise(e.firstChildElement());
else
domError(e);
}
}

//---------------------------------------------------------
// initPartState
//---------------------------------------------------------

/**
Initialize members as required for reading the MusicXML part element.
TODO: factor out part reading into a separate
*/

void MusicXml::initPartState()
{
fractionTSig = Fraction(0, 1);
tick = 0;
maxtick = 0;
prevtick = 0;
lastMeasureLen = 0;
multiMeasureRestCount = -1;
startMultiMeasureRest = false;
tie = 0;
for (int i = 0; i < MAX_NUMBER_LEVEL; ++i)
slur[i] = 0;
Expand All @@ -733,21 +763,12 @@ void MusicXml::import(Score* s)
ottava = 0;
trill = 0;
pedal = 0;
pedalContinue = 0;
harmony = 0;
tremStart = 0;
hairpin = 0;
figBass = 0;
figBassExtend = false;

// TODO only if multi-measure rests used ???
// score->style()->set(StyleIdx::createMultiMeasureRests, true);

for (QDomElement e = doc->documentElement(); !e.isNull(); e = e.nextSiblingElement()) {
if (e.tagName() == "score-partwise")
scorePartwise(e.firstChildElement());
else
domError(e);
}
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1713,13 +1734,9 @@ void MusicXml::xmlPart(QDomElement e, QString id)
qDebug("Import MusicXml:xmlPart: cannot find part %s", id.toLatin1().data());
return;
}
fractionTSig = Fraction(0, 1);
tick = 0;
maxtick = 0;
prevtick = 0;
lastMeasureLen = 0;
multiMeasureRestCount = -1;
startMultiMeasureRest = false;

initPartState();

KeySigEvent ev;
KeySig currKeySig;
currKeySig.setKeySigEvent(ev);
Expand Down Expand Up @@ -2930,9 +2947,9 @@ void MusicXml::direction(Measure* measure, int staff, QDomElement e)
else if (type == "change") {
// pedal change is implemented as two separate pedals
// first stop the first one
// TODO: this is not yet correct, the spanner must be stopped after the NEXT note
pedal->setEndHookType(HookType::HOOK_45);
handleSpannerStop(pedal, "pedal", tick, spanners);
pedalContinue = pedal; // mark for later fixup
pedal = 0;
// then start a new one
pedal = static_cast<Pedal*>(checkSpannerOverlap(pedal, new Pedal(score), "pedal"));
Expand Down Expand Up @@ -5235,6 +5252,13 @@ Note* MusicXml::xmlNote(Measure* measure, int staff, const QString& partId, Beam
}
figBassExtend = false;

// fixup pedal type="change" to end at the end of this note
// note tick is still at note start
if (pedalContinue) {
handleSpannerStop(pedalContinue, "pedal", tick + ticks, spanners);
pedalContinue = 0;
}

if (!chord)
prevtick = tick; // remember tick where last chordrest was inserted

Expand Down
2 changes: 2 additions & 0 deletions mscore/musicxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class MusicXml {
Ottava* ottava; ///< Current ottava
Trill* trill; ///< Current trill
Pedal* pedal; ///< Current pedal
Pedal* pedalContinue; ///< Current pedal type="change" requiring fixup
Harmony* harmony; ///< Current harmony
Hairpin* hairpin; ///< Current hairpin (obsoletes wedgelist)
Chord* tremStart; ///< Starting chord for current tremolo
Expand Down Expand Up @@ -215,6 +216,7 @@ class MusicXml {
void readPageFormat(PageFormat* pf, QDomElement de, qreal conversion);
QList<QDomElement> findSlurElements(QDomElement);
void addGraceNoteAfter(Chord*, Segment*);
void initPartState();
public:
MusicXml(QDomDocument* d, MxmlReaderFirstPass const& p1);
void import(Score*);
Expand Down

0 comments on commit 2b0fda1

Please sign in to comment.