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