mirror of
https://github.com/AxioDL/amuse.git
synced 2025-12-10 22:17:56 +00:00
Implement amuse playback
This commit is contained in:
@@ -3,13 +3,98 @@
|
||||
#include "ProjectModel.hpp"
|
||||
#include "Common.hpp"
|
||||
#include "athena/YAMLDocWriter.hpp"
|
||||
#include "MainWindow.hpp"
|
||||
#include <QUndoCommand>
|
||||
|
||||
QIcon ProjectModel::GroupNode::Icon;
|
||||
QIcon ProjectModel::SongGroupNode::Icon;
|
||||
QIcon ProjectModel::SoundGroupNode::Icon;
|
||||
|
||||
NullItemProxyModel::NullItemProxyModel(ProjectModel* source)
|
||||
: QIdentityProxyModel(source)
|
||||
{
|
||||
setSourceModel(source);
|
||||
}
|
||||
|
||||
QModelIndex NullItemProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
|
||||
{
|
||||
if (!sourceIndex.isValid())
|
||||
return QModelIndex();
|
||||
if (sourceIndex.row() == sourceModel()->rowCount(sourceIndex.parent()))
|
||||
return createIndex(0, sourceIndex.column(), sourceIndex.internalPointer());
|
||||
return createIndex(sourceIndex.row() + 1, sourceIndex.column(), sourceIndex.internalPointer());
|
||||
}
|
||||
|
||||
QModelIndex NullItemProxyModel::mapToSource(const QModelIndex& proxyIndex) const
|
||||
{
|
||||
if (!proxyIndex.isValid())
|
||||
return QModelIndex();
|
||||
return static_cast<ProjectModel*>(sourceModel())->
|
||||
proxyCreateIndex(proxyIndex.row() - 1, proxyIndex.column(), proxyIndex.internalPointer());
|
||||
}
|
||||
|
||||
int NullItemProxyModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return QIdentityProxyModel::rowCount(parent) + 1;
|
||||
}
|
||||
|
||||
QModelIndex NullItemProxyModel::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
const QModelIndex sourceParent = mapToSource(parent);
|
||||
const QModelIndex sourceIndex = sourceModel()->index(row - 1, column, sourceParent);
|
||||
return mapFromSource(sourceIndex);
|
||||
}
|
||||
|
||||
QVariant NullItemProxyModel::data(const QModelIndex& proxyIndex, int role) const
|
||||
{
|
||||
if (!proxyIndex.isValid() || proxyIndex.row() == 0)
|
||||
return QVariant();
|
||||
return QIdentityProxyModel::data(proxyIndex, role);
|
||||
}
|
||||
|
||||
ProjectModel::INode::INode(INode* parent, int row) : m_parent(parent), m_row(row)
|
||||
{
|
||||
m_nullChild = std::make_unique<NullNode>(this);
|
||||
}
|
||||
|
||||
ProjectModel::CollectionNode* ProjectModel::GroupNode::getCollectionOfType(Type tp) const
|
||||
{
|
||||
for (auto it = m_children.rbegin(); it != m_children.rend(); ++it)
|
||||
{
|
||||
if ((*it)->type() == Type::Collection)
|
||||
{
|
||||
CollectionNode* col = static_cast<CollectionNode*>(it->get());
|
||||
if (col->collectionType() == tp)
|
||||
return col;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ProjectModel::CollectionNode::indexOfId(amuse::ObjectId id) const
|
||||
{
|
||||
int ret = 0;
|
||||
for (auto& n : m_children)
|
||||
{
|
||||
if (static_cast<BasePoolObjectNode*>(n.get())->id() == id)
|
||||
return ret;
|
||||
++ret;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
amuse::ObjectId ProjectModel::CollectionNode::idOfIndex(int idx) const
|
||||
{
|
||||
return static_cast<BasePoolObjectNode*>(m_children[idx].get())->id();
|
||||
}
|
||||
|
||||
ProjectModel::BasePoolObjectNode* ProjectModel::CollectionNode::nodeOfIndex(int idx) const
|
||||
{
|
||||
return static_cast<BasePoolObjectNode*>(m_children[idx].get());
|
||||
}
|
||||
|
||||
ProjectModel::ProjectModel(const QString& path, QObject* parent)
|
||||
: QAbstractItemModel(parent), m_dir(path)
|
||||
: QAbstractItemModel(parent), m_dir(path), m_nullProxy(this)
|
||||
{
|
||||
m_root = std::make_shared<RootNode>();
|
||||
|
||||
@@ -43,8 +128,8 @@ bool ProjectModel::importGroupData(const QString& groupName, const amuse::AudioG
|
||||
m_projectDatabase.setIdDatabases();
|
||||
|
||||
amuse::AudioGroupDatabase& grp = m_groups.insert(std::make_pair(groupName, data)).first->second;
|
||||
grp.setIdDatabases();
|
||||
amuse::AudioGroupProject::BootstrapObjectIDs(data);
|
||||
//grp.setIdDatabases();
|
||||
//amuse::AudioGroupProject::BootstrapObjectIDs(data);
|
||||
|
||||
if (!MkPath(m_dir.path(), messenger))
|
||||
return false;
|
||||
@@ -120,15 +205,13 @@ void ProjectModel::_resetModelData()
|
||||
gn.makeChild<SongGroupNode>(grp.first, grp.second.get());
|
||||
for (const auto& grp : SortUnorderedMap(sfxGroups))
|
||||
gn.makeChild<SoundGroupNode>(grp.first, grp.second.get());
|
||||
if (soundMacros.size())
|
||||
{
|
||||
CollectionNode& col =
|
||||
gn.makeChild<CollectionNode>(tr("Sound Macros"), QIcon(":/icons/IconSoundMacro.svg"));
|
||||
gn.makeChild<CollectionNode>(tr("Sound Macros"), QIcon(":/icons/IconSoundMacro.svg"), INode::Type::SoundMacro);
|
||||
col.reserve(soundMacros.size());
|
||||
for (const auto& macro : SortUnorderedMap(soundMacros))
|
||||
col.makeChild<SoundMacroNode>(macro.first, macro.second.get());
|
||||
}
|
||||
if (tables.size())
|
||||
{
|
||||
auto tablesSort = SortUnorderedMap(tables);
|
||||
size_t ADSRCount = 0;
|
||||
@@ -141,10 +224,9 @@ void ProjectModel::_resetModelData()
|
||||
else if (tp == amuse::ITable::Type::Curve)
|
||||
curveCount += 1;
|
||||
}
|
||||
if (ADSRCount)
|
||||
{
|
||||
CollectionNode& col =
|
||||
gn.makeChild<CollectionNode>(tr("ADSRs"), QIcon(":/icons/IconADSR.svg"));
|
||||
gn.makeChild<CollectionNode>(tr("ADSRs"), QIcon(":/icons/IconADSR.svg"), INode::Type::ADSR);
|
||||
col.reserve(ADSRCount);
|
||||
for (auto& t : tablesSort)
|
||||
{
|
||||
@@ -153,10 +235,9 @@ void ProjectModel::_resetModelData()
|
||||
col.makeChild<ADSRNode>(t.first, t.second.get());
|
||||
}
|
||||
}
|
||||
if (curveCount)
|
||||
{
|
||||
CollectionNode& col =
|
||||
gn.makeChild<CollectionNode>(tr("Curves"), QIcon(":/icons/IconCurve.svg"));
|
||||
gn.makeChild<CollectionNode>(tr("Curves"), QIcon(":/icons/IconCurve.svg"), INode::Type::Curve);
|
||||
col.reserve(curveCount);
|
||||
for (auto& t : tablesSort)
|
||||
{
|
||||
@@ -166,18 +247,16 @@ void ProjectModel::_resetModelData()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keymaps.size())
|
||||
{
|
||||
CollectionNode& col =
|
||||
gn.makeChild<CollectionNode>(tr("Keymaps"), QIcon(":/icons/IconKeymap.svg"));
|
||||
gn.makeChild<CollectionNode>(tr("Keymaps"), QIcon(":/icons/IconKeymap.svg"), INode::Type::Keymap);
|
||||
col.reserve(keymaps.size());
|
||||
for (auto& keymap : SortUnorderedMap(keymaps))
|
||||
col.makeChild<KeymapNode>(keymap.first, keymap.second.get());
|
||||
}
|
||||
if (layers.size())
|
||||
{
|
||||
CollectionNode& col =
|
||||
gn.makeChild<CollectionNode>(tr("Layers"), QIcon(":/icons/IconLayers.svg"));
|
||||
gn.makeChild<CollectionNode>(tr("Layers"), QIcon(":/icons/IconLayers.svg"), INode::Type::Layer);
|
||||
col.reserve(layers.size());
|
||||
for (auto& keymap : SortUnorderedMap(layers))
|
||||
col.makeChild<LayersNode>(keymap.first, keymap.second.get());
|
||||
@@ -195,8 +274,30 @@ void ProjectModel::ensureModelData()
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex ProjectModel::proxyCreateIndex(int arow, int acolumn, void *adata) const
|
||||
{
|
||||
if (arow < 0)
|
||||
{
|
||||
INode* childItem = static_cast<INode*>(adata);
|
||||
return createIndex(childItem->parent()->childCount(), acolumn, adata);
|
||||
}
|
||||
return createIndex(arow, acolumn, adata);
|
||||
}
|
||||
|
||||
QModelIndex ProjectModel::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
if (row < 0)
|
||||
{
|
||||
INode* parentItem;
|
||||
if (!parent.isValid())
|
||||
parentItem = m_root.get();
|
||||
else
|
||||
parentItem = static_cast<INode*>(parent.internalPointer());
|
||||
|
||||
INode* childItem = parentItem->nullChild();
|
||||
return createIndex(childItem->row(), column, childItem);
|
||||
}
|
||||
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
@@ -213,6 +314,13 @@ QModelIndex ProjectModel::index(int row, int column, const QModelIndex& parent)
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex ProjectModel::index(INode* node) const
|
||||
{
|
||||
if (node == m_root.get())
|
||||
return QModelIndex();
|
||||
return createIndex(node->row(), 0, node);
|
||||
}
|
||||
|
||||
QModelIndex ProjectModel::parent(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
@@ -267,22 +375,73 @@ Qt::ItemFlags ProjectModel::flags(const QModelIndex& index) const
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
return QAbstractItemModel::flags(index);
|
||||
return static_cast<INode*>(index.internalPointer())->flags();
|
||||
}
|
||||
|
||||
ProjectModel::INode* ProjectModel::node(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return nullptr;
|
||||
return m_root.get();
|
||||
return static_cast<INode*>(index.internalPointer());
|
||||
}
|
||||
|
||||
bool ProjectModel::canDelete() const
|
||||
ProjectModel::GroupNode* ProjectModel::getGroupNode(INode* node) const
|
||||
{
|
||||
return false;
|
||||
if (!node)
|
||||
return nullptr;
|
||||
if (node->type() == INode::Type::Group)
|
||||
return static_cast<GroupNode*>(node);
|
||||
return getGroupNode(node->parent());
|
||||
}
|
||||
|
||||
void ProjectModel::del()
|
||||
bool ProjectModel::canEdit(const QModelIndex& index) const
|
||||
{
|
||||
|
||||
if (!index.isValid())
|
||||
return false;
|
||||
return (static_cast<INode*>(index.internalPointer())->flags() & Qt::ItemIsSelectable) != Qt::NoItemFlags;
|
||||
}
|
||||
|
||||
class DeleteNodeUndoCommand : public QUndoCommand
|
||||
{
|
||||
QModelIndex m_deleteIdx;
|
||||
std::shared_ptr<ProjectModel::INode> m_node;
|
||||
public:
|
||||
DeleteNodeUndoCommand(const QModelIndex& index)
|
||||
: QUndoCommand(QUndoStack::tr("Delete %1").arg(index.data().toString())), m_deleteIdx(index) {}
|
||||
void undo()
|
||||
{
|
||||
g_MainWindow->projectModel()->_undoDel(m_deleteIdx, std::move(m_node));
|
||||
m_node.reset();
|
||||
}
|
||||
void redo()
|
||||
{
|
||||
m_node = g_MainWindow->projectModel()->_redoDel(m_deleteIdx);
|
||||
}
|
||||
};
|
||||
|
||||
void ProjectModel::_undoDel(const QModelIndex& index, std::shared_ptr<ProjectModel::INode>&& n)
|
||||
{
|
||||
beginInsertRows(index.parent(), index.row(), index.row());
|
||||
node(index.parent())->insertChild(index.row(), std::move(n));
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
std::shared_ptr<ProjectModel::INode> ProjectModel::_redoDel(const QModelIndex& index)
|
||||
{
|
||||
node(index)->depthTraverse([](INode* node)
|
||||
{
|
||||
g_MainWindow->aboutToDeleteNode(node);
|
||||
return true;
|
||||
});
|
||||
beginRemoveRows(index.parent(), index.row(), index.row());
|
||||
std::shared_ptr<ProjectModel::INode> ret = node(index.parent())->removeChild(index.row());
|
||||
endRemoveRows();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ProjectModel::del(const QModelIndex& index)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return;
|
||||
g_MainWindow->pushUndoCommand(new DeleteNodeUndoCommand(index));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user