summaryrefslogtreecommitdiff
path: root/dgedit
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-04-20 21:01:02 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-04-20 21:01:02 +0200
commit60fd5c525b59e429c9b0a4c3d500b66f26ef7c85 (patch)
treeb24eb6a562d5a8ab8aadff60cbabf3ade6cc3307 /dgedit
parent35c4f0b6ca508f428c31ab991633142b1384e382 (diff)
Rework sliders in 'generate' tab. Add 'hold' slider.
Diffstat (limited to 'dgedit')
-rw-r--r--dgedit/Makefile.am1
-rw-r--r--dgedit/canvastoolselections.cc18
-rw-r--r--dgedit/canvastoolselections.h8
-rw-r--r--dgedit/mainwindow.cc121
-rw-r--r--dgedit/mainwindow.h11
-rw-r--r--dgedit/sleep.h57
6 files changed, 124 insertions, 92 deletions
diff --git a/dgedit/Makefile.am b/dgedit/Makefile.am
index 7fb2383..4dd8524 100644
--- a/dgedit/Makefile.am
+++ b/dgedit/Makefile.am
@@ -44,6 +44,7 @@ EXTRA_DIST = \
samplesorter.h \
selection.h \
selectioneditor.h \
+ sleep.h \
volumefader.h \
dgedit.qrc
diff --git a/dgedit/canvastoolselections.cc b/dgedit/canvastoolselections.cc
index 8218172..ad5e193 100644
--- a/dgedit/canvastoolselections.cc
+++ b/dgedit/canvastoolselections.cc
@@ -39,6 +39,7 @@ CanvasToolSelections::CanvasToolSelections(Canvas *c, Selections &s,
: selections(s), selections_preview(p)
{
threshold = 0.5; // Default from CanvasToolThreshold
+ hold = 100;
canvas = c;
@@ -228,6 +229,11 @@ void CanvasToolSelections::thresholdChanged(double t)
threshold = t;
}
+void CanvasToolSelections::holdChanged(int h)
+{
+ hold = h;
+}
+
void CanvasToolSelections::noiseFloorChanged(int t)
{
double div = 666.0 / 0.00003;
@@ -260,20 +266,20 @@ void CanvasToolSelections::doAutoCreateSelections(bool preview)
if(fabs(data[i]) > fabs(threshold)) {
int from = i;
- // FIXME: This doesn't work if the recording has a DC offset.
if(data[from] > 0.0) {
- while(data[from] > 0.0) { // Not crossing zero
+ while(data[from] > data[from-1] // Falling
+ && data[from-1] > 0.0 // Not crossing zero
+ ) {
from--;
}
- from++;
} else if(data[from] < 0.0) {
- while(data[from-1] < 0.0) { // Not crossing zero
+ while(data[from] < data[from-1] // Rising
+ && data[from-1] < 0.0 // Not crossing zero
+ ) {
from--;
}
- from++;
}
- int hold = 1000; // hold in number of samples
int to = i;
float runavg = fabs(data[from]);
while((runavg > noise_floor ||
diff --git a/dgedit/canvastoolselections.h b/dgedit/canvastoolselections.h
index 59786a7..0557520 100644
--- a/dgedit/canvastoolselections.h
+++ b/dgedit/canvastoolselections.h
@@ -60,7 +60,8 @@ public slots:
void clearSelections();
void thresholdChanged(double threshold);
void noiseFloorChanged(int t);
- void fadeoutChanged(int t);
+ void holdChanged(int h);
+ void fadeoutChanged(int f);
void setShowPreview(bool show_preview);
private:
@@ -73,8 +74,9 @@ private:
double threshold;
double noise_floor;
- double fadeout;
-
+ double fadeout;
+ int hold;
+
QColor colSelBg;
QColor colSel;
QColor colActiveSelBg;
diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc
index 702a99e..58e048f 100644
--- a/dgedit/mainwindow.cc
+++ b/dgedit/mainwindow.cc
@@ -43,8 +43,9 @@
#include <QTabWidget>
#include <QProgressBar>
#include <QTime>
+#include <QSpinBox>
-//#include <unistd.h>
+#include "sleep.h"
#include "canvastool.h"
#include "canvastoolthreshold.h"
@@ -167,6 +168,12 @@ MainWindow::MainWindow()
dockWidget->setWidget(new QWidget());
dockWidget->widget()->setLayout(new QVBoxLayout());
+ dockWidget->widget()->layout()->addWidget(new QLabel("Presets:"));
+ presets = new QComboBox();
+ connect(presets, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(setPreset(int)));
+ dockWidget->widget()->layout()->addWidget(presets);
+
QTabWidget *tabs = new QTabWidget(this);
tabs->addTab(createFilesTab(), "Files");
generateTabId = tabs->addTab(createGenerateTab(), "Generate");
@@ -263,6 +270,33 @@ QWidget *MainWindow::createEditTab()
return se;
}
+QSlider *createAttribute(QWidget *parent, QString name,
+ int range_from, int range_to)
+{
+ QSlider *slider;
+
+ QGridLayout *l = new QGridLayout();
+
+ l->addWidget(new QLabel(name), 0, 0, 1, 2);
+
+ QSpinBox *spin = new QSpinBox();
+ spin->setRange(range_from, range_to);
+ l->addWidget(spin, 1, 0, 1, 1);
+
+ slider = new QSlider(Qt::Horizontal);
+ slider->setRange(range_from, range_to);
+ l->addWidget(slider, 1, 1, 1,1);
+
+ QObject::connect(spin, SIGNAL(valueChanged(int)),
+ slider, SLOT(setValue(int)));
+ QObject::connect(slider, SIGNAL(valueChanged(int)),
+ spin, SLOT(setValue(int)));
+
+ ((QBoxLayout *)parent->layout())->addLayout(l);
+
+ return slider;
+}
+
QWidget *MainWindow::createGenerateTab()
{
QWidget *w = new QWidget();
@@ -293,68 +327,33 @@ QWidget *MainWindow::createGenerateTab()
l->addLayout(btns);
- l->addWidget(new QLabel("Presets:"));
- presets = new QComboBox();
- connect(presets, SIGNAL(currentIndexChanged(int)),
- this, SLOT(setPreset(int)));
- l->addWidget(presets);
-
- QGridLayout *attribs_layout = new QGridLayout();
-
- attribs_layout->addWidget(new QLabel("Attack length:"), 1, 1, 1, 2);
- lineed_attacklength = new QLineEdit();
- lineed_attacklength->setReadOnly(true);
- lineed_attacklength->setValidator(new QIntValidator(0, 1000,
- lineed_attacklength));
- attribs_layout->addWidget(lineed_attacklength, 2, 1);
- slider_attacklength = new QSlider(Qt::Horizontal);
- slider_attacklength->setRange(10, 1000);
- connect(slider_attacklength, SIGNAL(valueChanged(int)),
- this, SLOT(setAttackLengthLineEd(int)));
+ slider_attacklength = createAttribute(w, "Attack length:", 10, 1000);
connect(slider_attacklength, SIGNAL(valueChanged(int)),
sorter, SLOT(setAttackLength(int)));
connect(slider_attacklength, SIGNAL(valueChanged(int)),
tool_selections, SLOT(autoCreateSelectionsPreview()));
-
slider_attacklength->setValue(666);
- attribs_layout->addWidget(slider_attacklength, 2, 2);
-
- attribs_layout->addWidget(new QLabel("Falloff:"), 3, 1, 1, 2);
- lineed_falloff = new QLineEdit();
- lineed_falloff->setReadOnly(true);
- 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, 1000);
- connect(slider_falloff, SIGNAL(valueChanged(int)),
- this, SLOT(setFalloffLineEd(int)));
+
+ slider_hold = createAttribute(w, "Minimum size (samples):", 0, 200000);
+ connect(slider_hold, SIGNAL(valueChanged(int)),
+ tool_selections, SLOT(holdChanged(int)));
+ connect(slider_hold, SIGNAL(valueChanged(int)),
+ tool_selections, SLOT(autoCreateSelectionsPreview()));
+ slider_hold->setValue(100);
+
+ slider_falloff = createAttribute(w, "Falloff:", 10, 5000);
connect(slider_falloff, SIGNAL(valueChanged(int)),
tool_selections, SLOT(noiseFloorChanged(int)));
connect(slider_falloff, SIGNAL(valueChanged(int)),
tool_selections, SLOT(autoCreateSelectionsPreview()));
-
slider_falloff->setValue(666);
- attribs_layout->addWidget(slider_falloff, 4, 2);
-
- attribs_layout->addWidget(new QLabel("Fadelength:"), 5, 1, 1, 2);
- lineed_fadelength = new QLineEdit();
- lineed_fadelength->setReadOnly(true);
- lineed_fadelength->setValidator(new QIntValidator(0, 2000,
- lineed_fadelength));
- attribs_layout->addWidget(lineed_fadelength, 6, 1);
- slider_fadelength = new QSlider(Qt::Horizontal);
- slider_fadelength->setRange(1, 2000);
- connect(slider_fadelength, SIGNAL(valueChanged(int)),
- this, SLOT(setFadeLengthLineEd(int)));
+
+ slider_fadelength = createAttribute(w, "Fadelength:", 0, 2000);
connect(slider_fadelength, SIGNAL(valueChanged(int)),
tool_selections, SLOT(fadeoutChanged(int)));
connect(slider_fadelength, SIGNAL(valueChanged(int)),
tool_selections, SLOT(autoCreateSelectionsPreview()));
-
slider_fadelength->setValue(666);
- attribs_layout->addWidget(slider_fadelength, 6, 2);
-
- l->addLayout(attribs_layout);
l->addStretch();
@@ -401,27 +400,6 @@ QWidget *MainWindow::createExportTab()
return w;
}
-void MainWindow::setAttackLengthLineEd(int value)
-{
- lineed_attacklength->setText(QString::number(value));
-}
-
-void MainWindow::setFalloffLineEd(int value)
-{
- lineed_falloff->setText(QString::number(value));
-}
-
-void MainWindow::setFadeLengthLineEd(int value)
-{
- lineed_fadelength->setText(QString::number(value));
-}
-
-void MainWindow::setVolumeLineEd(int value)
-{
- lineed_slider4->setText(QString::number(value));
-}
-
-
void MainWindow::playSamples()
{
QVector<sel_id_t> ids = selections.ids();
@@ -461,7 +439,7 @@ void MainWindow::playSamples()
t.start();
while(t.elapsed() < sb_playsamples->value()) {
qApp->processEvents();
- usleep(25 * 1000);
+ q_usleep(25 * 1000);
}
player.stop();
@@ -558,11 +536,8 @@ void MainWindow::setPreset(int index)
QVariant v = presets->itemData(index);
Preset p = v.value<Preset>();
slider_attacklength->setValue(p.attacklength);
- lineed_attacklength->setText(QString::number(p.attacklength));
slider_falloff->setValue(p.falloff);
- lineed_falloff->setText(QString::number(p.falloff));
slider_fadelength->setValue(p.fadelength);
- lineed_fadelength->setText(QString::number(p.fadelength));
prefix->setText(p.prefix);
}
diff --git a/dgedit/mainwindow.h b/dgedit/mainwindow.h
index 6fef5db..a47e729 100644
--- a/dgedit/mainwindow.h
+++ b/dgedit/mainwindow.h
@@ -98,13 +98,10 @@ private:
QScrollBar *xoffset;
QScrollBar *sb_playsamples;
QComboBox *presets;
- QLineEdit *lineed_attacklength;
QSlider *slider_attacklength;
- QLineEdit *lineed_falloff;
+ QSlider *slider_hold;
QSlider *slider_falloff;
- QLineEdit *lineed_fadelength;
QSlider *slider_fadelength;
- QLineEdit *lineed_slider4;
QLineEdit *prefix;
QLineEdit *lineed_exportp;
@@ -112,12 +109,6 @@ private:
Selections selections;
Selections selections_preview;
Player player;
-
-private slots:
- void setAttackLengthLineEd(int);
- void setFalloffLineEd(int);
- void setFadeLengthLineEd(int);
- void setVolumeLineEd(int);
};
#endif/*__DRUMGIZMO_MAINWINDOW_H__*/
diff --git a/dgedit/sleep.h b/dgedit/sleep.h
new file mode 100644
index 0000000..107b7a8
--- /dev/null
+++ b/dgedit/sleep.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * sleep.h
+ *
+ * Sun Apr 20 18:54:58 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_SLEEP_H__
+#define __DRUMGIZMO_SLEEP_H__
+
+#include <QThread>
+
+class __Sleeper : public QThread {
+public:
+ void msleep(unsigned long msecs) { QThread::msleep(msecs); }
+ void sleep(unsigned long secs) { QThread::sleep(secs); }
+ void usleep(unsigned long usecs) { QThread::usleep(usecs); }
+};
+
+inline void q_msleep(unsigned long msecs)
+{
+ __Sleeper s;
+ s.msleep(msecs);
+}
+
+inline void q_sleep(unsigned long secs)
+{
+ __Sleeper s;
+ s.sleep(secs);
+}
+
+inline void q_usleep(unsigned long usecs)
+{
+ __Sleeper s;
+ s.usleep(usecs);
+}
+
+#endif/*__DRUMGIZMO_SLEEP_H__*/