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

Legend:
Removed from v.969  
changed lines
  Added in v.980

  ViewVC Help
Powered by ViewVC