Skip to content

Commit

Permalink
Tempo Popup
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharth-anand committed Aug 17, 2021
1 parent ac272b0 commit 21b5144
Show file tree
Hide file tree
Showing 54 changed files with 1,281 additions and 372 deletions.
Binary file modified fonts/mscore/MusescoreIcon.ttf
Binary file not shown.
3 changes: 3 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 Expand Up @@ -316,6 +318,7 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::SIZE_SPATIUM_DEPENDENT, false, "sizeIsSpatiumDependent",P_TYPE::BOOL, DUMMY_QT_TR_NOOP("propertyName", "spatium dependent font") },
{ Pid::ALIGN, false, "align", P_TYPE::ALIGN, DUMMY_QT_TR_NOOP("propertyName", "align") },
{ Pid::TEXT_SCRIPT_ALIGN, false, "align", P_TYPE::INT, DUMMY_QT_TR_NOOP("propertyName", "text script align") },
{ Pid::TEXT_HIDE_CURSOR, true, "hideTextCursor", P_TYPE::BOOL, DUMMY_QT_TR_NOOP("propertyName", "hideTextCursor") },
{ Pid::SYSTEM_FLAG, false, "systemFlag", P_TYPE::BOOL, DUMMY_QT_TR_NOOP("propertyName", "system flag") },

{ Pid::BEGIN_TEXT, true, "beginText", P_TYPE::STRING, DUMMY_QT_TR_NOOP("propertyName", "begin text") },
Expand Down
3 changes: 3 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 Expand Up @@ -320,6 +322,7 @@ enum class Pid {
SIZE_SPATIUM_DEPENDENT,
ALIGN,
TEXT_SCRIPT_ALIGN,
TEXT_HIDE_CURSOR,
SYSTEM_FLAG,
BEGIN_TEXT,

Expand Down
550 changes: 402 additions & 148 deletions src/engraving/libmscore/tempotext.cpp

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions src/engraving/libmscore/tempotext.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,34 @@ 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;
bool _isEquationVisible;
int _lastEquationIndex;

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;

protected:

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

public:
TempoText(Score*);

Expand All @@ -59,7 +77,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 +86,30 @@ 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();

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
18 changes: 17 additions & 1 deletion src/engraving/libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,8 @@ QVariant TextBase::getProperty(Pid propertyId) const
return static_cast<int>(_cursor->selectedFragmentsFormat().valign());
case Pid::TEXT:
return xmlText();
case Pid::TEXT_HIDE_CURSOR:
return _hideCursor;
default:
return Element::getProperty(propertyId);
}
Expand Down Expand Up @@ -2974,6 +2976,9 @@ bool TextBase::setProperty(Pid pid, const QVariant& v)
case Pid::TEXT_SCRIPT_ALIGN:
_cursor->setFormat(FormatId::Valign, v.toInt());
break;
case Pid::TEXT_HIDE_CURSOR:
_hideCursor = v.toBool();
break;
default:
rv = Element::setProperty(pid, v);
break;
Expand Down Expand Up @@ -3084,6 +3089,17 @@ Sid TextBase::offsetSid() const
return Sid::NOSTYLE;
}

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

//---------------------------------------------------------
// getHtmlStartTag - helper function for extractText with withFormat = true
//---------------------------------------------------------
Expand Down Expand Up @@ -3365,7 +3381,7 @@ void TextBase::drawEditMode(mu::draw::Painter* p, EditData& ed)
p->setPen(pen);

// Don't draw cursor if there is a selection
if (!cursor->hasSelection()) {
if (!cursor->hasSelection() && !_hideCursor) {
p->drawRect(cursor->cursorRect());
}

Expand Down
6 changes: 5 additions & 1 deletion src/engraving/libmscore/textbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class TextBase : public Element
bool _primed { 0 };

TextCursor* _cursor { nullptr };
bool _hideCursor { false };

void drawSelection(mu::draw::Painter*, const mu::RectF&) const;
void insert(TextCursor*, uint code);
Expand All @@ -311,6 +312,9 @@ class TextBase : public Element
void prepareFormat(const QString& token, Ms::TextCursor& cursor);
bool prepareFormat(const QString& token, Ms::CharFormat& format);

virtual bool moveCursor(TextCursor* cursor, int key, bool ctrlPressed, TextCursor::MoveMode moveMode) const;
virtual bool canDelete(TextCursor*, int) const { return true; }

public:
TextBase(Score* = 0, Tid tid = Tid::DEFAULT, ElementFlags = ElementFlag::NOTHING);
TextBase(Score*, ElementFlags);
Expand Down Expand Up @@ -378,7 +382,7 @@ class TextBase : public Element

mu::RectF pageRectangle() const;

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

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

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

case Qt::Key_Delete:
if (canDelete(cursor, ed.key)) {
return true;
}

if (!deleteSelectedText(ed)) {
// check for move down
if (cursor->column() == cursor->columns()) { // if you are on the end of the line, delete the newline char
Expand All @@ -337,6 +341,10 @@ bool TextBase::edit(EditData& ed)
return true;

case Qt::Key_Backspace:
if (canDelete(cursor, ed.key)) {
return true;
}

if (ctrlPressed) {
// delete last word
cursor->movePosition(TextCursor::MoveOperation::WordLeft, TextCursor::MoveMode::KeepAnchor);
Expand All @@ -357,21 +365,14 @@ bool TextBase::edit(EditData& ed)
return true;

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

case Qt::Key_Right:
if (!_cursor->movePosition(ctrlPressed ? TextCursor::MoveOperation::NextWord : TextCursor::MoveOperation::Right,
mm) && type() == ElementType::LYRICS) {
if (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(TextCursor::MoveOperation::Up, mm)) {
Expand Down
5 changes: 4 additions & 1 deletion src/engraving/tests/barline_data/barlinedelete-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>2</tempo>
<playbackTempo>2</playbackTempo>
<notatedTempo>120</notatedTempo>
<equation>q = 120</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>Tempo text</text>
</Tempo>
Expand Down
5 changes: 4 additions & 1 deletion src/engraving/tests/barline_data/barlinedelete.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>2</tempo>
<playbackTempo>2</playbackTempo>
<notatedTempo>120</notatedTempo>
<equation>q = 120</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>Tempo text</text>
</Tempo>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/keysig_data/keysig.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/keysig_data/keysig01-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/keysig_data/keysig02-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split01-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split01.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split02-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split02.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split03-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Spanner type="HairPin">
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split03.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Spanner type="HairPin">
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split04-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
6 changes: 5 additions & 1 deletion src/engraving/tests/split_data/split04.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
<sigD>4</sigD>
</TimeSig>
<Tempo>
<tempo>1.66667</tempo>
<playbackTempo>1.66667</playbackTempo>
<notatedTempo>100</notatedTempo>
<equation>q = 100</equation>
<equationVisible>1</equationVisible>
<followText>1</followText>
<text>𝅘𝅥 = 100</text>
</Tempo>
<Chord>
Expand Down
Loading

0 comments on commit 21b5144

Please sign in to comment.