/[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 2064 by capela, Fri Mar 12 16:02:32 2010 UTC revision 2071 by capela, Mon Mar 15 18:21:28 2010 UTC
# Line 39  namespace QSampler { Line 39  namespace QSampler {
39  //  //
40    
41  InstrumentListModel::InstrumentListModel ( QObject *pParent )  InstrumentListModel::InstrumentListModel ( QObject *pParent )
42          : QAbstractItemModel(pParent)          : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL)
43  {  {
44          m_iMidiMap = LSCP_MIDI_MAP_ALL;  //      QAbstractItemModel::reset();
   
         QAbstractItemModel::reset();  
45  }  }
46    
47  InstrumentListModel::~InstrumentListModel (void)  InstrumentListModel::~InstrumentListModel (void)
# Line 81  QVariant InstrumentListModel::data ( Line 79  QVariant InstrumentListModel::data (
79  {  {
80          if (!index.isValid())          if (!index.isValid())
81                  return QVariant();                  return QVariant();
   
82          const Instrument *pInstr          const Instrument *pInstr
83                  = static_cast<Instrument *> (index.internalPointer());                  = static_cast<Instrument *> (index.internalPointer());
84    
# Line 132  QModelIndex InstrumentListModel::index ( Line 129  QModelIndex InstrumentListModel::index (
129                  InstrumentMap::const_iterator itMap     = m_instruments.find(m_iMidiMap);                  InstrumentMap::const_iterator itMap     = m_instruments.find(m_iMidiMap);
130                  if (itMap != m_instruments.constEnd()) {                  if (itMap != m_instruments.constEnd()) {
131                          const InstrumentList& list = *itMap;                          const InstrumentList& list = *itMap;
                         // resolve instrument in that map  
132                          if (row < list.size())                          if (row < list.size())
133                                  pInstr = list.at(row);                                  pInstr = list.at(row);
134                  }                  }
# Line 145  QModelIndex InstrumentListModel::index ( Line 141  QModelIndex InstrumentListModel::index (
141  }  }
142    
143    
144  QModelIndex InstrumentListModel::parent ( const QModelIndex& child ) const  QModelIndex InstrumentListModel::parent ( const QModelIndex& /*child*/ ) const
145  {  {
146          return QModelIndex();          return QModelIndex();
147  }  }
# Line 194  const Instrument *InstrumentListModel::a Line 190  const Instrument *InstrumentListModel::a
190          // with the very same key (bank, program);          // with the very same key (bank, program);
191          // if yes, just remove it without prejudice...          // if yes, just remove it without prejudice...
192          InstrumentList& list = m_instruments[iMap];          InstrumentList& list = m_instruments[iMap];
193          for (int i = 0; i < list.size(); ++i) {  
194            int i = 0;
195            for ( ; i < list.size(); ++i) {
196                  const Instrument *pInstr = list.at(i);                  const Instrument *pInstr = list.at(i);
197                  if (pInstr->bank() == iBank && pInstr->prog() == iProg) {                  if (pInstr->bank() == iBank && pInstr->prog() == iProg) {
198                          delete pInstr;                          delete pInstr;
# Line 204  const Instrument *InstrumentListModel::a Line 202  const Instrument *InstrumentListModel::a
202          }          }
203    
204          // Resolve the appropriate place, we keep the list sorted that way...          // Resolve the appropriate place, we keep the list sorted that way...
205          int i = 0;          for (i = 0; i < list.size(); ++i) {
         for ( ; i < list.size(); ++i) {  
206                  const Instrument *pInstr = list.at(i);                  const Instrument *pInstr = list.at(i);
207                  if (iBank < pInstr->bank()                  if (iBank < pInstr->bank()
208                          || (iBank == pInstr->bank() && iProg < pInstr->prog())) {                          || (iBank == pInstr->bank() && iProg < pInstr->prog())) {
# Line 225  const Instrument *InstrumentListModel::a Line 222  const Instrument *InstrumentListModel::a
222  }  }
223    
224    
225  void InstrumentListModel::removeInstrument ( const Instrument *pInstrument )  void InstrumentListModel::removeInstrument ( Instrument *pInstrument )
226  {  {
227          const int iMap  = pInstrument->map();          const int iMap = pInstrument->map();
         const int iBank = pInstrument->bank();  
         const int iProg = pInstrument->prog();  
228    
229          if (m_instruments.contains(iMap)) {          if (m_instruments.contains(iMap)) {
230                  InstrumentList& list = m_instruments[iMap];                  InstrumentList& list = m_instruments[iMap];
231                  for (int i = 0; i < list.size(); ++i) {                  for (int i = 0; i < list.size(); ++i) {
232                          const Instrument *pInstr = list.at(i);                          if (pInstrument == list.at(i)) {
233                          if (pInstr->bank() == iBank && pInstr->prog() == iProg) {                                  delete pInstrument;
                                 delete pInstr;  
234                                  list.removeAt(i);                                  list.removeAt(i);
235                                  break;                                  break;
236                          }                          }
# Line 245  void InstrumentListModel::removeInstrume Line 239  void InstrumentListModel::removeInstrume
239  }  }
240    
241    
242    void InstrumentListModel::updateInstrument ( Instrument *pInstrument )
243    {
244            pInstrument->getInstrument();
245    }
246    
247    
248  // Reposition the instrument in the model (called when map/bank/prg changed)  // Reposition the instrument in the model (called when map/bank/prg changed)
249  void InstrumentListModel::updateInstrument ( const Instrument *pInstrument )  void InstrumentListModel::resortInstrument ( Instrument *pInstrument )
250  {  {
251          const int iMap  = pInstrument->map();          const int iMap  = pInstrument->map();
252          const int iBank = pInstrument->bank();          const int iBank = pInstrument->bank();
# Line 335  InstrumentListView::InstrumentListView ( Line 335  InstrumentListView::InstrumentListView (
335          m_pListModel = new InstrumentListModel(this);          m_pListModel = new InstrumentListModel(this);
336    
337          QTreeView::setModel(m_pListModel);          QTreeView::setModel(m_pListModel);
338    
339            QTreeView::setRootIsDecorated(false);
340            QTreeView::setUniformRowHeights(true);
341            QTreeView::setAlternatingRowColors(true);
342            QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows);
343            QTreeView::setSelectionMode(QAbstractItemView::SingleSelection);
344            QTreeView::setItemsExpandable(false);
345    
346            QHeaderView *pHeader = QTreeView::header();
347            pHeader->setDefaultAlignment(Qt::AlignLeft);
348            pHeader->setMovable(false);
349            pHeader->setStretchLastSection(true);
350            pHeader->resizeSection(0, 120);                 // Name
351            QTreeView::resizeColumnToContents(1);   // Map
352            QTreeView::resizeColumnToContents(2);   // Bank
353            QTreeView::resizeColumnToContents(3);   // Prog
354            QTreeView::resizeColumnToContents(4);   // Engine
355            pHeader->resizeSection(5, 240);                 // File
356            QTreeView::resizeColumnToContents(6);   // Nr
357            pHeader->resizeSection(7, 60);                  // Vol
358  }  }
359    
360    
# Line 369  const Instrument *InstrumentListView::ad Line 389  const Instrument *InstrumentListView::ad
389  }  }
390    
391    
392  void InstrumentListView::removeInstrument ( const Instrument *pInstrument )  void InstrumentListView::removeInstrument ( Instrument *pInstrument )
393  {  {
394          m_pListModel->beginReset();          m_pListModel->beginReset();
395          m_pListModel->removeInstrument(pInstrument);          m_pListModel->removeInstrument(pInstrument);
# Line 377  void InstrumentListView::removeInstrumen Line 397  void InstrumentListView::removeInstrumen
397  }  }
398    
399    
400  // Reposition the instrument in the model (called when map/bank/prg changed)  void InstrumentListView::updateInstrument ( Instrument *pInstrument )
 void InstrumentListView::updateInstrument ( const Instrument *pInstrument )  
401  {  {
402          m_pListModel->beginReset();          m_pListModel->beginReset();
403          m_pListModel->updateInstrument(pInstrument);          m_pListModel->updateInstrument(pInstrument);
404          m_pListModel->endReset();}          m_pListModel->endReset();
405    }
406    
407    
408    // Reposition the instrument in the model (called when map/bank/prg changed)
409    void InstrumentListView::resortInstrument ( Instrument *pInstrument )
410    {
411            m_pListModel->beginReset();
412            m_pListModel->resortInstrument(pInstrument);
413            m_pListModel->endReset();
414    }
415    
416    
417  // Refreshener.  // Refreshener.

Legend:
Removed from v.2064  
changed lines
  Added in v.2071

  ViewVC Help
Powered by ViewVC