1 |
// qsamplerInstrumentList.h |
// qsamplerInstrumentList.h |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
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 |
23 |
#ifndef __qsamplerInstrumentList_h |
#ifndef __qsamplerInstrumentList_h |
24 |
#define __qsamplerInstrumentList_h |
#define __qsamplerInstrumentList_h |
25 |
|
|
26 |
#include <QListWidget> |
#include <QTreeView> |
|
#include <QListWidgetItem> |
|
|
//#include <qheader.h> |
|
|
#include <QAbstractTableModel> |
|
|
#include <QItemDelegate> |
|
27 |
|
|
28 |
#include <lscp/client.h> |
namespace QSampler { |
29 |
|
|
30 |
#include <string.h> |
class Instrument; |
31 |
|
|
32 |
#include "qsamplerInstrument.h" |
//------------------------------------------------------------------------- |
33 |
|
// QSampler:InstrumentListModel - data model for MIDI prog mappings |
|
// Forward declarations. |
|
|
//class qsamplerInstrument; |
|
|
//class qsamplerInstrumentList; |
|
|
|
|
|
class QAction; |
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------- |
|
|
// class qsamplerInstrumentGroup -- custom group list view item. |
|
34 |
// |
// |
35 |
|
|
36 |
class qsamplerInstrumentGroup : public QListWidgetItem |
class InstrumentListModel : public QAbstractItemModel |
37 |
{ |
{ |
38 |
public: |
public: |
39 |
|
|
40 |
// Constructors. |
// Constructor. |
41 |
qsamplerInstrumentGroup(QListWidget *pListView, |
InstrumentListModel(QObject *pParent = NULL); |
|
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; |
|
42 |
|
|
43 |
// To show up whether its open or not. |
// Destructor. |
44 |
virtual void setOpen(bool bOpen); |
~InstrumentListModel(); |
45 |
|
|
46 |
// To virtually distinguish between list view items. |
// Overridden methods from subclass(es) |
47 |
virtual int rtti() const; |
int rowCount(const QModelIndex& parent) const; |
48 |
}; |
int columnCount(const QModelIndex& parent) const; |
49 |
|
|
50 |
|
QVariant data(const QModelIndex& index, int role) const; |
51 |
|
QVariant headerData(int section, Qt::Orientation orientation, |
52 |
|
int role = Qt::DisplayRole) const; |
53 |
|
|
54 |
|
// Map selector. |
55 |
|
void setMidiMap(int iMidiMap); |
56 |
|
int midiMap() const; |
57 |
|
|
58 |
//---------------------------------------------------------------------- |
// Own methods |
59 |
// class qsamplerInstrumentItem -- custom file list view item. |
const Instrument *addInstrument(int iMap, int iBank, int iProg); |
60 |
// |
void removeInstrument(const Instrument *pInstrument); |
61 |
|
void updateInstrument(const Instrument *pInstrument); |
62 |
|
|
63 |
class qsamplerInstrumentItem : public qsamplerInstrumentGroup |
// General reloader. |
64 |
{ |
void refresh(); |
|
public: |
|
65 |
|
|
66 |
// Constructors. |
// Make the following method public |
67 |
qsamplerInstrumentItem(QListWidget *pListView, |
void beginReset(); |
68 |
qsamplerInstrument *pInstrument, |
void endReset(); |
|
QListWidgetItem *pItemAfter = NULL); |
|
|
qsamplerInstrumentItem(qsamplerInstrumentGroup *pGroupItem, |
|
|
qsamplerInstrument *pInstrument); |
|
|
// Default destructor. |
|
|
virtual ~qsamplerInstrumentItem(); |
|
69 |
|
|
70 |
// To virtually distinguish between list view items. |
// Map clear. |
71 |
virtual int rtti() const; |
void clear(); |
72 |
|
|
73 |
// Payload accessor. |
protected: |
|
qsamplerInstrument *instrument() const; |
|
74 |
|
|
75 |
// View refreshment. |
QModelIndex index(int row, int col, const QModelIndex& parent) const; |
76 |
void update(); |
QModelIndex parent(const QModelIndex& child) const; |
77 |
|
|
78 |
private: |
private: |
79 |
|
|
80 |
// File item full path. |
typedef QList<Instrument *> InstrumentList; |
81 |
qsamplerInstrument *m_pInstrument; |
typedef QMap<int, InstrumentList> InstrumentMap; |
82 |
|
|
83 |
|
InstrumentMap m_instruments; |
84 |
|
|
85 |
|
// Current map selection. |
86 |
|
int m_iMidiMap; |
87 |
}; |
}; |
88 |
|
|
89 |
|
|
90 |
//---------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
91 |
// qsamplerInstrumentList -- MIDI instrument list view. |
// QSampler::InstrumentListView - list view for MIDI prog mappings |
92 |
// |
// |
93 |
|
|
94 |
#if 0 |
class InstrumentListView : public QTreeView |
|
class qsamplerInstrumentList : public QListView |
|
95 |
{ |
{ |
|
Q_OBJECT |
|
|
|
|
96 |
public: |
public: |
97 |
|
|
98 |
// Constructor. |
// Constructor. |
99 |
qsamplerInstrumentList(QWidget *pParent, const char *pszName = NULL); |
InstrumentListView(QWidget *pParent = NULL); |
100 |
// Default destructor. |
|
101 |
~qsamplerInstrumentList(); |
// Destructor. |
102 |
|
~InstrumentListView(); |
|
// 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; |
|
103 |
|
|
104 |
// Map selector. |
// Map selector. |
105 |
void setMidiMap(int iMidiMap); |
void setMidiMap(int iMidiMap); |
106 |
int midiMap() const; |
int midiMap() const; |
107 |
|
|
108 |
// List actions accessors. |
// Own methods |
109 |
QAction *newGroupAction() const; |
const Instrument *addInstrument(int iMap, int iBank, int iProg); |
110 |
QAction *newItemAction() const; |
void removeInstrument(const Instrument *pInstrument); |
111 |
QAction *editItemAction() const; |
void updateInstrument(const Instrument *pInstrument); |
|
QAction *renameAction() const; |
|
|
QAction *deleteAction() const; |
|
|
QAction *refreshAction() const; |
|
|
|
|
|
signals: |
|
|
|
|
|
// Instrument map/session change signal. |
|
|
void instrumentsChanged(); |
|
|
|
|
|
public slots: |
|
112 |
|
|
113 |
// General reloader. |
// General reloader. |
114 |
void refresh(); |
void refresh(); |
115 |
|
|
|
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); |
|
|
|
|
116 |
private: |
private: |
117 |
|
|
118 |
// List view actions. |
// Instance variables. |
119 |
QAction *m_pNewGroupAction; |
InstrumentListModel *m_pListModel; |
|
QAction *m_pNewItemAction; |
|
|
QAction *m_pEditItemAction; |
|
|
QAction *m_pRenameAction; |
|
|
QAction *m_pDeleteAction; |
|
|
QAction *m_pRefreshAction; |
|
|
|
|
|
// Current map selection. |
|
|
int m_iMidiMap; |
|
120 |
}; |
}; |
|
#endif |
|
121 |
|
|
|
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(); |
|
|
|
|
|
public slots: |
|
|
// General reloader. |
|
|
void refresh(); |
|
|
|
|
|
private: |
|
|
typedef QMap<int, QList<qsamplerInstrument> > InstrumentsMap; |
|
|
|
|
|
// Current map selection. |
|
|
int m_iMidiMap; |
|
|
|
|
|
InstrumentsMap instruments; |
|
|
}; |
|
|
|
|
|
class MidiInstrumentsDelegate : public QItemDelegate { |
|
|
Q_OBJECT |
|
|
public: |
|
|
MidiInstrumentsDelegate(QObject* parent = 0); |
|
|
|
|
|
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; |
|
|
|
|
|
void updateEditorGeometry(QWidget* editor, |
|
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
|
|
}; |
|
122 |
|
|
123 |
|
} // namespace QSampler |
124 |
|
|
125 |
#endif // __qsamplerInstrumentList_h |
#endif // __qsamplerInstrumentList_h |
126 |
|
|