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