summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dgedit/canvastoollisten.cc1
-rw-r--r--dgedit/mainwindow.cc15
-rw-r--r--dgedit/mainwindow.h2
-rw-r--r--dgedit/player.cc27
-rw-r--r--dgedit/player.h16
5 files changed, 45 insertions, 16 deletions
diff --git a/dgedit/canvastoollisten.cc b/dgedit/canvastoollisten.cc
index f842235..bd16b15 100644
--- a/dgedit/canvastoollisten.cc
+++ b/dgedit/canvastoollisten.cc
@@ -38,6 +38,7 @@ CanvasToolListen::CanvasToolListen(Canvas *c, Player &p)
bool CanvasToolListen::mousePressEvent(QMouseEvent *event)
{
if(!isActive()) return false;
+ player.setPosition(canvas->unmapX(event->x()));
player.playing = true;
canvas->update();
connect(&player, SIGNAL(positionUpdate(size_t)), this, SLOT(update(size_t)));
diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc
index 82eaaa6..70b6f78 100644
--- a/dgedit/mainwindow.cc
+++ b/dgedit/mainwindow.cc
@@ -73,11 +73,10 @@ MainWindow::MainWindow()
extractor = new AudioExtractor(session, this);
canvas = new Canvas(this);
- player = new Player(canvas);
- player->start();
+ player.start();
QToolBar *toolbar = addToolBar("Tools");
- g_listen = new CanvasToolListen(canvas, *player);
+ g_listen = new CanvasToolListen(canvas, player);
CanvasTool *listen = g_listen;
addTool(toolbar, canvas, listen);
CanvasTool *threshold = new CanvasToolThreshold(canvas);
@@ -303,7 +302,6 @@ MainWindow::MainWindow()
MainWindow::~MainWindow()
{
- delete player;
}
void MainWindow::setAttackLengthLineEd(int value)
@@ -437,9 +435,15 @@ void MainWindow::loadFile(QString filename)
setCursor(Qt::WaitCursor);
statusBar()->showMessage("Loading...");
qApp->processEvents();
+
sorter->setWavData(NULL, 0);
+ player.setPcmData(NULL, 0);
+
canvas->load(filename);
+
sorter->setWavData(canvas->data, canvas->size);
+ player.setPcmData(canvas->data, canvas->size);
+
statusBar()->showMessage("Ready");
setCursor(Qt::ArrowCursor);
}
@@ -458,6 +462,7 @@ void MainWindow::setPreset(int index)
}
void MainWindow::browse() {
- QString path = QFileDialog::getExistingDirectory(this, "Select export path", lineed_exportp->text());
+ QString path = QFileDialog::getExistingDirectory(this, "Select export path",
+ lineed_exportp->text());
lineed_exportp->setText(path);
}
diff --git a/dgedit/mainwindow.h b/dgedit/mainwindow.h
index ccb2f07..cd13132 100644
--- a/dgedit/mainwindow.h
+++ b/dgedit/mainwindow.h
@@ -98,7 +98,7 @@ private:
// Session state information:
Selections session;
- Player *player;
+ Player player;
private slots:
void setAttackLengthLineEd(int);
diff --git a/dgedit/player.cc b/dgedit/player.cc
index cb6b986..782020b 100644
--- a/dgedit/player.cc
+++ b/dgedit/player.cc
@@ -30,11 +30,15 @@
#define BUFSZ 1024 * 2
-Player::Player(Canvas *c)
+Player::Player()
{
- canvas = c;
playing = false;
+
+ peak = 0;
pos = 0;
+ gain_scalar = 1.0;
+ pcm_data = NULL;
+ pcm_size = 0;
ao_initialize();
@@ -46,10 +50,6 @@ Player::Player(Canvas *c)
dev = ao_open_live(ao_default_driver_id(), &sf, 0);
- gain_scalar = 1000;
-
- peak = 0;
-
connect(&report_timer, SIGNAL(timeout()), this, SLOT(reportTimeout()));
report_timer.start(50); // Update 25 times per second
}
@@ -67,8 +67,8 @@ void Player::run()
if(playing) {
for(size_t i = 0; i < BUFSZ; i++) {
double sample = 0.0;
- if(i + pos < canvas->size) {
- sample = canvas->data[pos + i] * gain_scalar;
+ if(i + pos < pcm_size) {
+ sample = pcm_data[pos + i] * gain_scalar;
} else {
playing = false;
}
@@ -105,3 +105,14 @@ void Player::reportTimeout()
emit positionUpdate(pos);
peak = 0.0;
}
+
+void Player::setPcmData(float *data, size_t size)
+{
+ pcm_data = data;
+ pcm_size = size;
+}
+
+ void Player::setPosition(size_t position)
+ {
+ pos = position;
+ }
diff --git a/dgedit/player.h b/dgedit/player.h
index 0289cd5..1aa4426 100644
--- a/dgedit/player.h
+++ b/dgedit/player.h
@@ -37,7 +37,7 @@
class Player : public QThread {
Q_OBJECT
public:
- Player(Canvas *canvas); // TODO: Don't use canvas pointer here. Instead introduce setData slot or similar.
+ Player();
~Player();
void run();
@@ -50,6 +50,11 @@ public:
public slots:
/**
+ * Assign PCM data to the player.
+ */
+ void setPcmData(float *data, size_t num_samples);
+
+ /**
* Set gain scalar.
* This value is multiplied with each sample before it is played.
*/
@@ -62,6 +67,11 @@ public slots:
*/
void setGainDB(double gain_db);
+ /**
+ * Set player position as sample offset.
+ */
+ void setPosition(size_t position);
+
signals:
/**
* The absolute maximum of samples seen since last update.
@@ -83,7 +93,9 @@ private slots:
private:
ao_device *dev;
- Canvas *canvas;
+
+ float *pcm_data;
+ size_t pcm_size;
QTimer report_timer;