1 |
// qsamplerInstrumentList.cpp |
// qsamplerInstrumentList.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2015, 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 |
24 |
#include "qsamplerInstrumentList.h" |
#include "qsamplerInstrumentList.h" |
25 |
|
|
26 |
#include "qsamplerInstrument.h" |
#include "qsamplerInstrument.h" |
|
#include "qsamplerInstrumentForm.h" |
|
27 |
|
|
28 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
29 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
30 |
|
|
31 |
#include <qmessagebox.h> |
#include <QApplication> |
32 |
#include <qaction.h> |
#include <QHeaderView> |
33 |
#include <qfileinfo.h> |
#include <QCursor> |
|
#include <qpopupmenu.h> |
|
34 |
|
|
|
// Needed for lroundf() |
|
|
#include <math.h> |
|
|
|
|
|
#ifndef CONFIG_ROUND |
|
|
static inline long lroundf ( float x ) |
|
|
{ |
|
|
if (x >= 0.0f) |
|
|
return long(x + 0.5f); |
|
|
else |
|
|
return long(x - 0.5f); |
|
|
} |
|
|
#endif |
|
35 |
|
|
36 |
|
namespace QSampler { |
37 |
|
|
38 |
//---------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
39 |
// class qsamplerInstrumentGroup -- custom group list view item. |
// QSampler::InstrumentListModel - data model for MIDI prog mappings |
40 |
// |
// |
41 |
|
|
42 |
// Constructors. |
InstrumentListModel::InstrumentListModel ( QObject *pParent ) |
43 |
qsamplerInstrumentGroup::qsamplerInstrumentGroup ( |
: QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL) |
|
qsamplerInstrumentList *pListView, const QString& sName, |
|
|
QListViewItem *pItemAfter ) |
|
|
: QListViewItem(pListView, pItemAfter ? pItemAfter : pListView->lastItem()) |
|
44 |
{ |
{ |
45 |
QListViewItem::setRenameEnabled(0, true); |
// QAbstractItemModel::reset(); |
|
|
|
|
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png")); |
|
|
QListViewItem::setText(0, sName); |
|
46 |
} |
} |
47 |
|
|
48 |
|
InstrumentListModel::~InstrumentListModel (void) |
|
qsamplerInstrumentGroup::qsamplerInstrumentGroup ( |
|
|
qsamplerInstrumentGroup *pGroupItem, const QString& sName ) |
|
|
: QListViewItem(pGroupItem, sName) |
|
49 |
{ |
{ |
50 |
QListViewItem::setRenameEnabled(0, true); |
clear(); |
|
|
|
|
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png")); |
|
51 |
} |
} |
52 |
|
|
53 |
|
|
54 |
// Default destructor. |
int InstrumentListModel::rowCount ( const QModelIndex& /*parent*/) const |
|
qsamplerInstrumentGroup::~qsamplerInstrumentGroup (void) |
|
55 |
{ |
{ |
56 |
} |
int nrows = 0; |
57 |
|
|
58 |
|
if (m_iMidiMap == LSCP_MIDI_MAP_ALL) { |
59 |
|
InstrumentMap::const_iterator itMap = m_instruments.constBegin(); |
60 |
|
for ( ; itMap != m_instruments.constEnd(); ++itMap) |
61 |
|
nrows += (*itMap).size(); |
62 |
|
} else { |
63 |
|
InstrumentMap::const_iterator itMap = m_instruments.find(m_iMidiMap); |
64 |
|
if (itMap != m_instruments.constEnd()) |
65 |
|
nrows += (*itMap).size(); |
66 |
|
} |
67 |
|
|
68 |
// Instance accessors. |
return nrows; |
|
void qsamplerInstrumentGroup::setName ( const QString& sName ) |
|
|
{ |
|
|
QListViewItem::setText(0, sName); |
|
69 |
} |
} |
70 |
|
|
71 |
|
|
72 |
QString qsamplerInstrumentGroup::name (void) const |
int InstrumentListModel::columnCount ( const QModelIndex& /*parent*/) const |
73 |
{ |
{ |
74 |
return QListViewItem::text(0); |
return 9; |
75 |
} |
} |
76 |
|
|
77 |
|
|
78 |
qsamplerInstrumentGroup *qsamplerInstrumentGroup::groupItem (void) const |
QVariant InstrumentListModel::data ( |
79 |
|
const QModelIndex &index, int role ) const |
80 |
{ |
{ |
81 |
QListViewItem *pParent = QListViewItem::parent(); |
if (!index.isValid()) |
82 |
while (pParent && pParent->rtti() != qsamplerInstrumentList::Group) |
return QVariant(); |
83 |
pParent = pParent->parent(); |
const Instrument *pInstr |
84 |
return static_cast<qsamplerInstrumentGroup *> (pParent); |
= static_cast<Instrument *> (index.internalPointer()); |
|
} |
|
85 |
|
|
86 |
|
if (pInstr && role == Qt::DisplayRole) { |
87 |
|
switch (index.column()) { |
88 |
|
case 0: return pInstr->name(); |
89 |
|
case 1: return QVariant::fromValue(pInstr->map()); |
90 |
|
case 2: return QVariant::fromValue(pInstr->bank()); |
91 |
|
case 3: return QVariant::fromValue(pInstr->prog() + 1); |
92 |
|
case 4: return pInstr->engineName(); |
93 |
|
case 5: return pInstr->instrumentFile(); |
94 |
|
case 6: return QVariant::fromValue(pInstr->instrumentNr()); |
95 |
|
case 7: return QString::number(pInstr->volume() * 100.0) + " %"; |
96 |
|
case 8: { |
97 |
|
switch (pInstr->loadMode()) { |
98 |
|
case 3: return tr("Persistent"); |
99 |
|
case 2: return tr("On Demand Hold"); |
100 |
|
case 1: return tr("On Demand"); |
101 |
|
} |
102 |
|
} |
103 |
|
default: |
104 |
|
break; |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
qsamplerInstrumentList *qsamplerInstrumentGroup::listView (void) const |
return QVariant(); |
|
{ |
|
|
return static_cast<qsamplerInstrumentList *> (QListViewItem::listView()); |
|
109 |
} |
} |
110 |
|
|
111 |
|
|
112 |
// To show up whether its open or not. |
QModelIndex InstrumentListModel::index ( |
113 |
void qsamplerInstrumentGroup::setOpen ( bool bOpen ) |
int row, int col, const QModelIndex& /*parent*/ ) const |
114 |
{ |
{ |
115 |
// Set the proper pixmap of this... |
const Instrument *pInstr = NULL; |
116 |
if (rtti() == qsamplerInstrumentList::Group) { |
|
117 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource( |
if (m_iMidiMap == LSCP_MIDI_MAP_ALL) { |
118 |
bOpen ? "itemGroupOpen.png" : "itemGroup.png")); |
int nrows = 0; |
119 |
|
InstrumentMap::const_iterator itMap = m_instruments.constBegin(); |
120 |
|
for ( ; itMap != m_instruments.constEnd(); ++itMap) { |
121 |
|
const InstrumentList& list = *itMap; |
122 |
|
nrows += list.size(); |
123 |
|
if (row < nrows) { |
124 |
|
pInstr = list.at(row + list.size() - nrows); |
125 |
|
break; |
126 |
|
} |
127 |
|
} |
128 |
|
} else { |
129 |
|
// Resolve MIDI instrument map... |
130 |
|
InstrumentMap::const_iterator itMap = m_instruments.find(m_iMidiMap); |
131 |
|
if (itMap != m_instruments.constEnd()) { |
132 |
|
const InstrumentList& list = *itMap; |
133 |
|
if (row < list.size()) |
134 |
|
pInstr = list.at(row); |
135 |
|
} |
136 |
} |
} |
|
// Open it up... |
|
|
QListViewItem::setOpen(bOpen); |
|
137 |
|
|
138 |
// All ancestors should be also visible. |
if (pInstr) |
139 |
if (bOpen && QListViewItem::parent()) |
return createIndex(row, col, (void *) pInstr); |
140 |
QListViewItem::parent()->setOpen(true); |
else |
141 |
|
return QModelIndex(); |
142 |
} |
} |
143 |
|
|
144 |
|
|
145 |
// To virtually distinguish between list view items. |
QModelIndex InstrumentListModel::parent ( const QModelIndex& /*child*/ ) const |
|
int qsamplerInstrumentGroup::rtti (void) const |
|
146 |
{ |
{ |
147 |
return qsamplerInstrumentList::Group; |
return QModelIndex(); |
148 |
} |
} |
149 |
|
|
150 |
|
|
151 |
//---------------------------------------------------------------------- |
QVariant InstrumentListModel::headerData ( |
152 |
// class qsamplerInstrumentItem -- custom file list view item. |
int section, Qt::Orientation orientation, int role ) const |
|
// |
|
|
|
|
|
// Constructors. |
|
|
qsamplerInstrumentItem::qsamplerInstrumentItem ( |
|
|
qsamplerInstrumentList *pListView, |
|
|
qsamplerInstrument *pInstrument, |
|
|
QListViewItem *pItemAfter ) |
|
|
: qsamplerInstrumentGroup(pListView, pInstrument->name(), pItemAfter) |
|
|
{ |
|
|
m_pInstrument = pInstrument; |
|
|
|
|
|
update(); |
|
|
} |
|
|
|
|
|
qsamplerInstrumentItem::qsamplerInstrumentItem ( |
|
|
qsamplerInstrumentGroup *pGroupItem, |
|
|
qsamplerInstrument *pInstrument ) |
|
|
: qsamplerInstrumentGroup(pGroupItem, pInstrument->name()) |
|
153 |
{ |
{ |
154 |
m_pInstrument = pInstrument; |
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
155 |
|
switch (section) { |
156 |
|
case 0: return tr("Name"); |
157 |
|
case 1: return tr("Map"); |
158 |
|
case 2: return tr("Bank"); |
159 |
|
case 3: return tr("Prog"); |
160 |
|
case 4: return tr("Engine"); |
161 |
|
case 5: return tr("File"); |
162 |
|
case 6: return tr("Nr"); |
163 |
|
case 7: return tr("Vol"); |
164 |
|
case 8: return tr("Mode"); |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
update(); |
return QAbstractItemModel::headerData(section, orientation, role); |
169 |
} |
} |
170 |
|
|
171 |
|
|
172 |
// Default destructor. |
void InstrumentListModel::setMidiMap ( int iMidiMap ) |
|
qsamplerInstrumentItem::~qsamplerInstrumentItem (void) |
|
173 |
{ |
{ |
174 |
if (m_pInstrument) |
if (iMidiMap < 0) |
175 |
delete m_pInstrument; |
iMidiMap = LSCP_MIDI_MAP_ALL; |
|
} |
|
|
|
|
176 |
|
|
177 |
// To virtually distinguish between list view items. |
m_iMidiMap = iMidiMap; |
|
int qsamplerInstrumentItem::rtti (void) const |
|
|
{ |
|
|
return qsamplerInstrumentList::Item; |
|
178 |
} |
} |
179 |
|
|
180 |
|
|
181 |
// Payload accessor. |
int InstrumentListModel::midiMap (void) const |
|
qsamplerInstrument *qsamplerInstrumentItem::instrument (void) const |
|
182 |
{ |
{ |
183 |
return m_pInstrument; |
return m_iMidiMap; |
184 |
} |
} |
185 |
|
|
186 |
|
|
187 |
// Item refreshment. |
const Instrument *InstrumentListModel::addInstrument ( |
188 |
void qsamplerInstrumentItem::update (void) |
int iMap, int iBank, int iProg ) |
189 |
{ |
{ |
190 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemFile.png")); |
// Check it there's already one instrument item |
191 |
|
// with the very same key (bank, program); |
192 |
|
// if yes, just remove it without prejudice... |
193 |
|
InstrumentList& list = m_instruments[iMap]; |
194 |
|
|
195 |
const QString s = "-"; |
int i = 0; |
196 |
if (m_pInstrument) { |
for ( ; i < list.size(); ++i) { |
197 |
setText(0, m_pInstrument->name()); |
const Instrument *pInstr = list.at(i); |
198 |
setText(1, QString::number(m_pInstrument->map())); |
if (pInstr->bank() == iBank && pInstr->prog() == iProg) { |
199 |
setText(2, QString::number(m_pInstrument->bank())); |
delete pInstr; |
200 |
setText(3, QString::number(m_pInstrument->prog() + 1)); |
list.removeAt(i); |
|
setText(4, m_pInstrument->engineName()); |
|
|
setText(5, QFileInfo(m_pInstrument->instrumentFile()).fileName()); |
|
|
setText(6, QString::number(m_pInstrument->instrumentNr())); |
|
|
setText(7, QString::number(::lroundf(100.0f * m_pInstrument->volume()))); |
|
|
QString sLoadMode = s; |
|
|
switch (m_pInstrument->loadMode()) { |
|
|
case 3: |
|
|
sLoadMode = QObject::tr("Persistent"); |
|
|
break; |
|
|
case 2: |
|
|
sLoadMode = QObject::tr("On Demand Hold"); |
|
|
break; |
|
|
case 1: |
|
|
sLoadMode = QObject::tr("On Demand"); |
|
201 |
break; |
break; |
202 |
} |
} |
|
setText(8, sLoadMode); |
|
|
} else { |
|
|
for (int i = 0; i < listView()->columns(); i++) |
|
|
setText(i, s); |
|
203 |
} |
} |
|
} |
|
|
|
|
204 |
|
|
205 |
//---------------------------------------------------------------------------- |
// Resolve the appropriate place, we keep the list sorted that way... |
206 |
// qsamplerInstrumentList -- MIDI instrument list view. |
for (i = 0; i < list.size(); ++i) { |
207 |
// |
const Instrument *pInstr = list.at(i); |
208 |
|
if (iBank < pInstr->bank() |
209 |
|
|| (iBank == pInstr->bank() && iProg < pInstr->prog())) { |
210 |
|
break; |
211 |
|
} |
212 |
|
} |
213 |
|
|
214 |
// Constructor. |
Instrument *pInstr = new Instrument(iMap, iBank, iProg); |
215 |
qsamplerInstrumentList::qsamplerInstrumentList ( |
if (pInstr->getInstrument()) { |
216 |
QWidget *pParent, const char *pszName ) |
list.insert(i, pInstr); |
|
: QListView(pParent, pszName) |
|
|
{ |
|
|
m_iMidiMap = LSCP_MIDI_MAP_ALL; |
|
|
|
|
|
// QListView::setRootIsDecorated(true); |
|
|
QListView::setAllColumnsShowFocus(true); |
|
|
QListView::setResizeMode(QListView::NoColumn); |
|
|
// QListView::setAcceptDrops(true); |
|
|
QListView::setDragAutoScroll(true); |
|
|
QListView::setSizePolicy( |
|
|
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
|
|
// QListView::setShowToolTips(false); |
|
|
QListView::setSortColumn(-1); |
|
|
|
|
|
QListView::addColumn(tr("Name")); |
|
|
QListView::addColumn(tr("Map")); |
|
|
QListView::addColumn(tr("Bank")); |
|
|
QListView::addColumn(tr("Prog")); |
|
|
QListView::addColumn(tr("Engine")); |
|
|
QListView::addColumn(tr("File")); |
|
|
QListView::addColumn(tr("Nr")); |
|
|
QListView::addColumn(tr("Vol")); |
|
|
QListView::addColumn(tr("Mode")); |
|
|
|
|
|
QListView::setColumnAlignment(1, Qt::AlignHCenter); // Map |
|
|
QListView::setColumnAlignment(2, Qt::AlignHCenter); // Bank |
|
|
QListView::setColumnAlignment(3, Qt::AlignHCenter); // Prog |
|
|
QListView::setColumnAlignment(6, Qt::AlignHCenter); // Nr |
|
|
QListView::setColumnAlignment(7, Qt::AlignHCenter); // Vol |
|
|
|
|
|
QListView::setColumnWidth(0, 120); // Name |
|
|
QListView::setColumnWidth(5, 240); // File |
|
|
|
|
|
m_pNewGroupAction = new QAction( |
|
|
QIconSet(QPixmap::fromMimeSource("itemGroupNew.png")), |
|
|
tr("New &Group"), tr("Ctrl+G"), this); |
|
|
m_pNewItemAction = new QAction( |
|
|
QIconSet(QPixmap::fromMimeSource("itemNew.png")), |
|
|
tr("New &Instrument..."), tr("Ins"), this); |
|
|
m_pEditItemAction = new QAction( |
|
|
QIconSet(QPixmap::fromMimeSource("formEdit.png")), |
|
|
tr("&Edit..."), tr("Enter"), this); |
|
|
m_pRenameAction = new QAction(tr("&Rename"), tr("F2"), this); |
|
|
m_pDeleteAction = new QAction( |
|
|
QIconSet(QPixmap::fromMimeSource("formRemove.png")), |
|
|
tr("&Delete"), tr("Del"), this); |
|
|
m_pRefreshAction = new QAction( |
|
|
QIconSet(QPixmap::fromMimeSource("formRefresh.png")), |
|
|
tr("Re&fresh"), tr("F5"), this); |
|
|
|
|
|
m_pNewGroupAction->setToolTip(tr("New Group")); |
|
|
m_pNewItemAction->setToolTip(tr("New Instrument")); |
|
|
m_pEditItemAction->setToolTip(tr("Edit")); |
|
|
m_pRenameAction->setToolTip(tr("Rename")); |
|
|
m_pDeleteAction->setToolTip(tr("Delete")); |
|
|
m_pRefreshAction->setToolTip(tr("Refresh")); |
|
|
|
|
|
QObject::connect(m_pNewGroupAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(newGroupSlot())); |
|
|
QObject::connect(m_pNewItemAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(newItemSlot())); |
|
|
QObject::connect(m_pEditItemAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(editItemSlot())); |
|
|
QObject::connect(m_pRenameAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(renameSlot())); |
|
|
QObject::connect(m_pDeleteAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(deleteSlot())); |
|
|
QObject::connect(m_pRefreshAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(refresh())); |
|
|
|
|
|
QObject::connect(this, |
|
|
SIGNAL(selectionChanged()), |
|
|
SLOT(selectionChangedSlot())); |
|
|
QObject::connect(this, |
|
|
SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)), |
|
|
SLOT(activatedSlot(QListViewItem*))); |
|
|
QObject::connect(this, |
|
|
SIGNAL(returnPressed(QListViewItem*)), |
|
|
SLOT(activatedSlot(QListViewItem*))); |
|
|
QObject::connect(this, |
|
|
SIGNAL(itemRenamed(QListViewItem*,int)), |
|
|
SLOT(renamedSlot(QListViewItem*))); |
|
|
|
|
|
selectionChangedSlot(); |
|
|
} |
|
|
|
|
|
|
|
|
// Default destructor. |
|
|
qsamplerInstrumentList::~qsamplerInstrumentList (void) |
|
|
{ |
|
|
delete m_pNewGroupAction; |
|
|
delete m_pNewItemAction; |
|
|
delete m_pEditItemAction; |
|
|
delete m_pRenameAction; |
|
|
delete m_pDeleteAction; |
|
|
} |
|
|
|
|
|
|
|
|
// Add a new instrument item, optionally under a given group. |
|
|
qsamplerInstrumentItem *qsamplerInstrumentList::addItem ( |
|
|
qsamplerInstrument *pInstrument, |
|
|
qsamplerInstrumentGroup *pParentGroup ) |
|
|
{ |
|
|
// Check it there's already one instrument item |
|
|
// with the very same key (bank, program); |
|
|
// if yes, just remove it without prejudice... |
|
|
qsamplerInstrumentItem *pItem = findItem(pInstrument); |
|
|
if (pItem) |
|
|
delete pItem; |
|
|
|
|
|
// Add the new item under proper group one, if any... |
|
|
if (pParentGroup) { |
|
|
pParentGroup->setOpen(true); |
|
|
pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument); |
|
217 |
} else { |
} else { |
218 |
pItem = new qsamplerInstrumentItem(this, pInstrument); |
delete pInstr; |
219 |
|
pInstr = NULL; |
220 |
} |
} |
221 |
|
|
222 |
// Set it as current selection... |
return pInstr; |
|
QListView::setSelected(pItem, true); |
|
|
|
|
|
return pItem; |
|
223 |
} |
} |
224 |
|
|
225 |
|
|
226 |
// Add a new instrument group, optionally under another group. |
void InstrumentListModel::removeInstrument ( Instrument *pInstrument ) |
|
qsamplerInstrumentGroup *qsamplerInstrumentList::addGroup ( |
|
|
const QString& sName, qsamplerInstrumentGroup *pParentGroup ) |
|
227 |
{ |
{ |
228 |
qsamplerInstrumentGroup *pGroup = findGroup(sName); |
const int iMap = pInstrument->map(); |
|
if (pGroup == NULL) { |
|
|
if (pParentGroup) { |
|
|
pParentGroup->setOpen(true); |
|
|
pGroup = new qsamplerInstrumentGroup(pParentGroup, sName); |
|
|
} else { |
|
|
pGroup = new qsamplerInstrumentGroup(this, sName); |
|
|
} |
|
|
} |
|
|
QListView::setSelected(pGroup, true); |
|
|
return pGroup; |
|
|
} |
|
229 |
|
|
230 |
|
if (m_instruments.contains(iMap)) { |
231 |
// Find a group item, given its name. |
InstrumentList& list = m_instruments[iMap]; |
232 |
qsamplerInstrumentGroup *qsamplerInstrumentList::findGroup ( |
for (int i = 0; i < list.size(); ++i) { |
233 |
const QString& sName ) const |
if (pInstrument == list.at(i)) { |
234 |
{ |
delete pInstrument; |
235 |
// Iterate all over the place to search for the group. |
list.removeAt(i); |
236 |
QListViewItemIterator iter((QListView *) this); |
break; |
237 |
while (iter.current()) { |
} |
|
QListViewItem *pItem = iter.current(); |
|
|
if (pItem->rtti() == Group && pItem->text(0) == sName) |
|
|
return static_cast<qsamplerInstrumentGroup *> (pItem); |
|
|
++iter; |
|
|
} |
|
|
// Not found. |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
|
|
|
// Find a file item, given its name. |
|
|
qsamplerInstrumentItem *qsamplerInstrumentList::findItem ( |
|
|
qsamplerInstrument *pInstrument ) const |
|
|
{ |
|
|
if (pInstrument == NULL) |
|
|
return NULL; |
|
|
|
|
|
// Iterate all over the place to search for the group. |
|
|
QListViewItemIterator iter((QListView *) this); |
|
|
while (iter.current()) { |
|
|
QListViewItem *pListItem = iter.current(); |
|
|
if (pListItem->rtti() == Item) { |
|
|
qsamplerInstrumentItem *pItem |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
|
|
if (pItem && pItem->instrument() |
|
|
&& pItem->instrument()->map() == pInstrument->map() |
|
|
&& pItem->instrument()->bank() == pInstrument->bank() |
|
|
&& pItem->instrument()->prog() == pInstrument->prog()) |
|
|
return pItem; |
|
238 |
} |
} |
|
++iter; |
|
239 |
} |
} |
|
// Not found. |
|
|
return NULL; |
|
240 |
} |
} |
241 |
|
|
242 |
|
|
243 |
// Find and return the nearest group item... |
void InstrumentListModel::updateInstrument ( Instrument *pInstrument ) |
|
qsamplerInstrumentGroup *qsamplerInstrumentList::groupItem ( |
|
|
QListViewItem *pItem ) const |
|
244 |
{ |
{ |
245 |
while (pItem && pItem->rtti() != Group) |
pInstrument->getInstrument(); |
|
pItem = pItem->parent(); |
|
|
return static_cast<qsamplerInstrumentGroup *> (pItem); |
|
246 |
} |
} |
247 |
|
|
248 |
|
|
249 |
// Add a new group item below the current one. |
// Reposition the instrument in the model (called when map/bank/prg changed) |
250 |
void qsamplerInstrumentList::newGroupSlot (void) |
void InstrumentListModel::resortInstrument ( Instrument *pInstrument ) |
251 |
{ |
{ |
252 |
qsamplerInstrumentGroup *pNewGroup |
const int iMap = pInstrument->map(); |
253 |
= addGroup(tr("New Group"), groupItem(QListView::selectedItem())); |
const int iBank = pInstrument->bank(); |
254 |
if (pNewGroup) |
const int iProg = pInstrument->prog(); |
255 |
pNewGroup->startRename(0); |
|
256 |
|
// Remove given instrument from its current list... |
257 |
|
removeInstrument(pInstrument); |
258 |
|
|
259 |
selectionChangedSlot(); |
// Re-add the instrument... |
260 |
|
addInstrument(iMap, iBank, iProg); |
261 |
} |
} |
262 |
|
|
263 |
|
|
264 |
// Map selector. |
void InstrumentListModel::refresh (void) |
|
void qsamplerInstrumentList::setMidiMap ( int iMidiMap ) |
|
265 |
{ |
{ |
266 |
if (iMidiMap < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
267 |
iMidiMap = LSCP_MIDI_MAP_ALL; |
if (pMainForm == NULL) |
268 |
|
return; |
269 |
|
if (pMainForm->client() == NULL) |
270 |
|
return; |
271 |
|
|
272 |
m_iMidiMap = iMidiMap; |
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
|
} |
|
273 |
|
|
274 |
int qsamplerInstrumentList::midiMap (void) const |
clear(); |
|
{ |
|
|
return m_iMidiMap; |
|
|
} |
|
275 |
|
|
276 |
|
// Load the whole bunch of instrument items... |
277 |
|
lscp_midi_instrument_t *pInstrs |
278 |
|
= ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap); |
279 |
|
for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) { |
280 |
|
const int iMap = pInstrs[iInstr].map; |
281 |
|
const int iBank = pInstrs[iInstr].bank; |
282 |
|
const int iProg = pInstrs[iInstr].prog; |
283 |
|
addInstrument(iMap, iBank, iProg); |
284 |
|
// Try to keep it snappy :) |
285 |
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
286 |
|
} |
287 |
|
|
288 |
// List actions accessors. |
QApplication::restoreOverrideCursor(); |
|
QAction *qsamplerInstrumentList::newGroupAction (void) const |
|
|
{ |
|
|
return m_pNewGroupAction; |
|
|
} |
|
289 |
|
|
290 |
QAction *qsamplerInstrumentList::newItemAction (void) const |
if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) { |
291 |
{ |
pMainForm->appendMessagesClient("lscp_list_midi_instruments"); |
292 |
return m_pNewItemAction; |
pMainForm->appendMessagesError( |
293 |
|
tr("Could not get current list of MIDI instrument mappings.\n\nSorry.")); |
294 |
|
} |
295 |
} |
} |
296 |
|
|
297 |
QAction *qsamplerInstrumentList::editItemAction (void) const |
void InstrumentListModel::beginReset (void) |
298 |
{ |
{ |
299 |
return m_pEditItemAction; |
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) |
300 |
|
QAbstractItemModel::beginResetModel(); |
301 |
|
#endif |
302 |
} |
} |
303 |
|
|
304 |
QAction *qsamplerInstrumentList::renameAction (void) const |
void InstrumentListModel::endReset (void) |
305 |
{ |
{ |
306 |
return m_pRenameAction; |
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) |
307 |
|
QAbstractItemModel::endResetModel(); |
308 |
|
#else |
309 |
|
QAbstractItemModel::reset(); |
310 |
|
#endif |
311 |
} |
} |
312 |
|
|
|
QAction *qsamplerInstrumentList::deleteAction (void) const |
|
|
{ |
|
|
return m_pDeleteAction; |
|
|
} |
|
313 |
|
|
314 |
QAction *qsamplerInstrumentList::refreshAction (void) const |
// Map clear. |
315 |
|
void InstrumentListModel::clear (void) |
316 |
{ |
{ |
317 |
return m_pRefreshAction; |
InstrumentMap::iterator itMap = m_instruments.begin(); |
318 |
|
for ( ; itMap != m_instruments.end(); ++itMap) { |
319 |
|
InstrumentList& list = itMap.value(); |
320 |
|
qDeleteAll(list); |
321 |
|
list.clear(); |
322 |
|
} |
323 |
|
|
324 |
|
m_instruments.clear(); |
325 |
} |
} |
326 |
|
|
327 |
|
|
328 |
// Add a new instrument item below the current one. |
//------------------------------------------------------------------------- |
329 |
void qsamplerInstrumentList::newItemSlot (void) |
// QSampler::InstrumentListView - list view for MIDI prog mappings |
330 |
{ |
// |
|
qsamplerInstrument *pInstrument = new qsamplerInstrument(); |
|
331 |
|
|
332 |
qsamplerInstrumentForm form(this); |
// Constructor. |
333 |
form.setup(pInstrument); |
InstrumentListView::InstrumentListView ( QWidget *pParent ) |
334 |
if (!form.exec()) { |
: QTreeView(pParent) |
335 |
delete pInstrument; |
{ |
336 |
return; |
m_pListModel = new InstrumentListModel(this); |
|
} |
|
337 |
|
|
338 |
// Commit... |
QTreeView::setModel(m_pListModel); |
|
pInstrument->mapInstrument(); |
|
|
// add new item to the tree... |
|
|
addItem(pInstrument, groupItem(QListView::selectedItem())); |
|
|
// Notify we've changes... |
|
|
emit instrumentsChanged(); |
|
339 |
|
|
340 |
selectionChangedSlot(); |
QTreeView::setRootIsDecorated(false); |
341 |
|
QTreeView::setUniformRowHeights(true); |
342 |
|
QTreeView::setAlternatingRowColors(true); |
343 |
|
QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows); |
344 |
|
QTreeView::setSelectionMode(QAbstractItemView::SingleSelection); |
345 |
|
QTreeView::setItemsExpandable(false); |
346 |
|
|
347 |
|
QHeaderView *pHeader = QTreeView::header(); |
348 |
|
pHeader->setDefaultAlignment(Qt::AlignLeft); |
349 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
350 |
|
pHeader->setMovable(false); |
351 |
|
#endif |
352 |
|
pHeader->setStretchLastSection(true); |
353 |
|
pHeader->resizeSection(0, 120); // Name |
354 |
|
QTreeView::resizeColumnToContents(1); // Map |
355 |
|
QTreeView::resizeColumnToContents(2); // Bank |
356 |
|
QTreeView::resizeColumnToContents(3); // Prog |
357 |
|
QTreeView::resizeColumnToContents(4); // Engine |
358 |
|
pHeader->resizeSection(5, 240); // File |
359 |
|
QTreeView::resizeColumnToContents(6); // Nr |
360 |
|
pHeader->resizeSection(7, 60); // Vol |
361 |
} |
} |
362 |
|
|
363 |
|
|
364 |
// Edit current item below the current one. |
// Destructor. |
365 |
void qsamplerInstrumentList::editItemSlot (void) |
InstrumentListView::~InstrumentListView (void) |
366 |
{ |
{ |
367 |
QListViewItem *pListItem = QListView::selectedItem(); |
delete m_pListModel; |
|
if (pListItem == NULL) |
|
|
return; |
|
|
if (pListItem->rtti() == Item) { |
|
|
qsamplerInstrument *pInstrument = NULL; |
|
|
qsamplerInstrumentItem *pItem |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
|
|
if (pItem) |
|
|
pInstrument = pItem->instrument(); |
|
|
if (pInstrument) { |
|
|
// Save current key values... |
|
|
int iMap = pInstrument->map(); |
|
|
int iBank = pInstrument->bank(); |
|
|
int iProg = pInstrument->prog(); |
|
|
// Do the edit dance... |
|
|
qsamplerInstrumentForm form(this); |
|
|
form.setup(pInstrument); |
|
|
if (form.exec()) { |
|
|
// Commit... |
|
|
pInstrument->mapInstrument(); |
|
|
// Check whether we changed instrument key... |
|
|
if (iMap == pInstrument->map() && |
|
|
iBank == pInstrument->bank() && |
|
|
iProg == pInstrument->prog()) { |
|
|
// just update tree item... |
|
|
pItem->update(); |
|
|
} else { |
|
|
// Change item tree, whether applicable... |
|
|
if (m_iMidiMap < 0 || m_iMidiMap == pInstrument->map()) { |
|
|
// Add new brand item into view... |
|
|
addItem(pInstrument, groupItem(pListItem)); |
|
|
} else { |
|
|
// Just remove/hide old one. |
|
|
delete pItem; |
|
|
} |
|
|
} |
|
|
// Notify we've changes... |
|
|
emit instrumentsChanged(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
selectionChangedSlot(); |
|
368 |
} |
} |
369 |
|
|
370 |
|
|
371 |
// Rename current group/item. |
void InstrumentListView::setMidiMap ( int iMidiMap ) |
|
void qsamplerInstrumentList::renameSlot (void) |
|
372 |
{ |
{ |
373 |
QListViewItem *pListItem = QListView::selectedItem(); |
m_pListModel->setMidiMap(iMidiMap); |
|
if (pListItem) |
|
|
pListItem->startRename(0); |
|
|
|
|
|
selectionChangedSlot(); |
|
374 |
} |
} |
375 |
|
|
376 |
|
|
377 |
// Remove current group/item. |
int InstrumentListView::midiMap (void) const |
|
void qsamplerInstrumentList::deleteSlot (void) |
|
378 |
{ |
{ |
379 |
QListViewItem *pListItem = QListView::selectedItem(); |
return m_pListModel->midiMap(); |
|
if (pListItem == NULL) |
|
|
return; |
|
|
|
|
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
|
|
if (pMainForm == NULL) |
|
|
return; |
|
|
|
|
|
// Prompt user if this is for real... |
|
|
qsamplerOptions *pOptions = pMainForm->options(); |
|
|
if (pOptions && pOptions->bConfirmRemove) { |
|
|
if (QMessageBox::warning(this, |
|
|
QSAMPLER_TITLE ": " + tr("Warning"), |
|
|
tr("Delete %1:\n\n" |
|
|
"%2\n\n" |
|
|
"Are you sure?") |
|
|
.arg(pListItem->rtti() == Item ? tr("instrument") : tr("group")) |
|
|
.arg(pListItem->text(0)), |
|
|
tr("OK"), tr("Cancel")) > 0) |
|
|
return; |
|
|
} |
|
|
|
|
|
// Unmap instrument entry... |
|
|
if (pListItem->rtti() == Item) { |
|
|
qsamplerInstrumentItem *pItem |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
|
|
if (pItem && pItem->instrument()) { |
|
|
pItem->instrument()->unmapInstrument(); |
|
|
emit instrumentsChanged(); |
|
|
} |
|
|
} |
|
|
|
|
|
// Do it for real... |
|
|
delete pListItem; |
|
|
|
|
|
selectionChangedSlot(); |
|
380 |
} |
} |
381 |
|
|
382 |
|
|
383 |
// In-place selection slot. |
const Instrument *InstrumentListView::addInstrument ( |
384 |
void qsamplerInstrumentList::selectionChangedSlot (void) |
int iMap, int iBank, int iProg ) |
385 |
{ |
{ |
386 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
m_pListModel->beginReset(); |
387 |
QListViewItem *pListItem = QListView::selectedItem(); |
const Instrument *pInstrument |
388 |
bool bEnabled = (pMainForm && pMainForm->client()); |
= m_pListModel->addInstrument(iMap, iBank, iProg); |
389 |
m_pNewItemAction->setEnabled(bEnabled); |
m_pListModel->endReset(); |
390 |
bEnabled = (bEnabled && pListItem != NULL); |
|
391 |
m_pEditItemAction->setEnabled(bEnabled && pListItem->rtti() == Item); |
return pInstrument; |
|
m_pRenameAction->setEnabled(bEnabled); |
|
|
m_pDeleteAction->setEnabled(bEnabled); |
|
392 |
} |
} |
393 |
|
|
394 |
|
|
395 |
// In-place activation slot. |
void InstrumentListView::removeInstrument ( Instrument *pInstrument ) |
|
void qsamplerInstrumentList::activatedSlot ( QListViewItem *pListItem ) |
|
396 |
{ |
{ |
397 |
// FIXME: Hope the list view item is the one selected. |
m_pListModel->beginReset(); |
398 |
if (pListItem->rtti() == Item) |
m_pListModel->removeInstrument(pInstrument); |
399 |
editItemSlot(); |
m_pListModel->endReset(); |
400 |
} |
} |
401 |
|
|
402 |
|
|
403 |
// In-place aliasing slot. |
void InstrumentListView::updateInstrument ( Instrument *pInstrument ) |
|
void qsamplerInstrumentList::renamedSlot ( QListViewItem *pListItem ) |
|
404 |
{ |
{ |
405 |
if (pListItem->rtti() == Item) { |
m_pListModel->beginReset(); |
406 |
qsamplerInstrumentItem *pItem |
m_pListModel->updateInstrument(pInstrument); |
407 |
= static_cast<qsamplerInstrumentItem *> (pListItem); |
m_pListModel->endReset(); |
|
if (pItem && pItem->instrument()) { |
|
|
pItem->instrument()->setName(pListItem->text(0)); |
|
|
pItem->instrument()->mapInstrument(); |
|
|
emit instrumentsChanged(); |
|
|
pItem->update(); |
|
|
} |
|
|
} |
|
408 |
} |
} |
409 |
|
|
410 |
|
|
411 |
// Context menu request event handler. |
// Reposition the instrument in the model (called when map/bank/prg changed) |
412 |
void qsamplerInstrumentList::contextMenuEvent ( |
void InstrumentListView::resortInstrument ( Instrument *pInstrument ) |
|
QContextMenuEvent *pContextMenuEvent ) |
|
413 |
{ |
{ |
414 |
if (!m_pNewItemAction->isEnabled()) |
m_pListModel->beginReset(); |
415 |
return; |
m_pListModel->resortInstrument(pInstrument); |
416 |
|
m_pListModel->endReset(); |
|
QPopupMenu menu(this); |
|
|
|
|
|
// Construct context menu. |
|
|
m_pNewItemAction->addTo(&menu); |
|
|
// m_pNewGroupAction->addTo(&menu); |
|
|
menu.insertSeparator(); |
|
|
m_pEditItemAction->addTo(&menu); |
|
|
m_pRenameAction->addTo(&menu); |
|
|
m_pDeleteAction->addTo(&menu); |
|
|
menu.insertSeparator(); |
|
|
m_pRefreshAction->addTo(&menu); |
|
|
|
|
|
menu.exec(pContextMenuEvent->globalPos()); |
|
417 |
} |
} |
418 |
|
|
419 |
|
|
420 |
// General reloader. |
// Refreshener. |
421 |
void qsamplerInstrumentList::refresh (void) |
void InstrumentListView::refresh (void) |
422 |
{ |
{ |
423 |
clear(); |
m_pListModel->beginReset(); |
424 |
|
m_pListModel->refresh(); |
425 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
m_pListModel->endReset(); |
426 |
if (pMainForm == NULL) |
} |
|
return; |
|
|
if (pMainForm->client() == NULL) |
|
|
return; |
|
|
|
|
|
qsamplerInstrumentItem *pItem = NULL; |
|
|
lscp_midi_instrument_t *pInstrs |
|
|
= ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap); |
|
|
for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) { |
|
|
int iMap = pInstrs[iInstr].map; |
|
|
int iBank = pInstrs[iInstr].bank; |
|
|
int iProg = pInstrs[iInstr].prog; |
|
|
qsamplerInstrument *pInstrument |
|
|
= new qsamplerInstrument(iMap, iBank, iProg); |
|
|
if (pInstrument->getInstrument()) |
|
|
pItem = new qsamplerInstrumentItem(this, pInstrument, pItem); |
|
|
} |
|
427 |
|
|
|
if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) { |
|
|
pMainForm->appendMessagesClient("lscp_list_midi_instruments"); |
|
|
pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry.")); |
|
|
} |
|
428 |
|
|
429 |
selectionChangedSlot(); |
} // namespace QSampler |
|
} |
|
430 |
|
|
431 |
|
|
432 |
// end of qsamplerInstrumentList.cpp |
// end of qsamplerInstrumentList.cpp |
|
|
|