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

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

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

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

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

  ViewVC Help
Powered by ViewVC