2018-07-09 18:05:31 +00:00
|
|
|
#ifndef AMUSE_PROJECT_MODEL_HPP
|
|
|
|
#define AMUSE_PROJECT_MODEL_HPP
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
2018-07-28 04:34:29 +00:00
|
|
|
#include <QIdentityProxyModel>
|
2018-08-26 04:57:02 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2018-07-14 06:06:33 +00:00
|
|
|
#include <QDir>
|
2018-07-17 04:48:38 +00:00
|
|
|
#include <QIcon>
|
2018-07-14 06:06:33 +00:00
|
|
|
#include <map>
|
2018-07-17 04:48:38 +00:00
|
|
|
#include "Common.hpp"
|
2018-08-10 06:19:23 +00:00
|
|
|
#include "NewSoundMacroDialog.hpp"
|
2018-07-17 04:48:38 +00:00
|
|
|
#include "amuse/AudioGroup.hpp"
|
2018-07-14 06:06:33 +00:00
|
|
|
#include "amuse/AudioGroupData.hpp"
|
|
|
|
#include "amuse/AudioGroupProject.hpp"
|
|
|
|
#include "amuse/AudioGroupPool.hpp"
|
|
|
|
#include "amuse/AudioGroupSampleDirectory.hpp"
|
2018-07-09 18:05:31 +00:00
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
class ProjectModel;
|
2018-08-25 08:34:04 +00:00
|
|
|
class EditorUndoCommand;
|
|
|
|
|
|
|
|
enum AmuseItemEditFlags
|
|
|
|
{
|
|
|
|
AmuseItemNone = 0,
|
|
|
|
AmuseItemCut = 1,
|
|
|
|
AmuseItemCopy = 2,
|
|
|
|
AmuseItemPaste = 4,
|
|
|
|
AmuseItemDelete = 8,
|
|
|
|
AmuseItemNoCut = (AmuseItemCopy | AmuseItemPaste | AmuseItemDelete),
|
|
|
|
AmuseItemAll = (AmuseItemCut | AmuseItemCopy | AmuseItemPaste | AmuseItemDelete)
|
|
|
|
};
|
2018-07-28 04:34:29 +00:00
|
|
|
|
2018-08-26 04:57:02 +00:00
|
|
|
class OutlineFilterProxyModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
QRegExp m_usageKey;
|
|
|
|
public:
|
|
|
|
explicit OutlineFilterProxyModel(ProjectModel* source);
|
|
|
|
public slots:
|
|
|
|
void setFilterRegExp(const QString &pattern);
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
|
|
|
};
|
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
class NullItemProxyModel : public QIdentityProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit NullItemProxyModel(ProjectModel* source);
|
|
|
|
QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
|
|
|
|
QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
|
|
|
|
int rowCount(const QModelIndex& parent) const;
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
|
|
|
QVariant data(const QModelIndex& proxyIndex, int role) const;
|
|
|
|
};
|
|
|
|
|
2018-08-09 07:42:17 +00:00
|
|
|
class PageObjectProxyModel : public QIdentityProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PageObjectProxyModel(ProjectModel* source);
|
|
|
|
QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
|
|
|
|
QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
|
|
|
|
QModelIndex parent(const QModelIndex& child) const;
|
|
|
|
int rowCount(const QModelIndex& parent) const;
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
|
|
|
QVariant data(const QModelIndex& proxyIndex, int role) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& proxyIndex) const;
|
|
|
|
};
|
|
|
|
|
2018-07-09 18:05:31 +00:00
|
|
|
class ProjectModel : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-07-14 06:06:33 +00:00
|
|
|
enum class ImportMode
|
|
|
|
{
|
|
|
|
Original,
|
|
|
|
WAVs,
|
|
|
|
Both
|
|
|
|
};
|
2018-07-17 04:48:38 +00:00
|
|
|
|
2018-08-10 06:19:23 +00:00
|
|
|
struct NameUndoRegistry
|
|
|
|
{
|
|
|
|
std::unordered_map<amuse::SongId, std::string> m_songIDs;
|
|
|
|
std::unordered_map<amuse::SFXId, std::string> m_sfxIDs;
|
2018-08-14 08:36:02 +00:00
|
|
|
void registerSongName(amuse::SongId id) const;
|
|
|
|
void unregisterSongName(amuse::SongId id);
|
|
|
|
void registerSFXName(amuse::SongId id) const;
|
|
|
|
void unregisterSFXName(amuse::SongId id);
|
2018-08-10 06:19:23 +00:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
m_songIDs.clear();
|
|
|
|
m_sfxIDs.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-17 04:48:38 +00:00
|
|
|
private:
|
|
|
|
QDir m_dir;
|
2018-08-26 04:57:02 +00:00
|
|
|
OutlineFilterProxyModel m_outlineProxy;
|
2018-07-28 04:34:29 +00:00
|
|
|
NullItemProxyModel m_nullProxy;
|
2018-08-09 07:42:17 +00:00
|
|
|
PageObjectProxyModel m_pageObjectProxy;
|
2018-07-17 04:48:38 +00:00
|
|
|
|
|
|
|
amuse::ProjectDatabase m_projectDatabase;
|
2018-08-19 20:05:39 +00:00
|
|
|
std::unordered_map<QString, std::unique_ptr<amuse::AudioGroupDatabase>> m_groups;
|
2018-08-10 06:19:23 +00:00
|
|
|
|
2018-08-14 08:36:02 +00:00
|
|
|
struct Song
|
|
|
|
{
|
|
|
|
QString m_path;
|
|
|
|
int m_refCount = 0;
|
|
|
|
};
|
|
|
|
std::unordered_map<amuse::SongId, Song> m_midiFiles;
|
2018-07-17 04:48:38 +00:00
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
public:
|
2018-07-30 06:20:03 +00:00
|
|
|
class INode : public amuse::IObj
|
2018-07-14 06:06:33 +00:00
|
|
|
{
|
2018-08-25 08:34:04 +00:00
|
|
|
friend class ProjectModel;
|
|
|
|
virtual void _sortChildren();
|
2018-07-18 07:39:26 +00:00
|
|
|
public:
|
2018-07-17 04:48:38 +00:00
|
|
|
enum class Type
|
|
|
|
{
|
2018-07-28 04:34:29 +00:00
|
|
|
Null,
|
2018-07-18 07:39:26 +00:00
|
|
|
Root,
|
2018-07-17 04:48:38 +00:00
|
|
|
Group, // Top-level group
|
|
|
|
SongGroup,
|
2018-07-18 07:39:26 +00:00
|
|
|
SoundGroup,
|
2018-07-17 04:48:38 +00:00
|
|
|
Collection, // Classified object collection, one of the following:
|
|
|
|
SoundMacro,
|
|
|
|
ADSR,
|
|
|
|
Curve,
|
|
|
|
Keymap,
|
2018-07-29 03:37:06 +00:00
|
|
|
Layer,
|
|
|
|
Sample
|
2018-07-17 04:48:38 +00:00
|
|
|
};
|
2018-07-28 04:34:29 +00:00
|
|
|
protected:
|
2018-08-11 06:31:10 +00:00
|
|
|
QString m_name;
|
|
|
|
INode* m_parent = nullptr;
|
|
|
|
int m_row = -1;
|
2018-07-30 06:20:03 +00:00
|
|
|
std::vector<amuse::IObjToken<INode>> m_children;
|
|
|
|
amuse::IObjToken<INode> m_nullChild;
|
2018-07-17 04:48:38 +00:00
|
|
|
public:
|
|
|
|
virtual ~INode() = default;
|
2018-08-11 06:31:10 +00:00
|
|
|
INode(const QString& name);
|
2018-07-28 04:34:29 +00:00
|
|
|
INode(INode* parent) : m_parent(parent), m_row(0)
|
|
|
|
{
|
|
|
|
/* ONLY USED BY NULL NODE! */
|
|
|
|
}
|
2018-07-17 04:48:38 +00:00
|
|
|
|
|
|
|
int childCount() const { return int(m_children.size()); }
|
2018-07-28 04:34:29 +00:00
|
|
|
INode* child(int row) const
|
|
|
|
{
|
|
|
|
if (row == m_children.size())
|
|
|
|
return nullChild();
|
|
|
|
return m_children[row].get();
|
|
|
|
}
|
|
|
|
INode* nullChild() const { return m_nullChild.get(); }
|
2018-07-17 04:48:38 +00:00
|
|
|
INode* parent() const { return m_parent; }
|
|
|
|
int row() const { return m_row; }
|
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
void reindexRows(int row)
|
|
|
|
{
|
|
|
|
for (auto it = m_children.begin() + row; it != m_children.end(); ++it)
|
|
|
|
(*it)->m_row = row++;
|
|
|
|
m_nullChild->m_row = row;
|
|
|
|
}
|
|
|
|
|
2018-08-11 06:31:10 +00:00
|
|
|
void insertChild(amuse::ObjToken<INode> n)
|
2018-07-28 04:34:29 +00:00
|
|
|
{
|
2018-08-11 06:31:10 +00:00
|
|
|
assert(n->m_parent == nullptr && "Inserting already-parented node");
|
|
|
|
n->m_parent = this;
|
|
|
|
int row = hypotheticalIndex(n->name());
|
2018-07-30 06:20:03 +00:00
|
|
|
m_children.insert(m_children.begin() + row, n.get());
|
2018-07-28 04:34:29 +00:00
|
|
|
reindexRows(row);
|
|
|
|
}
|
2018-08-11 06:31:10 +00:00
|
|
|
amuse::ObjToken<INode> removeChild(INode* n)
|
2018-07-28 04:34:29 +00:00
|
|
|
{
|
2018-08-25 08:34:04 +00:00
|
|
|
amuse::ObjToken<INode> ret = n;
|
|
|
|
int row = ret->row();
|
|
|
|
assert(ret.get() == m_children.at(row).get() && "Removing non-child from node");
|
2018-07-28 04:34:29 +00:00
|
|
|
m_children.erase(m_children.begin() + row);
|
|
|
|
reindexRows(row);
|
2018-08-25 08:34:04 +00:00
|
|
|
ret->m_parent = nullptr;
|
|
|
|
ret->m_row = -1;
|
|
|
|
return ret;
|
2018-07-28 04:34:29 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 04:48:38 +00:00
|
|
|
void reserve(size_t sz) { m_children.reserve(sz); }
|
|
|
|
template<class T, class... _Args>
|
|
|
|
T& makeChild(_Args&&... args)
|
2018-07-15 06:10:50 +00:00
|
|
|
{
|
2018-08-11 06:31:10 +00:00
|
|
|
auto tok = amuse::MakeObj<T>(std::forward<_Args>(args)...);
|
|
|
|
insertChild(tok.get());
|
|
|
|
return static_cast<T&>(*tok);
|
2018-07-15 06:10:50 +00:00
|
|
|
}
|
2018-08-10 06:19:23 +00:00
|
|
|
template<class T, class... _Args>
|
2018-08-11 06:31:10 +00:00
|
|
|
T& _appendChild(_Args&&... args)
|
2018-08-10 06:19:23 +00:00
|
|
|
{
|
2018-08-11 06:31:10 +00:00
|
|
|
auto tok = amuse::MakeObj<T>(std::forward<_Args>(args)...);
|
|
|
|
tok->m_parent = this;
|
|
|
|
tok->m_row = m_children.size();
|
|
|
|
m_children.push_back(tok.get());
|
|
|
|
m_nullChild->m_row = m_children.size();
|
2018-08-10 06:19:23 +00:00
|
|
|
return static_cast<T&>(*tok);
|
|
|
|
}
|
2018-07-17 04:48:38 +00:00
|
|
|
|
2018-08-25 08:34:04 +00:00
|
|
|
INode* findChild(const QString& name) const
|
|
|
|
{
|
|
|
|
int idx = hypotheticalIndex(name);
|
|
|
|
if (idx >= m_children.size())
|
|
|
|
return nullptr;
|
|
|
|
INode* ret = m_children[idx].get();
|
|
|
|
if (ret->name() == name)
|
|
|
|
return ret;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
bool depthTraverse(const std::function<bool(INode* node)>& func)
|
|
|
|
{
|
|
|
|
for (auto& n : m_children)
|
|
|
|
if (!n->depthTraverse(func))
|
|
|
|
break;
|
|
|
|
return func(this);
|
|
|
|
}
|
|
|
|
|
2018-08-09 07:42:17 +00:00
|
|
|
bool oneLevelTraverse(const std::function<bool(INode* node)>& func)
|
|
|
|
{
|
|
|
|
for (auto& n : m_children)
|
|
|
|
if (!func(n.get()))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-11 06:31:10 +00:00
|
|
|
const QString& name() const { return m_name; }
|
|
|
|
virtual int hypotheticalIndex(const QString& name) const;
|
|
|
|
|
2018-08-25 08:34:04 +00:00
|
|
|
virtual amuse::NameDB* getNameDb() const { return nullptr; }
|
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
virtual Type type() const = 0;
|
2018-07-17 04:48:38 +00:00
|
|
|
virtual QString text() const = 0;
|
|
|
|
virtual QIcon icon() const = 0;
|
2018-08-25 08:34:04 +00:00
|
|
|
virtual Qt::ItemFlags flags() const { return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; }
|
|
|
|
virtual AmuseItemEditFlags editFlags() const { return AmuseItemNone; }
|
2018-08-10 06:19:23 +00:00
|
|
|
|
|
|
|
virtual void registerNames(const NameUndoRegistry& registry) const {}
|
|
|
|
virtual void unregisterNames(NameUndoRegistry& registry) const {}
|
2018-07-28 04:34:29 +00:00
|
|
|
};
|
2018-08-25 08:34:04 +00:00
|
|
|
struct NullNode final : INode
|
2018-07-28 04:34:29 +00:00
|
|
|
{
|
|
|
|
NullNode(INode* parent) : INode(parent) {}
|
|
|
|
|
|
|
|
Type type() const { return Type::Null; }
|
|
|
|
QString text() const { return {}; }
|
|
|
|
QIcon icon() const { return {}; }
|
2018-07-14 06:06:33 +00:00
|
|
|
};
|
2018-08-25 08:34:04 +00:00
|
|
|
struct RootNode final : INode
|
2018-07-17 04:48:38 +00:00
|
|
|
{
|
2018-08-11 06:31:10 +00:00
|
|
|
RootNode() : INode(QStringLiteral("<root>")) {}
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
Type type() const { return Type::Root; }
|
2018-07-17 04:48:38 +00:00
|
|
|
QString text() const { return {}; }
|
|
|
|
QIcon icon() const { return {}; }
|
2018-07-28 04:34:29 +00:00
|
|
|
Qt::ItemFlags flags() const { return Qt::ItemIsEnabled; }
|
2018-07-17 04:48:38 +00:00
|
|
|
};
|
2018-07-28 04:34:29 +00:00
|
|
|
struct CollectionNode;
|
2018-08-09 07:42:17 +00:00
|
|
|
struct BasePoolObjectNode;
|
2018-08-25 08:34:04 +00:00
|
|
|
struct GroupNode final : INode
|
2018-07-17 04:48:38 +00:00
|
|
|
{
|
2018-08-19 20:05:39 +00:00
|
|
|
std::unordered_map<QString, std::unique_ptr<amuse::AudioGroupDatabase>>::iterator m_it;
|
2018-08-11 06:31:10 +00:00
|
|
|
GroupNode(const QString& name) : INode(name) {}
|
2018-08-19 20:05:39 +00:00
|
|
|
GroupNode(std::unordered_map<QString, std::unique_ptr<amuse::AudioGroupDatabase>>::iterator it)
|
2018-08-11 06:31:10 +00:00
|
|
|
: INode(it->first), m_it(it) {}
|
|
|
|
|
|
|
|
int hypotheticalIndex(const QString& name) const;
|
2018-08-25 08:34:04 +00:00
|
|
|
void _sortChildren();
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-07-17 04:48:38 +00:00
|
|
|
static QIcon Icon;
|
2018-07-18 07:39:26 +00:00
|
|
|
Type type() const { return Type::Group; }
|
2018-08-11 06:31:10 +00:00
|
|
|
QString text() const { return m_name; }
|
2018-07-17 04:48:38 +00:00
|
|
|
QIcon icon() const { return Icon; }
|
2018-08-25 08:34:04 +00:00
|
|
|
AmuseItemEditFlags editFlags() const { return AmuseItemNoCut; }
|
2018-07-26 03:41:48 +00:00
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
CollectionNode* getCollectionOfType(Type tp) const;
|
2018-08-19 20:05:39 +00:00
|
|
|
amuse::AudioGroupDatabase* getAudioGroup() const { return m_it->second.get(); }
|
2018-08-09 07:42:17 +00:00
|
|
|
BasePoolObjectNode* pageObjectNodeOfId(amuse::ObjectId id) const;
|
2018-07-17 04:48:38 +00:00
|
|
|
};
|
2018-08-25 08:34:04 +00:00
|
|
|
struct SongGroupNode final : INode
|
2018-07-17 04:48:38 +00:00
|
|
|
{
|
|
|
|
amuse::GroupId m_id;
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<amuse::SongGroupIndex> m_index;
|
2018-08-11 06:31:10 +00:00
|
|
|
SongGroupNode(const QString& name, amuse::ObjToken<amuse::SongGroupIndex> index)
|
|
|
|
: INode(name), m_index(index) {}
|
|
|
|
SongGroupNode(amuse::GroupId id, amuse::ObjToken<amuse::SongGroupIndex> index)
|
|
|
|
: INode(amuse::GroupId::CurNameDB->resolveNameFromId(id).data()), m_id(id), m_index(index) {}
|
2018-07-17 04:48:38 +00:00
|
|
|
|
|
|
|
static QIcon Icon;
|
2018-07-18 07:39:26 +00:00
|
|
|
Type type() const { return Type::SongGroup; }
|
2018-07-17 04:48:38 +00:00
|
|
|
QString text() const { return m_name; }
|
|
|
|
QIcon icon() const { return Icon; }
|
2018-08-25 08:34:04 +00:00
|
|
|
AmuseItemEditFlags editFlags() const { return AmuseItemAll; }
|
|
|
|
|
|
|
|
amuse::NameDB* getNameDb() const { return amuse::GroupId::CurNameDB; }
|
2018-08-10 06:19:23 +00:00
|
|
|
|
|
|
|
void registerNames(const NameUndoRegistry& registry) const
|
|
|
|
{
|
|
|
|
amuse::GroupId::CurNameDB->registerPair(text().toUtf8().data(), m_id);
|
|
|
|
for (auto& p : m_index->m_midiSetups)
|
|
|
|
registry.registerSongName(p.first);
|
|
|
|
}
|
|
|
|
void unregisterNames(NameUndoRegistry& registry) const
|
|
|
|
{
|
|
|
|
amuse::GroupId::CurNameDB->remove(m_id);
|
|
|
|
for (auto& p : m_index->m_midiSetups)
|
|
|
|
registry.unregisterSongName(p.first);
|
|
|
|
}
|
2018-07-17 04:48:38 +00:00
|
|
|
};
|
2018-08-25 08:34:04 +00:00
|
|
|
struct SoundGroupNode final : INode
|
2018-07-17 04:48:38 +00:00
|
|
|
{
|
|
|
|
amuse::GroupId m_id;
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<amuse::SFXGroupIndex> m_index;
|
2018-08-11 06:31:10 +00:00
|
|
|
SoundGroupNode(const QString& name, amuse::ObjToken<amuse::SFXGroupIndex> index)
|
|
|
|
: INode(name), m_index(index) {}
|
|
|
|
SoundGroupNode(amuse::GroupId id, amuse::ObjToken<amuse::SFXGroupIndex> index)
|
|
|
|
: INode(amuse::GroupId::CurNameDB->resolveNameFromId(id).data()), m_id(id), m_index(index) {}
|
2018-07-17 04:48:38 +00:00
|
|
|
|
|
|
|
static QIcon Icon;
|
2018-07-18 07:39:26 +00:00
|
|
|
Type type() const { return Type::SoundGroup; }
|
2018-07-17 04:48:38 +00:00
|
|
|
QString text() const { return m_name; }
|
|
|
|
QIcon icon() const { return Icon; }
|
2018-08-25 08:34:04 +00:00
|
|
|
AmuseItemEditFlags editFlags() const { return AmuseItemAll; }
|
|
|
|
|
|
|
|
amuse::NameDB* getNameDb() const { return amuse::GroupId::CurNameDB; }
|
2018-08-10 06:19:23 +00:00
|
|
|
|
|
|
|
void registerNames(const NameUndoRegistry& registry) const
|
|
|
|
{
|
|
|
|
amuse::GroupId::CurNameDB->registerPair(text().toUtf8().data(), m_id);
|
|
|
|
for (auto& p : m_index->m_sfxEntries)
|
|
|
|
registry.registerSFXName(p.first);
|
|
|
|
}
|
|
|
|
void unregisterNames(NameUndoRegistry& registry) const
|
|
|
|
{
|
|
|
|
amuse::GroupId::CurNameDB->remove(m_id);
|
|
|
|
for (auto& p : m_index->m_sfxEntries)
|
|
|
|
registry.unregisterSFXName(p.first);
|
|
|
|
}
|
2018-07-17 04:48:38 +00:00
|
|
|
};
|
2018-08-25 08:34:04 +00:00
|
|
|
struct CollectionNode final : INode
|
2018-07-17 04:48:38 +00:00
|
|
|
{
|
|
|
|
QIcon m_icon;
|
2018-07-28 04:34:29 +00:00
|
|
|
Type m_collectionType;
|
2018-08-11 06:31:10 +00:00
|
|
|
CollectionNode(const QString& name, const QIcon& icon, Type collectionType)
|
|
|
|
: INode(name), m_icon(icon), m_collectionType(collectionType) {}
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
Type type() const { return Type::Collection; }
|
2018-07-17 04:48:38 +00:00
|
|
|
QString text() const { return m_name; }
|
|
|
|
QIcon icon() const { return m_icon; }
|
2018-07-28 04:34:29 +00:00
|
|
|
Qt::ItemFlags flags() const { return Qt::ItemIsEnabled; }
|
|
|
|
|
|
|
|
Type collectionType() const { return m_collectionType; }
|
|
|
|
int indexOfId(amuse::ObjectId id) const;
|
|
|
|
amuse::ObjectId idOfIndex(int idx) const;
|
|
|
|
BasePoolObjectNode* nodeOfIndex(int idx) const;
|
2018-08-07 07:09:23 +00:00
|
|
|
BasePoolObjectNode* nodeOfId(amuse::ObjectId id) const;
|
2018-07-17 04:48:38 +00:00
|
|
|
};
|
2018-07-28 04:34:29 +00:00
|
|
|
struct BasePoolObjectNode : INode
|
|
|
|
{
|
|
|
|
amuse::ObjectId m_id;
|
2018-08-11 06:31:10 +00:00
|
|
|
BasePoolObjectNode(const QString& name) : INode(name) {}
|
|
|
|
BasePoolObjectNode(amuse::ObjectId id, const QString& name)
|
|
|
|
: INode(name), m_id(id) {}
|
2018-07-28 04:34:29 +00:00
|
|
|
amuse::ObjectId id() const { return m_id; }
|
2018-07-29 03:37:06 +00:00
|
|
|
QString text() const { return m_name; }
|
|
|
|
QIcon icon() const { return {}; }
|
2018-07-28 04:34:29 +00:00
|
|
|
};
|
2018-07-18 07:39:26 +00:00
|
|
|
template <class ID, class T, INode::Type TP>
|
2018-08-25 08:34:04 +00:00
|
|
|
struct PoolObjectNode final : BasePoolObjectNode
|
2018-07-15 06:10:50 +00:00
|
|
|
{
|
2018-07-29 03:37:06 +00:00
|
|
|
amuse::ObjToken<T> m_obj;
|
2018-08-11 06:31:10 +00:00
|
|
|
PoolObjectNode(const QString& name, amuse::ObjToken<T> obj) : BasePoolObjectNode(name), m_obj(obj) {}
|
|
|
|
PoolObjectNode(ID id, amuse::ObjToken<T> obj)
|
|
|
|
: BasePoolObjectNode(id, ID::CurNameDB->resolveNameFromId(id).data()), m_obj(obj) {}
|
2018-07-17 04:48:38 +00:00
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
Type type() const { return TP; }
|
2018-08-25 08:34:04 +00:00
|
|
|
AmuseItemEditFlags editFlags() const { return TP == INode::Type::Sample ? AmuseItemNoCut : AmuseItemAll; }
|
2018-08-10 06:19:23 +00:00
|
|
|
|
|
|
|
void registerNames(const NameUndoRegistry& registry) const
|
|
|
|
{
|
|
|
|
ID::CurNameDB->registerPair(text().toUtf8().data(), m_id);
|
|
|
|
}
|
|
|
|
void unregisterNames(NameUndoRegistry& registry) const
|
|
|
|
{
|
|
|
|
ID::CurNameDB->remove(m_id);
|
|
|
|
}
|
2018-08-25 08:34:04 +00:00
|
|
|
amuse::NameDB* getNameDb() const
|
|
|
|
{
|
|
|
|
return ID::CurNameDB;
|
|
|
|
}
|
2018-07-17 04:48:38 +00:00
|
|
|
};
|
2018-07-18 07:39:26 +00:00
|
|
|
using SoundMacroNode = PoolObjectNode<amuse::SoundMacroId, amuse::SoundMacro, INode::Type::SoundMacro>;
|
2018-07-29 03:37:06 +00:00
|
|
|
using ADSRNode = PoolObjectNode<amuse::TableId, std::unique_ptr<amuse::ITable>, INode::Type::ADSR>;
|
|
|
|
using CurveNode = PoolObjectNode<amuse::TableId, std::unique_ptr<amuse::ITable>, INode::Type::Curve>;
|
2018-08-06 04:20:42 +00:00
|
|
|
using KeymapNode = PoolObjectNode<amuse::KeymapId, std::array<amuse::Keymap, 128>, INode::Type::Keymap>;
|
2018-07-18 07:39:26 +00:00
|
|
|
using LayersNode = PoolObjectNode<amuse::LayersId, std::vector<amuse::LayerMapping>, INode::Type::Layer>;
|
2018-07-29 03:37:06 +00:00
|
|
|
using SampleNode = PoolObjectNode<amuse::SampleId, amuse::SampleEntry, INode::Type::Sample>;
|
2018-07-17 04:48:38 +00:00
|
|
|
|
2018-07-30 06:20:03 +00:00
|
|
|
amuse::ObjToken<RootNode> m_root;
|
2018-07-17 04:48:38 +00:00
|
|
|
|
|
|
|
bool m_needsReset = false;
|
2018-08-19 20:05:39 +00:00
|
|
|
void _buildGroupNodeCollections(GroupNode& gn);
|
2018-08-25 08:34:04 +00:00
|
|
|
void _buildGroupNode(GroupNode& gn, amuse::AudioGroup& group);
|
2018-07-17 04:48:38 +00:00
|
|
|
void _resetModelData();
|
2018-08-16 06:26:44 +00:00
|
|
|
void _resetSongRefCount();
|
2018-08-25 08:34:04 +00:00
|
|
|
QString MakeDedupedSubprojectName(const QString& origName);
|
|
|
|
static QString MakeDedupedName(const QString& origName, amuse::NameDB* db);
|
2018-07-15 06:10:50 +00:00
|
|
|
|
2018-07-14 06:06:33 +00:00
|
|
|
public:
|
|
|
|
explicit ProjectModel(const QString& path, QObject* parent = Q_NULLPTR);
|
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
bool clearProjectData();
|
|
|
|
bool openGroupData(const QString& groupName, UIMessenger& messenger);
|
2018-08-16 06:26:44 +00:00
|
|
|
void openSongsData();
|
|
|
|
void importSongsData(const QString& path);
|
2018-07-29 03:37:06 +00:00
|
|
|
bool reloadSampleData(const QString& groupName, UIMessenger& messenger);
|
2018-07-17 04:48:38 +00:00
|
|
|
bool importGroupData(const QString& groupName, const amuse::AudioGroupData& data,
|
|
|
|
ImportMode mode, UIMessenger& messenger);
|
2018-08-16 06:26:44 +00:00
|
|
|
void saveSongsIndex();
|
2018-07-17 04:48:38 +00:00
|
|
|
bool saveToFile(UIMessenger& messenger);
|
2018-08-19 00:28:52 +00:00
|
|
|
QStringList getGroupList() const;
|
|
|
|
bool exportGroup(const QString& path, const QString& groupName, UIMessenger& messenger) const;
|
2018-08-25 08:34:04 +00:00
|
|
|
bool importHeader(const QString& path, const QString& groupName, UIMessenger& messenger) const;
|
|
|
|
bool exportHeader(const QString& path, const QString& groupName, bool& yesToAll, UIMessenger& messenger) const;
|
2018-07-17 04:48:38 +00:00
|
|
|
|
2018-08-25 08:34:04 +00:00
|
|
|
void updateNodeNames();
|
2018-08-03 03:45:48 +00:00
|
|
|
bool ensureModelData();
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
QModelIndex proxyCreateIndex(int arow, int acolumn, void *adata) const;
|
2018-07-14 06:06:33 +00:00
|
|
|
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
|
2018-07-28 04:34:29 +00:00
|
|
|
QModelIndex index(INode* node) const;
|
2018-07-14 06:06:33 +00:00
|
|
|
QModelIndex parent(const QModelIndex& child) const;
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
2018-08-25 08:34:04 +00:00
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
2018-07-17 04:48:38 +00:00
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const;
|
2018-07-18 07:39:26 +00:00
|
|
|
INode* node(const QModelIndex& index) const;
|
2018-07-28 04:34:29 +00:00
|
|
|
GroupNode* getGroupNode(INode* node) const;
|
2018-08-25 08:34:04 +00:00
|
|
|
AmuseItemEditFlags editFlags(const QModelIndex& index) const;
|
2018-08-09 07:42:17 +00:00
|
|
|
RootNode* rootNode() const { return m_root.get(); }
|
2018-07-14 06:06:33 +00:00
|
|
|
|
2018-08-11 06:31:10 +00:00
|
|
|
void _postAddNode(INode* n, const NameUndoRegistry& registry);
|
|
|
|
void _preDelNode(INode* n, NameUndoRegistry& registry);
|
2018-08-19 20:05:39 +00:00
|
|
|
void _addNode(GroupNode* node, std::unique_ptr<amuse::AudioGroupDatabase>&& data, const NameUndoRegistry& registry);
|
|
|
|
std::unique_ptr<amuse::AudioGroupDatabase> _delNode(GroupNode* node, NameUndoRegistry& registry);
|
2018-08-11 06:31:10 +00:00
|
|
|
GroupNode* newSubproject(const QString& name);
|
|
|
|
template <class NT, class T>
|
|
|
|
void _addGroupNode(NT* node, GroupNode* parent, const NameUndoRegistry& registry, T& container);
|
|
|
|
template <class NT, class T>
|
|
|
|
void _delGroupNode(NT* node, GroupNode* parent, NameUndoRegistry& registry, T& container);
|
|
|
|
void _addNode(SoundGroupNode* node, GroupNode* parent, const NameUndoRegistry& registry);
|
|
|
|
void _delNode(SoundGroupNode* node, GroupNode* parent, NameUndoRegistry& registry);
|
|
|
|
SoundGroupNode* newSoundGroup(GroupNode* group, const QString& name);
|
|
|
|
void _addNode(SongGroupNode* node, GroupNode* parent, const NameUndoRegistry& registry);
|
|
|
|
void _delNode(SongGroupNode* node, GroupNode* parent, NameUndoRegistry& registry);
|
|
|
|
SongGroupNode* newSongGroup(GroupNode* group, const QString& name);
|
|
|
|
template <class NT, class T>
|
|
|
|
void _addPoolNode(NT* node, GroupNode* parent, const NameUndoRegistry& registry, T& container);
|
|
|
|
template <class NT, class T>
|
|
|
|
void _delPoolNode(NT* node, GroupNode* parent, NameUndoRegistry& registry, T& container);
|
|
|
|
void _addNode(SoundMacroNode* node, GroupNode* parent, const NameUndoRegistry& registry);
|
|
|
|
void _delNode(SoundMacroNode* node, GroupNode* parent, NameUndoRegistry& registry);
|
|
|
|
SoundMacroNode* newSoundMacro(GroupNode* group, const QString& name,
|
2018-08-10 06:19:23 +00:00
|
|
|
const SoundMacroTemplateEntry* templ = nullptr);
|
2018-08-11 06:31:10 +00:00
|
|
|
void _addNode(ADSRNode* node, GroupNode* parent, const NameUndoRegistry& registry);
|
|
|
|
void _delNode(ADSRNode* node, GroupNode* parent, NameUndoRegistry& registry);
|
|
|
|
ADSRNode* newADSR(GroupNode* group, const QString& name);
|
|
|
|
void _addNode(CurveNode* node, GroupNode* parent, const NameUndoRegistry& registry);
|
|
|
|
void _delNode(CurveNode* node, GroupNode* parent, NameUndoRegistry& registry);
|
|
|
|
CurveNode* newCurve(GroupNode* group, const QString& name);
|
|
|
|
void _addNode(KeymapNode* node, GroupNode* parent, const NameUndoRegistry& registry);
|
|
|
|
void _delNode(KeymapNode* node, GroupNode* parent, NameUndoRegistry& registry);
|
|
|
|
KeymapNode* newKeymap(GroupNode* group, const QString& name);
|
|
|
|
void _addNode(LayersNode* node, GroupNode* parent, const NameUndoRegistry& registry);
|
|
|
|
void _delNode(LayersNode* node, GroupNode* parent, NameUndoRegistry& registry);
|
|
|
|
LayersNode* newLayers(GroupNode* group, const QString& name);
|
2018-08-25 08:34:04 +00:00
|
|
|
void _renameNode(INode* node, const QString& name);
|
|
|
|
|
|
|
|
template <class NT>
|
|
|
|
EditorUndoCommand* readMimeYAML(athena::io::YAMLDocReader& r, const QString& name, GroupNode* gn);
|
|
|
|
template <class NT>
|
|
|
|
void loadMimeData(const QMimeData* data, const QString& mimeType, GroupNode* gn);
|
|
|
|
|
|
|
|
QStringList mimeTypes() const;
|
|
|
|
QMimeData* mimeData(const QModelIndexList& indexes) const;
|
|
|
|
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
|
|
|
|
|
|
|
void cut(const QModelIndex& index);
|
|
|
|
void copy(const QModelIndex& index);
|
|
|
|
void paste(const QModelIndex& index);
|
|
|
|
QModelIndex duplicate(const QModelIndex& index);
|
2018-08-11 06:31:10 +00:00
|
|
|
void del(const QModelIndex& index);
|
2018-08-10 06:19:23 +00:00
|
|
|
|
2018-08-09 07:42:17 +00:00
|
|
|
const QDir& dir() const { return m_dir; }
|
2018-07-14 06:06:33 +00:00
|
|
|
QString path() const { return m_dir.path(); }
|
2018-08-26 04:57:02 +00:00
|
|
|
OutlineFilterProxyModel* getOutlineProxy() { return &m_outlineProxy; }
|
2018-07-28 04:34:29 +00:00
|
|
|
NullItemProxyModel* getNullProxy() { return &m_nullProxy; }
|
2018-08-09 07:42:17 +00:00
|
|
|
PageObjectProxyModel* getPageObjectProxy() { return &m_pageObjectProxy; }
|
|
|
|
|
|
|
|
GroupNode* getGroupOfSfx(amuse::SFXId id) const;
|
|
|
|
QString getMIDIPathOfSong(amuse::SongId id) const;
|
|
|
|
void setMIDIPathOfSong(amuse::SongId id, const QString& path);
|
2018-08-30 20:34:10 +00:00
|
|
|
std::pair<amuse::SongId, std::string> bootstrapSongId();
|
|
|
|
void allocateSongId(amuse::SongId id, std::string_view name);
|
2018-08-14 08:36:02 +00:00
|
|
|
void deallocateSongId(amuse::SongId oldId);
|
|
|
|
amuse::SongId exchangeSongId(amuse::SongId oldId, std::string_view newName);
|
2018-08-10 06:19:23 +00:00
|
|
|
|
|
|
|
void setIdDatabases(INode* context) const;
|
2018-07-09 18:05:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //AMUSE_PROJECT_MODEL_HPP
|