From: werner s. <wsc...@us...> - 2005-10-13 09:08:14
|
Update of /cvsroot/lmuse/muse/awl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29621/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.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** tcanvas.cpp 10 Oct 2005 19:34:08 -0000 1.17 --- tcanvas.cpp 13 Oct 2005 09:08:05 -0000 1.18 *************** *** 8,11 **** --- 8,12 ---- #include "tcanvas.h" + #include "al/al.h" #include "al/sig.h" #include "al/tempo.h" *************** *** 77,80 **** --- 78,82 ---- timeTypeButton = new QToolButton; timeTypeButton->setFixedSize(20, rulerHeight); + _timeType = AL::TICKS; setTimeType(AL::TICKS); *************** *** 251,272 **** else if (rCanvas.contains(me->pos())) { if (!(cursor == pos)) { ! cursor = pos; showCursor = true; emit cursorPos(cursor, showCursor); widget()->update(rRuler); } ! pos.snap(raster); ! if (type == TIME_CANVAS_PIANOROLL) { ! int x = me->pos().x(); ! int y = me->pos().y(); ! QPoint p( ! lrint((x - MAP_OFFSET - pianoWidth + wpos.x()) / _xmag), ! lrint((y - rulerHeight + wpos.y()) / _ymag) ! ); ! mouseMove(p); ! } ! else { ! mouseMove(QPoint(me->pos().x(), me->pos().y() - rulerHeight)); ! } } } --- 253,262 ---- else if (rCanvas.contains(me->pos())) { if (!(cursor == pos)) { ! cursor = pos; showCursor = true; emit cursorPos(cursor, showCursor); widget()->update(rRuler); } ! mouseMove(QPoint(me->pos().x(), me->pos().y() - rulerHeight)); } } *************** *** 401,417 **** void TimeCanvas::paintClockRuler(QPainter& p, const QRect& r) { ! int x = r.x(); ! int w = r.width(); ! x -= 20; ! w += 40; // wg. Text ! // // draw Marker ! // ! int y = 12; p.setPen(Qt::black); p.setFont(*config.fonts[4]); - p.drawLine(r.x(), y+1, r.x() + r.width(), y+1); QRect tr(r); tr.setHeight(12); --- 391,412 ---- void TimeCanvas::paintClockRuler(QPainter& p, const QRect& r) { ! int x1 = r.x(); ! int x2 = x1 + r.width(); ! int y1 = r.y(); ! int rh = r.height(); ! if (y1 < rulerHeight) { ! rh -= rulerHeight - y1; ! y1 = rulerHeight; ! } ! int y2 = y1 + rh; ! //--------------------------------------------------- // draw Marker ! //--------------------------------------------------- ! ! int y = rulerHeight - 16; p.setPen(Qt::black); p.setFont(*config.fonts[4]); QRect tr(r); tr.setHeight(12); *************** *** 420,432 **** for (AL::iMarker m = marker->begin(); m != marker->end(); ++m) { int xp = mapx(int(m->second.frame())); ! if (xp > x+w) break; - int xe = r.x() + r.width(); AL::iMarker mm = m; ++mm; if (mm != marker->end()) { xe = mapx(mm->first); } ! QRect tr(xp, 0, xe-xp, 13); if (m->second.current()) { p.fillRect(tr, Qt::white); --- 415,427 ---- for (AL::iMarker m = marker->begin(); m != marker->end(); ++m) { int xp = mapx(int(m->second.frame())); ! if (xp > x2) break; AL::iMarker mm = m; ++mm; + int xe = x2; if (mm != marker->end()) { xe = mapx(mm->first); } ! QRect tr(xp, 0, x2 - xp, 13); if (m->second.current()) { p.fillRect(tr, Qt::white); *************** *** 451,459 **** //--------------------------------------------------- - int h = rulerHeight - 12; - for (int i = 0; i < 3; ++i) { int xp = pos2pix(pos[i]); ! if (xp >= x && xp < x+w) { QPixmap* pm = markIcon[i]; p.drawPixmap(xp - pm->width()/2, y-1, *pm); --- 446,452 ---- //--------------------------------------------------- for (int i = 0; i < 3; ++i) { int xp = pos2pix(pos[i]); ! if (xp >= x1 && xp < x2) { QPixmap* pm = markIcon[i]; p.drawPixmap(xp - pm->width()/2, y-1, *pm); *************** *** 463,533 **** if (showCursor) { int xp = pos2pix(cursor); ! if (xp >= x && xp < x+w) p.drawLine(xp, 0, xp, rulerHeight); } ! int ctick = AL::tempomap.frame2tick(mapxDev(x)); ! int bar1, bar2, beat; ! unsigned tick; ! AL::sigmap.tickValues(ctick, &bar1, &beat, &tick); ! AL::sigmap.tickValues(AL::tempomap.frame2tick(mapxDev(x+w)), &bar2, &beat, &tick); ! //printf("bar %d %d-%d=%d\n", bar, ntick, stick, ntick-stick); ! int stick = AL::sigmap.bar2tick(bar1, 0, 0); ! int ntick; ! for (int bar = bar1; bar <= bar2; bar++, stick = ntick) { ! ntick = AL::sigmap.bar2tick(bar+1, 0, 0); ! int a = AL::tempomap.tick2frame(ntick); ! int b = AL::tempomap.tick2frame(stick); ! int tpix = rmapx(a - b); ! if (tpix < 64) { ! // don´t show beats if measure is this small ! int n = 1; ! if (tpix < 32) ! n = 2; ! if (tpix <= 16) ! n = 4; ! if (tpix < 8) ! n = 8; ! if (tpix <= 4) ! n = 16; ! if (tpix <= 2) ! n = 32; ! if (bar % n) ! continue; ! p.setFont(*config.fonts[3]); ! int x = mapx(b); QString s; ! s.setNum(bar + 1); ! p.drawLine(x, y+1, x, y+1+h); ! QRect r = QRect(x+2, y, 0, h); ! p.drawText(r, Qt::AlignLeft|Qt::AlignVCenter|Qt::TextDontClip, s); ! } ! else { ! int z, n; ! AL::sigmap.timesig(stick, z, n); ! for (int beat = 0; beat < z; beat++) { ! int xx = AL::tempomap.tick2frame(AL::sigmap.bar2tick(bar, beat, 0)); ! int xp = mapx(xx); ! QString s; ! QRect r(xp+2, y, 0, h); ! int y1; ! int num; ! if (beat == 0) { ! num = bar + 1; ! y1 = y; ! p.setFont(*config.fonts[3]); ! } ! else { ! num = beat + 1; ! y1 = y + 7; ! p.setFont(*config.fonts[1]); ! r.setY(y+3); ! } ! s.setNum(num); ! p.drawLine(xp, y1, xp, y+1+h); ! p.drawText(r, Qt::AlignLeft|Qt::AlignVCenter|Qt::TextDontClip, s); } } } --- 456,509 ---- if (showCursor) { int xp = pos2pix(cursor); ! if (xp >= x1 && xp < x2) p.drawLine(xp, 0, xp, rulerHeight); } ! AL::Pos p1 = pix2pos(x1); ! AL::Pos p2 = pix2pos(x2); ! int sec1 = p1.frame() / AL::sampleRate; ! int sec2 = (p2.frame() + AL::sampleRate - 1) / AL::sampleRate; ! int sw = lrint(AL::sampleRate * _xmag); ! ! if (sw > 20) { ! for (int sec = sec1; sec < sec2; ++sec) { ! int min = sec / 60; ! int sr = sec % 60; ! ! int yy; QString s; ! if (sr == 0) { ! p.setFont(*config.fonts[3]); ! s.sprintf("%d:00", min); ! yy = y; ! } ! else { ! p.setFont(*config.fonts[1]); ! s.sprintf("%02d", sr); ! yy = y + 7; } + int xp = pos2pix(AL::Pos(sec * AL::sampleRate, false)); + p.setPen(Qt::black); + p.drawLine(xp, yy, xp, rulerHeight); + p.drawText(xp + 2, rulerHeight - 3, s); + p.setPen(sr == 0 ? Qt::lightGray : Qt::gray); + p.drawLine(xp, y1, xp, y2); + } + } + else { + int min1 = sec1/60; + int min2 = (sec2+59)/60; + for (int min = min1; min < min2; ++min) { + QString s; + p.setFont(*config.fonts[3]); + s.sprintf("%d", min); + int xp = pos2pix(AL::Pos(min * AL::sampleRate * 60, false)); + p.setPen(Qt::black); + p.drawLine(xp, y, xp, rulerHeight); + p.drawText(xp + 2, rulerHeight - 3, s); + p.setPen(Qt::lightGray); + p.drawLine(xp, y1, xp, y2); } } *************** *** 545,551 **** p.setFont(*config.fonts[4]); - p.drawLine(r.x(), y-1, r.x() + w, y-1); - p.setPen(QPen(Qt::black, 2)); - p.drawLine(r.x(), rulerHeight-1, r.x() + w, rulerHeight-1); int h = 14; --- 521,524 ---- *************** *** 646,649 **** --- 619,639 ---- //--------------------------------------------------------- + // tempoChanged + //--------------------------------------------------------- + + void TimeCanvas::tempoChanged() + { + if (_timeType == AL::TICKS) + return; + + int x = 0; + if (type == TIME_CANVAS_DRUMEDIT) + x = drumWidth; + else if (type == TIME_CANVAS_PIANOROLL) + x = pianoWidth; + widget()->update(x, 0, widget()->width() - x, widget()->height()); + } + + //--------------------------------------------------------- // canvasPaintEvent //--------------------------------------------------------- *************** *** 702,706 **** p.fillRect(r & rRuler, QColor(0xe0, 0xe0, 0xe0)); p.setClipRect(rr); ! p.setPen(Qt::black); if (_timeType == AL::TICKS) paintMetronomRuler(p, rr); --- 692,706 ---- p.fillRect(r & rRuler, QColor(0xe0, 0xe0, 0xe0)); p.setClipRect(rr); ! ! int x1 = rr.x(); ! int x2 = x1 + rr.width(); ! int y1 = rulerHeight - 17; ! int y2 = rulerHeight - 1; ! ! p.setPen(QPen(Qt::black, 1)); ! p.drawLine(x1, y1, x2, y1); ! p.setPen(QPen(Qt::black, 2)); ! p.drawLine(x1, y2, x2, y2); ! if (_timeType == AL::TICKS) paintMetronomRuler(p, rr); *************** *** 824,831 **** void TimeCanvas::scaleX(int val) { - // int y = lrint(wpos.y() / _ymag); _xmag = (_xmagMax - _xmagMin) / 100.0 * val + _xmagMin; - // y = lrint(y * _ymag); - // wpos.setX(x); updateScrollBars(); _widget->update(); --- 824,828 ---- *************** *** 872,892 **** //--------------------------------------------------------- ! // setLen //--------------------------------------------------------- ! void TimeCanvas::setHMax(int val) { ! view.setWidth(val); updateScrollBars(); } //--------------------------------------------------------- ! // setHRange //--------------------------------------------------------- ! void TimeCanvas::setHRange(int min, int max) { ! view.setX(min); ! view.setWidth(max); updateScrollBars(); } --- 869,889 ---- //--------------------------------------------------------- ! // setHRange //--------------------------------------------------------- ! void TimeCanvas::setHRange(const AL::Pos& p1, const AL::Pos& p2) { ! pos1 = p1; ! pos2 = p2; updateScrollBars(); } //--------------------------------------------------------- ! // setEndPos //--------------------------------------------------------- ! void TimeCanvas::setEndPos(const AL::Pos& p2) { ! pos2 = p2; updateScrollBars(); } *************** *** 908,911 **** --- 905,920 ---- void TimeCanvas::updateScrollBars() { + int x1, x2; + if (_timeType == AL::TICKS) { + x1 = pos1.tick(); + x2 = pos2.tick(); + } + else { + x1 = pos1.frame(); + x2 = pos2.frame(); + } + // view.setX(x2); + // view.setWidth(x2 - x1); + int wh = _widget->height(); int ww = _widget->width(); *************** *** 917,922 **** vbar->setPageStep(wh - rulerHeight); - int x1 = view.x(); - int x2 = x1 + view.width(); max = lrint(x2 * _xmag) - ww; if (max < 0) --- 926,929 ---- *************** *** 934,942 **** void TimeCanvas::setTimeType(AL::TType t) { ! _timeType = t; ! if (_timeType == AL::TICKS) timeTypeButton->setIcon(*metronomIcon); ! else timeTypeButton->setIcon(*clockIcon); widget()->update(); } --- 941,960 ---- void TimeCanvas::setTimeType(AL::TType t) { ! double conv = 1.0; ! if (t == AL::TICKS) { timeTypeButton->setIcon(*metronomIcon); ! if (_timeType == AL::FRAMES) ! conv = AL::sampleRate / double(AL::division * 120 / 60); ! } ! else { timeTypeButton->setIcon(*clockIcon); + if (_timeType == AL::TICKS) + conv = double(AL::division * 120 / 60) / double(AL::sampleRate); + } + _timeType = t; + _xmag *= conv; + _xmagMax *= conv; + _xmagMin *= conv; + updateScrollBars(); widget()->update(); } Index: tcanvas.h =================================================================== RCS file: /cvsroot/lmuse/muse/awl/tcanvas.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** tcanvas.h 10 Oct 2005 19:34:08 -0000 1.16 --- tcanvas.h 13 Oct 2005 09:08:05 -0000 1.17 *************** *** 36,39 **** --- 36,42 ---- QRect view; // virtual viewport of "widget" // used to calculate scroll bars + AL::Pos pos1; // time range + AL::Pos pos2; + double _xmagMin, _xmagMax; double _ymagMin, _ymagMax; *************** *** 72,76 **** protected: ! AL::Pos pos[4]; bool showCursor; AL::Pos cursor; --- 75,79 ---- protected: ! AL::Pos pos[3]; bool showCursor; AL::Pos cursor; *************** *** 152,163 **** public slots: void setLocatorPos(int idx, const AL::Pos&); - void setHMax(int); void setVSize(int); void setRaster(int); void setYPos(int y) { setWPos(QPoint(wpos.x(), y)); } public: TimeCanvas(TimeCanvasType = TIME_CANVAS); ! void setHRange(int, int); void setMag(double, double); double xmag() const { return _xmag; } --- 155,167 ---- public slots: void setLocatorPos(int idx, const AL::Pos&); void setVSize(int); void setRaster(int); void setYPos(int y) { setWPos(QPoint(wpos.x(), y)); } + void setEndPos(const AL::Pos&); + void tempoChanged(); public: TimeCanvas(TimeCanvasType = TIME_CANVAS); ! void setHRange(const AL::Pos&, const AL::Pos&); void setMag(double, double); double xmag() const { return _xmag; } |