1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
Description: Add Element::barbeat() and Element::accessibleBarbeat()
These are const, and useful for determining the positions of elements
within the score, generally; used by experiments/log-collisions.diff
.
Also fix some screenreader label mistakes.
Author: mirabilos <m@mirbsd.org>
Forwarded: https://github.com/musescore/MuseScore/pull/5096
--- a/libmscore/element.cpp
+++ b/libmscore/element.cpp
@@ -2432,4 +2432,53 @@ void Element::autoplaceMeasureElement(bo
setOffsetChanged(false);
}
+//---------------------------------------------------------
+// barbeat
+//---------------------------------------------------------
+
+std::pair<int, float> Element::barbeat() const
+ {
+ int bar = 0;
+ int beat = 0;
+ int ticks = 0;
+ TimeSigMap* tsm = this->score()->sigmap();
+ const Element* p = this;
+ int ticksB = ticks_beat(tsm->timesig(0).timesig().denominator());
+ while(p && p->type() != ElementType::SEGMENT && p->type() != ElementType::MEASURE)
+ p = p->parent();
+
+ if (!p) {
+ return std::pair<int, float>(0, 0.0F);
+ }
+ else if (p->type() == ElementType::SEGMENT) {
+ const Segment* seg = static_cast<const Segment*>(p);
+ tsm->tickValues(seg->tick().ticks(), &bar, &beat, &ticks);
+ ticksB = ticks_beat(tsm->timesig(seg->tick().ticks()).timesig().denominator());
+ }
+ else if (p->type() == ElementType::MEASURE) {
+ const Measure* m = static_cast<const Measure*>(p);
+ bar = m->no();
+ beat = -1;
+ ticks = 0;
+ }
+ return std::pair<int,float>(bar + 1, beat + 1 + ticks / static_cast<float>(ticksB));
+ }
+
+//---------------------------------------------------------
+// accessibleBarbeat
+//---------------------------------------------------------
+
+QString Element::accessibleBarbeat() const
+ {
+ QString barsAndBeats = "";
+ std::pair<int, float>bar_beat = barbeat();
+ if (bar_beat.first) {
+ barsAndBeats += "; " + QObject::tr("Measure: %1").arg(QString::number(bar_beat.first));
+ if (bar_beat.second)
+ barsAndBeats += "; " + QObject::tr("Beat: %1").arg(QString::number(bar_beat.second));
+ }
+ if (staffIdx() + 1)
+ barsAndBeats += "; " + QObject::tr("Staff: %1").arg(QString::number(staffIdx() + 1));
+ return barsAndBeats;
+ }
}
--- a/libmscore/element.h
+++ b/libmscore/element.h
@@ -197,6 +197,8 @@ class Element : public ScoreElement {
virtual bool isElement() const override { return true; }
qreal spatium() const;
+ std::pair<int, float>barbeat() const;
+ QString accessibleBarbeat() const;
inline void setFlag(ElementFlag f, bool v) { if (v) _flags |= f; else _flags &= ~ElementFlags(f); }
inline void setFlag(ElementFlag f, bool v) const { if (v) _flags |= f; else _flags &= ~ElementFlags(f); }
--- a/mscore/scoreaccessibility.cpp
+++ b/mscore/scoreaccessibility.cpp
@@ -124,8 +124,8 @@ void ScoreAccessibility::currentInfoChan
QString barsAndBeats = "";
if (el->isSpanner()){
Spanner* s = static_cast<Spanner*>(el);
- std::pair<int, float> bar_beat = barbeat(s->startSegment());
- barsAndBeats += tr("Start Measure: %1; Start Beat: %2").arg(QString::number(bar_beat.first)).arg(QString::number(bar_beat.second));
+ std::pair<int, float> bar_beat = s->startSegment()->barbeat();
+ barsAndBeats += " " + tr("Start Measure: %1; Start Beat: %2").arg(QString::number(bar_beat.first)).arg(QString::number(bar_beat.second));
Segment* seg = s->endSegment();
if(!seg)
seg = score->lastSegment()->prev1MM(SegmentType::ChordRest);
@@ -135,11 +135,11 @@ void ScoreAccessibility::currentInfoChan
s->type() != ElementType::TIE )
seg = seg->prev1MM(SegmentType::ChordRest);
- bar_beat = barbeat(seg);
+ bar_beat = seg->barbeat();
barsAndBeats += "; " + tr("End Measure: %1; End Beat: %2").arg(QString::number(bar_beat.first)).arg(QString::number(bar_beat.second));
}
else {
- std::pair<int, float>bar_beat = barbeat(el);
+ std::pair<int, float>bar_beat = el->barbeat();
if (bar_beat.first) {
barsAndBeats += " " + tr("Measure: %1").arg(QString::number(bar_beat.first));
if (bar_beat.second)
@@ -149,12 +149,12 @@ void ScoreAccessibility::currentInfoChan
QString rez = e->accessibleInfo();
if (!barsAndBeats.isEmpty())
- rez += "; " + barsAndBeats;
+ rez += ";" + barsAndBeats;
QString staff = "";
if (e->staffIdx() + 1) {
staff = tr("Staff %1").arg(QString::number(e->staffIdx() + 1));
- rez = QString("%1; %2").arg(rez).arg(staff);
+ rez += "; " + tr("Staff: %1").arg(QString::number(e->staffIdx() + 1));
}
statusBarLabel->setText(rez);
@@ -165,7 +165,7 @@ void ScoreAccessibility::currentInfoChan
QString barsAndBeats = "";
std::pair<int, float> bar_beat;
- bar_beat = barbeat(score->selection().startSegment());
+ bar_beat = score->selection().startSegment()->barbeat();
barsAndBeats += " " + tr("Start Measure: %1; Start Beat: %2").arg(QString::number(bar_beat.first)).arg(QString::number(bar_beat.second));
Segment* endSegment = score->selection().endSegment();
@@ -174,7 +174,7 @@ void ScoreAccessibility::currentInfoChan
else
endSegment = endSegment->prev1MM();
- bar_beat = barbeat(endSegment);
+ bar_beat = endSegment->barbeat();
barsAndBeats += " " + tr("End Measure: %1; End Beat: %2").arg(QString::number(bar_beat.first)).arg(QString::number(bar_beat.second));
statusBarLabel->setText(tr("Range Selection") + barsAndBeats);
score->setAccessibleInfo(tr("Range Selection") + barsAndBeats);
@@ -217,36 +217,4 @@ void ScoreAccessibility::updateAccessibi
QAccessibleValueChangeEvent ev(obj, w->score()->accessibleInfo());
QAccessible::updateAccessibility(&ev);
}
-
-std::pair<int, float> ScoreAccessibility::barbeat(Element *e)
- {
- if (!e) {
- return std::pair<int, float>(0, 0.0F);
- }
-
- int bar = 0;
- int beat = 0;
- int ticks = 0;
- TimeSigMap* tsm = e->score()->sigmap();
- Element* p = e;
- int ticksB = ticks_beat(tsm->timesig(0).timesig().denominator());
- while(p && p->type() != ElementType::SEGMENT && p->type() != ElementType::MEASURE)
- p = p->parent();
-
- if (!p) {
- return std::pair<int, float>(0, 0.0F);
- }
- else if (p->type() == ElementType::SEGMENT) {
- Segment* seg = static_cast<Segment*>(p);
- tsm->tickValues(seg->tick().ticks(), &bar, &beat, &ticks);
- ticksB = ticks_beat(tsm->timesig(seg->tick().ticks()).timesig().denominator());
- }
- else if (p->type() == ElementType::MEASURE) {
- Measure* m = static_cast<Measure*>(p);
- bar = m->no();
- beat = -1;
- ticks = 0;
- }
- return pair<int,float>(bar + 1, beat + 1 + ticks / static_cast<float>(ticksB));
- }
}
--- a/mscore/scoreaccessibility.h
+++ b/mscore/scoreaccessibility.h
@@ -39,7 +39,6 @@ class ScoreAccessibility : public QObjec
QMainWindow* mainWindow;
QLabel* statusBarLabel;
ScoreAccessibility(QMainWindow* statusBar);
- std::pair<int, float>barbeat(Element* e);
public:
~ScoreAccessibility();
|