Skip to content

Commit

Permalink
set correct tempo for metronome marking
Browse files Browse the repository at this point in the history
Amended by @cbjeukendrup: added @CoolSpy3 as a co-author, because they originally created almost the same solution in #21458.

Co-Authored-By: CoolSpy3 <55305038+coolspy3@users.noreply.github.com>
  • Loading branch information
rpatters1 and CoolSpy3 committed Feb 4, 2025
1 parent b3217a1 commit fbed537
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/notation/internal/masternotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,22 @@ void MasterNotation::applyOptions(mu::engraving::MasterScore* score, const Score
mu::engraving::Fraction ts(scoreOptions.timesigNumerator, scoreOptions.timesigDenominator);

QString text("<sym>metNoteQuarterUp</sym> = %1");
double bpm = scoreOptions.tempo.valueBpm;
const double bpm = scoreOptions.tempo.valueBpm;
double tempo = bpm; // initial value for tempo, which internally is always expressed in quarter notes

bool withDot = scoreOptions.tempo.withDot;
switch (scoreOptions.tempo.duration) {
case DurationType::V_WHOLE:
text = "<sym>metNoteWhole</sym> = %1";
tempo *= 4.0;
break;
case DurationType::V_HALF:
if (withDot) {
text = "<sym>metNoteHalfUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = %1";
} else {
text = "<sym>metNoteHalfUp</sym> = %1";
}
tempo *= 2.0;
break;
case DurationType::V_QUARTER:
if (withDot) {
Expand All @@ -453,24 +456,29 @@ void MasterNotation::applyOptions(mu::engraving::MasterScore* score, const Score
} else {
text = "<sym>metNote8thUp</sym> = %1";
}
tempo *= 0.5;
break;
case DurationType::V_16TH:
if (withDot) {
text = "<sym>metNote16thUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = %1";
} else {
text = "<sym>metNote16thUp</sym> = %1";
}
tempo *= 0.25;
break;
default:
break;
}

if (withDot) {
tempo *= 1.5;
}

mu::engraving::Segment* seg = score->firstMeasure()->first(mu::engraving::SegmentType::ChordRest);
mu::engraving::TempoText* tt = new mu::engraving::TempoText(seg);
tt->setXmlText(text.arg(bpm));

double tempo = scoreOptions.tempo.valueBpm;
tempo /= 60; // bpm -> bps
tempo /= 60; // qpm -> qps

tt->setTempo(tempo);
tt->setFollowText(true);
Expand Down

0 comments on commit fbed537

Please sign in to comment.