1
//=========================================================
4
// $Id: master.cpp,v 1.1 2002/01/30 14:10:08 muse Exp $
5
// (C) Copyright 2000 Werner Schweer (ws@seh.de)
6
//=========================================================
14
#include "scrollscale.h"
17
#include "midieditor.h"
19
#include "midithread.h"
21
#include <qlineedit.h>
22
#include <qpopupmenu.h>
24
extern void drawTickRaster(QPainter& p, int x, int y,
25
int w, int h, int quant);
27
//---------------------------------------------------------
29
//---------------------------------------------------------
31
Master::Master(MidiEditor* e, QWidget* parent, int xmag, int ymag)
32
: View(parent, xmag, ymag)
40
setMouseTracking(true);
41
connect(song, SIGNAL(posChanged(int, int, bool)), this, SLOT(setPos(int, int, bool)));
42
connect(song, SIGNAL(songChanged(int)), this, SLOT(redraw()));
45
//---------------------------------------------------------
47
//---------------------------------------------------------
49
void Master::setPos(int idx, int val, bool adjustScrollbar)
54
int opos = mapx(pos[idx]);
57
if (adjustScrollbar && idx == 0) {
58
switch (song->follow()) {
62
if (npos >= width()) {
63
int ppos = val - rmapxDev(width()/4);
66
emit followEvent(ppos);
67
opos = mapx(pos[idx]);
71
int ppos = val - rmapxDev(width()*3/4);
74
emit followEvent(ppos);
75
opos = mapx(pos[idx]);
79
case Song::CONTINUOUS:
80
if (npos > (width()*5)/8) {
81
int ppos = pos[idx] - rmapxDev(width()*5/8);
84
emit followEvent(ppos);
85
opos = mapx(pos[idx]);
88
else if (npos < (width()*3)/8) {
89
int ppos = pos[idx] - rmapxDev(width()*3/8);
92
emit followEvent(ppos);
93
opos = mapx(pos[idx]);
111
redraw(QRect(x, 0, w, height()));
114
//---------------------------------------------------------
116
//---------------------------------------------------------
118
void Master::leaveEvent(QEvent*)
120
emit tempoChanged(-1);
121
emit timeChanged(-1);
124
//---------------------------------------------------------
126
//---------------------------------------------------------
128
void Master::pdraw(QPainter& p, const QRect& rect)
130
View::pdraw(p, rect); // calls draw()
135
int w = rect.width() + 2;
136
int h = rect.height();
139
//---------------------------------------------------
141
//---------------------------------------------------
143
const TempoList* tl = &tempomap;
144
for (ciTEvent i = tl->begin(); i != tl->end(); ++i) {
145
TEvent* e = i->second;
146
int etick = mapx(i->first);
147
int stick = mapx(i->second->tick);
148
int tempo = mapy(280000 - int(60000000000.0/(e->tempo)));
153
p.fillRect(stick, tempo, etick-stick, wh, blue);
157
//---------------------------------------------------
159
//---------------------------------------------------
161
int xp = mapx(pos[0]);
162
if (xp >= x && xp < x+w) {
164
p.drawLine(xp, y, xp, y+h);
167
if (xp >= x && xp < x+w) {
169
p.drawLine(xp, y, xp, y+h);
172
if (xp >= x && xp < x+w) {
174
p.drawLine(xp, y, xp, y+h);
178
//---------------------------------------------------------
180
//---------------------------------------------------------
182
void Master::draw(QPainter& p, const QRect& rect)
184
drawTickRaster(p, rect.x(), rect.y(),
185
rect.width(), rect.height(), 0);
188
//---------------------------------------------------------
189
// viewMousePressEvent
190
//---------------------------------------------------------
192
void Master::viewMousePressEvent(QMouseEvent* event)
194
start = event->pos();
195
Tool activeTool = tool;
196
// bool shift = event->state() & ShiftButton;
198
switch (activeTool) {
200
drag = DRAG_LASSO_START;
206
newVal(start.x(), start.x(), start.y());
212
deleteVal(start.x(), start.x());
220
//---------------------------------------------------------
221
// viewMouseMoveEvent
222
//---------------------------------------------------------
224
void Master::viewMouseMoveEvent(QMouseEvent* event)
226
QPoint pos = event->pos();
227
// QPoint dist = pos - start;
228
// bool moving = dist.y() >= 3 || dist.y() <= 3 || dist.x() >= 3 || dist.x() <= 3;
232
newVal(start.x(), pos.x(), pos.y());
237
deleteVal(start.x(), pos.x());
244
emit tempoChanged(280000 - event->y());
245
emit timeChanged(event->x());
248
//---------------------------------------------------------
249
// viewMouseReleaseEvent
250
//---------------------------------------------------------
252
void Master::viewMouseReleaseEvent(QMouseEvent*)
258
song->endUndo(SC_TEMPO);
266
//---------------------------------------------------------
268
//---------------------------------------------------------
270
bool Master::deleteVal1(int x1, int x2)
272
bool songChanged = false;
274
TempoList* tl = &tempomap;
275
for (iTEvent i = tl->begin(); i != tl->end(); ++i) {
282
if (ii != tl->end()) {
283
int tempo = ii->second->tempo;
284
midiThread->msgDeleteTempo(i->first, tempo, false);
291
void Master::deleteVal(int x1, int x2)
293
if (deleteVal1(editor->rasterVal1(x1), x2))
297
//---------------------------------------------------------
299
//---------------------------------------------------------
301
void Master::setTool(int t)
308
setCursor(QCursor(*pencilIcon, 4, 15));
311
setCursor(QCursor(arrowCursor));
316
//---------------------------------------------------------
318
//---------------------------------------------------------
320
void Master::newVal(int x1, int x2, int y)
322
int xx1 = editor->rasterVal1(x1);
323
int xx2 = editor->rasterVal2(x2);
330
deleteVal1(xx1, xx2);
331
midiThread->msgAddTempo(xx1, int(60000000000.0/(280000 - y)), false);