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