/[svn]/qsampler/trunk/src/qsamplerInstrumentList.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerInstrumentList.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.962  
changed lines
  Added in v.971

  ViewVC Help
Powered by ViewVC