summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-05-12 16:23:54 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-05-12 16:24:05 +0200
commit627f2cb593daf219aad04cfa45668cbfa7a17a59 (patch)
tree9813f9238e180f2955df27962d7d559f06149c6a
parent654d77643199f53f6ff990963ce5c62794325910 (diff)
Move instrument editor components into their own (sub)window.
-rw-r--r--src/Makefile.am4
-rw-r--r--src/instrumentwindow.cc445
-rw-r--r--src/instrumentwindow.h111
-rw-r--r--src/mainwindow.cc383
-rw-r--r--src/mainwindow.h66
5 files changed, 566 insertions, 443 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 15d63d1..69b224b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,7 @@ bin_PROGRAMS = dgedit
dgedit_LDADD = $(SNDFILE_LIBS) $(QT_LIBS) $(AO_LIBS) \
$(shell ../tools/MocList o ) qrc_dgedit.o
-dgedit_CXXFLAGS = $(SNDFILE_CXXFLAGS) $(QT_CFLAGS) $(AO_CFLAGS) \
+dgedit_CXXFLAGS = -g $(SNDFILE_CXXFLAGS) $(QT_CFLAGS) $(AO_CFLAGS) \
-DLOCALEDIR='"$(localedir)"'
AM_CXXFLAGS = $(QT_CFLAGS)
@@ -23,6 +23,7 @@ dgedit_SOURCES = \
canvastoolthreshold.cc \
canvaswidget.cc \
filelist.cc \
+ instrumentwindow.cc \
itemeditor.cc \
localehandler.cc \
mainwindow.cc \
@@ -47,6 +48,7 @@ EXTRA_DIST = \
canvastoolthreshold.h \
canvaswidget.h \
filelist.h \
+ instrumentwindow.h \
itemeditor.h \
localehandler.h \
mainwindow.h \
diff --git a/src/instrumentwindow.cc b/src/instrumentwindow.cc
new file mode 100644
index 0000000..f40f527
--- /dev/null
+++ b/src/instrumentwindow.cc
@@ -0,0 +1,445 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * instrumentwindow.cc
+ *
+ * Sat May 12 15:38:38 CEST 2018
+ * Copyright 2018 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.
+ */
+#include "instrumentwindow.h"
+
+
+#include <iostream>
+
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+
+#include <QPushButton>
+#include <QLabel>
+#include <QStatusBar>
+#include <QApplication>
+#include <QDockWidget>
+#include <QToolBar>
+#include <QAction>
+#include <QMenuBar>
+#include <QFileDialog>
+#include <QIntValidator>
+#include <QTabWidget>
+#include <QProgressBar>
+#include <QTime>
+#include <QSpinBox>
+
+#include "sleep.h"
+#include "canvastool.h"
+#include "canvastoolthreshold.h"
+#include "volumefader.h"
+#include "selectioneditor.h"
+#include "zoomslider.h"
+#include "settings.h"
+
+#define MAXVAL 10000000L
+
+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);
+}
+
+InstrumentWindow::InstrumentWindow(Settings& settings)
+ : settings(settings)
+{
+ {
+ int start = 44100 * 60;
+ Selection p(start, start + 44100 * 60, 0, 0); // one minute selection
+ selections_preview.add(p);
+ }
+
+ QWidget* central = new QWidget();
+ QHBoxLayout* lh = new QHBoxLayout();
+ QVBoxLayout* lv = new QVBoxLayout();
+ central->setLayout(lv);
+ setCentralWidget(central);
+
+ extractor = new AudioExtractor(selections, this);
+ canvaswidget = new CanvasWidget(this);
+
+ QToolBar* toolbar = addToolBar(tr("Tools"));
+ listen = new CanvasToolListen(canvaswidget->canvas, player);
+ addTool(toolbar, canvaswidget->canvas, listen);
+ threshold = new CanvasToolThreshold(canvaswidget->canvas);
+ canvaswidget->canvas->tools.push_back(threshold);
+ tool_selections = new CanvasToolSelections(canvaswidget->canvas, selections,
+ selections_preview);
+ connect(threshold, SIGNAL(thresholdChanged(double)),
+ tool_selections, SLOT(thresholdChanged(double)));
+ connect(threshold, SIGNAL(thresholdChanging(double)),
+ tool_selections, SLOT(thresholdChanged(double)));
+ connect(&selections, SIGNAL(activeChanged(sel_id_t)),
+ canvaswidget->canvas, SLOT(update()));
+ connect(&selections, SIGNAL(updated(sel_id_t)),
+ canvaswidget->canvas, SLOT(update()));
+ addTool(toolbar, canvaswidget->canvas, tool_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()));
+
+ QPushButton* btn_playsamples = new QPushButton(tr("Play samples"));
+ connect(btn_playsamples, SIGNAL(clicked()), this, SLOT(playSamples()));
+
+ sb_playsamples = new QScrollBar(Qt::Horizontal);
+ sb_playsamples->setRange(100, 4000); // ms
+
+
+ lh->addWidget(canvaswidget);
+ lv->addLayout(lh, 100);
+ lv->addWidget(sorter, 15);
+ lv->addWidget(btn_playsamples);
+ lv->addWidget(sb_playsamples);
+
+
+ QDockWidget* dockWidget = new QDockWidget(tr("Dock Widget"), this);
+ dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+
+ dockWidget->setWidget(new QWidget());
+ dockWidget->widget()->setLayout(new QVBoxLayout());
+
+ tabs = new QTabWidget(this);
+ tabs->addTab(createFilesTab(), tr("Files"));
+ generateTabId = tabs->addTab(createGenerateTab(), tr("Generate"));
+ tabs->addTab(createEditTab(), tr("Edit"));
+ tabs->addTab(createExportTab(), tr("Export"));
+ connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
+ tabChanged(tabs->currentIndex());
+
+ dockWidget->widget()->layout()->addWidget(tabs);
+
+ VolumeFader* vol = new VolumeFader();
+ connect(vol, SIGNAL(volumeChangedDb(double)),
+ &player, SLOT(setGainDB(double)));
+ connect(&player, SIGNAL(peakUpdate(double)),
+ vol, SLOT(updatePeakPower(double)));
+
+ vol->setVolumeDb(0);
+ dockWidget->widget()->layout()->addWidget(vol);
+
+ addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
+
+ canvaswidget->yscale->setValue(0.9);
+ canvaswidget->yoffset->setValue(MAXVAL/2);
+ canvaswidget->xscale->setValue(0);
+ canvaswidget->xoffset->setValue(0);
+}
+
+InstrumentWindow::~InstrumentWindow()
+{
+}
+
+void InstrumentWindow::tabChanged(int tabid)
+{
+ tool_selections->setShowPreview(tabid == generateTabId);
+ sorter->setShowPreview(tabid == generateTabId);
+ tool_selections->autoCreateSelectionsPreview();
+ threshold->setActive(tabid == generateTabId);
+}
+
+QWidget* InstrumentWindow::createFilesTab()
+{
+ QWidget* w = new QWidget();
+ QVBoxLayout* l = new QVBoxLayout();
+ w->setLayout(l);
+
+ l->addWidget(new QLabel(tr("Files: (double-click to set as master)")));
+ QPushButton* loadbtn = new QPushButton();
+ loadbtn->setText(tr("Add files..."));
+ l->addWidget(loadbtn);
+
+ filelist = new FileList();
+ connect(filelist, SIGNAL(masterFileChanged(QString)),
+ this, SLOT(loadFile(QString)));
+ connect(loadbtn, SIGNAL(clicked()), filelist, SLOT(addFiles()));
+ connect(filelist, SIGNAL(fileAdded(QString, QString)),
+ extractor, SLOT(addFile(QString, QString)));
+ connect(filelist, SIGNAL(fileRemoved(QString, QString)),
+ extractor, SLOT(removeFile(QString, QString)));
+ connect(filelist, SIGNAL(nameChanged(QString, QString)),
+ extractor, SLOT(changeName(QString, QString)));
+ l->addWidget(filelist);
+
+ return w;
+}
+
+QWidget* InstrumentWindow::createEditTab()
+{
+ SelectionEditor* se = new SelectionEditor(selections);
+
+ connect(&selections, SIGNAL(added(sel_id_t)), se, SLOT(added(sel_id_t)));
+ connect(&selections, SIGNAL(updated(sel_id_t)), se, SLOT(updated(sel_id_t)));
+ connect(&selections, SIGNAL(removed(sel_id_t)), se, SLOT(removed(sel_id_t)));
+ connect(&selections, SIGNAL(activeChanged(sel_id_t)),
+ se, SLOT(activeChanged(sel_id_t)));
+
+ return se;
+}
+
+static 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* InstrumentWindow::createGenerateTab()
+{
+ QWidget* w = new QWidget();
+ QVBoxLayout* l = new QVBoxLayout();
+ w->setLayout(l);
+
+ QHBoxLayout* btns = new QHBoxLayout();
+
+ QPushButton* autosel = new QPushButton();
+ autosel->setText(tr("Generate"));
+ connect(autosel, SIGNAL(clicked()),
+ tool_selections, SLOT(clearSelections()));
+ connect(autosel, SIGNAL(clicked()),
+ tool_selections, SLOT(autoCreateSelections()));
+
+ connect(threshold, SIGNAL(thresholdChanged(double)),
+ tool_selections, SLOT(autoCreateSelectionsPreview()));
+ connect(threshold, SIGNAL(thresholdChanging(double)),
+ tool_selections, SLOT(autoCreateSelectionsPreview()));
+
+ QPushButton* clearsel = new QPushButton();
+ clearsel->setText(tr("Clear"));
+ connect(clearsel, SIGNAL(clicked()),
+ tool_selections, SLOT(clearSelections()));
+
+ btns->addWidget(autosel);
+ btns->addWidget(clearsel);
+
+ l->addLayout(btns);
+
+ slider_attacklength = createAttribute(w, tr("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(300);
+
+ slider_spread = createAttribute(w, tr("Power spread:"), 1, 2000);
+ connect(slider_spread, SIGNAL(valueChanged(int)),
+ sorter, SLOT(setSpreadFactor(int)));
+ connect(slider_spread, SIGNAL(valueChanged(int)),
+ tool_selections, SLOT(autoCreateSelectionsPreview()));
+ slider_spread->setValue(1000);
+
+ slider_hold = createAttribute(w, tr("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, tr("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(300);
+
+ slider_fadelength = createAttribute(w, tr("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);
+
+ l->addStretch();
+
+ return w;
+}
+
+QWidget* InstrumentWindow::createExportTab()
+{
+ QWidget* w = new QWidget();
+ QVBoxLayout* l = new QVBoxLayout();
+ w->setLayout(l);
+
+ l->addWidget(new QLabel(tr("Prefix:")));
+ prefix = new QLineEdit();
+ connect(prefix, SIGNAL(textChanged(const QString &)),
+ extractor, SLOT(setOutputPrefix(const QString &)));
+ l->addWidget(prefix);
+
+ l->addWidget(new QLabel(tr("Export path:")));
+ QHBoxLayout* lo_exportp = new QHBoxLayout();
+ lineed_exportp = new QLineEdit();
+ connect(lineed_exportp, SIGNAL(textChanged(const QString &)),
+ extractor, SLOT(setExportPath(const QString &)));
+ lo_exportp->addWidget(lineed_exportp);
+ QPushButton* btn_browse = new QPushButton(tr("..."));
+ connect(btn_browse, SIGNAL(clicked()), this, SLOT(browse()));
+ lo_exportp->addWidget(btn_browse);
+
+ l->addLayout(lo_exportp);
+
+ QPushButton* exportsel = new QPushButton();
+ exportsel->setText(tr("Export"));
+ connect(exportsel, SIGNAL(clicked()), this, SLOT(doExport()));
+ l->addWidget(exportsel);
+
+ QProgressBar* bar = new QProgressBar();
+ connect(extractor, SIGNAL(progressUpdate(int)), bar, SLOT(setValue(int)));
+ connect(extractor, SIGNAL(setMaximumProgress(int)),
+ bar, SLOT(setMaximum(int)));
+ l->addWidget(bar);
+
+ l->addStretch();
+
+ return w;
+}
+
+void InstrumentWindow::playSamples()
+{
+ Selections* sels = &selections;
+ if(tabs->currentIndex() == generateTabId)
+ {
+ sels = &selections_preview;
+ }
+
+ QVector<sel_id_t> ids = sels->ids();
+ for(int v1 = 0; v1 < ids.size(); v1++)
+ {
+ for(int v2 = 0; v2 < ids.size(); v2++)
+ {
+ Selection sel1 = sels->get(ids[v1]);
+ Selection sel2 = sels->get(ids[v2]);
+
+ if(sel1.energy < sel2.energy)
+ {
+ sel_id_t vtmp = ids[v1];
+ ids[v1] = ids[v2];
+ ids[v2] = vtmp;
+ }
+ }
+ }
+
+ QVector<sel_id_t>::iterator i = ids.begin();
+ while(i != ids.end())
+ {
+ Selection sel = sels->get(*i);
+
+ unsigned int length = sb_playsamples->value() * 44100 / 1000;
+
+ unsigned int sample_length = sel.to - sel.from;
+
+ unsigned int to = sel.to;
+
+ if(sample_length > length)
+ {
+ to = sel.from + length;
+ }
+
+ sels->setActive(*i);
+
+ connect(&player, SIGNAL(positionUpdate(size_t)),
+ listen, SLOT(update(size_t)));
+
+ player.playSelection(sel, to - sel.from);
+ QTime t;
+ t.start();
+ while(t.elapsed() < sb_playsamples->value())
+ {
+ qApp->processEvents();
+ q_usleep(25 * 1000);
+ }
+ player.stop();
+
+ disconnect(&player, SIGNAL(positionUpdate(size_t)),
+ listen, SLOT(update(size_t)));
+ i++;
+ }
+}
+
+void InstrumentWindow::doExport()
+{
+ extractor->exportSelections();
+}
+
+void InstrumentWindow::loadFile(QString filename)
+{
+ setCursor(Qt::WaitCursor);
+ statusBar()->showMessage(tr("Loading..."));
+ qApp->processEvents();
+
+ sorter->setWavData(NULL, 0);
+ player.setPcmData(NULL, 0);
+
+ canvaswidget->canvas->load(filename);
+
+ sorter->setWavData(canvaswidget->canvas->data, canvaswidget->canvas->size);
+ player.setPcmData(canvaswidget->canvas->data, canvaswidget->canvas->size);
+
+ statusBar()->showMessage(tr("Ready"));
+ setCursor(Qt::ArrowCursor);
+}
+
+void InstrumentWindow::browse()
+{
+ QString path =
+ QFileDialog::getExistingDirectory(this, tr("Select export path"),
+ lineed_exportp->text());
+ lineed_exportp->setText(path);
+}
diff --git a/src/instrumentwindow.h b/src/instrumentwindow.h
new file mode 100644
index 0000000..4e3a1a4
--- /dev/null
+++ b/src/instrumentwindow.h
@@ -0,0 +1,111 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * instrumentwindow.h
+ *
+ * Sat May 12 15:38:38 CEST 2018
+ * Copyright 2018 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.
+ */
+#pragma once
+
+#include <QMainWindow>
+#include <QScrollBar>
+#include <QComboBox>
+#include <QSlider>
+#include <QLineEdit>
+#include <QCloseEvent>
+#include <QTabWidget>
+
+#include "canvas.h"
+#include "audioextractor.h"
+#include "samplesorter.h"
+#include "filelist.h"
+#include "canvastoolselections.h"
+#include "canvastoolthreshold.h"
+#include "canvastoollisten.h"
+#include "selection.h"
+#include "player.h"
+#include "zoomslider.h"
+#include "canvaswidget.h"
+
+class Settings;
+
+class Preset
+{
+public:
+ QString prefix;
+ int attacklength;
+ int falloff;
+ int fadelength;
+};
+Q_DECLARE_METATYPE(Preset)
+
+class InstrumentWindow
+ : public QMainWindow
+{
+ Q_OBJECT
+public:
+ InstrumentWindow(Settings& settings);
+ ~InstrumentWindow();
+
+public slots:
+ void doExport();
+ void loadFile(QString filename);
+ void playSamples();
+ void browse();
+ void tabChanged(int tabid);
+
+private:
+ QWidget* createFilesTab();
+ QWidget* createEditTab();
+ QWidget* createGenerateTab();
+ QWidget* createExportTab();
+
+ int generateTabId;
+
+ SampleSorter* sorter;
+ CanvasToolSelections* tool_selections;
+ CanvasToolThreshold* threshold;
+ CanvasToolListen* listen;
+ AudioExtractor* extractor;
+ FileList* filelist;
+
+ CanvasWidget* canvaswidget;
+
+ QScrollBar* sb_playsamples;
+ QComboBox* presets;
+ QSlider* slider_attacklength;
+ QSlider* slider_spread;
+ QSlider* slider_hold;
+ QSlider* slider_falloff;
+ QSlider* slider_fadelength;
+ QLineEdit* prefix;
+ QLineEdit* lineed_exportp;
+
+ QTabWidget* tabs;
+
+ // Session state information:
+ Selections selections;
+ Selections selections_preview;
+ Player player;
+
+ Settings& settings;
+};
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 04c5f2a..8c08eed 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -58,51 +58,13 @@
#define MAXVAL 10000000L
-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(Settings& settings)
: settings(settings)
+ , instrument_window(settings)
{
setWindowTitle(tr("DGEdit - DrumGizmo Drumkit Editor"));
- {
- int start = 44100 * 60;
- Selection p(start, start + 44100 * 60, 0, 0); // one minute selection
- selections_preview.add(p);
- }
- QWidget* central = new QWidget();
- QHBoxLayout* lh = new QHBoxLayout();
- QVBoxLayout* lv = new QVBoxLayout();
- central->setLayout(lv);
- setCentralWidget(central);
-
- extractor = new AudioExtractor(selections, this);
- canvaswidget = new CanvasWidget(this);
-
- QToolBar* toolbar = addToolBar(tr("Tools"));
- listen = new CanvasToolListen(canvaswidget->canvas, player);
- addTool(toolbar, canvaswidget->canvas, listen);
- threshold = new CanvasToolThreshold(canvaswidget->canvas);
- canvaswidget->canvas->tools.push_back(threshold);
- tool_selections = new CanvasToolSelections(canvaswidget->canvas, selections,
- selections_preview);
- connect(threshold, SIGNAL(thresholdChanged(double)),
- tool_selections, SLOT(thresholdChanged(double)));
- connect(threshold, SIGNAL(thresholdChanging(double)),
- tool_selections, SLOT(thresholdChanged(double)));
- connect(&selections, SIGNAL(activeChanged(sel_id_t)),
- canvaswidget->canvas, SLOT(update()));
- connect(&selections, SIGNAL(updated(sel_id_t)),
- canvaswidget->canvas, SLOT(update()));
- addTool(toolbar, canvaswidget->canvas, tool_selections);
+ setCentralWidget(&instrument_window);
QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
@@ -122,66 +84,6 @@ MainWindow::MainWindow(Settings& settings)
fileMenu->addAction(act_quit);
connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
- 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()));
-
- QPushButton* btn_playsamples = new QPushButton(tr("Play samples"));
- connect(btn_playsamples, SIGNAL(clicked()), this, SLOT(playSamples()));
-
- sb_playsamples = new QScrollBar(Qt::Horizontal);
- sb_playsamples->setRange(100, 4000); // ms
-
-
- lh->addWidget(canvaswidget);
- lv->addLayout(lh, 100);
- lv->addWidget(sorter, 15);
- lv->addWidget(btn_playsamples);
- lv->addWidget(sb_playsamples);
-
-
- QDockWidget* dockWidget = new QDockWidget(tr("Dock Widget"), this);
- dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-
- dockWidget->setWidget(new QWidget());
- dockWidget->widget()->setLayout(new QVBoxLayout());
-
- tabs = new QTabWidget(this);
- tabs->addTab(createFilesTab(), tr("Files"));
- generateTabId = tabs->addTab(createGenerateTab(), tr("Generate"));
- tabs->addTab(createEditTab(), tr("Edit"));
- tabs->addTab(createExportTab(), tr("Export"));
- connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
- tabChanged(tabs->currentIndex());
-
- dockWidget->widget()->layout()->addWidget(tabs);
-
- VolumeFader* vol = new VolumeFader();
- connect(vol, SIGNAL(volumeChangedDb(double)),
- &player, SLOT(setGainDB(double)));
- connect(&player, SIGNAL(peakUpdate(double)),
- vol, SLOT(updatePeakPower(double)));
-
- vol->setVolumeDb(0);
- dockWidget->widget()->layout()->addWidget(vol);
-
- addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
-
- canvaswidget->yscale->setValue(0.9);
- canvaswidget->yoffset->setValue(MAXVAL/2);
- canvaswidget->xscale->setValue(0);
- canvaswidget->xoffset->setValue(0);
-
loadSettings();
statusBar()->showMessage(tr("Ready"));
@@ -193,252 +95,6 @@ MainWindow::~MainWindow()
{
}
-void MainWindow::tabChanged(int tabid)
-{
- tool_selections->setShowPreview(tabid == generateTabId);
- sorter->setShowPreview(tabid == generateTabId);
- tool_selections->autoCreateSelectionsPreview();
- threshold->setActive(tabid == generateTabId);
-}
-
-QWidget* MainWindow::createFilesTab()
-{
- QWidget* w = new QWidget();
- QVBoxLayout* l = new QVBoxLayout();
- w->setLayout(l);
-
- l->addWidget(new QLabel(tr("Files: (double-click to set as master)")));
- QPushButton* loadbtn = new QPushButton();
- loadbtn->setText(tr("Add files..."));
- l->addWidget(loadbtn);
-
- filelist = new FileList();
- connect(filelist, SIGNAL(masterFileChanged(QString)),
- this, SLOT(loadFile(QString)));
- connect(loadbtn, SIGNAL(clicked()), filelist, SLOT(addFiles()));
- connect(filelist, SIGNAL(fileAdded(QString, QString)),
- extractor, SLOT(addFile(QString, QString)));
- connect(filelist, SIGNAL(fileRemoved(QString, QString)),
- extractor, SLOT(removeFile(QString, QString)));
- connect(filelist, SIGNAL(nameChanged(QString, QString)),
- extractor, SLOT(changeName(QString, QString)));
- l->addWidget(filelist);
-
- return w;
-}
-
-QWidget* MainWindow::createEditTab()
-{
- SelectionEditor* se = new SelectionEditor(selections);
-
- connect(&selections, SIGNAL(added(sel_id_t)), se, SLOT(added(sel_id_t)));
- connect(&selections, SIGNAL(updated(sel_id_t)), se, SLOT(updated(sel_id_t)));
- connect(&selections, SIGNAL(removed(sel_id_t)), se, SLOT(removed(sel_id_t)));
- connect(&selections, SIGNAL(activeChanged(sel_id_t)),
- se, SLOT(activeChanged(sel_id_t)));
-
- 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();
- QVBoxLayout* l = new QVBoxLayout();
- w->setLayout(l);
-
- QHBoxLayout* btns = new QHBoxLayout();
-
- QPushButton* autosel = new QPushButton();
- autosel->setText(tr("Generate"));
- connect(autosel, SIGNAL(clicked()),
- tool_selections, SLOT(clearSelections()));
- connect(autosel, SIGNAL(clicked()),
- tool_selections, SLOT(autoCreateSelections()));
-
- connect(threshold, SIGNAL(thresholdChanged(double)),
- tool_selections, SLOT(autoCreateSelectionsPreview()));
- connect(threshold, SIGNAL(thresholdChanging(double)),
- tool_selections, SLOT(autoCreateSelectionsPreview()));
-
- QPushButton* clearsel = new QPushButton();
- clearsel->setText(tr("Clear"));
- connect(clearsel, SIGNAL(clicked()),
- tool_selections, SLOT(clearSelections()));
-
- btns->addWidget(autosel);
- btns->addWidget(clearsel);
-
- l->addLayout(btns);
-
- slider_attacklength = createAttribute(w, tr("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(300);
-
- slider_spread = createAttribute(w, tr("Power spread:"), 1, 2000);
- connect(slider_spread, SIGNAL(valueChanged(int)),
- sorter, SLOT(setSpreadFactor(int)));
- connect(slider_spread, SIGNAL(valueChanged(int)),
- tool_selections, SLOT(autoCreateSelectionsPreview()));
- slider_spread->setValue(1000);
-
- slider_hold = createAttribute(w, tr("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, tr("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(300);
-
- slider_fadelength = createAttribute(w, tr("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);
-
- l->addStretch();
-
- return w;
-}
-
-QWidget* MainWindow::createExportTab()
-{
- QWidget* w = new QWidget();
- QVBoxLayout* l = new QVBoxLayout();
- w->setLayout(l);
-
- l->addWidget(new QLabel(tr("Prefix:")));
- prefix = new QLineEdit();
- connect(prefix, SIGNAL(textChanged(const QString &)),
- extractor, SLOT(setOutputPrefix(const QString &)));
- l->addWidget(prefix);
-
- l->addWidget(new QLabel(tr("Export path:")));
- QHBoxLayout* lo_exportp = new QHBoxLayout();
- lineed_exportp = new QLineEdit();
- connect(lineed_exportp, SIGNAL(textChanged(const QString &)),
- extractor, SLOT(setExportPath(const QString &)));
- lo_exportp->addWidget(lineed_exportp);
- QPushButton* btn_browse = new QPushButton(tr("..."));
- connect(btn_browse, SIGNAL(clicked()), this, SLOT(browse()));
- lo_exportp->addWidget(btn_browse);
-
- l->addLayout(lo_exportp);
-
- QPushButton* exportsel = new QPushButton();
- exportsel->setText(tr("Export"));
- connect(exportsel, SIGNAL(clicked()), this, SLOT(doExport()));
- l->addWidget(exportsel);
-
- QProgressBar* bar = new QProgressBar();
- connect(extractor, SIGNAL(progressUpdate(int)), bar, SLOT(setValue(int)));
- connect(extractor, SIGNAL(setMaximumProgress(int)),
- bar, SLOT(setMaximum(int)));
- l->addWidget(bar);
-
- l->addStretch();
-
- return w;
-}
-
-void MainWindow::playSamples()
-{
- Selections* sels = &selections;
- if(tabs->currentIndex() == generateTabId)
- {
- sels = &selections_preview;
- }
-
- QVector<sel_id_t> ids = sels->ids();
- for(int v1 = 0; v1 < ids.size(); v1++)
- {
- for(int v2 = 0; v2 < ids.size(); v2++)
- {
- Selection sel1 = sels->get(ids[v1]);
- Selection sel2 = sels->get(ids[v2]);
-
- if(sel1.energy < sel2.energy)
- {
- sel_id_t vtmp = ids[v1];
- ids[v1] = ids[v2];
- ids[v2] = vtmp;
- }
- }
- }
-
- QVector<sel_id_t>::iterator i = ids.begin();
- while(i != ids.end())
- {
- Selection sel = sels->get(*i);
-
- unsigned int length = sb_playsamples->value() * 44100 / 1000;
-
- unsigned int sample_length = sel.to - sel.from;
-
- unsigned int to = sel.to;
-
- if(sample_length > length)
- {
- to = sel.from + length;
- }
-
- sels->setActive(*i);
-
- connect(&player, SIGNAL(positionUpdate(size_t)),
- listen, SLOT(update(size_t)));
-
- player.playSelection(sel, to - sel.from);
- QTime t;
- t.start();
- while(t.elapsed() < sb_playsamples->value())
- {
- qApp->processEvents();
- q_usleep(25 * 1000);
- }
- player.stop();
-
- disconnect(&player, SIGNAL(positionUpdate(size_t)),
- listen, SLOT(update(size_t)));
- i++;
- }
-}
-
void MainWindow::closeEvent(QCloseEvent*)
{
saveSettings();
@@ -452,13 +108,13 @@ void MainWindow::loadSettings()
settings.loadGeometry(size, pos);
resize(size);
move(pos);
- lineed_exportp->setText(settings.loadExportPath());
+ // TODO: lineed_exportp->setText(settings.loadExportPath());
}
void MainWindow::saveSettings()
{
settings.saveGeometry(size(), pos());
- settings.saveExportPath(lineed_exportp->text());
+ // TODO: settings.saveExportPath(lineed_exportp->text());
}
void MainWindow::newProject()
@@ -527,34 +183,3 @@ void MainWindow::projectChanged()
{
statusBar()->showMessage(tr("Unsaved"));
}
-
-void MainWindow::doExport()
-{
- extractor->exportSelections();
-}
-
-void MainWindow::loadFile(QString filename)
-{
- setCursor(Qt::WaitCursor);
- statusBar()->showMessage(tr("Loading..."));
- qApp->processEvents();
-
- sorter->setWavData(NULL, 0);
- player.setPcmData(NULL, 0);
-
- canvaswidget->canvas->load(filename);
-
- sorter->setWavData(canvaswidget->canvas->data, canvaswidget->canvas->size);
- player.setPcmData(canvaswidget->canvas->data, canvaswidget->canvas->size);
-
- statusBar()->showMessage(tr("Ready"));
- setCursor(Qt::ArrowCursor);
-}
-
-void MainWindow::browse()
-{
- QString path =
- QFileDialog::getExistingDirectory(this, tr("Select export path"),
- lineed_exportp->text());
- lineed_exportp->setText(path);
-}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index d1df144..a7c9ba2 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -27,38 +27,14 @@
#pragma once
#include <QMainWindow>
-#include <QScrollBar>
-#include <QComboBox>
-#include <QSlider>
-#include <QLineEdit>
#include <QCloseEvent>
#include <QTabWidget>
-#include "canvas.h"
-#include "audioextractor.h"
-#include "samplesorter.h"
-#include "filelist.h"
-#include "canvastoolselections.h"
-#include "canvastoolthreshold.h"
-#include "canvastoollisten.h"
-#include "selection.h"
-#include "player.h"
-#include "zoomslider.h"
-#include "canvaswidget.h"
#include "project.h"
+#include "instrumentwindow.h"
class Settings;
-class Preset
-{
-public:
- QString prefix;
- int attacklength;
- int falloff;
- int fadelength;
-};
-Q_DECLARE_METATYPE(Preset)
-
class MainWindow
: public QMainWindow
{
@@ -72,11 +48,6 @@ public slots:
void loadProject();
void saveProject();
void projectChanged();
- void doExport();
- void loadFile(QString filename);
- void playSamples();
- void browse();
- void tabChanged(int tabid);
protected:
void closeEvent(QCloseEvent*);
@@ -85,39 +56,8 @@ private:
void loadSettings();
void saveSettings();
- QWidget* createFilesTab();
- QWidget* createEditTab();
- QWidget* createGenerateTab();
- QWidget* createExportTab();
-
- int generateTabId;
-
- SampleSorter* sorter;
- CanvasToolSelections* tool_selections;
- CanvasToolThreshold* threshold;
- CanvasToolListen* listen;
- AudioExtractor* extractor;
- FileList* filelist;
-
- CanvasWidget* canvaswidget;
-
- QScrollBar* sb_playsamples;
- QComboBox* presets;
- QSlider* slider_attacklength;
- QSlider* slider_spread;
- QSlider* slider_hold;
- QSlider* slider_falloff;
- QSlider* slider_fadelength;
- QLineEdit* prefix;
- QLineEdit* lineed_exportp;
-
- QTabWidget* tabs;
-
- // Session state information:
- Selections selections;
- Selections selections_preview;
- Player player;
-
Settings& settings;
Project project;
+
+ InstrumentWindow instrument_window;
};