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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
//=========================================================
// MusE
// Linux Music Editor
// scoreedit.cpp
// (C) Copyright 2011 Florian Jung (florian.a.jung@web.de)
//=========================================================
#ifndef __SCOREEDIT_H__
#define __SCOREEDIT_H__
#include <QCloseEvent>
#include <QResizeEvent>
#include <QLabel>
#include <QKeyEvent>
#include <QPainter>
#include <QPixmap>
#include <values.h>
#include "noteinfo.h"
#include "cobject.h"
#include "midieditor.h"
#include "tools.h"
#include "event.h"
#include "view.h"
#include <set>
#include <map>
#include <list>
#include <vector>
using std::set;
using std::pair;
using std::map;
using std::list;
using std::vector;
class MidiPart;
class TimeLabel;
class PitchLabel;
class QLabel;
class PianoCanvas;
class MTScale;
class Track;
class QToolButton;
class QToolBar;
class QPushButton;
class CtrlEdit;
class Splitter;
class PartList;
class Toolbar1;
class Xml;
class QuantConfig;
class ScrollScale;
class Part;
class SNode;
class QMenu;
class QAction;
class QWidget;
class QScrollBar;
class MidiTrackInfo;
class QScrollArea;
//---------------------------------------------------------
// ScoreEdit
//---------------------------------------------------------
class ScoreEdit : public MidiEditor
{
Q_OBJECT
private:
private slots:
signals:
void deleted(unsigned long);
public slots:
CtrlEdit* addCtrl() {return NULL;}; //TODO does nothing
public:
ScoreEdit(PartList*, QWidget* parent = 0, const char* name = 0, unsigned initPos = MAXINT);
~ScoreEdit();
static void readConfiguration(Xml&){}; //TODO does nothing
static void writeConfiguration(int, Xml&){}; //TODO does nothing
};
enum tonart_t
{
SHARP_BEGIN,
C, // C or am, uses # for "black keys"
G,
D,
A,
E,
H,
FIS, //produces a #E (sounds like a F)
SHARP_END,
B_BEGIN,
C_B, // the same as C, but uses b for "black keys"
F,
ES,
AS,
DES,
GES, //sounds like FIS, but uses b instead of #
B_END
};
enum stem_t
{
UPWARDS,
DOWNWARDS
};
enum vorzeichen_t
{
B=-1,
NONE=0,
SHARP=1
};
struct note_pos_t
{
int height; // 0 means "C-line", 1 "D-line" and so on
vorzeichen_t vorzeichen;
bool operator== (const note_pos_t& that) const
{
return (this->height==that.height) && (this->vorzeichen == that.vorzeichen);
}
};
bool operator< (const note_pos_t& a, const note_pos_t& b);
class FloEvent
{
public:
enum typeEnum { NOTE_ON = 30, NOTE_OFF = 10, BAR = 20, TIME_SIG=23, KEY_CHANGE=26 }; //the order matters!
typeEnum type;
unsigned tick;
Part* source_part;
Event* source_event;
int pitch;
mutable int vel;
mutable int len;
int num;
int denom;
tonart_t tonart;
FloEvent(unsigned ti, int p,int v,int l,typeEnum t, Part* part=NULL, Event* event=NULL)
{
pitch=p;
vel=v;
len=l;
type= t;
tick=ti;
source_event=event;
source_part=part;
}
FloEvent(unsigned ti, typeEnum t, int num_, int denom_)
{
type=t;
num=num_;
denom=denom_;
tick=ti;
source_event=NULL;
source_part=NULL;
}
FloEvent(unsigned ti, typeEnum t, tonart_t k)
{
type=t;
tonart=k;
tick=ti;
source_event=NULL;
source_part=NULL;
}
};
class FloItem
{
public:
enum typeEnum { NOTE=21, REST=22, NOTE_END=01, REST_END=02, BAR =10, TIME_SIG=13, KEY_CHANGE=16}; //the order matters!
typeEnum type;
unsigned begin_tick;
Event* source_event;
Part* source_part;
note_pos_t pos;
int len;
int dots;
bool tied;
bool already_grouped;
int num;
int denom;
tonart_t tonart;
mutable stem_t stem;
mutable int shift;
mutable bool ausweich;
mutable bool is_tie_dest;
mutable int tie_from_x;
mutable int x;
mutable int y;
mutable int stem_x;
mutable QPixmap* pix;
QRect bbox() const;
FloItem(typeEnum t, note_pos_t p, int l=0,int d=0, bool ti=false, unsigned beg=0, Part* part=NULL, Event* event=NULL)
{
pos=p;
dots=d;
len=l;
type=t;
already_grouped=false;
tied=ti;
shift=0;
ausweich=false;
is_tie_dest=false;
begin_tick=beg;
source_event=event;
source_part=part;
}
FloItem(typeEnum t, int num_, int denom_)
{
type=t;
num=num_;
denom=denom_;
begin_tick=-1;
source_event=NULL;
source_part=NULL;
}
FloItem(typeEnum t, tonart_t k)
{
type=t;
tonart=k;
begin_tick=-1;
source_event=NULL;
source_part=NULL;
}
FloItem(typeEnum t)
{
type=t;
already_grouped=false;
tied=false;
shift=0;
ausweich=false;
is_tie_dest=false;
begin_tick=-1;
source_event=NULL;
source_part=NULL;
}
FloItem()
{
already_grouped=false;
tied=false;
shift=0;
ausweich=false;
is_tie_dest=false;
begin_tick=-1;
source_event=NULL;
source_part=NULL;
}
bool operator==(const FloItem& that)
{
if (this->type != that.type) return false;
switch(type)
{
case NOTE:
case REST:
case NOTE_END:
case REST_END:
return (this->pos == that.pos);
//the following may only occurr once in a set
//so we don't search for "the time signature with 4/4
//at t=0", but only for "some time signature at t=0"
//that's why true is returned, and not some conditional
//expression
case BAR:
case KEY_CHANGE:
case TIME_SIG:
return true;
}
}
};
struct floComp
{
bool operator() (const pair<unsigned, FloEvent>& a, const pair<unsigned, FloEvent>& b )
{
if (a.first < b.first) return true;
if (a.first > b.first) return false;
if (a.second.type<b.second.type) return true;
if (a.second.type>b.second.type) return false;
return (a.second.pitch<b.second.pitch);
}
bool operator() (const FloItem& a, const FloItem& b )
{
if (a.type < b.type) return true;
if (a.type > b.type) return false;
switch(a.type)
{
case FloItem::NOTE:
case FloItem::REST:
case FloItem::NOTE_END:
case FloItem::REST_END:
return (a.pos < b.pos);
//the following may only occurr once in a set
//so we don't search for "the time signature with 4/4
//at t=0", but only for "some time signature at t=0"
//that's why true is returned, and not some conditional
//expression
case FloItem::BAR:
case FloItem::KEY_CHANGE:
case FloItem::TIME_SIG:
return false;
}
return (a.pos < b.pos);
}
};
typedef set< pair<unsigned, FloEvent>, floComp > ScoreEventList;
typedef map< unsigned, set<FloItem, floComp> > ScoreItemList;
enum clef_t
{
VIOLIN,
BASS
};
struct note_len_t
{
int len;
int dots;
note_len_t(int l, int d)
{
len=l; dots=d;
}
note_len_t(int l)
{
len=l; dots=0;
}
};
bool operator< (const note_len_t& a,const note_len_t& b);
struct cumulative_t
{
int count;
int cumul;
cumulative_t()
{
count=0;
cumul=0;
}
void add(int v)
{
count++;
cumul+=v;
}
float mean()
{
return (float)cumul/count;
}
};
class ScoreCanvas : public View
{
Q_OBJECT
private:
void load_pixmaps();
ScoreEventList createAppropriateEventList(PartList* pl, Track* track);
note_pos_t note_pos_(int note, tonart_t key);
note_pos_t note_pos (int note, tonart_t key, clef_t clef);
int calc_len(int l, int d);
list<note_len_t> parse_note_len(int len_ticks, int begin_tick, vector<int>& foo, bool allow_dots=true, bool allow_normal=true);
void draw_tie (QPainter& p, int x1, int x4, int yo, bool up=true);
ScoreItemList create_itemlist(ScoreEventList& eventlist);
void process_itemlist(ScoreItemList& itemlist);
void draw_pixmap(QPainter& p, int x, int y, const QPixmap& pm);
void draw_note_lines(QPainter& p);
void draw_items(QPainter& p, ScoreItemList& itemlist, ScoreItemList::iterator from_it, ScoreItemList::iterator to_it);
void draw_items(QPainter& p, ScoreItemList& itemlist, int x1, int x2);
void draw_items(QPainter& p, ScoreItemList& itemlist);
void calc_item_pos(ScoreItemList& itemlist);
list<int> calc_accidentials(tonart_t key, clef_t clef, tonart_t next_key=C);
void draw_timesig(QPainter& p, int x, int y, int num, int denom);
int calc_timesig_width(int num, int denom);
void draw_number(QPainter& p, int x, int y, int n);
int calc_number_width(int n);
int y_to_pitch(int y, int t, clef_t clef);
int y_to_height(int y);
int height_to_pitch(int h, clef_t clef, tonart_t key);
int height_to_pitch(int h, clef_t clef);
tonart_t key_at_tick(int t);
int tick_to_x(int t);
int x_to_tick(int x);
int calc_posadd(int t);
QPixmap pix_whole, pix_half, pix_quarter;
QPixmap pix_r1, pix_r2, pix_r4, pix_r8, pix_r16;
QPixmap pix_dot, pix_flag_up[4], pix_flag_down[4];
QPixmap pix_b, pix_sharp, pix_noacc;
QPixmap pix_num[10];
std::map<int,int> pos_add_list;
ScoreEventList eventlist;
ScoreItemList itemlist;
int x_pos;
Part* curr_part;
int last_len;
int new_len; //when zero or negative, last_len is used
QPoint mouse_down_pos;
bool mouse_down;
enum operation_t
{
NO_OP=0,
BEGIN=1,
LENGTH=2,
PITCH=3
};
operation_t mouse_operation;
operation_t mouse_x_drag_operation;
bool mouse_erases_notes;
bool mouse_inserts_notes;
bool dragging;
Part* dragged_event_part;
Event dragged_event;
int dragged_event_original_pitch;
public slots:
void scroll_event(int);
void song_changed(int);
protected:
virtual void draw(QPainter& p, const QRect& rect);
MidiEditor* editor;
virtual void mousePressEvent (QMouseEvent* event);
virtual void mouseMoveEvent (QMouseEvent* event);
virtual void mouseReleaseEvent (QMouseEvent* event);
public:
ScoreCanvas(MidiEditor*, QWidget*, int, int);
~ScoreCanvas(){};
};
int calc_measure_len(const list<int>& nums, int denom);
vector<int> create_emphasize_list(const list<int>& nums, int denom);
vector<int> create_emphasize_list(int num, int denom);
#endif
|