summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-05-16 20:19:09 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-05-16 20:19:09 +0200
commit8a3a2834b84ba9cdb4b9c505b124774f14034d27 (patch)
treefa361c19792ca6580135197db7672fc5fa7cf911
parent2840e3b4047fd0987095fb17ecbb154def019a2d (diff)
Store file list in instrument and make initial connections fomr UI connections to project storage.
-rw-r--r--src/audioextractor.cc13
-rw-r--r--src/audioextractor.h6
-rw-r--r--src/instrumentwidget.cc9
-rw-r--r--src/mainwindow.cc10
-rw-r--r--src/project.cc41
-rw-r--r--src/project.h10
-rw-r--r--src/projectserialiser.cc27
7 files changed, 105 insertions, 11 deletions
diff --git a/src/audioextractor.cc b/src/audioextractor.cc
index eb86b2f..98cbccb 100644
--- a/src/audioextractor.cc
+++ b/src/audioextractor.cc
@@ -33,6 +33,8 @@
#include <sndfile.h>
+#include "project.h"
+
#define INSTRUMENT_VERSION "2.0"
typedef struct
@@ -41,8 +43,11 @@ typedef struct
float *data;
} audiodata_t;
-AudioExtractor::AudioExtractor(Selections &s, QObject *parent)
- : QObject(parent), selections(s)
+AudioExtractor::AudioExtractor(Instrument& instrument, Selections &selections,
+ QObject *parent)
+ : QObject(parent)
+ , instrument(instrument)
+ , selections(selections)
{
}
@@ -275,6 +280,7 @@ void AudioExtractor::addFile(QString file, QString name)
pair.first = file;
pair.second = name;
audiofiles.push_back(pair);
+ instrument.setFileList(audiofiles);
}
void AudioExtractor::removeFile(QString file, QString name)
@@ -285,10 +291,11 @@ void AudioExtractor::removeFile(QString file, QString name)
if(file == j->first/* && name == j->second*/)
{
audiofiles.erase(j);
- return;
+ break;
}
j++;
}
+ instrument.setFileList(audiofiles);
}
void AudioExtractor::setOutputPrefix(const QString &p)
diff --git a/src/audioextractor.h b/src/audioextractor.h
index 2c38f91..a38f706 100644
--- a/src/audioextractor.h
+++ b/src/audioextractor.h
@@ -35,6 +35,8 @@
#include "selection.h"
#include "samplesorter.h"
+class Instrument;
+
typedef QLinkedList< QPair<QString, QString> > AudioFileList;
class AudioExtractor
@@ -42,7 +44,8 @@ class AudioExtractor
{
Q_OBJECT
public:
- AudioExtractor(Selections& selections, QObject* parent);
+ AudioExtractor(Instrument& instrument, Selections& selections,
+ QObject* parent);
public slots:
void addFile(QString file, QString name);
@@ -58,6 +61,7 @@ signals:
void setMaximumProgress(int value);
private:
+ Instrument& instrument;
Selections& selections;
AudioFileList audiofiles;
QString exportpath;
diff --git a/src/instrumentwidget.cc b/src/instrumentwidget.cc
index e3b3061..d081f6a 100644
--- a/src/instrumentwidget.cc
+++ b/src/instrumentwidget.cc
@@ -84,7 +84,7 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument)
central->setLayout(lv);
setCentralWidget(central);
- extractor = new AudioExtractor(selections, this);
+ extractor = new AudioExtractor(instrument, selections, this);
canvaswidget = new CanvasWidget(this);
QToolBar* toolbar = addToolBar(tr("Tools"));
@@ -133,7 +133,8 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument)
QDockWidget* dockWidget = new QDockWidget(tr("Dock Widget"), this);
- dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+ dockWidget->setAllowedAreas(Qt::RightDockWidgetArea);
+ dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
dockWidget->setWidget(new QWidget());
dockWidget->widget()->setLayout(new QVBoxLayout());
@@ -157,7 +158,7 @@ InstrumentWidget::InstrumentWidget(Settings& settings, Instrument& instrument)
vol->setVolumeDb(0);
dockWidget->widget()->layout()->addWidget(vol);
- addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
+ addDockWidget(Qt::RightDockWidgetArea, dockWidget);
canvaswidget->yscale->setValue(0.9);
canvaswidget->yoffset->setValue(MAXVAL/2);
@@ -436,6 +437,8 @@ void InstrumentWidget::loadFile(QString filename)
statusBar()->showMessage(tr("Ready"));
setCursor(Qt::ArrowCursor);
+
+ instrument.setMasterFile(filename);
}
void InstrumentWidget::browse()
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 1217fe3..fa64a6a 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -54,9 +54,9 @@ MainWindow::MainWindow(Settings& settings)
auto instr_id2 = project.createInstrument();
auto instr_id3 = project.createInstrument();
- auto instr1 = project.getInstrument(instr_id1);
- auto instr2 = project.getInstrument(instr_id2);
- auto instr3 = project.getInstrument(instr_id3);
+ auto& instr1 = project.getInstrument(instr_id1);
+ auto& instr2 = project.getInstrument(instr_id2);
+ auto& instr3 = project.getInstrument(instr_id3);
tab_widget->addTab(new InstrumentWidget(settings, instr1),
QPixmap(":icons/instrument.png"), "Snare");
@@ -91,6 +91,7 @@ MainWindow::MainWindow(Settings& settings)
connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
instruments_dock = new QDockWidget(tr("Instruments:"), this);
+ instruments_dock->setObjectName("instruments_dock");
instruments_dock->setAllowedAreas(Qt::LeftDockWidgetArea);
instruments_dock->setFeatures(QDockWidget::DockWidgetMovable);
QListWidget* instrument_list = new QListWidget();
@@ -99,6 +100,7 @@ MainWindow::MainWindow(Settings& settings)
addDockWidget(Qt::LeftDockWidgetArea, instruments_dock);
channels_dock = new QDockWidget(tr("Channels:"), this);
+ channels_dock->setObjectName("channels_dock");
channels_dock->setAllowedAreas(Qt::LeftDockWidgetArea);
channels_dock->setFeatures(QDockWidget::DockWidgetMovable);
QListWidget* channel_list = new QListWidget();
@@ -200,7 +202,9 @@ void MainWindow::loadProject()
project.setProjectFile(filename);
+ project_dirty = false;
updateWindowTitle();
+
statusBar()->showMessage(tr("Loaded"));
}
diff --git a/src/project.cc b/src/project.cc
index ba7f279..0baf67d 100644
--- a/src/project.cc
+++ b/src/project.cc
@@ -28,6 +28,8 @@
#include <QtGlobal>
+#include <iostream>
+
Instrument::Instrument(Project& project, int id)
: id(id)
, project(project)
@@ -57,6 +59,42 @@ void Instrument::setInstrumentName(const QString& instrument_name)
}
}
+QString Instrument::getMasterFile() const
+{
+ return master_file;
+}
+
+void Instrument::setMasterFile(const QString& master_file)
+{
+ if(this->master_file == master_file)
+ {
+ return;
+ }
+
+ {
+ Project::RAIIBulkUpdate bulkUpdate(project);
+ this->master_file = master_file;
+ }
+}
+
+AudioFileList Instrument::getFileList() const
+{
+ return file_list;
+}
+
+void Instrument::setFileList(const AudioFileList& file_list)
+{
+ if(this->file_list == file_list)
+ {
+ return;
+ }
+
+ {
+ Project::RAIIBulkUpdate bulkUpdate(project);
+ this->file_list = file_list;
+ }
+}
+
void Project::bulkUpdateBegin()
{
++update_count;
@@ -121,6 +159,7 @@ void Project::setRawFileRoot(const QString& raw_file_root)
Instrument& Project::getInstrument(int id)
{
+ std::cout << "get " << id << std::endl;
for(auto& instrument : instruments)
{
if(instrument.getId() == id)
@@ -136,7 +175,7 @@ int Project::createInstrument()
{
RAIIBulkUpdate bulkUpdate(*this);
- instruments.emplace_back(Instrument(*this, next_id));
+ instruments.emplace_back(*this, next_id);
++next_id;
return instruments.back().getId();
diff --git a/src/project.h b/src/project.h
index 2124730..27fa0b5 100644
--- a/src/project.h
+++ b/src/project.h
@@ -31,6 +31,8 @@
#include <QObject>
#include <QString>
+#include "audioextractor.h"
+
class Project;
class Instrument
@@ -43,11 +45,19 @@ public:
QString getInstrumentName() const;
void setInstrumentName(const QString& instrument_name);
+ QString getMasterFile() const;
+ void setMasterFile(const QString& master_file);
+
+ AudioFileList getFileList() const;
+ void setFileList(const AudioFileList& file_list);
+
private:
friend class ProjectSerialiser;
int id;
QString instrument_name;
+ QString master_file;
+ AudioFileList file_list;
Project& project;
};
diff --git a/src/projectserialiser.cc b/src/projectserialiser.cc
index 707ff18..56fa58e 100644
--- a/src/projectserialiser.cc
+++ b/src/projectserialiser.cc
@@ -133,6 +133,18 @@ QString ProjectSerialiser::serialise(const Project& project)
auto instrument_name = doc.createElement("instrument_name");
instrument_name.appendChild(doc.createTextNode(i.instrument_name));
instrument.appendChild(instrument_name);
+
+ auto file_list = doc.createElement("file_list");
+ instrument.appendChild(file_list);
+
+ for(const auto& f : i.file_list)
+ {
+ auto file = doc.createElement("file");
+ file.appendChild(doc.createTextNode(f.first));
+ file.setAttribute("name", f.second);
+ file.setAttribute("master", i.master_file == f.first);
+ file_list.appendChild(file);
+ }
}
return doc.toString();
@@ -165,8 +177,23 @@ bool ProjectSerialiser::deserialise(const QString& data, Project& project)
{
project.instruments.emplace_back(Instrument(project, project.next_id));
++project.next_id;
+
auto& instr = project.instruments.back();
instr.instrument_name = instrument("instrument_name").text();
+
+ QString master_file;
+ AudioFileList file_list;
+ auto files = instrument("file_list").children("file");
+ for(auto& file : files)
+ {
+ if(file["master"] == "true")
+ {
+ master_file = file.text();
+ }
+ file_list.push_back(qMakePair(file.text(), file["name"]));
+ }
+ project.instruments.back().file_list = file_list;
+ project.instruments.back().master_file = master_file;
}
return true;