amuse/Editor/SongGroupEditor.hpp

290 lines
10 KiB
C++
Raw Normal View History

2018-10-07 03:40:25 +00:00
#pragma once
#include "EditorWidget.hpp"
2018-08-09 07:42:17 +00:00
#include <QTabWidget>
#include <QAbstractTableModel>
#include <QTableView>
#include <QToolButton>
#include <QAction>
#include <QSplitter>
#include <QListView>
#include <QLineEdit>
#include <QPushButton>
#include <QFileDialog>
#include <QProxyStyle>
2018-08-10 06:19:23 +00:00
#include "amuse/Sequencer.hpp"
2018-08-09 07:42:17 +00:00
2018-08-30 08:16:37 +00:00
class SetupTableView;
2018-12-08 05:20:09 +00:00
class PageObjectDelegate : public BaseObjectDelegate {
Q_OBJECT
protected:
2018-12-08 05:20:09 +00:00
ProjectModel::INode* getNode(const QAbstractItemModel* model, const QModelIndex& index) const;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit PageObjectDelegate(QObject* parent = Q_NULLPTR);
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void setEditorData(QWidget* editor, const QModelIndex& index) const;
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
2018-08-09 07:42:17 +00:00
private slots:
2018-12-08 05:20:09 +00:00
void objIndexChanged();
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class MIDIFileFieldWidget : public QWidget {
Q_OBJECT
QLineEdit m_le;
QPushButton m_button;
QFileDialog m_dialog;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit MIDIFileFieldWidget(QWidget* parent = Q_NULLPTR);
QString path() const { return m_le.text(); }
void setPath(const QString& path) { m_le.setText(path); }
2018-08-09 07:42:17 +00:00
public slots:
2018-12-08 05:20:09 +00:00
void buttonPressed();
void fileDialogOpened(const QString& path);
2018-08-09 07:42:17 +00:00
signals:
2018-12-08 05:20:09 +00:00
void pathChanged();
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class MIDIFileDelegate : public QStyledItemDelegate {
Q_OBJECT
QFileDialog m_fileDialogMid, m_fileDialogSng;
std::vector<uint8_t> m_exportData;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit MIDIFileDelegate(SetupTableView* parent = Q_NULLPTR);
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void destroyEditor(QWidget* editor, const QModelIndex& index) const;
void setEditorData(QWidget* editor, const QModelIndex& index) const;
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
const QModelIndex& index);
private slots:
2018-12-08 05:20:09 +00:00
void doExportMIDI();
void _doExportMIDI(const QString& path);
void doExportSNG();
void _doExportSNG(const QString& path);
2018-08-09 07:42:17 +00:00
public slots:
2018-12-08 05:20:09 +00:00
void pathChanged();
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class PageModel : public QAbstractTableModel {
Q_OBJECT
friend class SongGroupEditor;
friend class PageObjectDelegate;
friend class PageTableView;
amuse::ObjToken<ProjectModel::SongGroupNode> m_node;
struct Iterator {
using ItTp = std::unordered_map<uint8_t, amuse::SongGroupIndex::PageEntry>::iterator;
ItTp m_it;
Iterator(ItTp it) : m_it(it) {}
ItTp::pointer operator->() { return m_it.operator->(); }
bool operator<(const Iterator& other) const { return m_it->first < other.m_it->first; }
bool operator<(uint8_t other) const { return m_it->first < other; }
};
std::vector<Iterator> m_sorted;
bool m_drum;
std::unordered_map<uint8_t, amuse::SongGroupIndex::PageEntry>& _getMap() const;
void _buildSortedList();
QModelIndex _indexOfProgram(uint8_t prog) const;
int _hypotheticalIndexOfProgram(uint8_t prog) const;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit PageModel(bool drum, QObject* parent = Q_NULLPTR);
void loadData(ProjectModel::SongGroupNode* node);
void unloadData();
2018-08-09 07:42:17 +00:00
2018-12-08 05:20:09 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex& index) const;
2018-08-09 07:42:17 +00:00
2018-12-08 05:20:09 +00:00
int _insertRow(const std::pair<uint8_t, amuse::SongGroupIndex::PageEntry>& data);
std::pair<uint8_t, amuse::SongGroupIndex::PageEntry> _removeRow(uint8_t prog);
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class SetupListModel : public QAbstractTableModel {
Q_OBJECT
friend class SongGroupEditor;
friend class MIDIFileDelegate;
friend class SetupTableView;
friend class SetupModel;
amuse::ObjToken<ProjectModel::SongGroupNode> m_node;
struct Iterator {
using ItTp = std::unordered_map<amuse::SongId, std::array<amuse::SongGroupIndex::MIDISetup, 16>>::iterator;
ItTp m_it;
Iterator(ItTp it) : m_it(it) {}
ItTp::pointer operator->() { return m_it.operator->(); }
bool operator<(const Iterator& other) const {
return amuse::SongId::CurNameDB->resolveNameFromId(m_it->first) <
amuse::SongId::CurNameDB->resolveNameFromId(other.m_it->first);
}
bool operator<(amuse::SongId other) const {
return amuse::SongId::CurNameDB->resolveNameFromId(m_it->first) <
amuse::SongId::CurNameDB->resolveNameFromId(other);
}
bool operator<(const std::string& name) const {
return amuse::SongId::CurNameDB->resolveNameFromId(m_it->first) < name;
}
};
std::vector<Iterator> m_sorted;
std::unordered_map<amuse::SongId, std::array<amuse::SongGroupIndex::MIDISetup, 16>>& _getMap() const;
void _buildSortedList();
QModelIndex _indexOfSong(amuse::SongId id) const;
int _hypotheticalIndexOfSong(const std::string& songName) const;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit SetupListModel(QObject* parent = Q_NULLPTR);
void loadData(ProjectModel::SongGroupNode* node);
void unloadData();
2018-08-09 07:42:17 +00:00
2018-12-08 05:20:09 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex& index) const;
2018-08-09 07:42:17 +00:00
2018-12-08 05:20:09 +00:00
int _insertRow(std::tuple<amuse::SongId, std::string, std::array<amuse::SongGroupIndex::MIDISetup, 16>>& data);
std::tuple<amuse::SongId, std::string, std::array<amuse::SongGroupIndex::MIDISetup, 16>> _removeRow(amuse::SongId id);
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class SetupModel : public QAbstractTableModel {
Q_OBJECT
friend class SongGroupEditor;
std::pair<const amuse::SongId, std::array<amuse::SongGroupIndex::MIDISetup, 16>>* m_data = nullptr;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit SetupModel(QObject* parent = Q_NULLPTR);
void loadData(std::pair<const amuse::SongId, std::array<amuse::SongGroupIndex::MIDISetup, 16>>* data);
void unloadData();
2018-08-09 07:42:17 +00:00
2018-12-08 05:20:09 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex& index) const;
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class PageTableView : public QTableView {
Q_OBJECT
PageObjectDelegate m_poDelegate;
RangedValueFactory<0, 127> m_127Factory;
RangedValueFactory<1, 128> m_128Factory;
RangedValueFactory<0, 255> m_255Factory;
QStyledItemDelegate m_127Delegate, m_128Delegate, m_255Delegate;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit PageTableView(QWidget* parent = Q_NULLPTR);
void setModel(QAbstractItemModel* model);
void deleteSelection();
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class SetupTableView : public QSplitter {
Q_OBJECT
friend class SongGroupEditor;
friend class SetupRowUndoCommand;
QTableView* m_listView;
QTableView* m_tableView;
MIDIFileDelegate m_midiDelegate;
RangedValueFactory<0, 127> m_127Factory;
RangedValueFactory<1, 128> m_128Factory;
QStyledItemDelegate m_127Delegate, m_128Delegate;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit SetupTableView(QWidget* parent = Q_NULLPTR);
void setModel(QAbstractItemModel* list, QAbstractItemModel* table);
void deleteSelection();
void showEvent(QShowEvent* event);
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class ColoredTabBarStyle : public QProxyStyle {
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
using QProxyStyle::QProxyStyle;
void drawControl(QStyle::ControlElement element, const QStyleOption* option, QPainter* painter,
const QWidget* widget = nullptr) const;
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class ColoredTabBar : public QTabBar {
Q_OBJECT
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit ColoredTabBar(QWidget* parent = Q_NULLPTR);
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class ColoredTabWidget : public QTabWidget {
Q_OBJECT
ColoredTabBar m_tabBar;
2018-08-09 07:42:17 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit ColoredTabWidget(QWidget* parent = Q_NULLPTR);
2018-08-09 07:42:17 +00:00
};
2018-12-08 05:20:09 +00:00
class MIDIPlayerWidget : public QWidget {
Q_OBJECT
QAction m_playAction;
QToolButton m_button;
QModelIndex m_index;
amuse::GroupId m_groupId;
amuse::SongId m_songId;
QString m_path;
std::vector<uint8_t> m_arrData;
amuse::ObjToken<amuse::Sequencer> m_seq;
2018-08-10 06:19:23 +00:00
public:
2018-12-08 05:20:09 +00:00
explicit MIDIPlayerWidget(QModelIndex index, amuse::GroupId gid, amuse::SongId id, const QString& path,
QWidget* parent = Q_NULLPTR);
~MIDIPlayerWidget();
amuse::SongId songId() const { return m_songId; }
amuse::Sequencer* sequencer() const { return m_seq.get(); }
void stopped();
void resizeEvent(QResizeEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event) { event->ignore(); }
2018-08-10 06:19:23 +00:00
public slots:
2018-12-08 05:20:09 +00:00
void clicked();
2018-08-10 06:19:23 +00:00
};
2018-12-08 05:20:09 +00:00
class SongGroupEditor : public EditorWidget {
Q_OBJECT
friend class SetupModel;
PageModel m_normPages;
PageModel m_drumPages;
SetupListModel m_setupList;
SetupModel m_setup;
PageTableView* m_normTable;
PageTableView* m_drumTable;
SetupTableView* m_setupTable;
ColoredTabWidget m_tabs;
AddRemoveButtons m_addRemoveButtons;
public:
2018-12-08 05:20:09 +00:00
explicit SongGroupEditor(QWidget* parent = Q_NULLPTR);
bool loadData(ProjectModel::SongGroupNode* node);
void unloadData();
ProjectModel::INode* currentNode() const;
void setEditorEnabled(bool en) {}
void resizeEvent(QResizeEvent* ev);
QTableView* getSetupListView() const { return m_setupTable->m_listView; }
AmuseItemEditFlags itemEditFlags() const;
2018-08-30 20:34:10 +00:00
private slots:
2018-12-08 05:20:09 +00:00
void doAdd();
void doSelectionChanged();
void doSetupSelectionChanged();
void currentTabChanged(int idx);
void normRowsInserted(const QModelIndex& parent, int first, int last);
void normRowsMoved(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row);
void drumRowsInserted(const QModelIndex& parent, int first, int last);
void drumRowsMoved(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row);
void setupRowsInserted(const QModelIndex& parent, int first, int last);
void setupRowsMoved(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row);
void setupRowsAboutToBeRemoved(const QModelIndex& parent, int first, int last);
void setupModelAboutToBeReset();
void setupDataChanged();
void itemDeleteAction();
};