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

  ViewVC Help
Powered by ViewVC