MuseScore  3.4
Music composition and notation
omrpage.h
Go to the documentation of this file.
1 //=============================================================================
2 // MusE Reader
3 // Music Score Reader
4 //
5 // Copyright (C) 2010 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __OMRPAGE_H__
21 #define __OMRPAGE_H__
22 
23 #include "libmscore/mscore.h"
24 #include "libmscore/durationtype.h"
25 #include "libmscore/fraction.h"
26 #include "libmscore/clef.h"
27 #include "libmscore/xml.h"
28 #include "libmscore/sym.h"
29 
30 namespace Ms {
31 
32 class Omr;
33 class Score;
34 class XmlWriter;
35 class XmlReader;
36 class Pattern;
37 class OmrPage;
38 
39 
40 //---------------------------------------------------------
41 // HLine
42 //---------------------------------------------------------
43 
44 struct HLine {
45  int x1, x2, y;
46  HLine() {}
47  HLine(int a, int b, int c) : x1(a), x2(b), y(c) {}
48  };
49 
50 //---------------------------------------------------------
51 // OmrPattern
52 //---------------------------------------------------------
53 
54 class OmrPattern : public QRect {
55  public:
56  OmrPattern() : QRect(), sym(SymId::noSym), prob(0.0) {}
58  double prob;
59  };
60 
61 //---------------------------------------------------------
62 // OmrClef
63 //---------------------------------------------------------
64 
65 class OmrClef : public OmrPattern {
66  public:
68  OmrClef(const OmrPattern& p) : OmrPattern(p) {}
69  ClefType type = ClefType::G;//CLEF_G;
70  };
71 
72 //---------------------------------------------------------
73 // OmrNote
74 // object on staff line
75 //---------------------------------------------------------
76 
77 class OmrNote : public OmrPattern {
78  public:
79  int line;
80  };
81 
82 //---------------------------------------------------------
83 // OmrChord
84 //---------------------------------------------------------
85 
86 class OmrChord {
87  public:
89  QList<OmrNote*> notes;
90  };
91 
92 //---------------------------------------------------------
93 // OmrTimesig
94 //---------------------------------------------------------
95 
96 class OmrTimesig : public QRect {
97  public:
99  OmrTimesig(const QRect& r) : QRect(r) {}
101  };
102 
103 //---------------------------------------------------------
104 // OmrKeySig
105 //---------------------------------------------------------
106 
107 class OmrKeySig : public QRect {
108  public:
110  OmrKeySig(const QRect& r) : QRect(r) {}
111  int type = 0; // -7 -> +7
112  };
113 
114 //---------------------------------------------------------
115 // OmrMeasure
116 //---------------------------------------------------------
117 
118 class OmrMeasure {
119  int _x1, _x2;
120  QList<QList<OmrChord>> _chords; // list of notes for every staff
121  OmrTimesig* _timesig = 0;
122 
123  public:
125  OmrMeasure(int x1, int x2) : _x1(x1), _x2(x2) {}
126  QList<QList<OmrChord>>& chords() { return _chords; }
127  const QList<QList<OmrChord>>& chords() const { return _chords; }
128  int x1() const { return _x1; }
129  int x2() const { return _x2; }
130  OmrTimesig* timesig() const { return _timesig; }
131  void setTimesig(OmrTimesig* ts) { _timesig = ts;}
132  };
133 
134 //---------------------------------------------------------
135 // OmrStaff
136 // rectangle of staff lines
137 //---------------------------------------------------------
138 
139 class OmrStaff : public QRect {
140  QList<OmrNote*> _notes;
143 
144  public:
145  OmrStaff() : QRect() {}
146  OmrStaff(const QRect& r) : QRect(r) {}
147  OmrStaff(int x, int y, int w, int h) : QRect(x, y, w, h) {}
148  QList<OmrNote*>& notes() { return _notes; }
149  const QList<OmrNote*>& notes() const { return _notes; }
150  OmrClef clef() const { return _clef; }
151  void setClef(const OmrClef& c) { _clef = c; }
152  OmrKeySig keySig() const { return _keySig; }
153  void setKeySig(const OmrKeySig& s) { _keySig = s; };
154  };
155 
156 //---------------------------------------------------------
157 // OmrSystem
158 //---------------------------------------------------------
159 
160 class OmrSystem {
162  QList<OmrStaff> _staves;
163  QList<OmrMeasure>_measures;
164 
165  void searchNotes(QList<OmrNote*>*, int x1, int x2, int y, int line);
166 
167  public:
168  OmrSystem(OmrPage* p) { _page = p; }
169 
170  const QList<OmrStaff>& staves() const { return _staves; }
171  QList<OmrStaff>& staves() { return _staves; }
172  QList<OmrMeasure>& measures() { return _measures; }
173  const QList<OmrMeasure>& measures() const { return _measures; }
174 
175  QList<QLine> barLines;
176 
177  void searchSysBarLines();
178  float searchBarLinesvar(int n_staff, int **note_labels);
179  void searchNotes();
180  void searchNotes(int *note_labels, int ran);
181  };
182 
183 //---------------------------------------------------------
184 // OmrPage
185 //---------------------------------------------------------
186 
187 class OmrPage {
189  QImage _image;
190  double _spatium;
191  double _ratio;
192 
193  int cropL, cropR; // crop values in words (32 bit) units
194  int cropT, cropB; // crop values in pixel units
195 
196  QList<QRect> _slices;
197  QList<OmrStaff> staves;
198  QList<HLine> slines;
199 
200  QList<QLine> lines;
201  QList<OmrSystem> _systems;
202 
203  void removeBorder();
204  void crop();
205  void slice();
206  double skew(const QRect&);
207  void deSkew();
208  void getStaffLines();
209  void getRatio();
210  double xproject2(int y);
211  int xproject(const uint* p, int wl);
212  void radonTransform(ulong* projection, int w, int n, const QRect&);
213  OmrTimesig* searchTimeSig(OmrSystem* system);
214  OmrClef searchClef(OmrSystem* system, OmrStaff* staff);
215  void searchKeySig(OmrSystem* system, OmrStaff* staff);
216  OmrPattern searchPattern(const std::vector<Pattern*>& pl, int y, int x1, int x2);
217 
218  public:
219  OmrPage(Omr* _parent);
220  void setImage(const QImage& i) { _image = i; }
221  const QImage& image() const { return _image; }
222  QImage& image() { return _image; }
223  void read();
224  int width() const { return _image.width(); }
225  int height() const { return _image.height(); }
226  const uint* scanLine(int y) const { return (const uint*)_image.scanLine(y); }
227  const uint* bits() const { return (const uint*)_image.bits(); }
228  int wordsPerLine() const { return (_image.bytesPerLine() + 3)/4; }
229 
230  const QList<QLine>& sl() { return lines; }
231  const QList<HLine>& l() { return slines; }
232 
233  const QList<QRect>& slices() const { return _slices; }
234  double spatium() const { return _spatium; }
235  double ratio() const {return _ratio;}
236  double staffDistance() const;
237  double systemDistance() const;
238  void readHeader(Score* score);
239  void readBarLines();
240  float searchBarLines(int start_staff, int end_staff);
241  void identifySystems();
242 
243  const QList<OmrSystem>& systems() const { return _systems; }
244  //QList<OmrSystem>& systems() { return _systems; }
245  OmrSystem* system(int idx) { return &_systems[idx]; }
246 
247 
248  void write(XmlWriter&) const;
249  void read(XmlReader&);
250  bool dot(int x, int y) const;
251  bool isBlack(int x, int y) const;
252  };
253 
254 }
255 
256 #endif
257 
258 
OmrMeasure(int x1, int x2)
Definition: omrpage.h:125
void setKeySig(const OmrKeySig &s)
Definition: omrpage.h:153
Definition: durationtype.h:28
const uint * bits() const
Definition: omrpage.h:227
Definition: omrpage.h:65
QList< QLine > barLines
Definition: omrpage.h:175
Definition: omrpage.h:139
Definition: xml.h:67
OmrStaff(const QRect &r)
Definition: omrpage.h:146
Definition: omr.h:124
OmrClef()
Definition: omrpage.h:67
OmrPage * _page
Definition: omrpage.h:161
QList< OmrSystem > _systems
Definition: omrpage.h:201
QList< OmrNote * > _notes
Definition: omrpage.h:140
void setTimesig(OmrTimesig *ts)
Definition: omrpage.h:131
OmrStaff()
Definition: omrpage.h:145
QList< QList< OmrChord > > _chords
Definition: omrpage.h:120
const QList< OmrSystem > & systems() const
Definition: omrpage.h:243
HLine(int a, int b, int c)
Definition: omrpage.h:47
HLine()
Definition: omrpage.h:46
double ratio() const
Definition: omrpage.h:235
Definition: omrpage.h:54
Definition: omrpage.h:118
SymId
Definition: sym.h:30
const QList< QList< OmrChord > > & chords() const
Definition: omrpage.h:127
OmrTimesig * timesig() const
Definition: omrpage.h:130
const QList< HLine > & l()
Definition: omrpage.h:231
int x1
Definition: omrpage.h:45
OmrMeasure()
Definition: omrpage.h:124
OmrPattern()
Definition: omrpage.h:56
OmrClef clef() const
Definition: omrpage.h:150
const QList< OmrStaff > & staves() const
Definition: omrpage.h:170
OmrClef(const OmrPattern &p)
Definition: omrpage.h:68
Definition of classes Clef.
int cropT
Definition: omrpage.h:194
double spatium() const
Definition: omrpage.h:234
Definition: score.h:391
const QList< QRect > & slices() const
Definition: omrpage.h:233
int x1() const
Definition: omrpage.h:128
OmrSystem(OmrPage *p)
Definition: omrpage.h:168
double _ratio
Definition: omrpage.h:191
int cropR
Definition: omrpage.h:193
Fraction timesig
Definition: omrpage.h:100
int y
Definition: omrpage.h:45
Omr * _omr
Definition: omrpage.h:188
OmrKeySig _keySig
Definition: omrpage.h:142
Definition: omrpage.h:77
const QList< QLine > & sl()
Definition: omrpage.h:230
double _spatium
Definition: omrpage.h:190
int wordsPerLine() const
Definition: omrpage.h:228
QList< OmrStaff > & staves()
Definition: omrpage.h:171
QList< QList< OmrChord > > & chords()
Definition: omrpage.h:126
QList< OmrMeasure > & measures()
Definition: omrpage.h:172
int width() const
Definition: omrpage.h:224
OmrTimesig()
Definition: omrpage.h:98
OmrStaff(int x, int y, int w, int h)
Definition: omrpage.h:147
QList< QRect > _slices
Definition: omrpage.h:196
OmrKeySig keySig() const
Definition: omrpage.h:152
QList< OmrStaff > staves
Definition: omrpage.h:197
SymId sym
Definition: omrpage.h:57
Definition: aeolus.cpp:26
OmrKeySig(const QRect &r)
Definition: omrpage.h:110
QImage & image()
Definition: omrpage.h:222
OmrSystem * system(int idx)
Definition: omrpage.h:245
QList< OmrMeasure > _measures
Definition: omrpage.h:163
OmrKeySig()
Definition: omrpage.h:109
Definition: xml.h:218
double prob
Definition: omrpage.h:58
Definition: xmlwriter.h:26
int line
Definition: omrpage.h:79
OmrClef _clef
Definition: omrpage.h:141
QList< QLine > lines
Definition: omrpage.h:200
QList< HLine > slines
Definition: omrpage.h:198
Definition: xmlreader.h:28
TDuration duration
Definition: omrpage.h:88
int _x2
Definition: omrpage.h:119
QImage _image
Definition: omrpage.h:189
QList< OmrNote * > notes
Definition: omrpage.h:89
Definition: omrpage.h:96
void setClef(const OmrClef &c)
Definition: omrpage.h:151
ClefType
Definition: clef.h:37
Definition: fraction.h:46
QList< OmrStaff > _staves
Definition: omrpage.h:162
const QList< OmrNote * > & notes() const
Definition: omrpage.h:149
int x2
Definition: omrpage.h:45
const QImage & image() const
Definition: omrpage.h:221
Definition: omrpage.h:107
const uint * scanLine(int y) const
Definition: omrpage.h:226
OmrTimesig(const QRect &r)
Definition: omrpage.h:99
void setImage(const QImage &i)
Definition: omrpage.h:220
Definition: omrpage.h:187
QList< OmrNote * > & notes()
Definition: omrpage.h:148
int x2() const
Definition: omrpage.h:129
int height() const
Definition: omrpage.h:225
Definition: omrpage.h:44
const QList< OmrMeasure > & measures() const
Definition: omrpage.h:173
Definition: omrpage.h:160
Definition: omrpage.h:86