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
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <richard.bown@ferventsoftware.com>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "PitchDragLabel.h"
#include "base/NotationRules.h"
#include "base/NotationTypes.h"
#include "gui/editors/notation/NotePixmapFactory.h"
#include <tqcanvas.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqsize.h>
#include <tqwidget.h>
namespace Rosegarden
{
PitchDragLabel::PitchDragLabel(TQWidget *tqparent,
int defaultPitch,
bool defaultSharps) :
TQWidget(tqparent),
m_pitch(defaultPitch),
m_usingSharps(defaultSharps),
m_clickedY(0),
m_clicked(false),
m_npf(new NotePixmapFactory())
{
calculatePixmap();
}
PitchDragLabel::~PitchDragLabel()
{
delete m_npf;
}
void
PitchDragLabel::slotSetPitch(int p)
{
bool up = (p > m_pitch);
m_usingSharps = up;
if (m_pitch == p)
return ;
m_pitch = p;
calculatePixmap();
emitPitchChange();
paintEvent(0);
}
void
PitchDragLabel::slotSetPitch(int pitch, int octave, int step)
{
if (m_pitch == pitch)
return ;
m_pitch = pitch;
calculatePixmap(pitch, octave, step);
emit pitchChanged(pitch);
emit pitchChanged(pitch, octave, step);
paintEvent(0);
}
void
PitchDragLabel::mousePressEvent(TQMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
m_clickedY = e->y();
m_clickedPitch = m_pitch;
m_clicked = true;
emit preview(m_pitch);
}
}
void
PitchDragLabel::mouseMoveEvent(TQMouseEvent *e)
{
if (m_clicked) {
int y = e->y();
int diff = y - m_clickedY;
int pitchDiff = diff * 4 / m_npf->getLineSpacing();
int newPitch = m_clickedPitch - pitchDiff;
if (newPitch < 0)
newPitch = 0;
if (newPitch > 127)
newPitch = 127;
if (m_pitch != newPitch) {
bool up = (newPitch > m_pitch);
m_pitch = newPitch;
m_usingSharps = up;
calculatePixmap();
emit pitchDragged(m_pitch);
if (up)
{
// use sharps
emit pitchDragged(m_pitch, (int)(((long)m_pitch) / 12),
steps_Cmajor_with_sharps[m_pitch % 12]);
}
else
{
// use flats
emit pitchDragged(m_pitch, (int)(((long)m_pitch) / 12),
steps_Cmajor_with_flats[m_pitch % 12]);
}
emit preview(m_pitch);
paintEvent(0);
}
}
}
void
PitchDragLabel::mouseReleaseEvent(TQMouseEvent *e)
{
mouseMoveEvent(e);
emitPitchChange();
m_clicked = false;
}
void
PitchDragLabel::emitPitchChange()
{
emit pitchChanged(m_pitch);
Pitch newPitch(m_pitch);
if (m_usingSharps)
{
Rosegarden::Key key = Rosegarden::Key("C major");
emit pitchDragged(m_pitch, newPitch.getOctave(0), newPitch.getNoteInScale(key));
}
else
{
Rosegarden::Key key = Rosegarden::Key("A minor");
emit pitchDragged(m_pitch, newPitch.getOctave(0), (newPitch.getNoteInScale(key) + 5) % 7);
}
}
void
PitchDragLabel::wheelEvent(TQWheelEvent *e)
{
if (e->delta() > 0) {
if (m_pitch < 127) {
++m_pitch;
m_usingSharps = true;
calculatePixmap();
emitPitchChange();
emit preview(m_pitch);
paintEvent(0);
}
} else {
if (m_pitch > 0) {
--m_pitch;
m_usingSharps = false;
calculatePixmap();
emitPitchChange();
emit preview(m_pitch);
paintEvent(0);
}
}
}
void
PitchDragLabel::paintEvent(TQPaintEvent *)
{
TQPainter paint(this);
paint.fillRect(0, 0, width(), height(), paint.backgroundColor());
int x = width() / 2 - m_pixmap.width() / 2;
if (x < 0)
x = 0;
int y = height() / 2 - m_pixmap.height() / 2;
if (y < 0)
y = 0;
paint.drawPixmap(x, y, m_pixmap);
}
TQSize
PitchDragLabel::tqsizeHint() const
{
return TQSize(150, 135);
}
void
PitchDragLabel::calculatePixmap(int pitch, int octave, int step) const
{
std::string clefType = Clef::Treble;
int octaveOffset = 0;
if (m_pitch > 94) {
octaveOffset = 2;
} else if (m_pitch > 82) {
octaveOffset = 1;
} else if (m_pitch < 60) {
clefType = Clef::Bass;
if (m_pitch < 24) {
octaveOffset = -2;
} else if (m_pitch < 36) {
octaveOffset = -1;
}
}
TQCanvasPixmap *pmap = m_npf->makePitchDisplayPixmap
(m_pitch,
Clef(clefType, octaveOffset),
octave, step);
m_pixmap = *pmap;
delete pmap;
}
void
PitchDragLabel::calculatePixmap() const
{
std::string clefType = Clef::Treble;
int octaveOffset = 0;
if (m_pitch > 94) {
octaveOffset = 2;
} else if (m_pitch > 82) {
octaveOffset = 1;
} else if (m_pitch < 60) {
clefType = Clef::Bass;
if (m_pitch < 24) {
octaveOffset = -2;
} else if (m_pitch < 36) {
octaveOffset = -1;
}
}
TQCanvasPixmap *pmap = m_npf->makePitchDisplayPixmap
(m_pitch,
Clef(clefType, octaveOffset),
m_usingSharps);
m_pixmap = *pmap;
delete pmap;
}
}
#include "PitchDragLabel.moc"
|