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