Skip to content

Commit

Permalink
Tempo Popup
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharth-anand committed Jul 18, 2021
1 parent 13fb52a commit cf98f55
Show file tree
Hide file tree
Showing 25 changed files with 1,048 additions and 334 deletions.
2 changes: 2 additions & 0 deletions src/engraving/libmscore/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::SPACE, false, "space", P_TYPE::SP_REAL, DUMMY_QT_TR_NOOP("propertyName", "space") },
{ Pid::TEMPO, true, "tempo", P_TYPE::TEMPO, DUMMY_QT_TR_NOOP("propertyName", "tempo") },
{ Pid::TEMPO_FOLLOW_TEXT, true, "followText", P_TYPE::BOOL, DUMMY_QT_TR_NOOP("propertyName", "following text") },
{ Pid::TEMPO_EQUATION, true, "tempoEquation", P_TYPE::STRING, DUMMY_QT_TR_NOOP("propertyName", "tempo equation") },
{ Pid::TEMPO_EQUATION_VISIBLE, true, "tempoEquationVisible", P_TYPE::BOOL, DUMMY_QT_TR_NOOP("propertyName", "tempo is equation visible") },
{ Pid::ACCIDENTAL_BRACKET, false, "bracket", P_TYPE::INT, DUMMY_QT_TR_NOOP("propertyName", "bracket") },
{ Pid::ACCIDENTAL_TYPE, true, "subtype", P_TYPE::INT, DUMMY_QT_TR_NOOP("propertyName", "type") },
{ Pid::NUMERATOR_STRING, false, "textN", P_TYPE::STRING, DUMMY_QT_TR_NOOP("propertyName", "numerator string") },
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/libmscore/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ enum class Pid {
SPACE, // used for spacer
TEMPO,
TEMPO_FOLLOW_TEXT,
TEMPO_EQUATION,
TEMPO_EQUATION_VISIBLE,
ACCIDENTAL_BRACKET,
ACCIDENTAL_TYPE,
NUMERATOR_STRING,
Expand Down
522 changes: 374 additions & 148 deletions src/engraving/libmscore/tempotext.cpp

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions src/engraving/libmscore/tempotext.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,29 @@ namespace Ms {

class TempoText final : public TextBase
{
qreal _tempo; // beats per second
qreal _playbackTempo; // beats per second
qreal _notatedTempo; // tempo user enters
bool _followText; // parse text to determine tempo
qreal _relative;
bool _isRelative;
QString _equation;
QString _tempoText;
bool _isEquationVisible;

void updateScore();
void updateTempo();

void startEdit(EditData&) override;
void endEdit(EditData&) override;

void undoChangeProperty(Pid id, const QVariant&, PropertyFlags ps) override;

bool isEquationValid(const QString equation) const;

int textIndexFromCursor(int row, int column) const;
std::pair<int, int> cursorIndexFromTextIndex(int index) const;
std::pair<int, int> equationIndices() const;

public:
TempoText(Score*);

Expand All @@ -59,7 +72,7 @@ class TempoText final : public TextBase
Segment* segment() const { return toSegment(parent()); }
Measure* measure() const { return toMeasure(parent()->parent()); }

qreal tempo() const { return _tempo; }
qreal tempo() const { return _playbackTempo; }
qreal tempoBpm() const;
void setTempo(qreal v);
void undoSetTempo(qreal v);
Expand All @@ -68,16 +81,32 @@ class TempoText final : public TextBase

bool followText() const { return _followText; }
void setFollowText(bool v) { _followText = v; }
QString equation() const { return _equation; }
void setEquation(QString equation) { _equation = equation; }
void setEquationVisible(bool equationVisible) { _isEquationVisible = equationVisible; }
void undoSetFollowText(bool v);
void updateRelative();

void setEquationFromTempo(int tempo);

void parseEquation();

bool moveCursor(TextCursor* cursor, int key, bool ctrlPressed, QTextCursor::MoveMode moveMode) const override;

void dragTo(EditData& ed) override;

void layout() override;

TDuration duration() const;

static QString regexGroup(bool symbol = true);

static int findTempoDuration(const QString& s, int& len, TDuration& dur);
static TDuration findTempoDuration(const QString& s);
static QString duration2tempoTextString(const TDuration dur);
static QString duration2userName(const TDuration t);
static float getRelativeDuration(const QString marking);
static QString mapEquationToText(const QString equation, bool symbol = true);

QVariant getProperty(Pid propertyId) const override;
bool setProperty(Pid propertyId, const QVariant&) override;
Expand Down
11 changes: 11 additions & 0 deletions src/engraving/libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,17 @@ Sid TextBase::offsetSid() const
return Sid::NOSTYLE;
}

bool TextBase::moveCursor(TextCursor* cursor, int key, bool ctrlPressed, QTextCursor::MoveMode moveMode) const
{
if (key == Qt::Key_Left) {
return cursor->movePosition(ctrlPressed ? QTextCursor::WordLeft : QTextCursor::Left, moveMode);
} else if (key == Qt::Key_Right) {
return cursor->movePosition(ctrlPressed ? QTextCursor::WordRight : QTextCursor::Right, moveMode);
} else {
return false;
}
}

//---------------------------------------------------------
// getHtmlStartTag - helper function for extractText with withFormat = true
//---------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/engraving/libmscore/textbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ class TextBase : public Element

void insertText(EditData&, const QString&);

virtual bool moveCursor(TextCursor* cursor, int key, bool ctrlPressed, QTextCursor::MoveMode moveMode) const;

virtual void layout() override;
virtual void layout1();
qreal lineSpacing() const;
Expand Down Expand Up @@ -364,7 +366,7 @@ class TextBase : public Element

mu::RectF pageRectangle() const;

void dragTo(EditData&);
virtual void dragTo(EditData&);

QVector<mu::LineF> dragAnchorLines() const override;

Expand Down
13 changes: 3 additions & 10 deletions src/engraving/libmscore/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,14 @@ bool TextBase::edit(EditData& ed)
return true;

case Qt::Key_Left:
if (!_cursor->movePosition(ctrlPressed ? QTextCursor::WordLeft : QTextCursor::Left,
mm) && type() == ElementType::LYRICS) {
return false;
}
s.clear();
break;

case Qt::Key_Right:
if (!_cursor->movePosition(ctrlPressed ? QTextCursor::NextWord : QTextCursor::Right,
mm) && type() == ElementType::LYRICS) {
if (!toTextBase(ed.element)->moveCursor(_cursor, ed.key, ctrlPressed, mm) && type() == ElementType::LYRICS) {
return false;
}

s.clear();
break;

break;
case Qt::Key_Up:
#if defined(Q_OS_MAC)
if (!cursor->movePosition(QTextCursor::Up, mm)) {
Expand Down
6 changes: 2 additions & 4 deletions src/importexport/bww/internal/bww/importbww.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ static void xmlSetPitch(Ms::Note* n, char step, int alter, int octave)
static void setTempo(Ms::Score* score, int tempo)
{
Ms::TempoText* tt = new Ms::TempoText(score);
tt->setTempo(double(tempo) / 60.0);
tt->setEquationFromTempo(tempo);
tt->setTrack(0);
QString tempoText = Ms::TempoText::duration2tempoTextString(Ms::TDuration::DurationType::V_QUARTER);
tempoText += QString(" = %1").arg(tempo);
tt->setPlainText(tempoText);

Ms::Measure* measure = score->firstMeasure();
Ms::Segment* segment = measure->getSegment(Ms::SegmentType::ChordRest, Ms::Fraction(0, 1));
segment->add(tt);
Expand Down
3 changes: 1 addition & 2 deletions src/importexport/guitarpro/internal/importgtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,7 @@ void GuitarPro::setTempo(int temp, Measure* measure)
}

TempoText* tt = new TempoText(score);
tt->setTempo(double(temp) / 60.0);
tt->setXmlText(QString("<sym>metNoteQuarterUp</sym> = %1").arg(temp));
tt->setEquationFromTempo(temp);
tt->setTrack(0);

segment->add(tt);
Expand Down
3 changes: 1 addition & 2 deletions src/importexport/guitarpro/internal/importptb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,7 @@ void PowerTab::addToScore(ptSection& sec)
}
if (sec.tempo) {
TempoText* tt = new TempoText(score);
tt->setTempo(double(sec.tempo) / 60.0f);
tt->setXmlText(QString("<sym>metNoteQuarterUp</sym> = %1").arg(sec.tempo));
tt->setEquationFromTempo(sec.tempo);
tt->setTrack(0);
Segment* segment = measure->getSegment(SegmentType::ChordRest, measure->tick());
segment->add(tt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ void setTempoToScore(Score* score, int tick, double beatsPerSecond)
const int tempoInBpm = qRound(beatsPerSecond * 60.0);

TempoText* tempoText = new TempoText(score);
tempoText->setTempo(beatsPerSecond);
tempoText->setXmlText(QString("<sym>metNoteQuarterUp</sym> = %1").arg(tempoInBpm));
tempoText->setEquationFromTempo(tempoInBpm);
tempoText->setTrack(0);

Measure* measure = score->tick2measure(Fraction::fromTicks(tick));
Expand Down
6 changes: 6 additions & 0 deletions src/importexport/musicxml/internal/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4124,6 +4124,12 @@ static bool findMetronome(const QList<TextFragment>& list,
int rparen = s6.indexOf(")");
hasParen = (lparen == s1.length() - 1 && rparen == 0);

if (!hasParen) {
lparen = s1.indexOf("[");
rparen = s6.indexOf("]");
hasParen = (lparen == s1.length() - 1 && rparen == 0);
}

metroLeft = s2;
metroRight = s5;

Expand Down
15 changes: 3 additions & 12 deletions src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2136,10 +2136,8 @@ void MusicXMLParserPass2::measure(const QString& partId, const Fraction time)
} else {
double tpo = tempo.toDouble() / 60;
TempoText* t = new TempoText(_score);
t->setXmlText(QString("%1 = %2").arg(TempoText::duration2tempoTextString(TDuration(TDuration::DurationType::V_QUARTER)),
tempo));
t->setEquationFromTempo(tempo.toDouble());
t->setVisible(false);
t->setTempo(tpo);
t->setFollowText(true);

_score->setTempo(tick, tpo);
Expand Down Expand Up @@ -2631,17 +2629,10 @@ void MusicXMLParserDirection::direction(const QString& partId,
if (hasTempoTextAtTick(_score->tempomap(), tick.ticks())) {
_logger->logError(QString("duplicate tempo at tick %1").arg(tick.ticks()), &_e);
} else {
double tpo = _tpoSound / 60;
TempoText* t = new TempoText(_score);
t->setXmlText(QString("%1 = %2").arg(TempoText::duration2tempoTextString(TDuration(TDuration::DurationType::V_QUARTER))).arg(
_tpoSound));
t->setVisible(false);
t->setTempo(tpo);
t->setEquationFromTempo(_tpoSound);
t->setFollowText(true);

// TBD may want ro use tick + _offset if sound is affected
_score->setTempo(tick, tpo);

addElemOffset(t, track, placement, measure, tick + _offset);
}
}
Expand Down Expand Up @@ -3366,7 +3357,7 @@ QString MusicXMLParserDirection::metronome(double& r)
tempoText += ")";
}

return tempoText;
return TempoText::mapEquationToText(tempoText);
}

//---------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@
<Measure>
<voice>
<Tempo>
<tempo>1.3333299999999999</tempo>
<playbackTempo>1.3333299999999999</playbackTempo>
<notatedTempo>80</notatedTempo>
<equation>q = 80</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text><sym>metNoteQuarterUp</sym> = 80</text>
</Tempo>
Expand Down
Loading

0 comments on commit cf98f55

Please sign in to comment.