2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
24 |
#define __qsamplerInstrumentList_h |
#define __qsamplerInstrumentList_h |
25 |
|
|
26 |
#include <QListWidget> |
#include <QListWidget> |
|
#include <QListWidgetItem> |
|
|
//#include <qheader.h> |
|
|
#include <QAbstractTableModel> |
|
27 |
#include <QItemDelegate> |
#include <QItemDelegate> |
28 |
|
|
29 |
#include <lscp/client.h> |
#include <lscp/client.h> |
30 |
|
|
|
#include <string.h> |
|
|
|
|
31 |
#include "qsamplerInstrument.h" |
#include "qsamplerInstrument.h" |
32 |
|
|
33 |
// Forward declarations. |
namespace QSampler { |
|
//class qsamplerInstrument; |
|
|
//class qsamplerInstrumentList; |
|
|
|
|
|
class QAction; |
|
|
|
|
34 |
|
|
35 |
//---------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
36 |
// class qsamplerInstrumentGroup -- custom group list view item. |
// QSampler::MidiInstrumentsModel - data model for MIDI prog mappings |
37 |
// |
// (used for QTableView) |
38 |
|
|
39 |
class qsamplerInstrumentGroup : public QListWidgetItem |
class MidiInstrumentsModel : public QAbstractTableModel |
40 |
{ |
{ |
41 |
public: |
Q_OBJECT |
|
|
|
|
// Constructors. |
|
|
qsamplerInstrumentGroup(QListWidget *pListView, |
|
|
const QString& sName, QListWidgetItem *pItemAfter = NULL); |
|
|
qsamplerInstrumentGroup(qsamplerInstrumentGroup *pGroupItem, |
|
|
const QString& sName); |
|
|
// Default destructor. |
|
|
virtual ~qsamplerInstrumentGroup(); |
|
|
|
|
|
// Instance accessors. |
|
|
void setName(const QString& sName); |
|
|
QString name() const; |
|
|
|
|
|
QListWidget *listView() const; |
|
|
qsamplerInstrumentGroup *groupItem() const; |
|
|
|
|
|
// To show up whether its open or not. |
|
|
virtual void setOpen(bool bOpen); |
|
|
|
|
|
// To virtually distinguish between list view items. |
|
|
virtual int rtti() const; |
|
|
}; |
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------- |
|
|
// class qsamplerInstrumentItem -- custom file list view item. |
|
|
// |
|
42 |
|
|
|
class qsamplerInstrumentItem : public qsamplerInstrumentGroup |
|
|
{ |
|
43 |
public: |
public: |
44 |
|
|
45 |
// Constructors. |
MidiInstrumentsModel(QObject* pParent = NULL); |
|
qsamplerInstrumentItem(QListWidget *pListView, |
|
|
qsamplerInstrument *pInstrument, |
|
|
QListWidgetItem *pItemAfter = NULL); |
|
|
qsamplerInstrumentItem(qsamplerInstrumentGroup *pGroupItem, |
|
|
qsamplerInstrument *pInstrument); |
|
|
// Default destructor. |
|
|
virtual ~qsamplerInstrumentItem(); |
|
46 |
|
|
47 |
// To virtually distinguish between list view items. |
// Overridden methods from subclass(es) |
48 |
virtual int rtti() const; |
int rowCount(const QModelIndex& parent) const; |
49 |
|
int columnCount(const QModelIndex& parent) const; |
50 |
|
|
51 |
// Payload accessor. |
QVariant data(const QModelIndex& index, int role) const; |
52 |
qsamplerInstrument *instrument() const; |
QVariant headerData(int section, Qt::Orientation orientation, |
53 |
|
int role = Qt::DisplayRole) const; |
54 |
|
|
55 |
// View refreshment. |
// Make the following method public |
56 |
void update(); |
QAbstractTableModel::reset; |
57 |
|
|
58 |
private: |
// Own methods |
59 |
|
Instrument* addInstrument(int iMap = 0, |
60 |
// File item full path. |
int iBank = -1, int iProg = -1); |
61 |
qsamplerInstrument *m_pInstrument; |
void removeInstrument(const Instrument& instrument); |
|
}; |
|
62 |
|
|
63 |
|
void resort(const Instrument& instrument); |
|
//---------------------------------------------------------------------------- |
|
|
// qsamplerInstrumentList -- MIDI instrument list view. |
|
|
// |
|
|
|
|
|
#if 0 |
|
|
class qsamplerInstrumentList : public QListView |
|
|
{ |
|
|
Q_OBJECT |
|
|
|
|
|
public: |
|
|
|
|
|
// Constructor. |
|
|
qsamplerInstrumentList(QWidget *pParent, const char *pszName = NULL); |
|
|
// Default destructor. |
|
|
~qsamplerInstrumentList(); |
|
|
|
|
|
// QListViewItem::rtti() return values. |
|
|
enum ItemType { Group = 1001, Item = 1002 }; |
|
|
|
|
|
// Add a new group/file item, optionally under a given group. |
|
|
qsamplerInstrumentGroup *addGroup(const QString& sName, |
|
|
qsamplerInstrumentGroup *pParentGroup = NULL); |
|
|
qsamplerInstrumentItem *addItem( |
|
|
qsamplerInstrument *pInstrument, |
|
|
qsamplerInstrumentGroup *pParentGroup = NULL); |
|
|
|
|
|
// Find a group/file item, given its name. |
|
|
qsamplerInstrumentGroup *findGroup(const QString& sName) const; |
|
|
qsamplerInstrumentItem *findItem( |
|
|
qsamplerInstrument *pInstrument) const; |
|
64 |
|
|
65 |
// Map selector. |
// Map selector. |
66 |
void setMidiMap(int iMidiMap); |
void setMidiMap(int iMidiMap); |
67 |
int midiMap() const; |
int midiMap() const; |
68 |
|
|
|
// List actions accessors. |
|
|
QAction *newGroupAction() const; |
|
|
QAction *newItemAction() const; |
|
|
QAction *editItemAction() const; |
|
|
QAction *renameAction() const; |
|
|
QAction *deleteAction() const; |
|
|
QAction *refreshAction() const; |
|
|
|
|
69 |
signals: |
signals: |
70 |
|
|
71 |
// Instrument map/session change signal. |
// Instrument map/session change signal. |
76 |
// General reloader. |
// General reloader. |
77 |
void refresh(); |
void refresh(); |
78 |
|
|
|
protected slots: |
|
|
|
|
|
// Add a new group item below the current one. |
|
|
void newGroupSlot(); |
|
|
// Add a instrument item below the current one. |
|
|
void newItemSlot(); |
|
|
// Change current instrument item. |
|
|
void editItemSlot(); |
|
|
// Rename current group/item. |
|
|
void renameSlot(); |
|
|
// Remove current group/item. |
|
|
void deleteSlot(); |
|
|
|
|
|
// In-place selection slot. |
|
|
void selectionChangedSlot(); |
|
|
|
|
|
// In-place activation slot. |
|
|
void activatedSlot(QListWidgetItem *pListItem); |
|
|
|
|
|
// In-place aliasing slot. |
|
|
void renamedSlot(QListWidgetItem *pItem); |
|
|
|
|
|
protected: |
|
|
|
|
|
// Find and return the nearest group item... |
|
|
qsamplerInstrumentGroup *groupItem(QListWidgetItem *pListItem) const; |
|
|
|
|
|
// Context menu request event handler. |
|
|
void contextMenuEvent(QContextMenuEvent *pContextMenuEvent); |
|
|
|
|
79 |
private: |
private: |
80 |
|
|
81 |
// List view actions. |
typedef QMap<int, QList<Instrument> > InstrumentsMap; |
82 |
QAction *m_pNewGroupAction; |
|
83 |
QAction *m_pNewItemAction; |
InstrumentsMap m_instruments; |
|
QAction *m_pEditItemAction; |
|
|
QAction *m_pRenameAction; |
|
|
QAction *m_pDeleteAction; |
|
|
QAction *m_pRefreshAction; |
|
84 |
|
|
85 |
// Current map selection. |
// Current map selection. |
86 |
int m_iMidiMap; |
int m_iMidiMap; |
87 |
}; |
}; |
|
#endif |
|
|
|
|
|
class MidiInstrumentsModel : public QAbstractTableModel { |
|
|
Q_OBJECT |
|
|
public: |
|
|
MidiInstrumentsModel(QObject* parent = 0); |
|
|
|
|
|
// overridden methods from subclass(es) |
|
|
int rowCount(const QModelIndex &parent) const; |
|
|
int columnCount(const QModelIndex &parent) const; |
|
|
QVariant data(const QModelIndex &index, int role) const; |
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
|
|
|
|
|
qsamplerInstrument* addInstrument(int iMap = 0, int iBank = -1, int iProg = -1); |
|
|
|
|
|
// Map selector. |
|
|
void setMidiMap(int iMidiMap); |
|
|
int midiMap() const; |
|
|
|
|
|
signals: |
|
|
// Instrument map/session change signal. |
|
|
void instrumentsChanged(); |
|
88 |
|
|
|
public slots: |
|
|
// General reloader. |
|
|
void refresh(); |
|
89 |
|
|
90 |
private: |
//------------------------------------------------------------------------- |
91 |
typedef QMap<int, QList<qsamplerInstrument> > InstrumentsMap; |
// QSampler::MidiInstrumentsDelegate - table cell renderer for MIDI prog |
92 |
|
// mappings (doesn't actually do anything ATM, but is already there for |
93 |
|
// a future cell editor widget implementation) |
94 |
|
|
95 |
// Current map selection. |
class MidiInstrumentsDelegate : public QItemDelegate |
96 |
int m_iMidiMap; |
{ |
97 |
|
Q_OBJECT |
|
InstrumentsMap instruments; |
|
|
}; |
|
98 |
|
|
|
class MidiInstrumentsDelegate : public QItemDelegate { |
|
|
Q_OBJECT |
|
99 |
public: |
public: |
100 |
MidiInstrumentsDelegate(QObject* parent = 0); |
MidiInstrumentsDelegate(QObject *pParent = NULL); |
101 |
|
|
102 |
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, |
QWidget* createEditor(QWidget *pParent, |
103 |
const QModelIndex& index) const; |
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
104 |
|
|
105 |
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
void setEditorData(QWidget *pEditor, |
106 |
void setModelData(QWidget* editor, QAbstractItemModel* model, |
const QModelIndex& index) const; |
107 |
const QModelIndex& index) const; |
void setModelData(QWidget *pEditor, |
108 |
|
QAbstractItemModel* model, const QModelIndex& index) const; |
109 |
|
|
110 |
void updateEditorGeometry(QWidget* editor, |
void updateEditorGeometry(QWidget* pEditor, |
111 |
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
112 |
}; |
}; |
113 |
|
|
114 |
|
} // namespace QSampler |
115 |
|
|
116 |
#endif // __qsamplerInstrumentList_h |
#endif // __qsamplerInstrumentList_h |
117 |
|
|
118 |
|
|
119 |
// end of qsamplerInstrumentList.h |
// end of qsamplerInstrumentList.h |