summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-09-29 16:29:21 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-09-29 16:29:21 +0200
commit46efa2def1212dcb2610c545a78c8ab81bb22bbf (patch)
tree5bf8e1991126ba5795cdde44578a370a7a1b4a1f /src
parentc975247f9742bd7fcf5ae7d8ab174ed8728bb64c (diff)
Add main attribute to the filelist. Use QHash random seed hack in all places where QDomDocument is being used.
Diffstat (limited to 'src')
-rw-r--r--src/audioextractor.cc6
-rw-r--r--src/dgedit.cc6
-rw-r--r--src/filelist.cc76
-rw-r--r--src/project.cc18
-rw-r--r--src/project.h4
-rw-r--r--src/projectrenderer.cc10
-rw-r--r--src/projectserialiser.cc12
7 files changed, 107 insertions, 25 deletions
diff --git a/src/audioextractor.cc b/src/audioextractor.cc
index ed1aa5a..cf6e9e9 100644
--- a/src/audioextractor.cc
+++ b/src/audioextractor.cc
@@ -35,6 +35,8 @@
#include "project.h"
+extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
+
#define INSTRUMENT_VERSION "2.0"
typedef struct
@@ -215,6 +217,10 @@ void AudioExtractor::exportSelections()
sf_close(audiodata[i].fh);
}
+ // Ugly hack to ensure the xml attribute order is the same each time a save
+ // or export is performed.
+ qt_qhash_seed.store(0);
+
QDomDocument doc;
QDomProcessingInstruction header =
doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
diff --git a/src/dgedit.cc b/src/dgedit.cc
index 218c73e..fe78056 100644
--- a/src/dgedit.cc
+++ b/src/dgedit.cc
@@ -30,16 +30,10 @@
#include "settings.h"
#include "localehandler.h"
-extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
-
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- // Ugly hack to ensure the xml attribute order is the same each time a save
- // or export is performed.
- qt_qhash_seed.store(0);
-
LocaleHandler locale(app);
Settings settings;
diff --git a/src/filelist.cc b/src/filelist.cc
index 990ae4c..7b2ec2b 100644
--- a/src/filelist.cc
+++ b/src/filelist.cc
@@ -42,6 +42,7 @@
#include <QComboBox>
#include <QLineEdit>
+#include <QCheckBox>
#include <QStyledItemDelegate>
#include <QPainter>
#include <QHeaderView>
@@ -58,15 +59,22 @@ public:
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const override
{
- // Name:
+ // Main channel:
if(index.column() == 2)
{
+ auto w = new QCheckBox(parent);
+ return w;
+ }
+
+ // Name:
+ if(index.column() == 3)
+ {
auto w = new QLineEdit(parent);
return w;
}
// Channel Map ID:
- if(index.column() == 3)
+ if(index.column() == 4)
{
auto w = new QComboBox(parent);
w->addItem(tr("<None>"), -1);
@@ -84,16 +92,24 @@ public:
void setEditorData(QWidget *editor, const QModelIndex &index) const override
{
- // Name:
+ // Main channel:
if(index.column() == 2)
{
+ auto w = static_cast<QCheckBox*>(editor);
+ auto b = index.data(Qt::EditRole).toBool();
+ w->setCheckState(b ? Qt::Checked : Qt::Unchecked);
+ }
+
+ // Name:
+ if(index.column() == 3)
+ {
auto w = static_cast<QLineEdit*>(editor);
auto s = index.data(Qt::EditRole).toString();
w->setText(s);
}
// Channel Map ID:
- if(index.column() == 3)
+ if(index.column() == 4)
{
auto w = static_cast<QComboBox*>(editor);
auto i = w->findData(index.data(Qt::EditRole).toInt());
@@ -103,15 +119,24 @@ public:
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const override
- { // Name:
+ {
+ // Main channel:
if(index.column() == 2)
{
+ model->setData(index,
+ static_cast<QCheckBox*>(editor)->checkState() == Qt::Checked,
+ Qt::EditRole);
+ }
+
+ // Name:
+ if(index.column() == 3)
+ {
model->setData(index, static_cast<QLineEdit*>(editor)->text(),
Qt::EditRole);
}
// Channel Map ID:
- if(index.column() == 3)
+ if(index.column() == 4)
{
model->setData(index, static_cast<QComboBox*>(editor)->currentData(),
Qt::EditRole);
@@ -189,7 +214,7 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
- return 4;
+ return 5;
}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
@@ -223,9 +248,11 @@ public:
{
switch(index.column())
{
+ case 0: return QVariant(); // Master
case 1: return audiofile.getFile();
- case 2: return audiofile.getName();
- case 3:
+ case 2: return audiofile.getMainChannel() ? "x" : " ";
+ case 3: return audiofile.getName();
+ case 4:
{
auto channelMapId = audiofile.getChannelMapId();
if(channelMapId == -1)
@@ -241,9 +268,11 @@ public:
{
switch(index.column())
{
+ case 0: return QVariant(); // Master
case 1: return audiofile.getFile();
- case 2: return audiofile.getName();
- case 3: return audiofile.getChannelMapId();
+ case 2: return audiofile.getMainChannel();
+ case 3: return audiofile.getName();
+ case 4: return audiofile.getChannelMapId();
default: return QVariant();
}
}
@@ -262,8 +291,9 @@ public:
{
case 0: return tr("M");
case 1: return tr("Filename");
- case 2: return tr("Name");
- case 3: return tr("Kit Channel");
+ case 2: return tr("m");
+ case 3: return tr("Name");
+ case 4: return tr("Kit Channel");
default: return QVariant();
}
}
@@ -283,10 +313,12 @@ public:
case 0: // Master
return QAbstractItemModel::flags(index);
case 1: // File
- return QAbstractItemModel::flags(index); // only column 1 is editable
- case 2: // Name
+ return QAbstractItemModel::flags(index);
+ case 2: // Main channel
+ return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
+ case 3: // Name
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
- case 3: // Channel map id
+ case 4: // Channel map id
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
}
}
@@ -296,7 +328,8 @@ public:
{
auto audiofile_ids = instrument.getAudioFileList();
- if(index.row() > audiofile_ids.size() || index.column() > 2)
+ if(index.row() > audiofile_ids.size() ||
+ index.column() > (columnCount() - 1))
{
return false;
}
@@ -310,10 +343,13 @@ public:
break;
case 1: // File
break;
- case 2: // Name
+ case 2: // Main Channel
+ audiofile.setMainChannel(value.toBool());
+ break;
+ case 3: // Name
audiofile.setName(value.toString());
break;
- case 3: // Channel map id
+ case 4: // Channel map id
audiofile.setChannelMapId(value.toInt());
break;
default: break;
@@ -345,6 +381,7 @@ FileList::FileList(Instrument& instrument)
this, SLOT(onCustomContextMenu(const QPoint &)));
setRootIsDecorated(false);
header()->resizeSection(0, 24);
+ header()->resizeSection(2, 24);
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
this, SLOT(selectionChanged(const QModelIndex&)));
@@ -380,6 +417,7 @@ void FileList::addFiles()
audiofile.setName(name);
audiofile.setFile(file);
audiofile.setChannelMapId(-1);
+ audiofile.setMainChannel(false);
i++;
}
diff --git a/src/project.cc b/src/project.cc
index 86100bc..04919db 100644
--- a/src/project.cc
+++ b/src/project.cc
@@ -106,6 +106,24 @@ void AudioFile::setChannelMapId(int channel_map_id)
}
}
+bool AudioFile::getMainChannel() const
+{
+ return main_channel;
+}
+
+void AudioFile::setMainChannel(bool main_channel)
+{
+ if(this->main_channel == main_channel)
+ {
+ return;
+ }
+
+ {
+ Project::RAIIBulkUpdate bulkUpdate(instrument.getProject());
+ this->main_channel = main_channel;
+ }
+}
+
Instrument::Instrument(Project& project, int id)
: id(id)
, project(project)
diff --git a/src/project.h b/src/project.h
index b0f9060..a6593d8 100644
--- a/src/project.h
+++ b/src/project.h
@@ -54,12 +54,16 @@ public:
int getChannelMapId() const;
void setChannelMapId(int id);
+ bool getMainChannel() const;
+ void setMainChannel(bool main);
+
private:
friend class ProjectSerialiser;
QString file;
QString name;
int channel_map_id;
+ bool main_channel;
int id;
Instrument& instrument;
diff --git a/src/projectrenderer.cc b/src/projectrenderer.cc
index e1856cb..885b9f1 100644
--- a/src/projectrenderer.cc
+++ b/src/projectrenderer.cc
@@ -33,6 +33,8 @@
#include "project.h"
#include "audioextractor.h"
+extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
+
ProjectRenderer::ProjectRenderer(Project& project)
: project(project)
{
@@ -40,6 +42,10 @@ ProjectRenderer::ProjectRenderer(Project& project)
void ProjectRenderer::render()
{
+ // Ugly hack to ensure the xml attribute order is the same each time a save
+ // or export is performed.
+ qt_qhash_seed.store(0);
+
QDomDocument doc;
QDomProcessingInstruction header =
doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
@@ -107,6 +113,10 @@ void ProjectRenderer::render()
channelmap.setAttribute("in", audiofile.getName());
const auto& channel = project.getChannel(audiofile.getChannelMapId());
channelmap.setAttribute("out", channel.getChannelName());
+ if(audiofile.getMainChannel())
+ {
+ channelmap.setAttribute("main", "true");
+ }
instrument_node.appendChild(channelmap);
}
diff --git a/src/projectserialiser.cc b/src/projectserialiser.cc
index ced4636..ac872c7 100644
--- a/src/projectserialiser.cc
+++ b/src/projectserialiser.cc
@@ -39,6 +39,8 @@
</dgedit>
*/
+extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
+
class DomHelper
{
public:
@@ -104,6 +106,10 @@ private:
QString ProjectSerialiser::serialise(const Project& project)
{
+ // Ugly hack to ensure the xml attribute order is the same each time a save
+ // or export is performed.
+ qt_qhash_seed.store(0);
+
QDomDocument doc;
auto header =
doc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
@@ -177,6 +183,7 @@ QString ProjectSerialiser::serialise(const Project& project)
file.setAttribute("name", audiofile.getName());
file.setAttribute("channel_map_id", audiofile.getChannelMapId());
file.setAttribute("master", i.master_file == audiofile.getAbsoluteFile());
+ file.setAttribute("main", audiofile.getMainChannel() ? "true" : "false");
file_list.appendChild(file);
}
@@ -204,6 +211,10 @@ QString ProjectSerialiser::serialise(const Project& project)
bool ProjectSerialiser::deserialise(const QString& data, Project& project)
{
+ // Ugly hack to ensure the xml attribute order is the same each time a save
+ // or export is performed.
+ qt_qhash_seed.store(0);
+
QDomDocument doc;
if(!doc.setContent(data))
{
@@ -255,6 +266,7 @@ bool ProjectSerialiser::deserialise(const QString& data, Project& project)
audiofile.file = file.text();
audiofile.name = file["name"];
audiofile.channel_map_id = file["channel_map_id"].toInt();
+ audiofile.main_channel = file["main"] == "true";
if(file["master"] == "1")
{