From 02119553f51d418ebb6473f49784487fa954b50c Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 16 Apr 2014 12:18:05 +0200 Subject: Show energy circles in preview mode. --- dgedit/mainwindow.cc | 15 ++++++-- dgedit/samplesorter.cc | 100 ++++++++++++++++++++++++++++++++++++++----------- dgedit/samplesorter.h | 9 ++++- 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 ids = selections.ids(); - QVector::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 ids = selections.ids(); + QVector::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 ids = selections_preview.ids(); + QVector::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 ids = selections.ids(); + QVector::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 ids = selections.ids(); - QVector::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 ids = selections_preview.ids(); + QVector::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; -- cgit v1.2.3