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 |
23 |
#ifndef __qsamplerInstrumentList_h |
#ifndef __qsamplerInstrumentList_h |
24 |
#define __qsamplerInstrumentList_h |
#define __qsamplerInstrumentList_h |
25 |
|
|
26 |
#include <qlistview.h> |
#include <QListWidget> |
27 |
#include <qheader.h> |
#include <QItemDelegate> |
28 |
|
|
29 |
#include <lscp/client.h> |
#include <lscp/client.h> |
30 |
|
|
31 |
|
#include "qsamplerInstrument.h" |
32 |
|
|
|
// Forward declarations. |
|
|
class qsamplerInstrument; |
|
|
class qsamplerInstrumentList; |
|
33 |
|
|
34 |
class QAction; |
//------------------------------------------------------------------------- |
35 |
|
// MidiInstrumentsModel - data model for MIDI prog mappings (used for QTableView) |
|
|
|
|
//---------------------------------------------------------------------- |
|
|
// class qsamplerInstrumentGroup -- custom group list view item. |
|
|
// |
|
|
|
|
|
class qsamplerInstrumentGroup : public QListViewItem |
|
|
{ |
|
|
public: |
|
|
|
|
|
// Constructors. |
|
|
qsamplerInstrumentGroup(qsamplerInstrumentList *pListView, |
|
|
const QString& sName, QListViewItem *pItemAfter = NULL); |
|
|
qsamplerInstrumentGroup(qsamplerInstrumentGroup *pGroupItem, |
|
|
const QString& sName); |
|
|
// Default destructor. |
|
|
virtual ~qsamplerInstrumentGroup(); |
|
|
|
|
|
// Instance accessors. |
|
|
void setName(const QString& sName); |
|
|
QString name() const; |
|
|
|
|
|
qsamplerInstrumentList *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. |
|
|
// |
|
|
|
|
|
class qsamplerInstrumentItem : public qsamplerInstrumentGroup |
|
|
{ |
|
|
public: |
|
|
|
|
|
// Constructors. |
|
|
qsamplerInstrumentItem(qsamplerInstrumentList *pListView, |
|
|
qsamplerInstrument *pInstrument, |
|
|
QListViewItem *pItemAfter = NULL); |
|
|
qsamplerInstrumentItem(qsamplerInstrumentGroup *pGroupItem, |
|
|
qsamplerInstrument *pInstrument); |
|
|
// Default destructor. |
|
|
virtual ~qsamplerInstrumentItem(); |
|
|
|
|
|
// To virtually distinguish between list view items. |
|
|
virtual int rtti() const; |
|
|
|
|
|
// Payload accessor. |
|
|
qsamplerInstrument *instrument() const; |
|
|
|
|
|
// View refreshment. |
|
|
void update(); |
|
|
|
|
|
private: |
|
|
|
|
|
// File item full path. |
|
|
qsamplerInstrument *m_pInstrument; |
|
|
}; |
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------- |
|
|
// qsamplerInstrumentList -- MIDI instrument list view. |
|
36 |
// |
// |
37 |
|
|
38 |
class qsamplerInstrumentList : public QListView |
class MidiInstrumentsModel : public QAbstractTableModel { |
39 |
{ |
Q_OBJECT |
|
Q_OBJECT |
|
|
|
|
40 |
public: |
public: |
41 |
|
MidiInstrumentsModel(QObject* parent = 0); |
42 |
|
|
43 |
// Constructor. |
// overridden methods from subclass(es) |
44 |
qsamplerInstrumentList(QWidget *pParent, const char *pszName = NULL); |
int rowCount(const QModelIndex &parent) const; |
45 |
// Default destructor. |
int columnCount(const QModelIndex &parent) const; |
46 |
~qsamplerInstrumentList(); |
QVariant data(const QModelIndex &index, int role) const; |
47 |
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
48 |
// QListViewItem::rtti() return values. |
|
49 |
enum ItemType { Group = 1001, Item = 1002 }; |
// make the following method public |
50 |
|
QAbstractTableModel::reset; |
51 |
// Add a new group/file item, optionally under a given group. |
|
52 |
qsamplerInstrumentGroup *addGroup(const QString& sName, |
// own methods |
53 |
qsamplerInstrumentGroup *pParentGroup = NULL); |
qsamplerInstrument* addInstrument(int iMap = 0, int iBank = -1, int iProg = -1); |
54 |
qsamplerInstrumentItem *addItem( |
void removeInstrument(const qsamplerInstrument& instrument); |
55 |
qsamplerInstrument *pInstrument, |
void resort(const qsamplerInstrument instrument); |
56 |
qsamplerInstrumentGroup *pParentGroup = NULL); |
|
57 |
|
// Map selector. |
58 |
// Find a group/file item, given its name. |
void setMidiMap(int iMidiMap); |
59 |
qsamplerInstrumentGroup *findGroup(const QString& sName) const; |
int midiMap() const; |
|
qsamplerInstrumentItem *findItem( |
|
|
qsamplerInstrument *pInstrument) const; |
|
|
|
|
|
// Map selector. |
|
|
void setMidiMap(int iMidiMap); |
|
|
int midiMap() const; |
|
|
|
|
|
// List actions accessors. |
|
|
QAction *newGroupAction() const; |
|
|
QAction *newItemAction() const; |
|
|
QAction *editItemAction() const; |
|
|
QAction *renameAction() const; |
|
|
QAction *deleteAction() const; |
|
|
QAction *refreshAction() const; |
|
60 |
|
|
61 |
signals: |
signals: |
62 |
|
// Instrument map/session change signal. |
63 |
// Instrument map/session change signal. |
void instrumentsChanged(); |
|
void instrumentsChanged(); |
|
64 |
|
|
65 |
public slots: |
public slots: |
66 |
|
// General reloader. |
67 |
|
void refresh(); |
68 |
|
|
69 |
// General reloader. |
private: |
70 |
void refresh(); |
typedef QMap<int, QList<qsamplerInstrument> > InstrumentsMap; |
71 |
|
|
72 |
protected slots: |
// Current map selection. |
73 |
|
int m_iMidiMap; |
74 |
|
|
75 |
// Add a new group item below the current one. |
InstrumentsMap instruments; |
76 |
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); |
|
77 |
|
|
|
protected: |
|
78 |
|
|
79 |
// Find and return the nearest group item... |
//------------------------------------------------------------------------- |
80 |
qsamplerInstrumentGroup *groupItem(QListViewItem *pListItem) const; |
// MidiInstrumentsDelegate - table cell renderer for MIDI prog mappings |
81 |
|
// (doesn't actually do anything ATM, but is already there for a future |
82 |
|
// cell editor widget implementation) |
83 |
|
|
84 |
// Context menu request event handler. |
class MidiInstrumentsDelegate : public QItemDelegate { |
85 |
void contextMenuEvent(QContextMenuEvent *pContextMenuEvent); |
Q_OBJECT |
86 |
|
public: |
87 |
|
MidiInstrumentsDelegate(QObject* parent = 0); |
88 |
|
|
89 |
private: |
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, |
90 |
|
const QModelIndex& index) const; |
91 |
|
|
92 |
// List view actions. |
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
93 |
QAction *m_pNewGroupAction; |
void setModelData(QWidget* editor, QAbstractItemModel* model, |
94 |
QAction *m_pNewItemAction; |
const QModelIndex& index) const; |
|
QAction *m_pEditItemAction; |
|
|
QAction *m_pRenameAction; |
|
|
QAction *m_pDeleteAction; |
|
|
QAction *m_pRefreshAction; |
|
95 |
|
|
96 |
// Current map selection. |
void updateEditorGeometry(QWidget* editor, |
97 |
int m_iMidiMap; |
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
98 |
}; |
}; |
99 |
|
|
100 |
|
|
101 |
#endif // __qsamplerInstrumentList_h |
#endif // __qsamplerInstrumentList_h |
102 |
|
|
103 |
|
|
104 |
// end of qsamplerInstrumentList.h |
// end of qsamplerInstrumentList.h |