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

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

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

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

  ViewVC Help
Powered by ViewVC