1 |
capela |
971 |
// qsamplerInstrumentList.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
capela |
1013 |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
capela |
971 |
|
6 |
|
|
This program is free software; you can redistribute it and/or |
7 |
|
|
modify it under the terms of the GNU General Public License |
8 |
|
|
as published by the Free Software Foundation; either version 2 |
9 |
|
|
of the License, or (at your option) any later version. |
10 |
|
|
|
11 |
|
|
This program is distributed in the hope that it will be useful, |
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
GNU General Public License for more details. |
15 |
|
|
|
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 |
18 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
|
|
20 |
|
|
*****************************************************************************/ |
21 |
|
|
|
22 |
|
|
#include "qsamplerAbout.h" |
23 |
|
|
#include "qsamplerInstrumentList.h" |
24 |
|
|
|
25 |
|
|
#include "qsamplerInstrument.h" |
26 |
|
|
#include "qsamplerInstrumentForm.h" |
27 |
|
|
|
28 |
capela |
987 |
#include "qsamplerOptions.h" |
29 |
capela |
971 |
#include "qsamplerMainForm.h" |
30 |
|
|
|
31 |
capela |
987 |
#include <qmessagebox.h> |
32 |
capela |
971 |
#include <qaction.h> |
33 |
|
|
#include <qfileinfo.h> |
34 |
|
|
#include <qpopupmenu.h> |
35 |
|
|
|
36 |
|
|
// Needed for lroundf() |
37 |
|
|
#include <math.h> |
38 |
|
|
|
39 |
capela |
972 |
#ifndef CONFIG_ROUND |
40 |
capela |
980 |
static inline long lroundf ( float x ) |
41 |
capela |
971 |
{ |
42 |
capela |
980 |
if (x >= 0.0f) |
43 |
|
|
return long(x + 0.5f); |
44 |
|
|
else |
45 |
|
|
return long(x - 0.5f); |
46 |
capela |
971 |
} |
47 |
|
|
#endif |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
//---------------------------------------------------------------------- |
51 |
|
|
// class qsamplerInstrumentGroup -- custom group list view item. |
52 |
|
|
// |
53 |
|
|
|
54 |
|
|
// Constructors. |
55 |
|
|
qsamplerInstrumentGroup::qsamplerInstrumentGroup ( |
56 |
|
|
qsamplerInstrumentList *pListView, const QString& sName, |
57 |
|
|
QListViewItem *pItemAfter ) |
58 |
|
|
: QListViewItem(pListView, pItemAfter ? pItemAfter : pListView->lastItem()) |
59 |
|
|
{ |
60 |
|
|
QListViewItem::setRenameEnabled(0, true); |
61 |
|
|
|
62 |
|
|
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png")); |
63 |
|
|
QListViewItem::setText(0, sName); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
qsamplerInstrumentGroup::qsamplerInstrumentGroup ( |
68 |
|
|
qsamplerInstrumentGroup *pGroupItem, const QString& sName ) |
69 |
|
|
: QListViewItem(pGroupItem, sName) |
70 |
|
|
{ |
71 |
|
|
QListViewItem::setRenameEnabled(0, true); |
72 |
|
|
|
73 |
|
|
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png")); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
// Default destructor. |
78 |
|
|
qsamplerInstrumentGroup::~qsamplerInstrumentGroup (void) |
79 |
|
|
{ |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
// Instance accessors. |
84 |
|
|
void qsamplerInstrumentGroup::setName ( const QString& sName ) |
85 |
|
|
{ |
86 |
|
|
QListViewItem::setText(0, sName); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
|
90 |
|
|
QString qsamplerInstrumentGroup::name (void) const |
91 |
|
|
{ |
92 |
|
|
return QListViewItem::text(0); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
qsamplerInstrumentGroup *qsamplerInstrumentGroup::groupItem (void) const |
97 |
|
|
{ |
98 |
|
|
QListViewItem *pParent = QListViewItem::parent(); |
99 |
|
|
while (pParent && pParent->rtti() != qsamplerInstrumentList::Group) |
100 |
|
|
pParent = pParent->parent(); |
101 |
|
|
return static_cast<qsamplerInstrumentGroup *> (pParent); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
|
105 |
|
|
qsamplerInstrumentList *qsamplerInstrumentGroup::listView (void) const |
106 |
|
|
{ |
107 |
|
|
return static_cast<qsamplerInstrumentList *> (QListViewItem::listView()); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
// To show up whether its open or not. |
112 |
|
|
void qsamplerInstrumentGroup::setOpen ( bool bOpen ) |
113 |
|
|
{ |
114 |
|
|
// Set the proper pixmap of this... |
115 |
|
|
if (rtti() == qsamplerInstrumentList::Group) { |
116 |
|
|
QListViewItem::setPixmap(0, QPixmap::fromMimeSource( |
117 |
|
|
bOpen ? "itemGroupOpen.png" : "itemGroup.png")); |
118 |
|
|
} |
119 |
|
|
// Open it up... |
120 |
|
|
QListViewItem::setOpen(bOpen); |
121 |
|
|
|
122 |
|
|
// All ancestors should be also visible. |
123 |
|
|
if (bOpen && QListViewItem::parent()) |
124 |
|
|
QListViewItem::parent()->setOpen(true); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
// To virtually distinguish between list view items. |
129 |
|
|
int qsamplerInstrumentGroup::rtti (void) const |
130 |
|
|
{ |
131 |
|
|
return qsamplerInstrumentList::Group; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
|
135 |
|
|
//---------------------------------------------------------------------- |
136 |
|
|
// class qsamplerInstrumentItem -- custom file list view item. |
137 |
|
|
// |
138 |
|
|
|
139 |
|
|
// Constructors. |
140 |
|
|
qsamplerInstrumentItem::qsamplerInstrumentItem ( |
141 |
|
|
qsamplerInstrumentList *pListView, |
142 |
|
|
qsamplerInstrument *pInstrument, |
143 |
|
|
QListViewItem *pItemAfter ) |
144 |
|
|
: qsamplerInstrumentGroup(pListView, pInstrument->name(), pItemAfter) |
145 |
|
|
{ |
146 |
|
|
m_pInstrument = pInstrument; |
147 |
|
|
|
148 |
|
|
update(); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
qsamplerInstrumentItem::qsamplerInstrumentItem ( |
152 |
|
|
qsamplerInstrumentGroup *pGroupItem, |
153 |
|
|
qsamplerInstrument *pInstrument ) |
154 |
|
|
: qsamplerInstrumentGroup(pGroupItem, pInstrument->name()) |
155 |
|
|
{ |
156 |
|
|
m_pInstrument = pInstrument; |
157 |
|
|
|
158 |
|
|
update(); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
|
162 |
|
|
// Default destructor. |
163 |
|
|
qsamplerInstrumentItem::~qsamplerInstrumentItem (void) |
164 |
|
|
{ |
165 |
|
|
if (m_pInstrument) |
166 |
|
|
delete m_pInstrument; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
|
170 |
|
|
// To virtually distinguish between list view items. |
171 |
|
|
int qsamplerInstrumentItem::rtti (void) const |
172 |
|
|
{ |
173 |
|
|
return qsamplerInstrumentList::Item; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
|
177 |
|
|
// Payload accessor. |
178 |
|
|
qsamplerInstrument *qsamplerInstrumentItem::instrument (void) const |
179 |
|
|
{ |
180 |
|
|
return m_pInstrument; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
|
184 |
|
|
// Item refreshment. |
185 |
|
|
void qsamplerInstrumentItem::update (void) |
186 |
|
|
{ |
187 |
|
|
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemFile.png")); |
188 |
|
|
|
189 |
|
|
const QString s = "-"; |
190 |
|
|
if (m_pInstrument) { |
191 |
|
|
setText(0, m_pInstrument->name()); |
192 |
capela |
980 |
setText(1, QString::number(m_pInstrument->map())); |
193 |
|
|
setText(2, QString::number(m_pInstrument->bank())); |
194 |
|
|
setText(3, QString::number(m_pInstrument->prog() + 1)); |
195 |
|
|
setText(4, m_pInstrument->engineName()); |
196 |
|
|
setText(5, QFileInfo(m_pInstrument->instrumentFile()).fileName()); |
197 |
|
|
setText(6, QString::number(m_pInstrument->instrumentNr())); |
198 |
|
|
setText(7, QString::number(::lroundf(100.0f * m_pInstrument->volume()))); |
199 |
capela |
971 |
QString sLoadMode = s; |
200 |
|
|
switch (m_pInstrument->loadMode()) { |
201 |
|
|
case 3: |
202 |
|
|
sLoadMode = QObject::tr("Persistent"); |
203 |
|
|
break; |
204 |
|
|
case 2: |
205 |
|
|
sLoadMode = QObject::tr("On Demand Hold"); |
206 |
|
|
break; |
207 |
|
|
case 1: |
208 |
|
|
sLoadMode = QObject::tr("On Demand"); |
209 |
|
|
break; |
210 |
|
|
} |
211 |
capela |
980 |
setText(8, sLoadMode); |
212 |
capela |
971 |
} else { |
213 |
|
|
for (int i = 0; i < listView()->columns(); i++) |
214 |
|
|
setText(i, s); |
215 |
|
|
} |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
//---------------------------------------------------------------------------- |
220 |
|
|
// qsamplerInstrumentList -- MIDI instrument list view. |
221 |
|
|
// |
222 |
|
|
|
223 |
|
|
// Constructor. |
224 |
|
|
qsamplerInstrumentList::qsamplerInstrumentList ( |
225 |
|
|
QWidget *pParent, const char *pszName ) |
226 |
|
|
: QListView(pParent, pszName) |
227 |
|
|
{ |
228 |
capela |
1013 |
m_iMidiMap = LSCP_MIDI_MAP_ALL; |
229 |
|
|
|
230 |
capela |
971 |
// QListView::setRootIsDecorated(true); |
231 |
capela |
1013 |
QListView::setAllColumnsShowFocus(true); |
232 |
capela |
971 |
QListView::setResizeMode(QListView::NoColumn); |
233 |
|
|
// QListView::setAcceptDrops(true); |
234 |
|
|
QListView::setDragAutoScroll(true); |
235 |
|
|
QListView::setSizePolicy( |
236 |
|
|
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
237 |
|
|
// QListView::setShowToolTips(false); |
238 |
|
|
QListView::setSortColumn(-1); |
239 |
|
|
|
240 |
|
|
QListView::addColumn(tr("Name")); |
241 |
capela |
980 |
QListView::addColumn(tr("Map")); |
242 |
capela |
971 |
QListView::addColumn(tr("Bank")); |
243 |
|
|
QListView::addColumn(tr("Prog")); |
244 |
|
|
QListView::addColumn(tr("Engine")); |
245 |
|
|
QListView::addColumn(tr("File")); |
246 |
|
|
QListView::addColumn(tr("Nr")); |
247 |
|
|
QListView::addColumn(tr("Vol")); |
248 |
|
|
QListView::addColumn(tr("Mode")); |
249 |
|
|
|
250 |
capela |
980 |
QListView::setColumnAlignment(1, Qt::AlignHCenter); // Map |
251 |
|
|
QListView::setColumnAlignment(2, Qt::AlignHCenter); // Bank |
252 |
|
|
QListView::setColumnAlignment(3, Qt::AlignHCenter); // Prog |
253 |
|
|
QListView::setColumnAlignment(6, Qt::AlignHCenter); // Nr |
254 |
|
|
QListView::setColumnAlignment(7, Qt::AlignHCenter); // Vol |
255 |
capela |
971 |
|
256 |
capela |
980 |
QListView::setColumnWidth(0, 120); // Name |
257 |
|
|
QListView::setColumnWidth(5, 240); // File |
258 |
capela |
971 |
|
259 |
capela |
1013 |
m_pNewGroupAction = new QAction( |
260 |
|
|
QIconSet(QPixmap::fromMimeSource("itemGroupNew.png")), |
261 |
|
|
tr("New &Group"), tr("Ctrl+G"), this); |
262 |
|
|
m_pNewItemAction = new QAction( |
263 |
|
|
QIconSet(QPixmap::fromMimeSource("itemNew.png")), |
264 |
|
|
tr("New &Instrument..."), tr("Ins"), this); |
265 |
|
|
m_pEditItemAction = new QAction( |
266 |
|
|
QIconSet(QPixmap::fromMimeSource("formEdit.png")), |
267 |
|
|
tr("&Edit..."), tr("Enter"), this); |
268 |
capela |
987 |
m_pRenameAction = new QAction(tr("&Rename"), tr("F2"), this); |
269 |
capela |
1013 |
m_pDeleteAction = new QAction( |
270 |
|
|
QIconSet(QPixmap::fromMimeSource("formRemove.png")), |
271 |
|
|
tr("&Delete"), tr("Del"), this); |
272 |
|
|
m_pRefreshAction = new QAction( |
273 |
|
|
QIconSet(QPixmap::fromMimeSource("formRefresh.png")), |
274 |
|
|
tr("Re&fresh"), tr("F5"), this); |
275 |
capela |
971 |
|
276 |
capela |
1013 |
m_pNewGroupAction->setToolTip(tr("New Group")); |
277 |
|
|
m_pNewItemAction->setToolTip(tr("New Instrument")); |
278 |
|
|
m_pEditItemAction->setToolTip(tr("Edit")); |
279 |
|
|
m_pRenameAction->setToolTip(tr("Rename")); |
280 |
|
|
m_pDeleteAction->setToolTip(tr("Delete")); |
281 |
|
|
m_pRefreshAction->setToolTip(tr("Refresh")); |
282 |
|
|
|
283 |
capela |
971 |
QObject::connect(m_pNewGroupAction, |
284 |
|
|
SIGNAL(activated()), |
285 |
|
|
SLOT(newGroupSlot())); |
286 |
|
|
QObject::connect(m_pNewItemAction, |
287 |
|
|
SIGNAL(activated()), |
288 |
|
|
SLOT(newItemSlot())); |
289 |
|
|
QObject::connect(m_pEditItemAction, |
290 |
|
|
SIGNAL(activated()), |
291 |
|
|
SLOT(editItemSlot())); |
292 |
|
|
QObject::connect(m_pRenameAction, |
293 |
|
|
SIGNAL(activated()), |
294 |
|
|
SLOT(renameSlot())); |
295 |
|
|
QObject::connect(m_pDeleteAction, |
296 |
|
|
SIGNAL(activated()), |
297 |
|
|
SLOT(deleteSlot())); |
298 |
|
|
QObject::connect(m_pRefreshAction, |
299 |
|
|
SIGNAL(activated()), |
300 |
|
|
SLOT(refresh())); |
301 |
|
|
|
302 |
|
|
QObject::connect(this, |
303 |
|
|
SIGNAL(selectionChanged()), |
304 |
|
|
SLOT(selectionChangedSlot())); |
305 |
|
|
QObject::connect(this, |
306 |
|
|
SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)), |
307 |
|
|
SLOT(activatedSlot(QListViewItem*))); |
308 |
|
|
QObject::connect(this, |
309 |
|
|
SIGNAL(returnPressed(QListViewItem*)), |
310 |
|
|
SLOT(activatedSlot(QListViewItem*))); |
311 |
|
|
QObject::connect(this, |
312 |
|
|
SIGNAL(itemRenamed(QListViewItem*,int)), |
313 |
|
|
SLOT(renamedSlot(QListViewItem*))); |
314 |
|
|
|
315 |
|
|
selectionChangedSlot(); |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
|
319 |
|
|
// Default destructor. |
320 |
|
|
qsamplerInstrumentList::~qsamplerInstrumentList (void) |
321 |
|
|
{ |
322 |
|
|
delete m_pNewGroupAction; |
323 |
|
|
delete m_pNewItemAction; |
324 |
|
|
delete m_pEditItemAction; |
325 |
|
|
delete m_pRenameAction; |
326 |
|
|
delete m_pDeleteAction; |
327 |
|
|
} |
328 |
|
|
|
329 |
|
|
|
330 |
|
|
// Add a new instrument item, optionally under a given group. |
331 |
|
|
qsamplerInstrumentItem *qsamplerInstrumentList::addItem ( |
332 |
|
|
qsamplerInstrument *pInstrument, |
333 |
|
|
qsamplerInstrumentGroup *pParentGroup ) |
334 |
|
|
{ |
335 |
capela |
1013 |
// Check it there's already one instrument item |
336 |
|
|
// with the very same key (bank, program); |
337 |
|
|
// if yes, just remove it without prejudice... |
338 |
capela |
971 |
qsamplerInstrumentItem *pItem = findItem(pInstrument); |
339 |
capela |
1013 |
if (pItem) |
340 |
|
|
delete pItem; |
341 |
|
|
|
342 |
|
|
// Add the new item under proper group one, if any... |
343 |
|
|
if (pParentGroup) { |
344 |
|
|
pParentGroup->setOpen(true); |
345 |
|
|
pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument); |
346 |
|
|
} else { |
347 |
|
|
pItem = new qsamplerInstrumentItem(this, pInstrument); |
348 |
capela |
971 |
} |
349 |
capela |
1013 |
|
350 |
|
|
// Set it as current selection... |
351 |
capela |
971 |
QListView::setSelected(pItem, true); |
352 |
capela |
1013 |
|
353 |
capela |
971 |
return pItem; |
354 |
|
|
} |
355 |
|
|
|
356 |
|
|
|
357 |
|
|
// Add a new instrument group, optionally under another group. |
358 |
|
|
qsamplerInstrumentGroup *qsamplerInstrumentList::addGroup ( |
359 |
|
|
const QString& sName, qsamplerInstrumentGroup *pParentGroup ) |
360 |
|
|
{ |
361 |
|
|
qsamplerInstrumentGroup *pGroup = findGroup(sName); |
362 |
|
|
if (pGroup == NULL) { |
363 |
capela |
1013 |
if (pParentGroup) { |
364 |
|
|
pParentGroup->setOpen(true); |
365 |
capela |
971 |
pGroup = new qsamplerInstrumentGroup(pParentGroup, sName); |
366 |
capela |
1013 |
} else { |
367 |
capela |
971 |
pGroup = new qsamplerInstrumentGroup(this, sName); |
368 |
capela |
1013 |
} |
369 |
capela |
971 |
} |
370 |
|
|
QListView::setSelected(pGroup, true); |
371 |
|
|
return pGroup; |
372 |
|
|
} |
373 |
|
|
|
374 |
|
|
|
375 |
|
|
// Find a group item, given its name. |
376 |
|
|
qsamplerInstrumentGroup *qsamplerInstrumentList::findGroup ( |
377 |
|
|
const QString& sName ) const |
378 |
|
|
{ |
379 |
|
|
// Iterate all over the place to search for the group. |
380 |
|
|
QListViewItemIterator iter((QListView *) this); |
381 |
|
|
while (iter.current()) { |
382 |
|
|
QListViewItem *pItem = iter.current(); |
383 |
|
|
if (pItem->rtti() == Group && pItem->text(0) == sName) |
384 |
|
|
return static_cast<qsamplerInstrumentGroup *> (pItem); |
385 |
|
|
++iter; |
386 |
|
|
} |
387 |
|
|
// Not found. |
388 |
|
|
return NULL; |
389 |
|
|
} |
390 |
|
|
|
391 |
|
|
|
392 |
|
|
// Find a file item, given its name. |
393 |
|
|
qsamplerInstrumentItem *qsamplerInstrumentList::findItem ( |
394 |
|
|
qsamplerInstrument *pInstrument ) const |
395 |
|
|
{ |
396 |
|
|
if (pInstrument == NULL) |
397 |
|
|
return NULL; |
398 |
|
|
|
399 |
|
|
// Iterate all over the place to search for the group. |
400 |
|
|
QListViewItemIterator iter((QListView *) this); |
401 |
|
|
while (iter.current()) { |
402 |
|
|
QListViewItem *pListItem = iter.current(); |
403 |
|
|
if (pListItem->rtti() == Item) { |
404 |
|
|
qsamplerInstrumentItem *pItem |
405 |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
406 |
|
|
if (pItem && pItem->instrument() |
407 |
capela |
980 |
&& pItem->instrument()->map() == pInstrument->map() |
408 |
capela |
971 |
&& pItem->instrument()->bank() == pInstrument->bank() |
409 |
capela |
980 |
&& pItem->instrument()->prog() == pInstrument->prog()) |
410 |
capela |
971 |
return pItem; |
411 |
|
|
} |
412 |
|
|
++iter; |
413 |
|
|
} |
414 |
|
|
// Not found. |
415 |
|
|
return NULL; |
416 |
|
|
} |
417 |
|
|
|
418 |
|
|
|
419 |
|
|
// Find and return the nearest group item... |
420 |
|
|
qsamplerInstrumentGroup *qsamplerInstrumentList::groupItem ( |
421 |
|
|
QListViewItem *pItem ) const |
422 |
|
|
{ |
423 |
|
|
while (pItem && pItem->rtti() != Group) |
424 |
|
|
pItem = pItem->parent(); |
425 |
|
|
return static_cast<qsamplerInstrumentGroup *> (pItem); |
426 |
|
|
} |
427 |
|
|
|
428 |
|
|
|
429 |
|
|
// Add a new group item below the current one. |
430 |
|
|
void qsamplerInstrumentList::newGroupSlot (void) |
431 |
|
|
{ |
432 |
|
|
qsamplerInstrumentGroup *pNewGroup |
433 |
capela |
1013 |
= addGroup(tr("New Group"), groupItem(QListView::selectedItem())); |
434 |
capela |
971 |
if (pNewGroup) |
435 |
|
|
pNewGroup->startRename(0); |
436 |
|
|
|
437 |
|
|
selectionChangedSlot(); |
438 |
|
|
} |
439 |
|
|
|
440 |
|
|
|
441 |
capela |
1013 |
// Map selector. |
442 |
|
|
void qsamplerInstrumentList::setMidiMap ( int iMidiMap ) |
443 |
|
|
{ |
444 |
|
|
if (iMidiMap < 0) |
445 |
|
|
iMidiMap = LSCP_MIDI_MAP_ALL; |
446 |
|
|
|
447 |
|
|
m_iMidiMap = iMidiMap; |
448 |
|
|
} |
449 |
|
|
|
450 |
|
|
int qsamplerInstrumentList::midiMap (void) const |
451 |
|
|
{ |
452 |
|
|
return m_iMidiMap; |
453 |
|
|
} |
454 |
|
|
|
455 |
|
|
|
456 |
|
|
// List actions accessors. |
457 |
|
|
QAction *qsamplerInstrumentList::newGroupAction (void) const |
458 |
|
|
{ |
459 |
|
|
return m_pNewGroupAction; |
460 |
|
|
} |
461 |
|
|
|
462 |
|
|
QAction *qsamplerInstrumentList::newItemAction (void) const |
463 |
|
|
{ |
464 |
|
|
return m_pNewItemAction; |
465 |
|
|
} |
466 |
|
|
|
467 |
|
|
QAction *qsamplerInstrumentList::editItemAction (void) const |
468 |
|
|
{ |
469 |
|
|
return m_pEditItemAction; |
470 |
|
|
} |
471 |
|
|
|
472 |
|
|
QAction *qsamplerInstrumentList::renameAction (void) const |
473 |
|
|
{ |
474 |
|
|
return m_pRenameAction; |
475 |
|
|
} |
476 |
|
|
|
477 |
|
|
QAction *qsamplerInstrumentList::deleteAction (void) const |
478 |
|
|
{ |
479 |
|
|
return m_pDeleteAction; |
480 |
|
|
} |
481 |
|
|
|
482 |
|
|
QAction *qsamplerInstrumentList::refreshAction (void) const |
483 |
|
|
{ |
484 |
|
|
return m_pRefreshAction; |
485 |
|
|
} |
486 |
|
|
|
487 |
|
|
|
488 |
capela |
971 |
// Add a new instrument item below the current one. |
489 |
|
|
void qsamplerInstrumentList::newItemSlot (void) |
490 |
|
|
{ |
491 |
|
|
qsamplerInstrument *pInstrument = new qsamplerInstrument(); |
492 |
|
|
|
493 |
|
|
qsamplerInstrumentForm form(this); |
494 |
|
|
form.setup(pInstrument); |
495 |
|
|
if (!form.exec()) { |
496 |
|
|
delete pInstrument; |
497 |
|
|
return; |
498 |
|
|
} |
499 |
|
|
|
500 |
capela |
1013 |
// Commit... |
501 |
capela |
980 |
pInstrument->mapInstrument(); |
502 |
capela |
1013 |
// add new item to the tree... |
503 |
|
|
addItem(pInstrument, groupItem(QListView::selectedItem())); |
504 |
|
|
// Notify we've changes... |
505 |
capela |
971 |
emit instrumentsChanged(); |
506 |
|
|
|
507 |
|
|
selectionChangedSlot(); |
508 |
|
|
} |
509 |
|
|
|
510 |
|
|
|
511 |
|
|
// Edit current item below the current one. |
512 |
|
|
void qsamplerInstrumentList::editItemSlot (void) |
513 |
|
|
{ |
514 |
|
|
QListViewItem *pListItem = QListView::selectedItem(); |
515 |
|
|
if (pListItem == NULL) |
516 |
|
|
return; |
517 |
|
|
if (pListItem->rtti() == Item) { |
518 |
capela |
1013 |
qsamplerInstrument *pInstrument = NULL; |
519 |
capela |
971 |
qsamplerInstrumentItem *pItem |
520 |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
521 |
capela |
1013 |
if (pItem) |
522 |
|
|
pInstrument = pItem->instrument(); |
523 |
|
|
if (pInstrument) { |
524 |
|
|
// Save current key values... |
525 |
|
|
int iMap = pInstrument->map(); |
526 |
|
|
int iBank = pInstrument->bank(); |
527 |
|
|
int iProg = pInstrument->prog(); |
528 |
|
|
// Do the edit dance... |
529 |
capela |
971 |
qsamplerInstrumentForm form(this); |
530 |
capela |
1013 |
form.setup(pInstrument); |
531 |
capela |
971 |
if (form.exec()) { |
532 |
capela |
1013 |
// Commit... |
533 |
|
|
pInstrument->mapInstrument(); |
534 |
|
|
// Check whether we changed instrument key... |
535 |
|
|
if (iMap == pInstrument->map() && |
536 |
|
|
iBank == pInstrument->bank() && |
537 |
|
|
iProg == pInstrument->prog()) { |
538 |
|
|
// just update tree item... |
539 |
|
|
pItem->update(); |
540 |
|
|
} else { |
541 |
|
|
// Change item tree, whether applicable... |
542 |
|
|
if (m_iMidiMap < 0 || m_iMidiMap == pInstrument->map()) { |
543 |
|
|
// Add new brand item into view... |
544 |
|
|
addItem(pInstrument, groupItem(pListItem)); |
545 |
|
|
} else { |
546 |
|
|
// Just remove/hide old one. |
547 |
|
|
delete pItem; |
548 |
|
|
} |
549 |
|
|
} |
550 |
|
|
// Notify we've changes... |
551 |
capela |
971 |
emit instrumentsChanged(); |
552 |
|
|
} |
553 |
|
|
} |
554 |
|
|
} |
555 |
|
|
|
556 |
|
|
selectionChangedSlot(); |
557 |
|
|
} |
558 |
|
|
|
559 |
|
|
|
560 |
|
|
// Rename current group/item. |
561 |
|
|
void qsamplerInstrumentList::renameSlot (void) |
562 |
|
|
{ |
563 |
|
|
QListViewItem *pListItem = QListView::selectedItem(); |
564 |
|
|
if (pListItem) |
565 |
|
|
pListItem->startRename(0); |
566 |
|
|
|
567 |
|
|
selectionChangedSlot(); |
568 |
|
|
} |
569 |
|
|
|
570 |
|
|
|
571 |
|
|
// Remove current group/item. |
572 |
|
|
void qsamplerInstrumentList::deleteSlot (void) |
573 |
|
|
{ |
574 |
|
|
QListViewItem *pListItem = QListView::selectedItem(); |
575 |
capela |
987 |
if (pListItem == NULL) |
576 |
|
|
return; |
577 |
|
|
|
578 |
|
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
579 |
|
|
if (pMainForm == NULL) |
580 |
|
|
return; |
581 |
|
|
|
582 |
|
|
// Prompt user if this is for real... |
583 |
|
|
qsamplerOptions *pOptions = pMainForm->options(); |
584 |
|
|
if (pOptions && pOptions->bConfirmRemove) { |
585 |
|
|
if (QMessageBox::warning(this, |
586 |
|
|
QSAMPLER_TITLE ": " + tr("Warning"), |
587 |
|
|
tr("Delete %1:\n\n" |
588 |
|
|
"%2\n\n" |
589 |
|
|
"Are you sure?") |
590 |
|
|
.arg(pListItem->rtti() == Item ? tr("instrument") : tr("group")) |
591 |
|
|
.arg(pListItem->text(0)), |
592 |
|
|
tr("OK"), tr("Cancel")) > 0) |
593 |
|
|
return; |
594 |
|
|
} |
595 |
|
|
|
596 |
|
|
// Unmap instrument entry... |
597 |
|
|
if (pListItem->rtti() == Item) { |
598 |
|
|
qsamplerInstrumentItem *pItem |
599 |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
600 |
|
|
if (pItem && pItem->instrument()) { |
601 |
|
|
pItem->instrument()->unmapInstrument(); |
602 |
|
|
emit instrumentsChanged(); |
603 |
capela |
971 |
} |
604 |
|
|
} |
605 |
|
|
|
606 |
capela |
987 |
// Do it for real... |
607 |
|
|
delete pListItem; |
608 |
|
|
|
609 |
capela |
971 |
selectionChangedSlot(); |
610 |
|
|
} |
611 |
|
|
|
612 |
|
|
|
613 |
|
|
// In-place selection slot. |
614 |
|
|
void qsamplerInstrumentList::selectionChangedSlot (void) |
615 |
|
|
{ |
616 |
|
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
617 |
|
|
QListViewItem *pListItem = QListView::selectedItem(); |
618 |
|
|
bool bEnabled = (pMainForm && pMainForm->client()); |
619 |
|
|
m_pNewItemAction->setEnabled(bEnabled); |
620 |
|
|
bEnabled = (bEnabled && pListItem != NULL); |
621 |
|
|
m_pEditItemAction->setEnabled(bEnabled && pListItem->rtti() == Item); |
622 |
|
|
m_pRenameAction->setEnabled(bEnabled); |
623 |
|
|
m_pDeleteAction->setEnabled(bEnabled); |
624 |
|
|
} |
625 |
|
|
|
626 |
|
|
|
627 |
|
|
// In-place activation slot. |
628 |
|
|
void qsamplerInstrumentList::activatedSlot ( QListViewItem *pListItem ) |
629 |
|
|
{ |
630 |
|
|
// FIXME: Hope the list view item is the one selected. |
631 |
|
|
if (pListItem->rtti() == Item) |
632 |
|
|
editItemSlot(); |
633 |
|
|
} |
634 |
|
|
|
635 |
|
|
|
636 |
|
|
// In-place aliasing slot. |
637 |
|
|
void qsamplerInstrumentList::renamedSlot ( QListViewItem *pListItem ) |
638 |
|
|
{ |
639 |
|
|
if (pListItem->rtti() == Item) { |
640 |
|
|
qsamplerInstrumentItem *pItem |
641 |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
642 |
|
|
if (pItem && pItem->instrument()) { |
643 |
|
|
pItem->instrument()->setName(pListItem->text(0)); |
644 |
capela |
980 |
pItem->instrument()->mapInstrument(); |
645 |
capela |
971 |
emit instrumentsChanged(); |
646 |
|
|
pItem->update(); |
647 |
|
|
} |
648 |
|
|
} |
649 |
|
|
} |
650 |
|
|
|
651 |
|
|
|
652 |
|
|
// Context menu request event handler. |
653 |
|
|
void qsamplerInstrumentList::contextMenuEvent ( |
654 |
|
|
QContextMenuEvent *pContextMenuEvent ) |
655 |
|
|
{ |
656 |
|
|
if (!m_pNewItemAction->isEnabled()) |
657 |
|
|
return; |
658 |
|
|
|
659 |
|
|
QPopupMenu menu(this); |
660 |
|
|
|
661 |
|
|
// Construct context menu. |
662 |
|
|
m_pNewItemAction->addTo(&menu); |
663 |
|
|
// m_pNewGroupAction->addTo(&menu); |
664 |
|
|
menu.insertSeparator(); |
665 |
|
|
m_pEditItemAction->addTo(&menu); |
666 |
|
|
m_pRenameAction->addTo(&menu); |
667 |
|
|
m_pDeleteAction->addTo(&menu); |
668 |
|
|
menu.insertSeparator(); |
669 |
|
|
m_pRefreshAction->addTo(&menu); |
670 |
|
|
|
671 |
|
|
menu.exec(pContextMenuEvent->globalPos()); |
672 |
|
|
} |
673 |
|
|
|
674 |
|
|
|
675 |
|
|
// General reloader. |
676 |
|
|
void qsamplerInstrumentList::refresh (void) |
677 |
|
|
{ |
678 |
|
|
clear(); |
679 |
|
|
|
680 |
|
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
681 |
|
|
if (pMainForm == NULL) |
682 |
|
|
return; |
683 |
|
|
if (pMainForm->client() == NULL) |
684 |
|
|
return; |
685 |
|
|
|
686 |
|
|
qsamplerInstrumentItem *pItem = NULL; |
687 |
|
|
lscp_midi_instrument_t *pInstrs |
688 |
capela |
1013 |
= ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap); |
689 |
capela |
987 |
for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) { |
690 |
capela |
980 |
int iMap = pInstrs[iInstr].map; |
691 |
|
|
int iBank = pInstrs[iInstr].bank; |
692 |
|
|
int iProg = pInstrs[iInstr].prog; |
693 |
capela |
971 |
qsamplerInstrument *pInstrument |
694 |
capela |
980 |
= new qsamplerInstrument(iMap, iBank, iProg); |
695 |
|
|
if (pInstrument->getInstrument()) |
696 |
capela |
971 |
pItem = new qsamplerInstrumentItem(this, pInstrument, pItem); |
697 |
|
|
} |
698 |
|
|
|
699 |
|
|
if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) { |
700 |
|
|
pMainForm->appendMessagesClient("lscp_list_midi_instruments"); |
701 |
|
|
pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry.")); |
702 |
|
|
} |
703 |
|
|
|
704 |
|
|
selectionChangedSlot(); |
705 |
|
|
} |
706 |
|
|
|
707 |
|
|
|
708 |
|
|
// end of qsamplerInstrumentList.cpp |
709 |
|
|
|