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

  ViewVC Help
Powered by ViewVC