Skip to content

Commit

Permalink
Fix: anacrusis has wrong tempo if not explicitly set
Browse files Browse the repository at this point in the history
Backport of musescore#23656 / musescore#24643

Plus some includes files cleanup
  • Loading branch information
mikekirin authored and Jojo-Schmitz committed Sep 11, 2024
1 parent 1f21da2 commit 9364d4f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
32 changes: 32 additions & 0 deletions libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ void Score::fixTicks()
sigmap()->clear();
sigmap()->add(0, SigEvent(fm->ticks(), fm->timesig(), 0));
}
std::vector<Measure*> anacrusisMeasures;

for (MeasureBase* mb = first(); mb; mb = mb->next()) {
if (mb->type() != ElementType::MEASURE) {
Expand All @@ -440,13 +441,18 @@ void Score::fixTicks()
if (m->mmRest())
m->mmRest()->moveTicks(diff);

if (m->isAnacrusis())
anacrusisMeasures.push_back(m);

rebuildTempoAndTimeSigMaps(m);

tick += measureTicks;
}
// Now done in getNextMeasure(), do we keep?
if (tempomap()->empty())
tempomap()->setTempo(0, _defaultTempo);
if (!anacrusisMeasures.empty())
fixAnacrusisTempo(anacrusisMeasures);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -548,6 +554,32 @@ void Score::rebuildTempoAndTimeSigMaps(Measure* measure)
}
}

void Score::fixAnacrusisTempo(const std::vector<Measure*>& measures) const
{
auto getTempoTextIfExist = [](const Measure* m) -> TempoText* {
for (const Segment& s : m->segments()) {
if (s.isChordRestType()) {
for (Element* e : s.annotations()) {
if (e->isTempoText())
return toTempoText(e);
}
}
}
return nullptr;
};

for (Measure* measure : measures) {
if (getTempoTextIfExist(measure))
continue;
Measure* nextMeasure = measure->nextMeasure();
if (nextMeasure) {
TempoText* tt = getTempoTextIfExist(nextMeasure);
if (tt)
tempomap()->setTempo(measure->tick().ticks(), tt->tempo());
}
}
}

//---------------------------------------------------------
// pos2measure
// Return measure for canvas relative position \a p.
Expand Down
12 changes: 6 additions & 6 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
Definition of Score class.
*/

#include "config.h"
#include "input.h"
#include "instrument.h"
#include "select.h"
#include "synthesizerstate.h"
#include "mscoreview.h"
#include "spannermap.h"
#include "layoutbreak.h"
#include "mscoreview.h"
#include "property.h"
#include "select.h"
#include "spannermap.h"
#include "synthesizerstate.h"
#include "sym.h"

namespace Ms {
Expand Down Expand Up @@ -853,6 +852,7 @@ class Score : public QObject, public ScoreElement {
Segment* tick2leftSegmentMM(const Fraction& tick) { return tick2leftSegment(tick, /* useMMRest */ true); }
void fixTicks();
void rebuildTempoAndTimeSigMaps(Measure* m);
void fixAnacrusisTempo(const std::vector<Measure*>& measures) const;
Element* nextElement();
Element* prevElement();
ChordRest* cmdNextPrevSystem(ChordRest*, bool);
Expand Down Expand Up @@ -937,7 +937,7 @@ class Score : public QObject, public ScoreElement {
void setInputTrack(int t) { inputState().setTrack(t); }

void spatiumChanged(qreal oldValue, qreal newValue);
void styleChanged();
void styleChanged() override;

void cmdPaste(const QMimeData* ms, MuseScoreView* view, Fraction scale = Fraction(1, 1));
bool pasteStaff(XmlReader&, Segment* dst, int staffIdx, Fraction scale = Fraction(1, 1));
Expand Down

0 comments on commit 9364d4f

Please sign in to comment.