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