Skip to content

Commit

Permalink
Merge pull request #3937 from handrok/fix#271616-Fermata_tempo
Browse files Browse the repository at this point in the history
fix #271616: Fermata tempo is not applied when importing 2.X->3.0 score
  • Loading branch information
anatoly-os committed Sep 14, 2018
2 parents 619c132 + 34cf407 commit fb9dcac
Show file tree
Hide file tree
Showing 10 changed files with 677 additions and 24 deletions.
6 changes: 6 additions & 0 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,7 @@ void Score::getNextMeasure(LayoutContext& lc)
}
}

measure->computeTicks();
for (Segment& segment : measure->segments()) {
if (segment.isBreathType()) {
qreal length = 0.0;
Expand Down Expand Up @@ -3817,6 +3818,11 @@ void Score::doLayoutRange(int stick, int etick)

lc.prevMeasure = 0;

// we need to reset tempo because fermata is setted
//inside getNextMeasure and it lead to twice timeStretch
if (isMaster())
resetTempo();

getNextMeasure(lc);
lc.curSystem = collectSystem(lc);

Expand Down
3 changes: 3 additions & 0 deletions libmscore/layoutlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ static void processLines(System* system, std::vector<Spanner*> lines, bool align
void Score::collectLinearSystem(LayoutContext& lc)
{
System* system = systems().front();
// we need to reset tempo because fermata is setted
//inside getNextMeasure and it lead to twice timeStretch
resetTempo();

QPointF pos;
bool firstMeasure = true;
Expand Down
54 changes: 31 additions & 23 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3514,29 +3514,7 @@ void Measure::stretchMeasure(qreal targetWidth)
{
bbox().setWidth(targetWidth);

//---------------------------------------------------
// compute minTick and set ticks for all segments
//---------------------------------------------------

int minTick = ticks();
if (minTick <= 0) {
qDebug("=====minTick %d measure %p", minTick, this);
}
Q_ASSERT(minTick > 0);

Segment* ns = first();
while (ns && !ns->enabled())
ns = ns->next();
while (ns) {
Segment* s = ns;
ns = s->nextEnabled();
int nticks = (ns ? ns->rtick() : ticks()) - s->rtick();
if (nticks) {
if (nticks < minTick)
minTick = nticks;
}
s->setTicks(nticks);
}
int minTick = computeTicks();

//---------------------------------------------------
// compute stretch
Expand Down Expand Up @@ -3670,6 +3648,36 @@ void Measure::stretchMeasure(qreal targetWidth)
}
}

//---------------------------------------------------
// computeTicks
// set ticks for all segments
// return minTick
//---------------------------------------------------

int Measure::computeTicks() {
int minTick = ticks();
if (minTick <= 0) {
qDebug("=====minTick %d measure %p", minTick, this);
}
Q_ASSERT(minTick > 0);

Segment* ns = first();
while (ns && !ns->enabled())
ns = ns->next();
while (ns) {
Segment* s = ns;
ns = s->nextEnabled();
int nticks = (ns ? ns->rtick() : ticks()) - s->rtick();
if (nticks) {
if (nticks < minTick)
minTick = nticks;
}
s->setTicks(nticks);
}

return minTick;
}

//---------------------------------------------------------
// endBarLine
// return the first one
Expand Down
1 change: 1 addition & 0 deletions libmscore/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Measure final : public MeasureBase {
void setUserStretch(qreal v) { _userStretch = v; }

void stretchMeasure(qreal stretch);
int computeTicks();
void layout2();

Chord* findChord(int tick, int track);
Expand Down
4 changes: 4 additions & 0 deletions libmscore/read206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,10 @@ Element* readArticulation(ChordRest* cr, XmlReader& e)
el->readProperties300(e);
}
}
else if (tag == "timeStretch") {
if (el && el->isFermata())
el->setProperty(Pid::TIME_STRETCH ,e.readDouble());
}
else {
if (!el) {
qDebug("not handled <%s>", qPrintable(tag.toString()));
Expand Down
13 changes: 12 additions & 1 deletion libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void Score::fixTicks()
}
// Now done in getNextMeasure(), do we keep?
if (tempomap()->empty())
tempomap()->setTempo(0, 2.0);
tempomap()->setTempo(0, defaultTempo);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -3259,6 +3259,17 @@ void Score::removeTempo(int tick)
_playlistDirty = true;
}

//---------------------------------------------------------
// resetTempo
//---------------------------------------------------------

void Score::resetTempo() {
tempomap()->clear();
tempomap()->setTempo(0, defaultTempo);
sigmap()->clear();
sigmap()->add(0, SigEvent(firstMeasure()->len(), firstMeasure()->timesig(), 0));
}

//---------------------------------------------------------
// setPause
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ class Score : public QObject, public ScoreElement {

QMap<QString, QString> _metaTags;

constexpr static double defaultTempo = 2.0; //defautl tempo is equal 120 bpm

Selection _selection;
SelectionFilter _selectionFilter;
Expand Down Expand Up @@ -510,6 +511,7 @@ class Score : public QObject, public ScoreElement {

void resetSystems(bool layoutAll, LayoutContext& lc);
void collectLinearSystem(LayoutContext& lc);
void resetTempo();

protected:
int _fileDivision; ///< division of current loading *.msc file
Expand Down
Loading

0 comments on commit fb9dcac

Please sign in to comment.