1 |
// qsamplerInstrumentList.h |
// qsamplerInstrumentList.h |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
8 |
as published by the Free Software Foundation; either version 2 |
as published by the Free Software Foundation; either version 2 |
9 |
of the License, or (at your option) any later version. |
of the License, or (at your option) any later version. |
10 |
|
|
11 |
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
GNU General Public License for more details. |
15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
|
20 |
*****************************************************************************/ |
*****************************************************************************/ |
21 |
|
|
22 |
#ifndef __qsamplerInstrumentList_h |
#ifndef __qsamplerInstrumentList_h |
23 |
#define __qsamplerInstrumentList_h |
#define __qsamplerInstrumentList_h |
24 |
|
|
25 |
#include <qlistview.h> |
#include <QListWidget> |
26 |
#include <qheader.h> |
#include <QListWidgetItem> |
27 |
|
//#include <qheader.h> |
28 |
#include <lscp/client.h> |
#include <QAbstractTableModel> |
29 |
|
#include <QItemDelegate> |
30 |
|
|
31 |
// Forward declarations. |
#include <lscp/client.h> |
32 |
class qsamplerInstrument; |
|
33 |
class qsamplerInstrumentList; |
#include <string.h> |
34 |
|
|
35 |
class QAction; |
#include "qsamplerInstrument.h" |
36 |
|
|
37 |
|
// Forward declarations. |
38 |
//---------------------------------------------------------------------- |
//class qsamplerInstrument; |
39 |
// class qsamplerInstrumentGroup -- custom group list view item. |
//class qsamplerInstrumentList; |
40 |
// |
|
41 |
|
class QAction; |
42 |
class qsamplerInstrumentGroup : public QListViewItem |
|
43 |
{ |
|
44 |
public: |
//---------------------------------------------------------------------- |
45 |
|
// class qsamplerInstrumentGroup -- custom group list view item. |
46 |
// Constructors. |
// |
47 |
qsamplerInstrumentGroup(qsamplerInstrumentList *pListView, |
|
48 |
const QString& sName, QListViewItem *pItemAfter = NULL); |
class qsamplerInstrumentGroup : public QListWidgetItem |
49 |
qsamplerInstrumentGroup(qsamplerInstrumentGroup *pGroupItem, |
{ |
50 |
const QString& sName); |
public: |
51 |
// Default destructor. |
|
52 |
virtual ~qsamplerInstrumentGroup(); |
// Constructors. |
53 |
|
qsamplerInstrumentGroup(QListWidget *pListView, |
54 |
// Instance accessors. |
const QString& sName, QListWidgetItem *pItemAfter = NULL); |
55 |
void setName(const QString& sName); |
qsamplerInstrumentGroup(qsamplerInstrumentGroup *pGroupItem, |
56 |
QString name() const; |
const QString& sName); |
57 |
|
// Default destructor. |
58 |
qsamplerInstrumentList *listView() const; |
virtual ~qsamplerInstrumentGroup(); |
59 |
qsamplerInstrumentGroup *groupItem() const; |
|
60 |
|
// Instance accessors. |
61 |
// To show up whether its open or not. |
void setName(const QString& sName); |
62 |
virtual void setOpen(bool bOpen); |
QString name() const; |
63 |
|
|
64 |
// To virtually distinguish between list view items. |
QListWidget *listView() const; |
65 |
virtual int rtti() const; |
qsamplerInstrumentGroup *groupItem() const; |
66 |
}; |
|
67 |
|
// To show up whether its open or not. |
68 |
|
virtual void setOpen(bool bOpen); |
69 |
//---------------------------------------------------------------------- |
|
70 |
// class qsamplerInstrumentItem -- custom file list view item. |
// To virtually distinguish between list view items. |
71 |
// |
virtual int rtti() const; |
72 |
|
}; |
73 |
class qsamplerInstrumentItem : public qsamplerInstrumentGroup |
|
74 |
{ |
|
75 |
public: |
//---------------------------------------------------------------------- |
76 |
|
// class qsamplerInstrumentItem -- custom file list view item. |
77 |
// Constructors. |
// |
78 |
qsamplerInstrumentItem(qsamplerInstrumentList *pListView, |
|
79 |
qsamplerInstrument *pInstrument, |
class qsamplerInstrumentItem : public qsamplerInstrumentGroup |
80 |
QListViewItem *pItemAfter = NULL); |
{ |
81 |
qsamplerInstrumentItem(qsamplerInstrumentGroup *pGroupItem, |
public: |
82 |
qsamplerInstrument *pInstrument); |
|
83 |
// Default destructor. |
// Constructors. |
84 |
virtual ~qsamplerInstrumentItem(); |
qsamplerInstrumentItem(QListWidget *pListView, |
85 |
|
qsamplerInstrument *pInstrument, |
86 |
// To virtually distinguish between list view items. |
QListWidgetItem *pItemAfter = NULL); |
87 |
virtual int rtti() const; |
qsamplerInstrumentItem(qsamplerInstrumentGroup *pGroupItem, |
88 |
|
qsamplerInstrument *pInstrument); |
89 |
// Payload accessor. |
// Default destructor. |
90 |
qsamplerInstrument *Instrument() const; |
virtual ~qsamplerInstrumentItem(); |
91 |
|
|
92 |
// View refreshment. |
// To virtually distinguish between list view items. |
93 |
void update(); |
virtual int rtti() const; |
94 |
|
|
95 |
private: |
// Payload accessor. |
96 |
|
qsamplerInstrument *instrument() const; |
97 |
// File item full path. |
|
98 |
qsamplerInstrument *m_pInstrument; |
// View refreshment. |
99 |
}; |
void update(); |
100 |
|
|
101 |
|
private: |
102 |
//---------------------------------------------------------------------------- |
|
103 |
// qsamplerInstrumentList -- MIDI instrument list view. |
// File item full path. |
104 |
// |
qsamplerInstrument *m_pInstrument; |
105 |
|
}; |
106 |
class qsamplerInstrumentList : public QListView |
|
107 |
{ |
|
108 |
Q_OBJECT |
//---------------------------------------------------------------------------- |
109 |
|
// qsamplerInstrumentList -- MIDI instrument list view. |
110 |
public: |
// |
111 |
|
|
112 |
// Constructor. |
#if 0 |
113 |
qsamplerInstrumentList(QWidget *pParent, const char *pszName = NULL); |
class qsamplerInstrumentList : public QListView |
114 |
// Default destructor. |
{ |
115 |
~qsamplerInstrumentList(); |
Q_OBJECT |
116 |
|
|
117 |
// QListViewItem::rtti() return values. |
public: |
118 |
enum ItemType { Group = 1001, Item = 1002 }; |
|
119 |
|
// Constructor. |
120 |
// Add a new group/file item, optionally under a given group. |
qsamplerInstrumentList(QWidget *pParent, const char *pszName = NULL); |
121 |
qsamplerInstrumentGroup *addGroup(const QString& sName, |
// Default destructor. |
122 |
qsamplerInstrumentGroup *pParentGroup = NULL); |
~qsamplerInstrumentList(); |
123 |
qsamplerInstrumentItem *addItem( |
|
124 |
qsamplerInstrument *pInstrument, |
// QListViewItem::rtti() return values. |
125 |
qsamplerInstrumentGroup *pParentGroup = NULL); |
enum ItemType { Group = 1001, Item = 1002 }; |
126 |
|
|
127 |
// Find a group/file item, given its name. |
// Add a new group/file item, optionally under a given group. |
128 |
qsamplerInstrumentGroup *findGroup(const QString& sName) const; |
qsamplerInstrumentGroup *addGroup(const QString& sName, |
129 |
qsamplerInstrumentItem *findItem( |
qsamplerInstrumentGroup *pParentGroup = NULL); |
130 |
qsamplerInstrument *pInstrument) const; |
qsamplerInstrumentItem *addItem( |
131 |
|
qsamplerInstrument *pInstrument, |
132 |
signals: |
qsamplerInstrumentGroup *pParentGroup = NULL); |
133 |
|
|
134 |
// Instrument map/session change signal. |
// Find a group/file item, given its name. |
135 |
void instrumentsChanged(); |
qsamplerInstrumentGroup *findGroup(const QString& sName) const; |
136 |
|
qsamplerInstrumentItem *findItem( |
137 |
public slots: |
qsamplerInstrument *pInstrument) const; |
138 |
|
|
139 |
// General reloader. |
// Map selector. |
140 |
void refresh(); |
void setMidiMap(int iMidiMap); |
141 |
|
int midiMap() const; |
142 |
protected slots: |
|
143 |
|
// List actions accessors. |
144 |
// Add a new group item below the current one. |
QAction *newGroupAction() const; |
145 |
void newGroupSlot(); |
QAction *newItemAction() const; |
146 |
// Add a instrument item below the current one. |
QAction *editItemAction() const; |
147 |
void newItemSlot(); |
QAction *renameAction() const; |
148 |
// Change current instrument item. |
QAction *deleteAction() const; |
149 |
void editItemSlot(); |
QAction *refreshAction() const; |
150 |
// Rename current group/item. |
|
151 |
void renameSlot(); |
signals: |
152 |
// Remove current group/item. |
|
153 |
void deleteSlot(); |
// Instrument map/session change signal. |
154 |
|
void instrumentsChanged(); |
155 |
// In-place selection slot. |
|
156 |
void selectionChangedSlot(); |
public slots: |
157 |
|
|
158 |
// In-place activation slot. |
// General reloader. |
159 |
void activatedSlot(QListViewItem *pListItem); |
void refresh(); |
160 |
|
|
161 |
// In-place aliasing slot. |
protected slots: |
162 |
void renamedSlot(QListViewItem *pItem); |
|
163 |
|
// Add a new group item below the current one. |
164 |
protected: |
void newGroupSlot(); |
165 |
|
// Add a instrument item below the current one. |
166 |
// Find and return the nearest group item... |
void newItemSlot(); |
167 |
qsamplerInstrumentGroup *groupItem(QListViewItem *pListItem) const; |
// Change current instrument item. |
168 |
|
void editItemSlot(); |
169 |
// Context menu request event handler. |
// Rename current group/item. |
170 |
void contextMenuEvent(QContextMenuEvent *pContextMenuEvent); |
void renameSlot(); |
171 |
|
// Remove current group/item. |
172 |
private: |
void deleteSlot(); |
173 |
|
|
174 |
// List view actions. |
// In-place selection slot. |
175 |
QAction *m_pNewGroupAction; |
void selectionChangedSlot(); |
176 |
QAction *m_pNewItemAction; |
|
177 |
QAction *m_pEditItemAction; |
// In-place activation slot. |
178 |
QAction *m_pRenameAction; |
void activatedSlot(QListWidgetItem *pListItem); |
179 |
QAction *m_pDeleteAction; |
|
180 |
QAction *m_pRefreshAction; |
// In-place aliasing slot. |
181 |
}; |
void renamedSlot(QListWidgetItem *pItem); |
182 |
|
|
183 |
|
protected: |
184 |
#endif // __qsamplerInstrumentList_h |
|
185 |
|
// Find and return the nearest group item... |
186 |
// end of qsamplerInstrumentList.h |
qsamplerInstrumentGroup *groupItem(QListWidgetItem *pListItem) const; |
187 |
|
|
188 |
|
// Context menu request event handler. |
189 |
|
void contextMenuEvent(QContextMenuEvent *pContextMenuEvent); |
190 |
|
|
191 |
|
private: |
192 |
|
|
193 |
|
// List view actions. |
194 |
|
QAction *m_pNewGroupAction; |
195 |
|
QAction *m_pNewItemAction; |
196 |
|
QAction *m_pEditItemAction; |
197 |
|
QAction *m_pRenameAction; |
198 |
|
QAction *m_pDeleteAction; |
199 |
|
QAction *m_pRefreshAction; |
200 |
|
|
201 |
|
// Current map selection. |
202 |
|
int m_iMidiMap; |
203 |
|
}; |
204 |
|
#endif |
205 |
|
|
206 |
|
class MidiInstrumentsModel : public QAbstractTableModel { |
207 |
|
Q_OBJECT |
208 |
|
public: |
209 |
|
MidiInstrumentsModel(QObject* parent = 0); |
210 |
|
|
211 |
|
// overridden methods from subclass(es) |
212 |
|
int rowCount(const QModelIndex &parent) const; |
213 |
|
int columnCount(const QModelIndex &parent) const; |
214 |
|
QVariant data(const QModelIndex &index, int role) const; |
215 |
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
216 |
|
|
217 |
|
qsamplerInstrument* addInstrument(int iMap = 0, int iBank = -1, int iProg = -1); |
218 |
|
|
219 |
|
// Map selector. |
220 |
|
void setMidiMap(int iMidiMap); |
221 |
|
int midiMap() const; |
222 |
|
|
223 |
|
signals: |
224 |
|
// Instrument map/session change signal. |
225 |
|
void instrumentsChanged(); |
226 |
|
|
227 |
|
public slots: |
228 |
|
// General reloader. |
229 |
|
void refresh(); |
230 |
|
|
231 |
|
private: |
232 |
|
typedef QMap<int, QList<qsamplerInstrument> > InstrumentsMap; |
233 |
|
|
234 |
|
// Current map selection. |
235 |
|
int m_iMidiMap; |
236 |
|
|
237 |
|
InstrumentsMap instruments; |
238 |
|
}; |
239 |
|
|
240 |
|
class MidiInstrumentsDelegate : public QItemDelegate { |
241 |
|
Q_OBJECT |
242 |
|
public: |
243 |
|
MidiInstrumentsDelegate(QObject* parent = 0); |
244 |
|
|
245 |
|
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, |
246 |
|
const QModelIndex& index) const; |
247 |
|
|
248 |
|
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
249 |
|
void setModelData(QWidget* editor, QAbstractItemModel* model, |
250 |
|
const QModelIndex& index) const; |
251 |
|
|
252 |
|
void updateEditorGeometry(QWidget* editor, |
253 |
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
254 |
|
}; |
255 |
|
|
256 |
|
|
257 |
|
#endif // __qsamplerInstrumentList_h |
258 |
|
|
259 |
|
// end of qsamplerInstrumentList.h |