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 <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 |
|
|
38 |
//---------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
39 |
// class qsamplerInstrumentGroup -- custom group list view item. |
// MidiInstrumentsModel - data model for MIDI prog mappings (used for QTableView) |
40 |
// |
// |
41 |
|
|
42 |
class qsamplerInstrumentGroup : public QListViewItem |
class MidiInstrumentsModel : public QAbstractTableModel { |
43 |
{ |
Q_OBJECT |
44 |
public: |
public: |
45 |
|
MidiInstrumentsModel(QObject* parent = 0); |
46 |
// Constructors. |
|
47 |
qsamplerInstrumentGroup(qsamplerInstrumentList *pListView, |
// overridden methods from subclass(es) |
48 |
const QString& sName, QListViewItem *pItemAfter = NULL); |
int rowCount(const QModelIndex &parent) const; |
49 |
qsamplerInstrumentGroup(qsamplerInstrumentGroup *pGroupItem, |
int columnCount(const QModelIndex &parent) const; |
50 |
const QString& sName); |
QVariant data(const QModelIndex &index, int role) const; |
51 |
// Default destructor. |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
52 |
virtual ~qsamplerInstrumentGroup(); |
|
53 |
|
// make the following method public |
54 |
// Instance accessors. |
QAbstractTableModel::reset; |
55 |
void setName(const QString& sName); |
|
56 |
QString name() const; |
// own methods |
57 |
|
qsamplerInstrument* addInstrument(int iMap = 0, int iBank = -1, int iProg = -1); |
58 |
qsamplerInstrumentList *listView() const; |
void removeInstrument(const qsamplerInstrument& instrument); |
59 |
qsamplerInstrumentGroup *groupItem() const; |
void resort(const qsamplerInstrument instrument); |
60 |
|
|
61 |
// To show up whether its open or not. |
// Map selector. |
62 |
virtual void setOpen(bool bOpen); |
void setMidiMap(int iMidiMap); |
63 |
|
int midiMap() const; |
64 |
// To virtually distinguish between list view items. |
|
65 |
virtual int rtti() const; |
signals: |
66 |
}; |
// Instrument map/session change signal. |
67 |
|
void instrumentsChanged(); |
68 |
|
|
69 |
//---------------------------------------------------------------------- |
public slots: |
70 |
// class qsamplerInstrumentItem -- custom file list view item. |
// General reloader. |
71 |
// |
void refresh(); |
72 |
|
|
73 |
class qsamplerInstrumentItem : public qsamplerInstrumentGroup |
private: |
74 |
{ |
typedef QMap<int, QList<qsamplerInstrument> > InstrumentsMap; |
75 |
public: |
|
76 |
|
// Current map selection. |
77 |
// Constructors. |
int m_iMidiMap; |
78 |
qsamplerInstrumentItem(qsamplerInstrumentList *pListView, |
|
79 |
qsamplerInstrument *pInstrument, |
InstrumentsMap instruments; |
80 |
QListViewItem *pItemAfter = NULL); |
}; |
81 |
qsamplerInstrumentItem(qsamplerInstrumentGroup *pGroupItem, |
|
82 |
qsamplerInstrument *pInstrument); |
|
83 |
// Default destructor. |
//------------------------------------------------------------------------- |
84 |
virtual ~qsamplerInstrumentItem(); |
// MidiInstrumentsDelegate - table cell renderer for MIDI prog mappings |
85 |
|
// (doesn't actually do anything ATM, but is already there for a future |
86 |
// To virtually distinguish between list view items. |
// cell editor widget implementation) |
87 |
virtual int rtti() const; |
|
88 |
|
class MidiInstrumentsDelegate : public QItemDelegate { |
89 |
// Payload accessor. |
Q_OBJECT |
90 |
qsamplerInstrument *Instrument() const; |
public: |
91 |
|
MidiInstrumentsDelegate(QObject* parent = 0); |
92 |
// View refreshment. |
|
93 |
void update(); |
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, |
94 |
|
const QModelIndex& index) const; |
95 |
private: |
|
96 |
|
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
97 |
// File item full path. |
void setModelData(QWidget* editor, QAbstractItemModel* model, |
98 |
qsamplerInstrument *m_pInstrument; |
const QModelIndex& index) const; |
99 |
}; |
|
100 |
|
void updateEditorGeometry(QWidget* editor, |
101 |
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
102 |
//---------------------------------------------------------------------------- |
}; |
103 |
// qsamplerInstrumentList -- MIDI instrument list view. |
|
104 |
// |
|
105 |
|
#endif // __qsamplerInstrumentList_h |
106 |
class qsamplerInstrumentList : public QListView |
|
107 |
{ |
|
108 |
Q_OBJECT |
// end of qsamplerInstrumentList.h |
|
|
|
|
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; |
|
|
|
|
|
signals: |
|
|
|
|
|
// Instrument map/session change signal. |
|
|
void instrumentsChanged(); |
|
|
|
|
|
public slots: |
|
|
|
|
|
// General reloader. |
|
|
void refresh(); |
|
|
|
|
|
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(QListViewItem *pListItem); |
|
|
|
|
|
// In-place aliasing slot. |
|
|
void renamedSlot(QListViewItem *pItem); |
|
|
|
|
|
protected: |
|
|
|
|
|
// Find and return the nearest group item... |
|
|
qsamplerInstrumentGroup *groupItem(QListViewItem *pListItem) const; |
|
|
|
|
|
// Context menu request event handler. |
|
|
void contextMenuEvent(QContextMenuEvent *pContextMenuEvent); |
|
|
|
|
|
private: |
|
|
|
|
|
// List view actions. |
|
|
QAction *m_pNewGroupAction; |
|
|
QAction *m_pNewItemAction; |
|
|
QAction *m_pEditItemAction; |
|
|
QAction *m_pRenameAction; |
|
|
QAction *m_pDeleteAction; |
|
|
QAction *m_pRefreshAction; |
|
|
}; |
|
|
|
|
|
|
|
|
#endif // __qsamplerInstrumentList_h |
|
|
|
|
|
// end of qsamplerInstrumentList.h |
|