summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-04-16 12:18:05 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-04-16 12:18:05 +0200
commit02119553f51d418ebb6473f49784487fa954b50c (patch)
treef638c16e1fc3262def32939809a5b1a884b0332a
parent50b1911fb718823b596aaa0ac600ebc2fd85f18d (diff)
Show energy circles in preview mode.
-rw-r--r--dgedit/mainwindow.cc15
-rw-r--r--dgedit/samplesorter.cc100
-rw-r--r--dgedit/samplesorter.h9
3 files changed, 99 insertions, 25 deletions
diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc
index 6585c67..1b82841 100644
--- a/dgedit/mainwindow.cc
+++ b/dgedit/mainwindow.cc
@@ -125,11 +125,17 @@ MainWindow::MainWindow()
xoffset->setSingleStep(SINGLESTEP);
connect(xoffset, SIGNAL(valueChanged(int)), this, SLOT(setXOffset(int)));
- sorter = new SampleSorter(selections);
+ sorter = new SampleSorter(selections, selections_preview);
connect(&selections, SIGNAL(added(sel_id_t)),
sorter, SLOT(addSelection(sel_id_t)));
+ connect(&selections_preview, SIGNAL(added(sel_id_t)),
+ sorter, SLOT(addSelectionPreview(sel_id_t)));
connect(&selections, SIGNAL(updated(sel_id_t)), sorter, SLOT(relayout()));
+ connect(&selections_preview, SIGNAL(updated(sel_id_t)),
+ sorter, SLOT(relayout()));
connect(&selections, SIGNAL(removed(sel_id_t)), sorter, SLOT(relayout()));
+ connect(&selections_preview, SIGNAL(removed(sel_id_t)),
+ sorter, SLOT(relayout()));
connect(&selections, SIGNAL(activeChanged(sel_id_t)),
sorter, SLOT(relayout()));
@@ -163,6 +169,7 @@ MainWindow::MainWindow()
tabs->addTab(createEditTab(), "Edit");
tabs->addTab(createExportTab(), "Export");
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
+ tabChanged(tabs->currentIndex());
dockWidget->widget()->layout()->addWidget(tabs);
@@ -208,6 +215,8 @@ MainWindow::~MainWindow()
void MainWindow::tabChanged(int tabid)
{
tool_selections->setShowPreview(tabid == generateTabId);
+ sorter->setShowPreview(tabid == generateTabId);
+ tool_selections->autoCreateSelectionsPreview();
}
QWidget *MainWindow::createFilesTab()
@@ -298,10 +307,10 @@ QWidget *MainWindow::createGenerateTab()
attribs_layout->addWidget(new QLabel("Falloff:"), 3, 1, 1, 2);
lineed_falloff = new QLineEdit();
lineed_falloff->setReadOnly(true);
- lineed_falloff->setValidator(new QIntValidator(0, 10000, lineed_falloff));
+ lineed_falloff->setValidator(new QIntValidator(0, 1000, lineed_falloff));
attribs_layout->addWidget(lineed_falloff, 4, 1);
slider_falloff = new QSlider(Qt::Horizontal);
- slider_falloff->setRange(1, 10000);
+ slider_falloff->setRange(1, 1000);
connect(slider_falloff, SIGNAL(sliderMoved(int)),
this, SLOT(setFalloffLineEd(int)));
connect(slider_falloff, SIGNAL(sliderMoved(int)),
diff --git a/dgedit/samplesorter.cc b/dgedit/samplesorter.cc
index 57af071..402bc37 100644
--- a/dgedit/samplesorter.cc
+++ b/dgedit/samplesorter.cc
@@ -36,8 +36,8 @@
#define MAXFLOAT (3.40282347e+38F)
#endif
-SampleSorter::SampleSorter(Selections &s)
- : selections(s)
+SampleSorter::SampleSorter(Selections &s, Selections &p)
+ : selections(s), selections_preview(p)
{
setMouseTracking(true);
@@ -48,6 +48,12 @@ SampleSorter::SampleSorter(Selections &s)
sel_moving = SEL_NONE;
}
+void SampleSorter::setShowPreview(bool s)
+{
+ show_preview = s;
+ update();
+}
+
void SampleSorter::setWavData(const float *data, size_t size)
{
this->data = data;
@@ -84,20 +90,53 @@ void SampleSorter::addSelection(sel_id_t id)
relayout();
}
+void SampleSorter::addSelectionPreview(sel_id_t id)
+{
+ Selection s = selections_preview.get(id);
+
+ double energy = 0.0;
+ for(size_t idx = s.from;
+ (idx < (size_t)s.from + (size_t)attackLength()) &&
+ (idx < (size_t)s.to) && (idx < size);
+ idx++) {
+ energy += data[idx] * data[idx];
+ }
+
+ s.energy = energy;
+ selections_preview.update(id, s);
+
+ relayout();
+}
+
void SampleSorter::relayout()
{
min = MAXFLOAT;
max = 0.0;
- QVector<sel_id_t> ids = selections.ids();
- QVector<sel_id_t>::iterator i = ids.begin();
- while(i != ids.end()) {
- Selection sel = selections.get(*i);
-
- if(sel.energy < min) min = sel.energy;
- if(sel.energy > max) max = sel.energy;
+ {
+ QVector<sel_id_t> ids = selections.ids();
+ QVector<sel_id_t>::iterator i = ids.begin();
+ while(i != ids.end()) {
+ Selection sel = selections.get(*i);
+
+ if(sel.energy < min) min = sel.energy;
+ if(sel.energy > max) max = sel.energy;
+
+ i++;
+ }
+ }
- i++;
+ if(show_preview) {
+ QVector<sel_id_t> ids = selections_preview.ids();
+ QVector<sel_id_t>::iterator i = ids.begin();
+ while(i != ids.end()) {
+ Selection sel = selections_preview.get(*i);
+
+ if(sel.energy < min) min = sel.energy;
+ if(sel.energy > max) max = sel.energy;
+
+ i++;
+ }
}
update();
@@ -123,6 +162,7 @@ void SampleSorter::paintEvent(QPaintEvent *event)
QColor colBg = QColor(180, 200, 180);
QColor colFg = QColor(160, 180, 160);
QColor colPt = QColor(255, 100, 100);
+ QColor colPtPreview = QColor(0, 0, 255);
QColor colPtSel = QColor(255, 255, 100);
painter.setPen(colBg);
@@ -131,19 +171,37 @@ void SampleSorter::paintEvent(QPaintEvent *event)
painter.setPen(colFg);
painter.drawLine(0,height(),width(),0);
+
+ {
+ QVector<sel_id_t> ids = selections.ids();
+ QVector<sel_id_t>::iterator i = ids.begin();
+ while(i != ids.end()) {
+ Selection sel = selections.get(*i);
+ if(*i == selections.active()) painter.setPen(colPtSel);
+ else painter.setPen(colPt);
+ float x = sel.energy / max;
+ x = sqrt(x);
+ x *= (float)width();
+ drawCircle(painter, x, MAP(x));
+ i++;
+ }
+ }
- QVector<sel_id_t> ids = selections.ids();
- QVector<sel_id_t>::iterator i = ids.begin();
- while(i != ids.end()) {
- Selection sel = selections.get(*i);
- if(*i == selections.active()) painter.setPen(colPtSel);
- else painter.setPen(colPt);
- float x = sel.energy / max;
- x = sqrt(x);
- x *= (float)width();
- drawCircle(painter, x, MAP(x));
- i++;
+ if(show_preview) {
+ QVector<sel_id_t> ids = selections_preview.ids();
+ QVector<sel_id_t>::iterator i = ids.begin();
+ while(i != ids.end()) {
+ Selection sel = selections_preview.get(*i);
+ painter.setPen(colPtPreview);
+ float x = sel.energy / max;
+ x = sqrt(x);
+ x *= (float)width();
+ drawCircle(painter, x, MAP(x));
+ i++;
+ }
}
+
+
}
sel_id_t SampleSorter::getSelectionByCoordinate(int px, int py)
diff --git a/dgedit/samplesorter.h b/dgedit/samplesorter.h
index f35622a..ada7fd8 100644
--- a/dgedit/samplesorter.h
+++ b/dgedit/samplesorter.h
@@ -34,7 +34,7 @@
class SampleSorter : public QWidget {
Q_OBJECT
public:
- SampleSorter(Selections &selections);
+ SampleSorter(Selections &selections, Selections &selections_preview);
public slots:
void setWavData(const float *data, size_t size);
@@ -42,8 +42,12 @@ public slots:
int attackLength();
void addSelection(sel_id_t id);
+ void addSelectionPreview(sel_id_t id);
+
void relayout();
+ void setShowPreview(bool show_preview);
+
protected:
void paintEvent(QPaintEvent *event);
void mouseMoveEvent(QMouseEvent *event);
@@ -54,6 +58,9 @@ private:
sel_id_t getSelectionByCoordinate(int x, int y);
Selections &selections;
+ Selections &selections_preview;
+
+ bool show_preview;
float min;
float max;