File: element-barbeat.diff

package info (click to toggle)
musescore2 2.3.2%2Bdfsg4-17
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 170,488 kB
  • sloc: cpp: 262,612; xml: 176,707; sh: 3,377; ansic: 1,246; python: 356; makefile: 224; perl: 82; pascal: 78
file content (213 lines) | stat: -rw-r--r-- 8,636 bytes parent folder | download | duplicates (3)
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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.
 .
 For pre-3.1, backports commit 29cd62df329525da59d01a54796171076acc9eb1
 from upstream, to fix bad barbeat counting in cut time.
Author: mirabilos <m@mirbsd.org>
Forwarded: https://github.com/musescore/MuseScore/pull/5096

--- a/libmscore/element.cpp
+++ b/libmscore/element.cpp
@@ -60,6 +60,7 @@
 #include "rest.h"
 #include "score.h"
 #include "segment.h"
+#include "sig.h"
 #include "slur.h"
 #include "spacer.h"
 #include "staff.h"
@@ -1998,4 +1999,53 @@ bool Element::isUserModified() const
       return !visible() || !userOff().isNull() || (color() != MScore::defaultColor);
       }
 
+//---------------------------------------------------------
+//   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() != Element::Type::SEGMENT && p->type() != Element::Type::MEASURE)
+            p = p->parent();
+
+      if (!p) {
+            return std::pair<int, float>(0, 0);
+            }
+      else if (p->type() == Element::Type::SEGMENT) {
+            const Segment* seg = static_cast<const Segment*>(p);
+            tsm->tickValues(seg->tick(), &bar, &beat, &ticks);
+            ticksB = ticks_beat(tsm->timesig(seg->tick()).timesig().denominator());
+            }
+      else if (p->type() == Element::Type::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 += "; " + tr("Measure: %1").arg(QString::number(bar_beat.first));
+            if (bar_beat.second)
+                  barsAndBeats += "; " + tr("Beat: %1").arg(QString::number(bar_beat.second));
+            }
+      if (staffIdx() + 1)
+            barsAndBeats += "; " + tr("Staff: %1").arg(QString::number(staffIdx() + 1));
+      return barsAndBeats;
+      }
 }
--- a/libmscore/element.h
+++ b/libmscore/element.h
@@ -327,6 +327,8 @@ class Element : public QObject, public S
       Element* findMeasure();
 
       qreal spatium() const;
+      std::pair<int, float>barbeat() const;
+      QString accessibleBarbeat() const;
 
       bool selected() const                   { return _selected;   }
       virtual void setSelected(bool f)        { _selected = f;      }
--- a/libmscore/sig.cpp
+++ b/libmscore/sig.cpp
@@ -19,7 +19,7 @@ namespace Ms {
 //   ticks_beat
 //---------------------------------------------------------
 
-static int ticks_beat(int n)
+int ticks_beat(int n)
       {
       int m = (MScore::division * 4) / n;
       if ((MScore::division * 4) % n) {
--- a/libmscore/sig.h
+++ b/libmscore/sig.h
@@ -21,6 +21,8 @@ namespace Ms {
 class Xml;
 class XmlReader;
 
+int ticks_beat(int n);
+
 //-------------------------------------------------------------------
 //   BeatType
 //-------------------------------------------------------------------
--- a/mscore/scoreaccessibility.cpp
+++ b/mscore/scoreaccessibility.cpp
@@ -110,8 +110,8 @@ void ScoreAccessibility::currentInfoChan
             std::pair<int, float> bar_beat;
             if (el->isSpanner()){
                   Spanner* s = static_cast<Spanner*>(el);
-                  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));
+                  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(Segment::Type::ChordRest);
@@ -121,11 +121,11 @@ void ScoreAccessibility::currentInfoChan
                       s->type() != Element::Type::TIE                                                )
                         seg = seg->prev1MM(Segment::Type::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)
@@ -135,12 +135,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);
@@ -151,7 +151,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();
 
@@ -160,7 +160,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);
@@ -204,34 +204,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);
-            }
-
-      int bar = 0;
-      int beat = 0;
-      int ticks = 0;
-      TimeSigMap* tsm = e->score()->sigmap();
-      Element* p = e;
-      while(p && p->type() != Element::Type::SEGMENT && p->type() != Element::Type::MEASURE)
-            p = p->parent();
-
-      if (!p) {
-            return std::pair<int, float>(0, 0);
-            }
-      else if (p->type() == Element::Type::SEGMENT) {
-            Segment* seg = static_cast<Segment*>(p);
-            tsm->tickValues(seg->tick(), &bar, &beat, &ticks);
-            }
-      else if (p->type() == Element::Type::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>(MScore::division));
-      }
 }
--- a/mscore/scoreaccessibility.h
+++ b/mscore/scoreaccessibility.h
@@ -30,7 +30,6 @@ private:
       QMainWindow* mainWindow;
       QLabel* statusBarLabel;
       ScoreAccessibility(QMainWindow* statusBar);
-      std::pair<int, float>barbeat(Element* e);
 
 public:
       ~ScoreAccessibility();