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

  ViewVC Help
Powered by ViewVC