summaryrefslogtreecommitdiff
path: root/dgedit
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-10-02 09:58:10 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2011-10-02 09:58:10 +0200
commitf474c3c923fe5bb27c1ee11e2c6dd57e41889f27 (patch)
tree93e2a3e2624bb2e4d238d22124956cd066643b03 /dgedit
parent83807cf93ef362098d6fea6030646653cc62e37f (diff)
Made conenctions for CanvasTool work (again...).
Diffstat (limited to 'dgedit')
-rw-r--r--dgedit/canvas.cc8
-rw-r--r--dgedit/canvas.h5
-rw-r--r--dgedit/canvastool.cc3
-rw-r--r--dgedit/canvastool.h2
-rw-r--r--dgedit/canvastoollisten.cc4
-rw-r--r--dgedit/canvastoollisten.h1
-rw-r--r--dgedit/canvastoolselections.cc17
-rw-r--r--dgedit/canvastoolselections.h5
-rw-r--r--dgedit/canvastoolthreshold.cc3
-rw-r--r--dgedit/canvastoolthreshold.h4
-rw-r--r--dgedit/mainwindow.cc43
11 files changed, 74 insertions, 21 deletions
diff --git a/dgedit/canvas.cc b/dgedit/canvas.cc
index c70f730..b119a94 100644
--- a/dgedit/canvas.cc
+++ b/dgedit/canvas.cc
@@ -34,10 +34,6 @@
#include <math.h>
-#include "canvastoolselections.h"
-#include "canvastoolthreshold.h"
-#include "canvastoollisten.h"
-
#define DEFYSCALE 200
Canvas::Canvas(QWidget *parent)
@@ -67,10 +63,6 @@ Canvas::Canvas(QWidget *parent)
setCursor(Qt::ArrowCursor);
wav = QImage(width(), height(), QImage::Format_RGB32);
-
- tools.push_back(new CanvasToolListen(this));
- tools.push_back(new CanvasToolThreshold(this));
- tools.push_back(new CanvasToolSelections(this));
}
Canvas::~Canvas()
diff --git a/dgedit/canvas.h b/dgedit/canvas.h
index 3c268ed..c83a726 100644
--- a/dgedit/canvas.h
+++ b/dgedit/canvas.h
@@ -75,6 +75,9 @@ private:
public:
float *data;
size_t size;
+
+ QVector<CanvasTool*> tools;
+
private:
float xscale;
float yscale;
@@ -87,8 +90,6 @@ private:
QColor colHalf;
QColor colWavMax;
QColor colWavAvg;
-
- QVector<CanvasTool*> tools;
};
#endif/*__DRUMGIZMO_CANVAS_H__*/
diff --git a/dgedit/canvastool.cc b/dgedit/canvastool.cc
index 196be0b..9d23d97 100644
--- a/dgedit/canvastool.cc
+++ b/dgedit/canvastool.cc
@@ -26,6 +26,8 @@
*/
#include "canvastool.h"
+#include <stdio.h>
+
bool CanvasTool::mouseMoveEvent(QMouseEvent *)
{
return false;
@@ -55,6 +57,7 @@ void CanvasTool::keyReleaseEvent(QKeyEvent *)
void CanvasTool::setActive(bool active)
{
+ printf("setActive(%d)\n", active);
_active = active;
emit activateChanged(active);
}
diff --git a/dgedit/canvastool.h b/dgedit/canvastool.h
index 0e802ba..56cfa84 100644
--- a/dgedit/canvastool.h
+++ b/dgedit/canvastool.h
@@ -32,10 +32,12 @@
#include <QPaintEvent>
#include <QKeyEvent>
#include <QPainter>
+#include <QString>
class CanvasTool : public QObject {
Q_OBJECT
public:
+ virtual QString name() = 0;
virtual bool mouseMoveEvent(QMouseEvent *event);
virtual bool mousePressEvent(QMouseEvent *event);
virtual bool mouseReleaseEvent(QMouseEvent *event);
diff --git a/dgedit/canvastoollisten.cc b/dgedit/canvastoollisten.cc
index 74bf176..4254137 100644
--- a/dgedit/canvastoollisten.cc
+++ b/dgedit/canvastoollisten.cc
@@ -86,6 +86,7 @@ CanvasToolListen::CanvasToolListen(Canvas *c)
bool CanvasToolListen::mousePressEvent(QMouseEvent *event)
{
+ if(!isActive()) return false;
player.pos = canvas->unmapX(event->x());
player.playing = true;
canvas->update();
@@ -95,6 +96,7 @@ bool CanvasToolListen::mousePressEvent(QMouseEvent *event)
bool CanvasToolListen::mouseReleaseEvent(QMouseEvent *event)
{
+ if(!isActive()) return false;
player.playing = false;
timer.stop();
lastpos = 0;
@@ -104,6 +106,8 @@ bool CanvasToolListen::mouseReleaseEvent(QMouseEvent *event)
void CanvasToolListen::paintEvent(QPaintEvent *event, QPainter &painter)
{
+ if(!isActive()) return;
+
if(player.playing) {
painter.setPen(QColor(0, 127, 127));
painter.drawLine(canvas->mapX(player.pos),
diff --git a/dgedit/canvastoollisten.h b/dgedit/canvastoollisten.h
index 22daafd..74a7831 100644
--- a/dgedit/canvastoollisten.h
+++ b/dgedit/canvastoollisten.h
@@ -56,6 +56,7 @@ Q_OBJECT
public:
CanvasToolListen(Canvas *canvas);
+ QString name() { return "Listen"; }
bool mousePressEvent(QMouseEvent *event);
bool mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event, QPainter &painter);
diff --git a/dgedit/canvastoolselections.cc b/dgedit/canvastoolselections.cc
index 51cc1ad..ba2d6b0 100644
--- a/dgedit/canvastoolselections.cc
+++ b/dgedit/canvastoolselections.cc
@@ -27,6 +27,7 @@
#include "canvastoolselections.h"
#include <math.h>
+#include <stdio.h>
#define mapX(x) canvas->mapX(x)
#define mapY(x) canvas->mapY(x)
@@ -35,9 +36,11 @@
CanvasToolSelections::CanvasToolSelections(Canvas *c)
{
+ threshold = 0.5; // Default from CanvasToolThreshold
+
canvas = c;
- data = canvas->data;
- size = canvas->size;
+ // data = canvas->data;
+ // size = canvas->size;
selection_is_moving_left = false;
selection_is_moving_right = false;
@@ -185,9 +188,16 @@ void CanvasToolSelections::keyReleaseEvent(QKeyEvent *event)
}
}
+void CanvasToolSelections::thresholdChanged(double t)
+{
+ threshold = t;
+}
+
void CanvasToolSelections::autoCreateSelections()
{
- /*
+ float *data = canvas->data;
+ size_t size = canvas->size;
+
for(size_t i = 0; i < size; i++) {
if(fabs(data[i]) > fabs(threshold)) {
int from = i;
@@ -224,7 +234,6 @@ void CanvasToolSelections::autoCreateSelections()
}
canvas->update();
emit selectionsChanged(_selections);
- */
}
void CanvasToolSelections::clearSelections()
diff --git a/dgedit/canvastoolselections.h b/dgedit/canvastoolselections.h
index a8b37a3..a9e4d56 100644
--- a/dgedit/canvastoolselections.h
+++ b/dgedit/canvastoolselections.h
@@ -40,6 +40,7 @@ Q_OBJECT
public:
CanvasToolSelections(Canvas *canvas);
+ QString name() { return "Selections"; }
bool mouseMoveEvent(QMouseEvent *event);
bool mousePressEvent(QMouseEvent *event);
bool mouseReleaseEvent(QMouseEvent *event);
@@ -55,6 +56,7 @@ signals:
public slots:
void autoCreateSelections();
void clearSelections();
+ void thresholdChanged(double threshold);
private:
bool selection_is_moving_left;
@@ -64,8 +66,7 @@ private:
Canvas *canvas;
- float *data;
- size_t size;
+ double threshold;
QColor colSelBg;
QColor colSel;
diff --git a/dgedit/canvastoolthreshold.cc b/dgedit/canvastoolthreshold.cc
index e933592..d8e2dff 100644
--- a/dgedit/canvastoolthreshold.cc
+++ b/dgedit/canvastoolthreshold.cc
@@ -87,6 +87,9 @@ bool CanvasToolThreshold::mouseReleaseEvent(QMouseEvent *event)
threshold_is_moving = false;
canvas->setCursor(Qt::ArrowCursor);
canvas->update();
+
+ emit thresholdChanged(threshold);
+
return true;
}
}
diff --git a/dgedit/canvastoolthreshold.h b/dgedit/canvastoolthreshold.h
index b19bf01..0c593e8 100644
--- a/dgedit/canvastoolthreshold.h
+++ b/dgedit/canvastoolthreshold.h
@@ -38,11 +38,15 @@ Q_OBJECT
public:
CanvasToolThreshold(Canvas *canvas);
+ QString name() { return "Threshold"; }
bool mouseMoveEvent(QMouseEvent *event);
bool mousePressEvent(QMouseEvent *event);
bool mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event, QPainter &painter);
+signals:
+ void thresholdChanged(double threshold);
+
private:
float threshold;
bool threshold_is_moving;
diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc
index 9454a97..c750a22 100644
--- a/dgedit/mainwindow.cc
+++ b/dgedit/mainwindow.cc
@@ -36,11 +36,29 @@
#include <QApplication>
#include <QDockWidget>
#include <QSettings>
+#include <QToolBar>
+#include <QAction>
+#include <QMenuBar>
+
+#include "canvastool.h"
+#include "canvastoolselections.h"
+#include "canvastoolthreshold.h"
+#include "canvastoollisten.h"
#define MAXVAL 10000000L
#define SINGLESTEP MAXVAL/100000
#define PAGESTEP MAXVAL/10000
+static void addTool(QToolBar *toolbar, Canvas *canvas, CanvasTool *tool)
+{
+ QAction *action = new QAction(tool->name(), toolbar);
+ action->setCheckable(true);
+ toolbar->addAction(action);
+ tool->connect(action, SIGNAL(toggled(bool)), tool, SLOT(setActive(bool)));
+ tool->setActive(false);
+ canvas->tools.push_back(tool);
+}
+
MainWindow::MainWindow()
{
QWidget *central = new QWidget();
@@ -52,6 +70,21 @@ MainWindow::MainWindow()
extractor = new AudioExtractor(this);
canvas = new Canvas(this);
+ QToolBar *toolbar = addToolBar("Tools");
+ CanvasTool *listen = new CanvasToolListen(canvas);
+ addTool(toolbar, canvas, listen);
+ CanvasTool *threshold = new CanvasToolThreshold(canvas);
+ addTool(toolbar, canvas, threshold);
+ CanvasTool *selections = new CanvasToolSelections(canvas);
+ connect(threshold, SIGNAL(thresholdChanged(double)),
+ selections, SLOT(thresholdChanged(double)));
+ addTool(toolbar, canvas, selections);
+
+ QMenu *fileMenu = menuBar()->addMenu("&File");
+ QAction *act_quit = new QAction("&Quit", this);
+ fileMenu->addAction(act_quit);
+ connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
+
QWidget *dock = new QWidget();
yoffset = new QScrollBar(Qt::Vertical);
yoffset->setRange(0, MAXVAL);
@@ -78,9 +111,9 @@ MainWindow::MainWindow()
connect(xoffset, SIGNAL(valueChanged(int)), this, SLOT(setXOffset(int)));
sorter = new SampleSorter();
- connect(canvas, SIGNAL(selectionsChanged(Selections)),
+ connect(selections, SIGNAL(selectionsChanged(Selections)),
sorter, SLOT(setSelections(Selections)));
- connect(canvas, SIGNAL(activeSelectionChanged(Selection)),
+ connect(selections, SIGNAL(activeSelectionChanged(Selection)),
sorter, SLOT(setActiveSelection(Selection)));
lh->addWidget(canvas);
@@ -96,12 +129,12 @@ MainWindow::MainWindow()
QPushButton *autosel = new QPushButton();
autosel->setText("Auto");
- connect(autosel, SIGNAL(clicked()), canvas, SLOT(clearSelections()));
- connect(autosel, SIGNAL(clicked()), canvas, SLOT(autoCreateSelections()));
+ connect(autosel, SIGNAL(clicked()), selections, SLOT(clearSelections()));
+ connect(autosel, SIGNAL(clicked()), selections, SLOT(autoCreateSelections()));
QPushButton *clearsel = new QPushButton();
clearsel->setText("Clear");
- connect(clearsel, SIGNAL(clicked()), canvas, SLOT(clearSelections()));
+ connect(clearsel, SIGNAL(clicked()), selections, SLOT(clearSelections()));
QPushButton *exportsel = new QPushButton();
exportsel->setText("Export");