From 08a41cf525193e90ce8f397476ac3825e5e9fdb8 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 30 Jul 2011 15:18:29 +0200 Subject: Redraw listening position line in timer. --- dgedit/canvastoollisten.cc | 25 ++++++++++++++++++++++--- dgedit/canvastoollisten.h | 6 ++++++ 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'dgedit') diff --git a/dgedit/canvastoollisten.cc b/dgedit/canvastoollisten.cc index 0734cf5..74bf176 100644 --- a/dgedit/canvastoollisten.cc +++ b/dgedit/canvastoollisten.cc @@ -26,7 +26,7 @@ */ #include "canvastoollisten.h" -#define BUFSZ 1024 +#define BUFSZ 1024 * 2 Player::Player(Canvas *c) { @@ -65,12 +65,12 @@ void Player::run() } ao_play(dev, (char*)s, BUFSZ * sizeof(short)); - canvas->update(); + // canvas->update(); pos += BUFSZ; } else { - msleep(100); + msleep(22); } } } @@ -78,20 +78,27 @@ void Player::run() CanvasToolListen::CanvasToolListen(Canvas *c) : player(c) { + lastpos = 0; canvas = c ; player.start(); + QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(update())); } bool CanvasToolListen::mousePressEvent(QMouseEvent *event) { player.pos = canvas->unmapX(event->x()); player.playing = true; + canvas->update(); + timer.start(50); return true; } bool CanvasToolListen::mouseReleaseEvent(QMouseEvent *event) { player.playing = false; + timer.stop(); + lastpos = 0; + canvas->update(); return true; } @@ -105,3 +112,15 @@ void CanvasToolListen::paintEvent(QPaintEvent *event, QPainter &painter) event->rect().y() + event->rect().height()); } } + +void CanvasToolListen::update() +{ + size_t pos = player.pos; + size_t last = canvas->mapX(lastpos); + size_t x = canvas->mapX(player.pos); + QRect r(last, 0, + x - last + 2, canvas->height()); + + canvas->update(r); + lastpos = pos; +} diff --git a/dgedit/canvastoollisten.h b/dgedit/canvastoollisten.h index dfbea97..22daafd 100644 --- a/dgedit/canvastoollisten.h +++ b/dgedit/canvastoollisten.h @@ -30,6 +30,7 @@ #include "canvastool.h" #include +#include #include @@ -59,10 +60,15 @@ public: bool mouseReleaseEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event, QPainter &painter); +public slots: + void update(); + private: Canvas *canvas; Player player; + QTimer timer; + size_t lastpos; }; #endif/*__DRUMGIZMO_CANVASTOOLLISTEN_H__*/ -- cgit v1.2.3