/[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 1523 by capela, Sun Nov 25 11:40:47 2007 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-2007, 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    #include "qsamplerInstrumentForm.h"
28  #include "qsamplerMainForm.h"  
29    #include "qsamplerOptions.h"
30  #include <qaction.h>  #include "qsamplerMainForm.h"
31  #include <qfileinfo.h>  
32  #include <qpopupmenu.h>  #include <QApplication>
33    #include <QMessageBox>
34    #include <QMenu>
35  //----------------------------------------------------------------------  #include <QAction>
36  // class qsamplerInstrumentGroup -- custom group list view item.  #include <QCursor>
37  //  #include <QFileInfo>
38    
39  // Constructors.  // Needed for lroundf()
40  qsamplerInstrumentGroup::qsamplerInstrumentGroup (  #include <math.h>
41          qsamplerInstrumentList *pListView, const QString& sName,  
42          QListViewItem *pItemAfter )  #ifndef CONFIG_ROUND
43          : QListViewItem(pListView, pItemAfter ? pItemAfter : pListView->lastItem())  static inline long lroundf ( float x )
44  {  {
45          QListViewItem::setRenameEnabled(0, true);          if (x >= 0.0f)
46                    return long(x + 0.5f);
47          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png"));          else
48          QListViewItem::setText(0, sName);                  return long(x - 0.5f);
49  }  }
50    #endif
51    
52  qsamplerInstrumentGroup::qsamplerInstrumentGroup (  using namespace QSampler;
53          qsamplerInstrumentGroup *pGroupItem, const QString& sName )  
54          : QListViewItem(pGroupItem, sName)  
55  {  //-------------------------------------------------------------------------
56          QListViewItem::setRenameEnabled(0, true);  // MidiInstrumentsModel - data model for MIDI prog mappings (used for QTableView)
57    //
58          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png"));  
59  }  MidiInstrumentsModel::MidiInstrumentsModel ( QObject* pParent)
60            : QAbstractTableModel(pParent)
61    {
62  // Default destructor.          m_iMidiMap = LSCP_MIDI_MAP_ALL;
63  qsamplerInstrumentGroup::~qsamplerInstrumentGroup (void)  }
64  {  
65  }  
66    int MidiInstrumentsModel::rowCount ( const QModelIndex& /*parent*/) const
67    {
68  // Instance accessors.          if (m_iMidiMap == LSCP_MIDI_MAP_ALL) {
69  void qsamplerInstrumentGroup::setName ( const QString& sName )                  int n = 0;
70  {                  for (InstrumentsMap::const_iterator itMap = m_instruments.begin();
71          QListViewItem::setText(0, sName);                                  itMap != m_instruments.end(); ++itMap)
72  }                          n += (*itMap).size();
73                    return n;
74            }
75  QString qsamplerInstrumentGroup::name (void) const          InstrumentsMap::const_iterator itMap = m_instruments.find(m_iMidiMap);
76  {          if (itMap == m_instruments.end()) return 0;
77          return QListViewItem::text(0);          return (*itMap).size();
78  }  }
79    
80    
81  qsamplerInstrumentGroup *qsamplerInstrumentGroup::groupItem (void) const  int MidiInstrumentsModel::columnCount ( const QModelIndex& /*parent*/) const
82  {  {
83          QListViewItem *pParent = QListViewItem::parent();          return 9;
84          while (pParent && pParent->rtti() != qsamplerInstrumentList::Group)  }
85                  pParent = pParent->parent();  
86          return static_cast<qsamplerInstrumentGroup *> (pParent);  
87  }  QVariant MidiInstrumentsModel::data ( const QModelIndex &index, int role ) const
88    {
89            if (!index.isValid())
90  qsamplerInstrumentList *qsamplerInstrumentGroup::listView (void) const                  return QVariant();
91  {  
92          return static_cast<qsamplerInstrumentList *> (QListViewItem::listView());          const qsamplerInstrument* pInstr = NULL;
93  }  
94            if (m_iMidiMap == LSCP_MIDI_MAP_ALL) {
95                    int n = 0;
96  // To show up whether its open or not.                  for (InstrumentsMap::const_iterator itMap = m_instruments.begin();
97  void qsamplerInstrumentGroup::setOpen ( bool bOpen )                                  itMap != m_instruments.end(); ++itMap) {
98  {                          n += (*itMap).size();
99          // Set the proper pixmap of this...                          if (index.row() < n)
100          if (rtti() == qsamplerInstrumentList::Group) {                                  pInstr = &(*itMap)[index.row() + (*itMap).size() - n];
101                  QListViewItem::setPixmap(0, QPixmap::fromMimeSource(                  }
102                          bOpen ? "itemGroupOpen.png" : "itemGroup.png"));          } else {
103          }                  // resolve MIDI instrument map
104          // Open it up...                  InstrumentsMap::const_iterator itMap = m_instruments.find(m_iMidiMap);
105          QListViewItem::setOpen(bOpen);                  if (itMap == m_instruments.end()) return QVariant();
106                    // resolve instrument in that map
107          // All ancestors should be also visible.                  if (index.row() >= (*itMap).size()) return QVariant();
108          if (bOpen && QListViewItem::parent())                  pInstr = &(*itMap)[index.row()];
109                  QListViewItem::parent()->setOpen(true);          }
110  }  
111            if (!pInstr)
112                    return QVariant();
113  // To virtually distinguish between list view items.  
114  int qsamplerInstrumentGroup::rtti (void) const          if (role == Qt::UserRole)
115  {                  return QVariant::fromValue((void *) pInstr);
116          return qsamplerInstrumentList::Group;  
117  }          if (role == Qt::DisplayRole) {
118                    switch (index.column()) {
119                            case 0: return pInstr->name();
120  //----------------------------------------------------------------------                          case 1: return QVariant::fromValue(pInstr->map());
121  // class qsamplerInstrumentItem -- custom file list view item.                          case 2: return QVariant::fromValue(pInstr->bank());
122  //                          case 3: return QVariant::fromValue(pInstr->prog());
123                            case 4: return pInstr->engineName();
124  // Constructors.                          case 5: return pInstr->instrumentFile();
125  qsamplerInstrumentItem::qsamplerInstrumentItem (                          case 6: return QVariant::fromValue(pInstr->instrumentNr());
126          qsamplerInstrumentList *pListView,                          case 7: return QString::number(pInstr->volume() * 100.0) + " %";
127          qsamplerInstrument *pInstrument,                          case 8: {
128          QListViewItem *pItemAfter )                                  switch (pInstr->loadMode()) {
129          : qsamplerInstrumentGroup(pListView, pInstrument->name(), pItemAfter)                                          case 3: return QObject::tr("Persistent");
130  {                                          case 2: return QObject::tr("On Demand Hold");
131          m_pInstrument = pInstrument;                                          case 1: return QObject::tr("On Demand");
132                                            default: return QVariant();
133          update();                                  }
134  }                          }
135                            default: return QVariant();
136  qsamplerInstrumentItem::qsamplerInstrumentItem (                  }
137          qsamplerInstrumentGroup *pGroupItem,          }
138          qsamplerInstrument *pInstrument )  
139          : qsamplerInstrumentGroup(pGroupItem, pInstrument->name())          return QVariant();
140  {  }
141          m_pInstrument = pInstrument;  
142    
143          update();  QVariant MidiInstrumentsModel::headerData (
144  }          int section, Qt::Orientation orientation, int role ) const
145    {
146            if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
147  // Default destructor.                  return QVariant();
148  qsamplerInstrumentItem::~qsamplerInstrumentItem (void)  
149  {          switch (section) {
150          if (m_pInstrument)                  case 0: return tr("Name");
151                  delete m_pInstrument;                  case 1: return tr("Map");
152  }                  case 2: return tr("Bank");
153                    case 3: return tr("Prog");
154                    case 4: return tr("Engine");
155  // To virtually distinguish between list view items.                  case 5: return tr("File");
156  int qsamplerInstrumentItem::rtti (void) const                  case 6: return tr("Nr");
157  {                  case 7: return tr("Vol");
158          return qsamplerInstrumentList::Item;                  case 8: return tr("Mode");
159  }                  default: return QVariant();
160            }
161    }
162  // Payload accessor.  
163  qsamplerInstrument *qsamplerInstrumentItem::Instrument (void) const  
164  {  qsamplerInstrument* MidiInstrumentsModel::addInstrument (
165          return m_pInstrument;          int iMap, int iBank, int iProg )
166  }  {
167            // Check it there's already one instrument item
168            // with the very same key (bank, program);
169  // Item refreshment.          // if yes, just remove it without prejudice...
170  void qsamplerInstrumentItem::update (void)          for (int i = 0; i < m_instruments[iMap].size(); i++) {
171  {                  if (m_instruments[iMap][i].bank() == iBank &&
172          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemFile.png"));                          m_instruments[iMap][i].prog() == iProg) {
173                            m_instruments[iMap].removeAt(i);
174          const QString s = "-";                          break;
175          if (m_pInstrument) {                  }
176                  setText(0, m_pInstrument->name());          }
177                  setText(1, QString::number(m_pInstrument->bank()));  
178                  setText(2, QString::number(m_pInstrument->program()));          // Resolve the appropriate place, we keep the list sorted that way ...
179                  setText(3, m_pInstrument->engineName());          int i = 0;
180                  setText(4, QFileInfo(m_pInstrument->instrumentFile()).fileName());          for (; i < m_instruments[iMap].size(); ++i) {
181                  setText(5, QString::number(m_pInstrument->instrumentNr()));                  if (iBank < m_instruments[iMap][i].bank()
182                  setText(6, QString::number(int(m_pInstrument->volume() * 100.0f)));                          || (iBank == m_instruments[iMap][i].bank() &&
183                  QString sLoadMode = s;                                  iProg < m_instruments[iMap][i].prog())) {
184                  switch (m_pInstrument->loadMode()) {                          break;
185                  case 3:                  }
186                          sLoadMode = QObject::tr("Persistent");          }
187                          break;  
188                  case 2:          m_instruments[iMap].insert(i, qsamplerInstrument(iMap, iBank, iProg));
189                          sLoadMode = QObject::tr("On Demand Hold");          qsamplerInstrument& instr = m_instruments[iMap][i];
190                          break;          if (!instr.getInstrument())
191                  case 1:                  m_instruments[iMap].removeAt(i);
192                          sLoadMode = QObject::tr("On Demand");  
193                          break;          return &instr;
194                  }  }
195                  setText(7, sLoadMode);  
196          } else {  
197                  for (int i = 0; i < listView()->columns(); i++)  void MidiInstrumentsModel::removeInstrument (
198                          setText(i, s);          const qsamplerInstrument& instrument )
199          }  {
200  }          const int iMap  = instrument.map();
201            const int iBank = instrument.bank();
202            const int iProg = instrument.prog();
203  //----------------------------------------------------------------------------          for (int i = 0; i < m_instruments[iMap].size(); i++) {
204  // qsamplerInstrumentList -- MIDI instrument list view.                  if (m_instruments[iMap][i].bank() == iBank &&
205  //                          m_instruments[iMap][i].prog() == iProg) {
206                            m_instruments[iMap].removeAt(i);
207  // Constructor.                          break;
208  qsamplerInstrumentList::qsamplerInstrumentList (                  }
209          QWidget *pParent, const char *pszName )          }
210          : QListView(pParent, pszName)  }
211  {  
212  //  QListView::setRootIsDecorated(true);  
213          QListView::setResizeMode(QListView::NoColumn);  // Reposition the instrument in the model (called when map/bank/prg changed)
214  //      QListView::setAcceptDrops(true);  void MidiInstrumentsModel::resort ( const qsamplerInstrument& instrument )
215          QListView::setDragAutoScroll(true);  {
216          QListView::setSizePolicy(          const int iMap  = instrument.map();
217                  QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));          const int iBank = instrument.bank();
218  //      QListView::setShowToolTips(false);          const int iProg = instrument.prog();
219          QListView::setSortColumn(-1);          // Remove given instrument from its current list
220            removeInstrument(instrument);
221          QListView::addColumn(tr("Name"));          // Re-add the instrument
222          QListView::addColumn(tr("Bank"));          addInstrument(iMap, iBank, iProg);
223          QListView::addColumn(tr("Prog"));  }
224          QListView::addColumn(tr("Engine"));  
225          QListView::addColumn(tr("File"));  
226          QListView::addColumn(tr("Nr"));  void MidiInstrumentsModel::setMidiMap ( int iMidiMap )
227          QListView::addColumn(tr("Vol"));  {
228          QListView::addColumn(tr("Mode"));          if (iMidiMap < 0)
229                    iMidiMap = LSCP_MIDI_MAP_ALL;
230          QListView::setColumnAlignment(1, Qt::AlignHCenter);     // Bank  
231          QListView::setColumnAlignment(2, Qt::AlignHCenter);     // Prog          m_iMidiMap = iMidiMap;
232          QListView::setColumnAlignment(5, Qt::AlignHCenter);     // Nr  }
233          QListView::setColumnAlignment(6, Qt::AlignHCenter);     // Vol  
234    
235          QListView::setColumnWidth(0, 60);       // Name  int MidiInstrumentsModel::midiMap (void) const
236          QListView::setColumnWidth(0, 120);      // File  {
237            return m_iMidiMap;
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);  void MidiInstrumentsModel::refresh (void)
241          m_pRenameAction   = new QAction(tr("&Rename"), tr("Ctrl+R"), this);  {
242          m_pDeleteAction   = new QAction(tr("&Delete"), tr("Ctrl+D"), this);          m_instruments.clear();
243          m_pRefreshAction  = new QAction(tr("Re&fresh"), tr("Ctrl+F"), this);  
244            MainForm* pMainForm = MainForm::getInstance();
245          QObject::connect(m_pNewGroupAction,          if (pMainForm == NULL)
246                  SIGNAL(activated()),                  return;
247                  SLOT(newGroupSlot()));          if (pMainForm->client() == NULL)
248          QObject::connect(m_pNewItemAction,                  return;
249                  SIGNAL(activated()),  
250                  SLOT(newItemSlot()));          QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
251          QObject::connect(m_pEditItemAction,  
252                  SIGNAL(activated()),          // Load the whole bunch of instrument items...
253                  SLOT(editItemSlot()));          lscp_midi_instrument_t* pInstrs
254          QObject::connect(m_pRenameAction,                  = ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap);
255                  SIGNAL(activated()),          for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {
256                  SLOT(renameSlot()));                  const int iMap  = pInstrs[iInstr].map;
257          QObject::connect(m_pDeleteAction,                  const int iBank = pInstrs[iInstr].bank;
258                  SIGNAL(activated()),                  const int iProg = pInstrs[iInstr].prog;
259                  SLOT(deleteSlot()));                  addInstrument(iMap, iBank, iProg);
260          QObject::connect(m_pRefreshAction,                  // Try to keep it snappy :)
261                  SIGNAL(activated()),                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
262                  SLOT(refresh()));          }
263    
264          QObject::connect(this,          QApplication::restoreOverrideCursor();
265                  SIGNAL(selectionChanged()),  
266                  SLOT(selectionChangedSlot()));          if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) {
267          QObject::connect(this,                  pMainForm->appendMessagesClient("lscp_list_midi_instruments");
268                  SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)),                  pMainForm->appendMessagesError(
269                  SLOT(activatedSlot(QListViewItem*)));                          tr("Could not get current list of MIDI instrument mappings.\n\nSorry."));
270          QObject::connect(this,          }
271                  SIGNAL(returnPressed(QListViewItem*)),  
272                  SLOT(activatedSlot(QListViewItem*)));          // inform the outer world (QTableView) that our data changed
273          QObject::connect(this,          QAbstractTableModel::reset();
274                  SIGNAL(itemRenamed(QListViewItem*,int)),  }
275                  SLOT(renamedSlot(QListViewItem*)));  
276    
277          selectionChangedSlot();  //-------------------------------------------------------------------------
278  }  // MidiInstrumentsDelegate - table cell renderer for MIDI prog mappings
279    // (doesn't actually do anything ATM, but is already there for a future
280    // cell editor widget implementation)
281  // Default destructor.  
282  qsamplerInstrumentList::~qsamplerInstrumentList (void)  MidiInstrumentsDelegate::MidiInstrumentsDelegate ( QObject* pParent )
283  {          : QItemDelegate(pParent)
284          delete m_pNewGroupAction;  {
285          delete m_pNewItemAction;  }
286          delete m_pEditItemAction;  
287          delete m_pRenameAction;  
288          delete m_pDeleteAction;  QWidget* MidiInstrumentsDelegate::createEditor ( QWidget* pParent,
289  }          const QStyleOptionViewItem& option, const QModelIndex& index ) const
290    {
291            return QItemDelegate::createEditor(pParent, option, index);
292  // Add a new instrument item, optionally under a given group.  //      return new QLabel(index.model()->data(index, Qt::DisplayRole).toString(), parent);
293  qsamplerInstrumentItem *qsamplerInstrumentList::addItem (  }
294          qsamplerInstrument *pInstrument,  
295          qsamplerInstrumentGroup *pParentGroup )  
296  {  void MidiInstrumentsDelegate::setEditorData ( QWidget */*pEditor*/,
297          qsamplerInstrumentItem *pItem = findItem(pInstrument);          const QModelIndex& /*index*/) const
298          if (pItem == NULL) {  {
299                  if (pParentGroup)  }
300                          pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument);  
301                  else  
302                          pItem = new qsamplerInstrumentItem(this, pInstrument);  void MidiInstrumentsDelegate::setModelData ( QWidget */*pEditor*/,
303          }          QAbstractItemModel* /*model*/, const QModelIndex& /*index*/) const
304          QListView::setSelected(pItem, true);  {
305          return pItem;  }
306  }  
307    
308    void MidiInstrumentsDelegate::updateEditorGeometry ( QWidget *pEditor,
309  // Add a new instrument group, optionally under another group.          const QStyleOptionViewItem& option, const QModelIndex& index) const
310  qsamplerInstrumentGroup *qsamplerInstrumentList::addGroup (  {
311          const QString& sName, qsamplerInstrumentGroup *pParentGroup )          QItemDelegate::updateEditorGeometry(pEditor, option, index);
312  {  //      if (pEditor) pEditor->setGeometry(option.rect);
313          qsamplerInstrumentGroup *pGroup = findGroup(sName);  }
314          if (pGroup == NULL) {  
315                  if (pParentGroup)  
316                          pGroup = new qsamplerInstrumentGroup(pParentGroup, sName);  // end of qsamplerInstrumentList.cpp
                 else  
                         pGroup = new qsamplerInstrumentGroup(this, sName);  
         }  
         QListView::setSelected(pGroup, true);  
         return pGroup;  
 }  
   
   
 // Find a group item, given its name.  
 qsamplerInstrumentGroup *qsamplerInstrumentList::findGroup (  
         const QString& sName ) const  
 {  
         // Iterate all over the place to search for the group.  
         QListViewItemIterator iter((QListView *) this);  
         while (iter.current()) {  
                 QListViewItem *pItem = iter.current();  
                 if (pItem->rtti() == Group && pItem->text(0) == sName)  
                         return static_cast<qsamplerInstrumentGroup *> (pItem);  
                 ++iter;  
         }  
         // Not found.  
         return NULL;  
 }  
   
   
 // Find a file item, given its name.  
 qsamplerInstrumentItem *qsamplerInstrumentList::findItem (  
         qsamplerInstrument *pInstrument ) const  
 {  
         // Iterate all over the place to search for the group.  
         QListViewItemIterator iter((QListView *) this);  
         while (iter.current()) {  
                 QListViewItem *pListItem = iter.current();  
                 if (pListItem->rtti() == Item) {  
                         qsamplerInstrumentItem *pItem  
                                 = static_cast<qsamplerInstrumentItem *> (pListItem);  
                         if (pItem && pItem->Instrument() == pInstrument)  
                                 return pItem;  
                 }  
                 ++iter;  
         }  
         // Not found.  
         return NULL;  
 }  
   
   
 // Find and return the nearest group item...  
 qsamplerInstrumentGroup *qsamplerInstrumentList::groupItem (  
         QListViewItem *pItem ) const  
 {  
         while (pItem && pItem->rtti() != Group)  
                 pItem = pItem->parent();  
         return static_cast<qsamplerInstrumentGroup *> (pItem);  
 }  
   
   
 // Add a new group item below the current one.  
 void qsamplerInstrumentList::newGroupSlot (void)  
 {  
         qsamplerInstrumentGroup *pParentGroup  
                 = groupItem(QListView::selectedItem());  
         qsamplerInstrumentGroup *pNewGroup  
                 = addGroup(tr("New Group"), pParentGroup);  
         if (pParentGroup)  
                 pParentGroup->setOpen(true);  
         if (pNewGroup)  
                 pNewGroup->startRename(0);  
   
         selectionChangedSlot();  
 }  
   
   
 // Add a new instrument item below the current one.  
 void qsamplerInstrumentList::newItemSlot (void)  
 {  
         qsamplerInstrument *pInstrument = new qsamplerInstrument();  
   
         qsamplerInstrumentForm form(this);  
         form.setup(pInstrument);  
         if (!form.exec()) {  
                 delete pInstrument;  
                 return;  
         }  
   
         pInstrument->map();  
         emit instrumentsChanged();  
   
         qsamplerInstrumentGroup *pParentGroup  
                 = groupItem(QListView::selectedItem());  
         addItem(pInstrument, pParentGroup);  
         if (pParentGroup)  
                 pParentGroup->setOpen(true);  
   
         selectionChangedSlot();  
 }  
   
   
 // Edit current item below the current one.  
 void qsamplerInstrumentList::editItemSlot (void)  
 {  
         QListViewItem *pListItem = QListView::selectedItem();  
         if (pListItem == NULL)  
                 return;  
         if (pListItem->rtti() == Item) {  
                 qsamplerInstrumentItem *pItem  
                         = static_cast<qsamplerInstrumentItem *> (pListItem);  
                 if (pItem && pItem->Instrument()) {  
                         qsamplerInstrumentForm form(this);  
                         form.setup(pItem->Instrument());  
                         if (form.exec()) {  
                                 pItem->Instrument()->map();  
                                 emit instrumentsChanged();  
                                 pItem->update();  
                         }  
                 }  
         }  
   
         selectionChangedSlot();  
 }  
   
   
 // Rename current group/item.  
 void qsamplerInstrumentList::renameSlot (void)  
 {  
         QListViewItem *pListItem = QListView::selectedItem();  
         if (pListItem)  
                 pListItem->startRename(0);  
   
         selectionChangedSlot();  
 }  
   
   
 // Remove current group/item.  
 void qsamplerInstrumentList::deleteSlot (void)  
 {  
         QListViewItem *pListItem = QListView::selectedItem();  
         if (pListItem) {  
                 if (pListItem->rtti() == Item) {  
                         qsamplerInstrumentItem *pItem  
                                 = static_cast<qsamplerInstrumentItem *> (pListItem);  
                         if (pItem && pItem->Instrument()) {  
                                 pItem->Instrument()->unmap();  
                                 emit instrumentsChanged();  
                         }  
                 }  
                 delete pListItem;  
         }  
   
         selectionChangedSlot();  
 }  
   
   
 // In-place selection slot.  
 void qsamplerInstrumentList::selectionChangedSlot (void)  
 {  
         qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();  
         QListViewItem *pListItem = QListView::selectedItem();  
         bool bEnabled = (pMainForm && pMainForm->client());  
         m_pNewItemAction->setEnabled(bEnabled);  
         bEnabled = (bEnabled && pListItem != NULL);  
         m_pEditItemAction->setEnabled(bEnabled && pListItem->rtti() == Item);  
         m_pRenameAction->setEnabled(bEnabled);  
         m_pDeleteAction->setEnabled(bEnabled);  
 }  
   
   
 // In-place activation slot.  
 void qsamplerInstrumentList::activatedSlot ( QListViewItem *pListItem )  
 {  
         // FIXME: Hope the list view item is the one selected.  
         if (pListItem->rtti() == Item)  
                 editItemSlot();  
 }  
   
   
 // In-place aliasing slot.  
 void qsamplerInstrumentList::renamedSlot ( QListViewItem *pListItem )  
 {  
         if (pListItem->rtti() == Item) {  
                 qsamplerInstrumentItem *pItem  
                         = static_cast<qsamplerInstrumentItem *> (pListItem);  
                 if (pItem && pItem->Instrument()) {  
                         pItem->Instrument()->setName(pListItem->text(0));  
                         pItem->Instrument()->map();  
                         emit instrumentsChanged();  
                         pItem->update();  
                 }  
         }  
 }  
   
   
 // Context menu request event handler.  
 void qsamplerInstrumentList::contextMenuEvent (  
         QContextMenuEvent *pContextMenuEvent )  
 {  
         QPopupMenu menu(this);  
   
         // Construct context menu.  
         m_pNewItemAction->addTo(&menu);  
 //      m_pNewGroupAction->addTo(&menu);  
         menu.insertSeparator();  
         m_pEditItemAction->addTo(&menu);  
         m_pRenameAction->addTo(&menu);  
         m_pDeleteAction->addTo(&menu);  
         menu.insertSeparator();  
         m_pRefreshAction->addTo(&menu);  
   
         menu.exec(pContextMenuEvent->globalPos());  
 }  
   
   
 // General reloader.  
 void qsamplerInstrumentList::refresh (void)  
 {  
         clear();  
   
         qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();  
         if (pMainForm == NULL)  
                 return;  
         if (pMainForm->client() == NULL)  
                 return;  
   
         qsamplerInstrumentItem *pItem = NULL;  
         lscp_midi_instrument_t *pInstrs  
                 = ::lscp_list_midi_instruments(pMainForm->client());  
         for (int iInstr = 0; pInstrs && pInstrs[iInstr].program >= 0; ++iInstr) {  
                 int iBank = (pInstrs[iInstr].bank_msb << 7) | pInstrs[iInstr].bank_lsb;  
                 int iProgram = pInstrs[iInstr].program;  
                 qsamplerInstrument *pInstrument  
                         = new qsamplerInstrument(iBank, iProgram);  
                 if (pInstrument->get())  
                         pItem = new qsamplerInstrumentItem(this, pInstrument, pItem);  
         }  
   
         if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) {  
                 pMainForm->appendMessagesClient("lscp_list_midi_instruments");  
                 pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry."));  
         }  
   
         selectionChangedSlot();  
 }  
   
   
 // end of qsamplerInstrumentList.cpp  
   

Legend:
Removed from v.962  
changed lines
  Added in v.1523

  ViewVC Help
Powered by ViewVC