From: werner s. <wsc...@us...> - 2005-10-06 15:23:55
|
Update of /cvsroot/lmuse/muse/awl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20803/awl Modified Files: tcanvas.cpp tcanvas.h Log Message: misc updates Index: tcanvas.cpp =================================================================== RCS file: /cvsroot/lmuse/muse/awl/tcanvas.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** tcanvas.cpp 5 Oct 2005 18:46:16 -0000 1.14 --- tcanvas.cpp 6 Oct 2005 15:23:42 -0000 1.15 *************** *** 42,47 **** metronomIcon = new QIcon(QPixmap(metronom_xpm)); } ! button = Qt::NoButton; ! grid = new QGridLayout; grid->setMargin(0); grid->setSpacing(5); --- 42,47 ---- metronomIcon = new QIcon(QPixmap(metronom_xpm)); } ! button = Qt::NoButton; ! grid = new QGridLayout; grid->setMargin(0); grid->setSpacing(5); *************** *** 61,67 **** hmag->setValue(lrint((_xmag-_xmagMin)*100.0/(_xmagMax-_xmagMin))); ! vmag = new QSlider(Qt::Vertical); ! vmag->setRange(0, 100); ! vmag->setPageStep(1); _ymag = 1.0; --- 61,70 ---- hmag->setValue(lrint((_xmag-_xmagMin)*100.0/(_xmagMax-_xmagMin))); ! vmag = 0; ! if (type != TIME_CANVAS_DRUMEDIT) { ! vmag = new QSlider(Qt::Vertical); ! vmag->setRange(0, 100); ! vmag->setPageStep(1); ! } _ymag = 1.0; *************** *** 83,86 **** --- 86,94 ---- connect(addCtrlButton, SIGNAL(clicked()), SLOT(addCtrl())); } + else if (type == TIME_CANVAS_DRUMEDIT) { + _ymagMin = 1.0; + _ymagMax = 1.0; + view.setHeight(drumHeight * 128); + } grid->addWidget(_widget, 0, 0, 3, 2); *************** *** 89,93 **** grid->addWidget(timeTypeButton, 0, 2); grid->addWidget(vbar, 1, 2); ! grid->addWidget(vmag, 2, 2); grid->setColumnStretch(0, 100); --- 97,102 ---- grid->addWidget(timeTypeButton, 0, 2); grid->addWidget(vbar, 1, 2); ! if (vmag) ! grid->addWidget(vmag, 2, 2); grid->setColumnStretch(0, 100); *************** *** 99,103 **** connect(vbar, SIGNAL(valueChanged(int)), SLOT(moveY(int))); connect(hmag, SIGNAL(valueChanged(int)), SLOT(scaleX(int))); ! connect(vmag, SIGNAL(valueChanged(int)), SLOT(scaleY(int))); connect(timeTypeButton, SIGNAL(clicked()), SLOT(toggleTimeType())); } --- 108,113 ---- connect(vbar, SIGNAL(valueChanged(int)), SLOT(moveY(int))); connect(hmag, SIGNAL(valueChanged(int)), SLOT(scaleX(int))); ! if (vmag) ! connect(vmag, SIGNAL(valueChanged(int)), SLOT(scaleY(int))); connect(timeTypeButton, SIGNAL(clicked()), SLOT(toggleTimeType())); } *************** *** 112,119 **** return QFrame::eventFilter(obj, event); ! int wh = height(); QRect rPiano(0, rulerHeight, pianoWidth, wh - rulerHeight); ! QRect rRuler(0, 0, width(), rulerHeight); ! QRect rCanvas(0, rulerHeight, width(), wh - rulerHeight); if (type == TIME_CANVAS_PIANOROLL) { --- 122,131 ---- return QFrame::eventFilter(obj, event); ! int wh = _widget->height(); ! int ww = _widget->width(); ! QRect rPiano(0, rulerHeight, pianoWidth, wh - rulerHeight); ! QRect rRuler(0, 0, ww, rulerHeight); ! QRect rCanvas(0, rulerHeight, ww, wh - rulerHeight); if (type == TIME_CANVAS_PIANOROLL) { *************** *** 121,124 **** --- 133,140 ---- rCanvas.setLeft(pianoWidth); } + else if (type == TIME_CANVAS_DRUMEDIT) { + rRuler.setLeft(drumWidth); + rCanvas.setLeft(drumWidth); + } switch(event->type()) { *************** *** 189,193 **** if (curPitch != pitch) { curPitch = pitch; ! widget()->update(0, 0, pianoWidth, height()); emit pitchChanged(curPitch); if (button != Qt::NoButton) { --- 205,209 ---- if (curPitch != pitch) { curPitch = pitch; ! widget()->update(0, 0, pianoWidth, wh); emit pitchChanged(curPitch); if (button != Qt::NoButton) { *************** *** 202,206 **** if (showCursor && me->pos().x() < pianoWidth) { showCursor = false; ! widget()->update(QRect(0, 0, width(), rulerHeight)); emit cursorPos(cursor, showCursor); } --- 218,222 ---- if (showCursor && me->pos().x() < pianoWidth) { showCursor = false; ! widget()->update(rRuler); emit cursorPos(cursor, showCursor); } *************** *** 212,216 **** showCursor = true; emit cursorPos(cursor, showCursor); ! widget()->update(QRect(0, 0, width(), rulerHeight)); } int i; --- 228,232 ---- showCursor = true; emit cursorPos(cursor, showCursor); ! widget()->update(rRuler); } int i; *************** *** 234,238 **** showCursor = true; emit cursorPos(cursor, showCursor); ! widget()->update(QRect(0, 0, width(), rulerHeight)); } pos.snap(raster); --- 250,254 ---- showCursor = true; emit cursorPos(cursor, showCursor); ! widget()->update(rRuler); } pos.snap(raster); *************** *** 323,331 **** showCursor = false; emit pitchChanged(-1); ! widget()->update(0, 0, pianoWidth, height()); curPitch = -1; return false; default: break; } --- 339,348 ---- showCursor = false; emit pitchChanged(-1); ! widget()->update(rPiano); curPitch = -1; return false; default: + // printf("event %d missed\n", event->type()); break; } *************** *** 342,348 **** wpos.setX(x); if (type == TIME_CANVAS_PIANOROLL) ! _widget->scroll(dx, 0, ! QRect(pianoWidth, 0, width() - pianoWidth, height())); else _widget->scroll(dx, 0); --- 359,369 ---- wpos.setX(x); + int ww = _widget->width(); + int wh = _widget->height(); + if (type == TIME_CANVAS_PIANOROLL) ! _widget->scroll(dx, 0, QRect(pianoWidth, 0, ww - pianoWidth, wh)); ! else if (type == TIME_CANVAS_DRUMEDIT) ! _widget->scroll(dx, 0, QRect(drumWidth, 0, ww - drumWidth, wh)); else _widget->scroll(dx, 0); *************** *** 359,364 **** wpos.setY(y); ! // dont move ruler ! _widget->scroll(0, dy, QRect(0, rulerHeight, width(), height() - rulerHeight)); emit contentsMoving(wpos.x(), wpos.y()); } --- 380,391 ---- wpos.setY(y); ! // dont move ruler: ! ! int ww = _widget->width(); ! int wh = _widget->height(); ! QRect r(0, rulerHeight, ww, wh - rulerHeight); ! ! _widget->scroll(0, dy, r); ! _widget->update(); emit contentsMoving(wpos.x(), wpos.y()); } *************** *** 661,674 **** p.setRenderHint(QPainter::SmoothPixmapTransform, true); ! int wh = height(); ! QRect rPiano(0, rulerHeight, pianoWidth, wh - rulerHeight); ! QRect rRuler(0, 0, width(), rulerHeight); ! QRect rCanvas(0, rulerHeight, width(), wh - rulerHeight); //--------------------------------------------------- // draw Piano //--------------------------------------------------- ! if (type == TIME_CANVAS_PIANOROLL) { QRect pr = r & rPiano; if (!pr.isEmpty()) --- 688,712 ---- p.setRenderHint(QPainter::SmoothPixmapTransform, true); ! int wh = _widget->height(); ! int ww = _widget->width(); ! QRect rPiano (0, rulerHeight, pianoWidth, wh - rulerHeight); ! QRect rRuler (0, 0, ww, rulerHeight); ! QRect rCanvas(0, rulerHeight, ww, wh - rulerHeight); ! QRect rDrum (0, 0, drumWidth, wh); //--------------------------------------------------- + // draw Drum Instrument List // draw Piano //--------------------------------------------------- ! if (type == TIME_CANVAS_DRUMEDIT) { ! QRect pr = r & rDrum; ! p.fillRect(pr, QColor(0xe0, 0xe0, 0xe0)); ! if (!pr.isEmpty()) ! paintDrumList(p, pr); ! rRuler.setLeft(drumWidth); ! rCanvas.setLeft(drumWidth); ! } ! else if (type == TIME_CANVAS_PIANOROLL) { QRect pr = r & rPiano; if (!pr.isEmpty()) *************** *** 678,703 **** } - //--------------------------------------------------- - // draw canvas - //--------------------------------------------------- - QRect cr = r & rCanvas; bool drawCanvas = !cr.isEmpty(); if (drawCanvas) { p.fillRect(cr, QColor(0x71, 0x8d, 0xbe)); ! p.setClipRect(cr); ! if (type == TIME_CANVAS_PIANOROLL) { ! paintPianorollHorizontalGrid(p, cr); ! QPoint off(MAP_OFFSET + pianoWidth - wpos.x(), rulerHeight - wpos.y()); ! p.translate(off); ! p.scale(_xmag, _ymag); ! paint(p, p.matrix().inverted().mapRect(QRectF(cr))); ! } ! else { ! QPoint off(0, rCanvas.y() - wpos.y()); ! p.translate(off); ! paint(p, QRectF(cr.translated(-off))); ! } ! p.resetMatrix(); } --- 716,724 ---- } QRect cr = r & rCanvas; bool drawCanvas = !cr.isEmpty(); if (drawCanvas) { p.fillRect(cr, QColor(0x71, 0x8d, 0xbe)); ! paintCanvas(p, cr); } *************** *** 709,716 **** QRect rr = r & rRuler; bool drawRuler = !rr.isEmpty(); - if (drawRuler) - p.fillRect(rr, QColor(0xe0, 0xe0, 0xe0)); if (drawRuler || drawCanvas) { r = r & (rRuler | rCanvas); p.setClipRect(r); --- 730,736 ---- QRect rr = r & rRuler; bool drawRuler = !rr.isEmpty(); if (drawRuler || drawCanvas) { + p.fillRect(rr, QColor(0xe0, 0xe0, 0xe0)); r = r & (rRuler | rCanvas); p.setClipRect(r); *************** *** 724,727 **** --- 744,776 ---- //--------------------------------------------------------- + // paintCanvas + //--------------------------------------------------------- + + void TimeCanvas::paintCanvas(QPainter& p, const QRect& cr) + { + p.setClipRect(cr); + if (type == TIME_CANVAS_PIANOROLL) { + paintPianorollHorizontalGrid(p, cr); + QPoint off(MAP_OFFSET + pianoWidth - wpos.x(), rulerHeight - wpos.y()); + p.translate(off); + p.scale(_xmag, _ymag); + paint(p, p.matrix().inverted().mapRect(QRectF(cr))); + } + else if (type == TIME_CANVAS_DRUMEDIT) { + paintDrumeditHorizontalGrid(p, cr); + QPoint off(MAP_OFFSET + drumWidth - wpos.x(), rulerHeight - wpos.y()); + p.translate(off); + p.scale(_xmag, _ymag); + paint(p, p.matrix().inverted().mapRect(QRectF(cr))); + } + else { + QPoint off(0, rulerHeight - wpos.y()); + p.translate(off); + paint(p, QRectF(cr.translated(-off))); + } + p.resetMatrix(); + } + + //--------------------------------------------------------- // setLocatorPos //--------------------------------------------------------- *************** *** 749,753 **** _xmag = x; _ymag = y; ! vmag->setValue(lrint((_ymag-_ymagMin)*100.0/(_ymagMax-_ymagMin))); hmag->setValue(lrint((_xmag-_xmagMin)*100.0/(_xmagMax-_xmagMin))); updateScrollBars(); --- 798,803 ---- _xmag = x; _ymag = y; ! if (vmag) ! vmag->setValue(lrint((_ymag-_ymagMin)*100.0/(_ymagMax-_ymagMin))); hmag->setValue(lrint((_xmag-_xmagMin)*100.0/(_xmagMax-_xmagMin))); updateScrollBars(); *************** *** 845,857 **** void TimeCanvas::updateScrollBars() { ! int max = lrint(view.height() * _ymag) - (_widget->height() - rulerHeight); if (max < 0) max = 0; vbar->setMaxValue(max); ! vbar->setPageStep(_widget->height() - rulerHeight); int x1 = view.x(); int x2 = x1 + view.width(); ! max = lrint(x2 * _xmag) - _widget->width(); if (max < 0) max = 0; --- 895,910 ---- void TimeCanvas::updateScrollBars() { ! int wh = _widget->height(); ! int ww = _widget->width(); ! ! int max = lrint(view.height() * _ymag) - (wh - rulerHeight); if (max < 0) max = 0; vbar->setMaxValue(max); ! vbar->setPageStep(wh - rulerHeight); int x1 = view.x(); int x2 = x1 + view.width(); ! max = lrint(x2 * _xmag) - ww; if (max < 0) max = 0; *************** *** 859,863 **** hbar->setMaxValue(max); hbar->setMinValue(min); ! hbar->setPageStep(_widget->width()); } --- 912,916 ---- hbar->setMaxValue(max); hbar->setMinValue(min); ! hbar->setPageStep(ww); } *************** *** 1174,1177 **** --- 1227,1233 ---- int TimeCanvas::pitch2y(int pitch) const { + if (type == TIME_CANVAS_DRUMEDIT) + return pitch * drumHeight; + int tt[] = { 12, 19, 25, 32, 38, 51, 58, 64, 71, 77, 84, 90 *************** *** 1190,1193 **** --- 1246,1252 ---- int TimeCanvas::y2pitch(int y) const { + if (type == TIME_CANVAS_DRUMEDIT) + return y / drumHeight; + const int total = (10 * 7 + 5) * keyHeight; // 75 Ganztonschritte y = total - y; *************** *** 1281,1291 **** if (x1 < pianoWidth) x1 = pianoWidth; ! qreal y = kh + offset; for (int key = 1; key < 75; ++key, y += kh) { ! if (y < r.y()) continue; ! /* if (y > r.bottom()) break; - */ switch (key % 7) { case 2: --- 1340,1351 ---- if (x1 < pianoWidth) x1 = pianoWidth; ! qreal y = kh + offset; ! qreal y1 = r.y() - _ymag; ! qreal y2 = y1 + r.height() + _ymag; for (int key = 1; key < 75; ++key, y += kh) { ! if (y < y1) continue; ! if (y > y2) break; switch (key % 7) { case 2: *************** *** 1301,1302 **** --- 1361,1390 ---- } + //--------------------------------------------------------- + // paintDrumeditHorizontalGrid + //--------------------------------------------------------- + + void TimeCanvas::paintDrumeditHorizontalGrid(QPainter& p, QRect r) + { + int offset = rulerHeight - wpos.y(); + + p.setPen(QPen(Qt::lightGray)); + int x1 = r.x(); + int x2 = x1 + r.width(); + if (x1 < drumWidth) + x1 = drumWidth; + + p.setPen(QPen(Qt::lightGray)); + + int y = offset; + int y1 = r.y(); + int y2 = y1 + r.height(); + for (int i = 0; i < 128; ++i, y += drumHeight) { + if (y < y1) + continue; + if (y > y2) + break; + p.drawLine(QLine(x1, y, x2, y)); + } + } + Index: tcanvas.h =================================================================== RCS file: /cvsroot/lmuse/muse/awl/tcanvas.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcanvas.h 5 Oct 2005 18:46:17 -0000 1.13 --- tcanvas.h 6 Oct 2005 15:23:42 -0000 1.14 *************** *** 21,24 **** --- 21,26 ---- static const int rulerHeight = 28; static const int pianoWidth = 40; + static const int drumWidth = 120; + static const int drumHeight = 18; static const int keyHeight = 13; *************** *** 60,63 **** --- 62,66 ---- void updateScrollBars(); void canvasPaintEvent(QPaintEvent*); + void paintCanvas(QPainter&, const QRect&); void paintMetronomRuler(QPainter&, const QRect&); void paintClockRuler(QPainter&, const QRect&); *************** *** 66,69 **** --- 69,73 ---- void paintPiano(QPainter&, QRect); void paintPianorollHorizontalGrid(QPainter&, QRect); + void paintDrumeditHorizontalGrid(QPainter&, QRect); protected: *************** *** 90,93 **** --- 94,98 ---- virtual void pianoPressed(int /*pitch*/, int /*velocity*/, bool /*shift*/) {} virtual void pianoReleased(int /*pitch*/, bool) {} + virtual void paintDrumList(QPainter&, QRect) {} virtual void dragEnter(QDragEnterEvent*, const QPoint&) {} |