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