1
//=========================================================
4
// $Id: master.cpp,v 1.1.1.1 2003/10/29 10:06:13 wschweer Exp $
5
// (C) Copyright 2000 Werner Schweer (ws@seh.de)
6
//=========================================================
15
#include "scrollscale.h"
18
#include "midieditor.h"
20
#include "midithread.h"
22
#include <qlineedit.h>
23
#include <qpopupmenu.h>
25
extern void drawTickRaster(QPainter& p, int x, int y,
26
int w, int h, int quant);
28
//---------------------------------------------------------
30
//---------------------------------------------------------
32
Master::Master(MidiEditor* e, QWidget* parent, int xmag, int ymag)
33
: View(parent, xmag, ymag)
41
setMouseTracking(true);
42
connect(song, SIGNAL(posChanged(int, int, bool)), this, SLOT(setPos(int, int, bool)));
43
connect(song, SIGNAL(songChanged(int)), this, SLOT(redraw()));
46
//---------------------------------------------------------
48
//---------------------------------------------------------
50
void Master::setPos(int idx, int val, bool adjustScrollbar)
55
int opos = mapx(pos[idx]);
58
if (adjustScrollbar && idx == 0) {
59
switch (song->follow()) {
63
if (npos >= width()) {
64
int ppos = val - rmapxDev(width()/4);
67
emit followEvent(ppos);
68
opos = mapx(pos[idx]);
72
int ppos = val - rmapxDev(width()*3/4);
75
emit followEvent(ppos);
76
opos = mapx(pos[idx]);
80
case Song::CONTINUOUS:
81
if (npos > (width()*5)/8) {
82
int ppos = pos[idx] - rmapxDev(width()*5/8);
85
emit followEvent(ppos);
86
opos = mapx(pos[idx]);
89
else if (npos < (width()*3)/8) {
90
int ppos = pos[idx] - rmapxDev(width()*3/8);
93
emit followEvent(ppos);
94
opos = mapx(pos[idx]);
112
redraw(QRect(x, 0, w, height()));
115
//---------------------------------------------------------
117
//---------------------------------------------------------
119
void Master::leaveEvent(QEvent*)
121
emit tempoChanged(-1);
122
emit timeChanged(-1);
125
//---------------------------------------------------------
127
//---------------------------------------------------------
129
void Master::pdraw(QPainter& p, const QRect& rect)
131
View::pdraw(p, rect); // calls draw()
136
int w = rect.width() + 2;
137
int h = rect.height();
140
//---------------------------------------------------
142
//---------------------------------------------------
144
const TempoList* tl = &tempomap;
145
for (ciTEvent i = tl->begin(); i != tl->end(); ++i) {
146
TEvent* e = i->second;
147
int etick = mapx(i->first);
148
int stick = mapx(i->second->tick);
149
int tempo = mapy(280000 - int(60000000000.0/(e->tempo)));
154
p.fillRect(stick, tempo, etick-stick, wh, blue);
158
//---------------------------------------------------
160
//---------------------------------------------------
162
int xp = mapx(pos[0]);
163
if (xp >= x && xp < x+w) {
165
p.drawLine(xp, y, xp, y+h);
168
if (xp >= x && xp < x+w) {
170
p.drawLine(xp, y, xp, y+h);
173
if (xp >= x && xp < x+w) {
175
p.drawLine(xp, y, xp, y+h);
179
//---------------------------------------------------------
181
//---------------------------------------------------------
183
void Master::draw(QPainter& p, const QRect& rect)
185
drawTickRaster(p, rect.x(), rect.y(),
186
rect.width(), rect.height(), 0);
189
//---------------------------------------------------------
190
// viewMousePressEvent
191
//---------------------------------------------------------
193
void Master::viewMousePressEvent(QMouseEvent* event)
195
start = event->pos();
196
Tool activeTool = tool;
197
// bool shift = event->state() & ShiftButton;
199
switch (activeTool) {
201
drag = DRAG_LASSO_START;
207
newVal(start.x(), start.x(), start.y());
213
deleteVal(start.x(), start.x());
221
//---------------------------------------------------------
222
// viewMouseMoveEvent
223
//---------------------------------------------------------
225
void Master::viewMouseMoveEvent(QMouseEvent* event)
227
QPoint pos = event->pos();
228
// QPoint dist = pos - start;
229
// bool moving = dist.y() >= 3 || dist.y() <= 3 || dist.x() >= 3 || dist.x() <= 3;
233
newVal(start.x(), pos.x(), pos.y());
238
deleteVal(start.x(), pos.x());
245
emit tempoChanged(280000 - event->y());
246
emit timeChanged(event->x());
249
//---------------------------------------------------------
250
// viewMouseReleaseEvent
251
//---------------------------------------------------------
253
void Master::viewMouseReleaseEvent(QMouseEvent*)
259
song->endUndo(SC_TEMPO);
267
//---------------------------------------------------------
269
//---------------------------------------------------------
271
bool Master::deleteVal1(int x1, int x2)
273
bool songChanged = false;
275
TempoList* tl = &tempomap;
276
for (iTEvent i = tl->begin(); i != tl->end(); ++i) {
283
if (ii != tl->end()) {
284
int tempo = ii->second->tempo;
285
midiThread->msgDeleteTempo(i->first, tempo, false);
292
void Master::deleteVal(int x1, int x2)
294
if (deleteVal1(editor->rasterVal1(x1), x2))
298
//---------------------------------------------------------
300
//---------------------------------------------------------
302
void Master::setTool(int t)
309
setCursor(QCursor(*pencilIcon, 4, 15));
312
setCursor(QCursor(arrowCursor));
317
//---------------------------------------------------------
319
//---------------------------------------------------------
321
void Master::newVal(int x1, int x2, int y)
323
int xx1 = editor->rasterVal1(x1);
324
int xx2 = editor->rasterVal2(x2);
331
deleteVal1(xx1, xx2);
332
midiThread->msgAddTempo(xx1, int(60000000000.0/(280000 - y)), false);