/[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 2064 by capela, Fri Mar 12 16:02:32 2010 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-2010, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, Christian Schoenebeck
6     This program is free software; you can redistribute it and/or  
7     modify it under the terms of the GNU General Public License     This program is free software; you can redistribute it and/or
8     as published by the Free Software Foundation; either version 2     modify it under the terms of the GNU General Public License
9     of the License, or (at your option) any later version.     as published by the Free Software Foundation; either version 2
10       of the License, or (at your option) any later version.
11     This program is distributed in the hope that it will be useful,  
12     but WITHOUT ANY WARRANTY; without even the implied warranty of     This program is distributed in the hope that it will be useful,
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     GNU General Public License for more details.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15       GNU General Public License for more details.
16     You should have received a copy of the GNU General Public License  
17     along with this program; if not, write to the Free Software     You should have received a copy of the GNU General Public License
18     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     along with this program; if not, write to the Free Software
19       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *****************************************************************************/  
21    *****************************************************************************/
22  #include "qsamplerAbout.h"  
23  #include "qsamplerInstrumentList.h"  #include "qsamplerAbout.h"
24    #include "qsamplerInstrumentList.h"
25  #include "qsamplerInstrument.h"  
26  #include "qsamplerInstrumentForm.h"  #include "qsamplerInstrument.h"
27    
28  #include "qsamplerMainForm.h"  #include "qsamplerOptions.h"
29    #include "qsamplerMainForm.h"
30  #include <qaction.h>  
31  #include <qfileinfo.h>  #include <QApplication>
32  #include <qpopupmenu.h>  #include <QCursor>
33    
34  // Needed for lroundf()  
35  #include <math.h>  namespace QSampler {
36    
37    //-------------------------------------------------------------------------
38  //----------------------------------------------------------------------  // QSampler::InstrumentListModel - data model for MIDI prog mappings
39  // class qsamplerInstrumentGroup -- custom group list view item.  //
40  //  
41    InstrumentListModel::InstrumentListModel ( QObject *pParent )
42  // Constructors.          : QAbstractItemModel(pParent)
43  qsamplerInstrumentGroup::qsamplerInstrumentGroup (  {
44          qsamplerInstrumentList *pListView, const QString& sName,          m_iMidiMap = LSCP_MIDI_MAP_ALL;
45          QListViewItem *pItemAfter )  
46          : QListViewItem(pListView, pItemAfter ? pItemAfter : pListView->lastItem())          QAbstractItemModel::reset();
47  {  }
48          QListViewItem::setRenameEnabled(0, true);  
49    InstrumentListModel::~InstrumentListModel (void)
50          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png"));  {
51          QListViewItem::setText(0, sName);          clear();
52  }  }
53    
54    
55  qsamplerInstrumentGroup::qsamplerInstrumentGroup (  int InstrumentListModel::rowCount ( const QModelIndex& /*parent*/) const
56          qsamplerInstrumentGroup *pGroupItem, const QString& sName )  {
57          : QListViewItem(pGroupItem, sName)          int nrows = 0;
58  {  
59          QListViewItem::setRenameEnabled(0, true);          if (m_iMidiMap == LSCP_MIDI_MAP_ALL) {
60                    InstrumentMap::const_iterator itMap = m_instruments.constBegin();
61          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png"));                  for ( ; itMap != m_instruments.constEnd(); ++itMap)
62  }                          nrows += (*itMap).size();
63            } else {
64                    InstrumentMap::const_iterator itMap = m_instruments.find(m_iMidiMap);
65  // Default destructor.                  if (itMap != m_instruments.constEnd())
66  qsamplerInstrumentGroup::~qsamplerInstrumentGroup (void)                          nrows += (*itMap).size();
67  {          }
68  }  
69            return nrows;
70    }
71  // Instance accessors.  
72  void qsamplerInstrumentGroup::setName ( const QString& sName )  
73  {  int InstrumentListModel::columnCount ( const QModelIndex& /*parent*/) const
74          QListViewItem::setText(0, sName);  {
75  }          return 9;
76    }
77    
78  QString qsamplerInstrumentGroup::name (void) const  
79  {  QVariant InstrumentListModel::data (
80          return QListViewItem::text(0);          const QModelIndex &index, int role ) const
81  }  {
82            if (!index.isValid())
83                    return QVariant();
84  qsamplerInstrumentGroup *qsamplerInstrumentGroup::groupItem (void) const  
85  {          const Instrument *pInstr
86          QListViewItem *pParent = QListViewItem::parent();                  = static_cast<Instrument *> (index.internalPointer());
87          while (pParent && pParent->rtti() != qsamplerInstrumentList::Group)  
88                  pParent = pParent->parent();          if (pInstr && role == Qt::DisplayRole) {
89          return static_cast<qsamplerInstrumentGroup *> (pParent);                  switch (index.column()) {
90  }                          case 0: return pInstr->name();
91                            case 1: return QVariant::fromValue(pInstr->map());
92                            case 2: return QVariant::fromValue(pInstr->bank());
93  qsamplerInstrumentList *qsamplerInstrumentGroup::listView (void) const                          case 3: return QVariant::fromValue(pInstr->prog() + 1);
94  {                          case 4: return pInstr->engineName();
95          return static_cast<qsamplerInstrumentList *> (QListViewItem::listView());                          case 5: return pInstr->instrumentFile();
96  }                          case 6: return QVariant::fromValue(pInstr->instrumentNr());
97                            case 7: return QString::number(pInstr->volume() * 100.0) + " %";
98                            case 8: {
99  // To show up whether its open or not.                                  switch (pInstr->loadMode()) {
100  void qsamplerInstrumentGroup::setOpen ( bool bOpen )                                          case 3: return tr("Persistent");
101  {                                          case 2: return tr("On Demand Hold");
102          // Set the proper pixmap of this...                                          case 1: return tr("On Demand");
103          if (rtti() == qsamplerInstrumentList::Group) {                                  }
104                  QListViewItem::setPixmap(0, QPixmap::fromMimeSource(                          }
105                          bOpen ? "itemGroupOpen.png" : "itemGroup.png"));                          default:
106          }                                  break;
107          // Open it up...                  }
108          QListViewItem::setOpen(bOpen);          }
109    
110          // All ancestors should be also visible.          return QVariant();
111          if (bOpen && QListViewItem::parent())  }
112                  QListViewItem::parent()->setOpen(true);  
113  }  
114    QModelIndex InstrumentListModel::index (
115            int row, int col, const QModelIndex& /*parent*/ ) const
116  // To virtually distinguish between list view items.  {
117  int qsamplerInstrumentGroup::rtti (void) const          const Instrument *pInstr = NULL;
118  {  
119          return qsamplerInstrumentList::Group;          if (m_iMidiMap == LSCP_MIDI_MAP_ALL) {
120  }                  int nrows = 0;
121                    InstrumentMap::const_iterator itMap = m_instruments.constBegin();
122                    for ( ; itMap != m_instruments.constEnd(); ++itMap) {
123  //----------------------------------------------------------------------                          const InstrumentList& list = *itMap;
124  // class qsamplerInstrumentItem -- custom file list view item.                          nrows += list.size();
125  //                          if (row < nrows) {
126                                    pInstr = list.at(row + list.size() - nrows);
127  // Constructors.                                  break;
128  qsamplerInstrumentItem::qsamplerInstrumentItem (                          }
129          qsamplerInstrumentList *pListView,                  }
130          qsamplerInstrument *pInstrument,          } else {
131          QListViewItem *pItemAfter )                  // Resolve MIDI instrument map...
132          : qsamplerInstrumentGroup(pListView, pInstrument->name(), pItemAfter)                  InstrumentMap::const_iterator itMap     = m_instruments.find(m_iMidiMap);
133  {                  if (itMap != m_instruments.constEnd()) {
134          m_pInstrument = pInstrument;                          const InstrumentList& list = *itMap;
135                            // resolve instrument in that map
136          update();                          if (row < list.size())
137  }                                  pInstr = list.at(row);
138                    }
139  qsamplerInstrumentItem::qsamplerInstrumentItem (          }
140          qsamplerInstrumentGroup *pGroupItem,  
141          qsamplerInstrument *pInstrument )          if (pInstr)
142          : qsamplerInstrumentGroup(pGroupItem, pInstrument->name())                  return createIndex(row, col, (void *) pInstr);
143  {          else
144          m_pInstrument = pInstrument;                  return QModelIndex();
145    }
146          update();  
147  }  
148    QModelIndex InstrumentListModel::parent ( const QModelIndex& child ) const
149    {
150  // Default destructor.          return QModelIndex();
151  qsamplerInstrumentItem::~qsamplerInstrumentItem (void)  }
152  {  
153          if (m_pInstrument)  
154                  delete m_pInstrument;  QVariant InstrumentListModel::headerData (
155  }          int section, Qt::Orientation orientation, int role ) const
156    {
157            if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
158  // To virtually distinguish between list view items.                  switch (section) {
159  int qsamplerInstrumentItem::rtti (void) const                          case 0: return tr("Name");
160  {                          case 1: return tr("Map");
161          return qsamplerInstrumentList::Item;                          case 2: return tr("Bank");
162  }                          case 3: return tr("Prog");
163                            case 4: return tr("Engine");
164                            case 5: return tr("File");
165  // Payload accessor.                          case 6: return tr("Nr");
166  qsamplerInstrument *qsamplerInstrumentItem::instrument (void) const                          case 7: return tr("Vol");
167  {                          case 8: return tr("Mode");
168          return m_pInstrument;                  }
169  }          }
170    
171            return QAbstractItemModel::headerData(section, orientation, role);
172  // Item refreshment.  }
173  void qsamplerInstrumentItem::update (void)  
174  {  
175          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemFile.png"));  void InstrumentListModel::setMidiMap ( int iMidiMap )
176    {
177          const QString s = "-";          if (iMidiMap < 0)
178          if (m_pInstrument) {                  iMidiMap = LSCP_MIDI_MAP_ALL;
179                  setText(0, m_pInstrument->name());  
180                  setText(1, QString::number(m_pInstrument->bank()));          m_iMidiMap = iMidiMap;
181                  setText(2, QString::number(m_pInstrument->program()));  }
182                  setText(3, m_pInstrument->engineName());  
183                  setText(4, QFileInfo(m_pInstrument->instrumentFile()).fileName());  
184                  setText(5, QString::number(m_pInstrument->instrumentNr()));  int InstrumentListModel::midiMap (void) const
185                  setText(6, QString::number(::lroundf(100.0f * m_pInstrument->volume())));  {
186                  QString sLoadMode = s;          return m_iMidiMap;
187                  switch (m_pInstrument->loadMode()) {  }
188                  case 3:  
189                          sLoadMode = QObject::tr("Persistent");  
190                          break;  const Instrument *InstrumentListModel::addInstrument (
191                  case 2:          int iMap, int iBank, int iProg )
192                          sLoadMode = QObject::tr("On Demand Hold");  {
193                          break;          // Check it there's already one instrument item
194                  case 1:          // with the very same key (bank, program);
195                          sLoadMode = QObject::tr("On Demand");          // if yes, just remove it without prejudice...
196                          break;          InstrumentList& list = m_instruments[iMap];
197                  }          for (int i = 0; i < list.size(); ++i) {
198                  setText(7, sLoadMode);                  const Instrument *pInstr = list.at(i);
199          } else {                  if (pInstr->bank() == iBank && pInstr->prog() == iProg) {
200                  for (int i = 0; i < listView()->columns(); i++)                          delete pInstr;
201                          setText(i, s);                          list.removeAt(i);
202          }                          break;
203  }                  }
204            }
205    
206  //----------------------------------------------------------------------------          // Resolve the appropriate place, we keep the list sorted that way...
207  // qsamplerInstrumentList -- MIDI instrument list view.          int i = 0;
208  //          for ( ; i < list.size(); ++i) {
209                    const Instrument *pInstr = list.at(i);
210  // Constructor.                  if (iBank < pInstr->bank()
211  qsamplerInstrumentList::qsamplerInstrumentList (                          || (iBank == pInstr->bank() && iProg < pInstr->prog())) {
212          QWidget *pParent, const char *pszName )                          break;
213          : QListView(pParent, pszName)                  }
214  {          }
215  //  QListView::setRootIsDecorated(true);  
216          QListView::setResizeMode(QListView::NoColumn);          Instrument *pInstr = new Instrument(iMap, iBank, iProg);
217  //      QListView::setAcceptDrops(true);          if (pInstr->getInstrument()) {
218          QListView::setDragAutoScroll(true);                  list.insert(i, pInstr);
219          QListView::setSizePolicy(          } else {
220                  QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));                  delete pInstr;
221  //      QListView::setShowToolTips(false);                  pInstr = NULL;
222          QListView::setSortColumn(-1);          }
223    
224          QListView::addColumn(tr("Name"));          return pInstr;
225          QListView::addColumn(tr("Bank"));  }
226          QListView::addColumn(tr("Prog"));  
227          QListView::addColumn(tr("Engine"));  
228          QListView::addColumn(tr("File"));  void InstrumentListModel::removeInstrument ( const Instrument *pInstrument )
229          QListView::addColumn(tr("Nr"));  {
230          QListView::addColumn(tr("Vol"));          const int iMap  = pInstrument->map();
231          QListView::addColumn(tr("Mode"));          const int iBank = pInstrument->bank();
232            const int iProg = pInstrument->prog();
233          QListView::setColumnAlignment(1, Qt::AlignHCenter);     // Bank  
234          QListView::setColumnAlignment(2, Qt::AlignHCenter);     // Prog          if (m_instruments.contains(iMap)) {
235          QListView::setColumnAlignment(5, Qt::AlignHCenter);     // Nr                  InstrumentList& list = m_instruments[iMap];
236          QListView::setColumnAlignment(6, Qt::AlignHCenter);     // Vol                  for (int i = 0; i < list.size(); ++i) {
237                            const Instrument *pInstr = list.at(i);
238          QListView::setColumnWidth(0, 60);       // Name                          if (pInstr->bank() == iBank && pInstr->prog() == iProg) {
239          QListView::setColumnWidth(0, 120);      // File                                  delete pInstr;
240                                    list.removeAt(i);
241          m_pNewGroupAction = new QAction(tr("New &Group"), tr("Ctrl+G"), this);                                  break;
242          m_pNewItemAction  = new QAction(tr("New &Instrument..."), tr("Ctrl+I"), this);                          }
243          m_pEditItemAction = new QAction(tr("&Edit..."), tr("Ctrl+E"), this);                  }
244          m_pRenameAction   = new QAction(tr("&Rename"), tr("Ctrl+R"), this);          }
245          m_pDeleteAction   = new QAction(tr("&Delete"), tr("Ctrl+D"), this);  }
246          m_pRefreshAction  = new QAction(tr("Re&fresh"), tr("Ctrl+F"), this);  
247    
248          QObject::connect(m_pNewGroupAction,  // Reposition the instrument in the model (called when map/bank/prg changed)
249                  SIGNAL(activated()),  void InstrumentListModel::updateInstrument ( const Instrument *pInstrument )
250                  SLOT(newGroupSlot()));  {
251          QObject::connect(m_pNewItemAction,          const int iMap  = pInstrument->map();
252                  SIGNAL(activated()),          const int iBank = pInstrument->bank();
253                  SLOT(newItemSlot()));          const int iProg = pInstrument->prog();
254          QObject::connect(m_pEditItemAction,  
255                  SIGNAL(activated()),          // Remove given instrument from its current list...
256                  SLOT(editItemSlot()));          removeInstrument(pInstrument);
257          QObject::connect(m_pRenameAction,  
258                  SIGNAL(activated()),          // Re-add the instrument...
259                  SLOT(renameSlot()));          addInstrument(iMap, iBank, iProg);
260          QObject::connect(m_pDeleteAction,  }
261                  SIGNAL(activated()),  
262                  SLOT(deleteSlot()));  
263          QObject::connect(m_pRefreshAction,  void InstrumentListModel::refresh (void)
264                  SIGNAL(activated()),  {
265                  SLOT(refresh()));          MainForm *pMainForm = MainForm::getInstance();
266            if (pMainForm == NULL)
267          QObject::connect(this,                  return;
268                  SIGNAL(selectionChanged()),          if (pMainForm->client() == NULL)
269                  SLOT(selectionChangedSlot()));                  return;
270          QObject::connect(this,  
271                  SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)),          QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
272                  SLOT(activatedSlot(QListViewItem*)));  
273          QObject::connect(this,          clear();
274                  SIGNAL(returnPressed(QListViewItem*)),  
275                  SLOT(activatedSlot(QListViewItem*)));          // Load the whole bunch of instrument items...
276          QObject::connect(this,          lscp_midi_instrument_t *pInstrs
277                  SIGNAL(itemRenamed(QListViewItem*,int)),                  = ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap);
278                  SLOT(renamedSlot(QListViewItem*)));          for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {
279                    const int iMap  = pInstrs[iInstr].map;
280          selectionChangedSlot();                  const int iBank = pInstrs[iInstr].bank;
281  }                  const int iProg = pInstrs[iInstr].prog;
282                    addInstrument(iMap, iBank, iProg);
283                    // Try to keep it snappy :)
284  // Default destructor.                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
285  qsamplerInstrumentList::~qsamplerInstrumentList (void)          }
286  {  
287          delete m_pNewGroupAction;          QApplication::restoreOverrideCursor();
288          delete m_pNewItemAction;  
289          delete m_pEditItemAction;          if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) {
290          delete m_pRenameAction;                  pMainForm->appendMessagesClient("lscp_list_midi_instruments");
291          delete m_pDeleteAction;                  pMainForm->appendMessagesError(
292  }                          tr("Could not get current list of MIDI instrument mappings.\n\nSorry."));
293            }
294    }
295  // Add a new instrument item, optionally under a given group.  
296  qsamplerInstrumentItem *qsamplerInstrumentList::addItem (  void InstrumentListModel::beginReset (void)
297          qsamplerInstrument *pInstrument,  {
298          qsamplerInstrumentGroup *pParentGroup )  #if QT_VERSION >= 0x040600
299  {          QAbstractItemModel::beginResetModel();
300          qsamplerInstrumentItem *pItem = findItem(pInstrument);  #endif
301          if (pItem == NULL) {  }
302                  if (pParentGroup)  
303                          pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument);  void InstrumentListModel::endReset (void)
304                  else  {
305                          pItem = new qsamplerInstrumentItem(this, pInstrument);  #if QT_VERSION >= 0x040600
306          }          QAbstractItemModel::endResetModel();
307          QListView::setSelected(pItem, true);  #else
308          return pItem;          QAbstractItemModel::reset();
309  }  #endif
310    }
311    
312  // Add a new instrument group, optionally under another group.  
313  qsamplerInstrumentGroup *qsamplerInstrumentList::addGroup (  // Map clear.
314          const QString& sName, qsamplerInstrumentGroup *pParentGroup )  void InstrumentListModel::clear (void)
315  {  {
316          qsamplerInstrumentGroup *pGroup = findGroup(sName);          InstrumentMap::iterator itMap = m_instruments.begin();
317          if (pGroup == NULL) {          for ( ; itMap != m_instruments.end(); ++itMap) {
318                  if (pParentGroup)                  InstrumentList& list = itMap.value();
319                          pGroup = new qsamplerInstrumentGroup(pParentGroup, sName);                  qDeleteAll(list);
320                  else                  list.clear();
321                          pGroup = new qsamplerInstrumentGroup(this, sName);          }
322          }  
323          QListView::setSelected(pGroup, true);          m_instruments.clear();
324          return pGroup;  }
325  }  
326    
327    //-------------------------------------------------------------------------
328  // Find a group item, given its name.  // QSampler::InstrumentListView - list view for MIDI prog mappings
329  qsamplerInstrumentGroup *qsamplerInstrumentList::findGroup (  //
330          const QString& sName ) const  
331  {  // Constructor.
332          // Iterate all over the place to search for the group.  InstrumentListView::InstrumentListView ( QWidget *pParent )
333          QListViewItemIterator iter((QListView *) this);          : QTreeView(pParent)
334          while (iter.current()) {  {
335                  QListViewItem *pItem = iter.current();          m_pListModel = new InstrumentListModel(this);
336                  if (pItem->rtti() == Group && pItem->text(0) == sName)  
337                          return static_cast<qsamplerInstrumentGroup *> (pItem);          QTreeView::setModel(m_pListModel);
338                  ++iter;  }
339          }  
340          // Not found.  
341          return NULL;  // Destructor.
342  }  InstrumentListView::~InstrumentListView (void)
343    {
344            delete m_pListModel;
345  // Find a file item, given its name.  }
346  qsamplerInstrumentItem *qsamplerInstrumentList::findItem (  
347          qsamplerInstrument *pInstrument ) const  
348  {  void InstrumentListView::setMidiMap ( int iMidiMap )
349          if (pInstrument == NULL)  {
350                  return NULL;          m_pListModel->setMidiMap(iMidiMap);
351    }
352          // Iterate all over the place to search for the group.  
353          QListViewItemIterator iter((QListView *) this);  
354          while (iter.current()) {  int InstrumentListView::midiMap (void) const
355                  QListViewItem *pListItem = iter.current();  {
356                  if (pListItem->rtti() == Item) {          return m_pListModel->midiMap();
357                          qsamplerInstrumentItem *pItem  }
358                                  = static_cast<qsamplerInstrumentItem *> (pListItem);  
359                          if (pItem && pItem->instrument()  
360                                  && pItem->instrument()->bank() == pInstrument->bank()  const Instrument *InstrumentListView::addInstrument (
361                                  && pItem->instrument()->program() == pInstrument->program())          int iMap, int iBank, int iProg )
362                                  return pItem;  {
363                  }          m_pListModel->beginReset();
364                  ++iter;          const Instrument *pInstrument
365          }                  = m_pListModel->addInstrument(iMap, iBank, iProg);
366          // Not found.          m_pListModel->endReset();
367          return NULL;  
368  }          return pInstrument;
369    }
370    
371  // Find and return the nearest group item...  
372  qsamplerInstrumentGroup *qsamplerInstrumentList::groupItem (  void InstrumentListView::removeInstrument ( const Instrument *pInstrument )
373          QListViewItem *pItem ) const  {
374  {          m_pListModel->beginReset();
375          while (pItem && pItem->rtti() != Group)          m_pListModel->removeInstrument(pInstrument);
376                  pItem = pItem->parent();          m_pListModel->endReset();
377          return static_cast<qsamplerInstrumentGroup *> (pItem);  }
378  }  
379    
380    // Reposition the instrument in the model (called when map/bank/prg changed)
381  // Add a new group item below the current one.  void InstrumentListView::updateInstrument ( const Instrument *pInstrument )
382  void qsamplerInstrumentList::newGroupSlot (void)  {
383  {          m_pListModel->beginReset();
384          qsamplerInstrumentGroup *pParentGroup          m_pListModel->updateInstrument(pInstrument);
385                  = groupItem(QListView::selectedItem());          m_pListModel->endReset();}
386          qsamplerInstrumentGroup *pNewGroup  
387                  = addGroup(tr("New Group"), pParentGroup);  
388          if (pParentGroup)  // Refreshener.
389                  pParentGroup->setOpen(true);  void InstrumentListView::refresh (void)
390          if (pNewGroup)  {
391                  pNewGroup->startRename(0);          m_pListModel->beginReset();
392            m_pListModel->refresh();
393          selectionChangedSlot();          m_pListModel->endReset();
394  }  }
395    
396    
397  // Add a new instrument item below the current one.  } // namespace QSampler
398  void qsamplerInstrumentList::newItemSlot (void)  
399  {  
400          qsamplerInstrument *pInstrument = new qsamplerInstrument();  // end of qsamplerInstrumentList.cpp
   
         qsamplerInstrumentForm form(this);  
         form.setup(pInstrument);  
         if (!form.exec()) {  
                 delete pInstrument;  
                 return;  
         }  
   
         // Check it there's already one for the same key (bank, program)  
         qsamplerInstrumentItem *pItem = findItem(pInstrument);  
         if (pItem)  
                 delete pItem;  
   
         pInstrument->map();  
         emit instrumentsChanged();  
   
         qsamplerInstrumentGroup *pParentGroup  
                 = groupItem(QListView::selectedItem());  
         addItem(pInstrument, pParentGroup);  
         if (pParentGroup)  
                 pParentGroup->setOpen(true);  
   
         selectionChangedSlot();  
 }  
   
   
 // Edit current item below the current one.  
 void qsamplerInstrumentList::editItemSlot (void)  
 {  
         QListViewItem *pListItem = QListView::selectedItem();  
         if (pListItem == NULL)  
                 return;  
         if (pListItem->rtti() == Item) {  
                 qsamplerInstrumentItem *pItem  
                         = static_cast<qsamplerInstrumentItem *> (pListItem);  
                 if (pItem && pItem->instrument()) {  
                         qsamplerInstrumentForm form(this);  
                         form.setup(pItem->instrument());  
                         if (form.exec()) {  
                                 pItem->instrument()->map();  
                                 emit instrumentsChanged();  
                                 pItem->update();  
                         }  
                 }  
         }  
   
         selectionChangedSlot();  
 }  
   
   
 // Rename current group/item.  
 void qsamplerInstrumentList::renameSlot (void)  
 {  
         QListViewItem *pListItem = QListView::selectedItem();  
         if (pListItem)  
                 pListItem->startRename(0);  
   
         selectionChangedSlot();  
 }  
   
   
 // Remove current group/item.  
 void qsamplerInstrumentList::deleteSlot (void)  
 {  
         QListViewItem *pListItem = QListView::selectedItem();  
         if (pListItem) {  
                 if (pListItem->rtti() == Item) {  
                         qsamplerInstrumentItem *pItem  
                                 = static_cast<qsamplerInstrumentItem *> (pListItem);  
                         if (pItem && pItem->instrument()) {  
                                 pItem->instrument()->unmap();  
                                 emit instrumentsChanged();  
                         }  
                 }  
                 delete pListItem;  
         }  
   
         selectionChangedSlot();  
 }  
   
   
 // In-place selection slot.  
 void qsamplerInstrumentList::selectionChangedSlot (void)  
 {  
         qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();  
         QListViewItem *pListItem = QListView::selectedItem();  
         bool bEnabled = (pMainForm && pMainForm->client());  
         m_pNewItemAction->setEnabled(bEnabled);  
         bEnabled = (bEnabled && pListItem != NULL);  
         m_pEditItemAction->setEnabled(bEnabled && pListItem->rtti() == Item);  
         m_pRenameAction->setEnabled(bEnabled);  
         m_pDeleteAction->setEnabled(bEnabled);  
 }  
   
   
 // In-place activation slot.  
 void qsamplerInstrumentList::activatedSlot ( QListViewItem *pListItem )  
 {  
         // FIXME: Hope the list view item is the one selected.  
         if (pListItem->rtti() == Item)  
                 editItemSlot();  
 }  
   
   
 // In-place aliasing slot.  
 void qsamplerInstrumentList::renamedSlot ( QListViewItem *pListItem )  
 {  
         if (pListItem->rtti() == Item) {  
                 qsamplerInstrumentItem *pItem  
                         = static_cast<qsamplerInstrumentItem *> (pListItem);  
                 if (pItem && pItem->instrument()) {  
                         pItem->instrument()->setName(pListItem->text(0));  
                         pItem->instrument()->map();  
                         emit instrumentsChanged();  
                         pItem->update();  
                 }  
         }  
 }  
   
   
 // Context menu request event handler.  
 void qsamplerInstrumentList::contextMenuEvent (  
         QContextMenuEvent *pContextMenuEvent )  
 {  
         QPopupMenu menu(this);  
   
         // Construct context menu.  
         m_pNewItemAction->addTo(&menu);  
 //      m_pNewGroupAction->addTo(&menu);  
         menu.insertSeparator();  
         m_pEditItemAction->addTo(&menu);  
         m_pRenameAction->addTo(&menu);  
         m_pDeleteAction->addTo(&menu);  
         menu.insertSeparator();  
         m_pRefreshAction->addTo(&menu);  
   
         menu.exec(pContextMenuEvent->globalPos());  
 }  
   
   
 // General reloader.  
 void qsamplerInstrumentList::refresh (void)  
 {  
         clear();  
   
         qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();  
         if (pMainForm == NULL)  
                 return;  
         if (pMainForm->client() == NULL)  
                 return;  
   
         qsamplerInstrumentItem *pItem = NULL;  
         lscp_midi_instrument_t *pInstrs  
                 = ::lscp_list_midi_instruments(pMainForm->client());  
         for (int iInstr = 0; pInstrs && pInstrs[iInstr].program >= 0; ++iInstr) {  
                 int iBank = (pInstrs[iInstr].bank_msb << 7) | pInstrs[iInstr].bank_lsb;  
                 int iProgram = pInstrs[iInstr].program;  
                 qsamplerInstrument *pInstrument  
                         = new qsamplerInstrument(iBank, iProgram);  
                 if (pInstrument->get())  
                         pItem = new qsamplerInstrumentItem(this, pInstrument, pItem);  
         }  
   
         if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) {  
                 pMainForm->appendMessagesClient("lscp_list_midi_instruments");  
                 pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry."));  
         }  
   
         selectionChangedSlot();  
 }  
   
   
 // end of qsamplerInstrumentList.cpp  
   

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

  ViewVC Help
Powered by ViewVC