/[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 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-2010, 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     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 29  Line 29 
29  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
30    
31  #include <QApplication>  #include <QApplication>
32    #include <QHeaderView>
33  #include <QCursor>  #include <QCursor>
34    
35    
# Line 39  namespace QSampler { Line 40  namespace QSampler {
40  //  //
41    
42  InstrumentListModel::InstrumentListModel ( QObject *pParent )  InstrumentListModel::InstrumentListModel ( QObject *pParent )
43          : QAbstractItemModel(pParent)          : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL)
44  {  {
45          m_iMidiMap = LSCP_MIDI_MAP_ALL;  //      QAbstractItemModel::reset();
   
         QAbstractItemModel::reset();  
46  }  }
47    
48  InstrumentListModel::~InstrumentListModel (void)  InstrumentListModel::~InstrumentListModel (void)
# Line 81  QVariant InstrumentListModel::data ( Line 80  QVariant InstrumentListModel::data (
80  {  {
81          if (!index.isValid())          if (!index.isValid())
82                  return QVariant();                  return QVariant();
   
83          const Instrument *pInstr          const Instrument *pInstr
84                  = static_cast<Instrument *> (index.internalPointer());                  = static_cast<Instrument *> (index.internalPointer());
85    
# Line 132  QModelIndex InstrumentListModel::index ( Line 130  QModelIndex InstrumentListModel::index (
130                  InstrumentMap::const_iterator itMap     = m_instruments.find(m_iMidiMap);                  InstrumentMap::const_iterator itMap     = m_instruments.find(m_iMidiMap);
131                  if (itMap != m_instruments.constEnd()) {                  if (itMap != m_instruments.constEnd()) {
132                          const InstrumentList& list = *itMap;                          const InstrumentList& list = *itMap;
                         // resolve instrument in that map  
133                          if (row < list.size())                          if (row < list.size())
134                                  pInstr = list.at(row);                                  pInstr = list.at(row);
135                  }                  }
# Line 145  QModelIndex InstrumentListModel::index ( Line 142  QModelIndex InstrumentListModel::index (
142  }  }
143    
144    
145  QModelIndex InstrumentListModel::parent ( const QModelIndex& child ) const  QModelIndex InstrumentListModel::parent ( const QModelIndex& /*child*/ ) const
146  {  {
147          return QModelIndex();          return QModelIndex();
148  }  }
# Line 194  const Instrument *InstrumentListModel::a Line 191  const Instrument *InstrumentListModel::a
191          // with the very same key (bank, program);          // with the very same key (bank, program);
192          // if yes, just remove it without prejudice...          // if yes, just remove it without prejudice...
193          InstrumentList& list = m_instruments[iMap];          InstrumentList& list = m_instruments[iMap];
194          for (int i = 0; i < list.size(); ++i) {  
195            int i = 0;
196            for ( ; i < list.size(); ++i) {
197                  const Instrument *pInstr = list.at(i);                  const Instrument *pInstr = list.at(i);
198                  if (pInstr->bank() == iBank && pInstr->prog() == iProg) {                  if (pInstr->bank() == iBank && pInstr->prog() == iProg) {
199                          delete pInstr;                          delete pInstr;
# Line 204  const Instrument *InstrumentListModel::a Line 203  const Instrument *InstrumentListModel::a
203          }          }
204    
205          // Resolve the appropriate place, we keep the list sorted that way...          // Resolve the appropriate place, we keep the list sorted that way...
206          int i = 0;          for (i = 0; i < list.size(); ++i) {
         for ( ; i < list.size(); ++i) {  
207                  const Instrument *pInstr = list.at(i);                  const Instrument *pInstr = list.at(i);
208                  if (iBank < pInstr->bank()                  if (iBank < pInstr->bank()
209                          || (iBank == pInstr->bank() && iProg < pInstr->prog())) {                          || (iBank == pInstr->bank() && iProg < pInstr->prog())) {
# Line 225  const Instrument *InstrumentListModel::a Line 223  const Instrument *InstrumentListModel::a
223  }  }
224    
225    
226  void InstrumentListModel::removeInstrument ( const Instrument *pInstrument )  void InstrumentListModel::removeInstrument ( Instrument *pInstrument )
227  {  {
228          const int iMap  = pInstrument->map();          const int iMap = pInstrument->map();
         const int iBank = pInstrument->bank();  
         const int iProg = pInstrument->prog();  
229    
230          if (m_instruments.contains(iMap)) {          if (m_instruments.contains(iMap)) {
231                  InstrumentList& list = m_instruments[iMap];                  InstrumentList& list = m_instruments[iMap];
232                  for (int i = 0; i < list.size(); ++i) {                  for (int i = 0; i < list.size(); ++i) {
233                          const Instrument *pInstr = list.at(i);                          if (pInstrument == list.at(i)) {
234                          if (pInstr->bank() == iBank && pInstr->prog() == iProg) {                                  delete pInstrument;
                                 delete pInstr;  
235                                  list.removeAt(i);                                  list.removeAt(i);
236                                  break;                                  break;
237                          }                          }
# Line 245  void InstrumentListModel::removeInstrume Line 240  void InstrumentListModel::removeInstrume
240  }  }
241    
242    
243    void InstrumentListModel::updateInstrument ( Instrument *pInstrument )
244    {
245            pInstrument->getInstrument();
246    }
247    
248    
249  // Reposition the instrument in the model (called when map/bank/prg changed)  // Reposition the instrument in the model (called when map/bank/prg changed)
250  void InstrumentListModel::updateInstrument ( const Instrument *pInstrument )  void InstrumentListModel::resortInstrument ( Instrument *pInstrument )
251  {  {
252          const int iMap  = pInstrument->map();          const int iMap  = pInstrument->map();
253          const int iBank = pInstrument->bank();          const int iBank = pInstrument->bank();
# Line 335  InstrumentListView::InstrumentListView ( Line 336  InstrumentListView::InstrumentListView (
336          m_pListModel = new InstrumentListModel(this);          m_pListModel = new InstrumentListModel(this);
337    
338          QTreeView::setModel(m_pListModel);          QTreeView::setModel(m_pListModel);
339    
340            QTreeView::setRootIsDecorated(false);
341            QTreeView::setUniformRowHeights(true);
342            QTreeView::setAlternatingRowColors(true);
343            QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows);
344            QTreeView::setSelectionMode(QAbstractItemView::SingleSelection);
345            QTreeView::setItemsExpandable(false);
346    
347            QHeaderView *pHeader = QTreeView::header();
348            pHeader->setDefaultAlignment(Qt::AlignLeft);
349    #if QT_VERSION < 0x050000
350            pHeader->setMovable(false);
351    #endif
352            pHeader->setStretchLastSection(true);
353            pHeader->resizeSection(0, 120);                 // Name
354            QTreeView::resizeColumnToContents(1);   // Map
355            QTreeView::resizeColumnToContents(2);   // Bank
356            QTreeView::resizeColumnToContents(3);   // Prog
357            QTreeView::resizeColumnToContents(4);   // Engine
358            pHeader->resizeSection(5, 240);                 // File
359            QTreeView::resizeColumnToContents(6);   // Nr
360            pHeader->resizeSection(7, 60);                  // Vol
361  }  }
362    
363    
# Line 369  const Instrument *InstrumentListView::ad Line 392  const Instrument *InstrumentListView::ad
392  }  }
393    
394    
395  void InstrumentListView::removeInstrument ( const Instrument *pInstrument )  void InstrumentListView::removeInstrument ( Instrument *pInstrument )
396  {  {
397          m_pListModel->beginReset();          m_pListModel->beginReset();
398          m_pListModel->removeInstrument(pInstrument);          m_pListModel->removeInstrument(pInstrument);
# Line 377  void InstrumentListView::removeInstrumen Line 400  void InstrumentListView::removeInstrumen
400  }  }
401    
402    
403  // Reposition the instrument in the model (called when map/bank/prg changed)  void InstrumentListView::updateInstrument ( Instrument *pInstrument )
 void InstrumentListView::updateInstrument ( const Instrument *pInstrument )  
404  {  {
405          m_pListModel->beginReset();          m_pListModel->beginReset();
406          m_pListModel->updateInstrument(pInstrument);          m_pListModel->updateInstrument(pInstrument);
407          m_pListModel->endReset();}          m_pListModel->endReset();
408    }
409    
410    
411    // Reposition the instrument in the model (called when map/bank/prg changed)
412    void InstrumentListView::resortInstrument ( Instrument *pInstrument )
413    {
414            m_pListModel->beginReset();
415            m_pListModel->resortInstrument(pInstrument);
416            m_pListModel->endReset();
417    }
418    
419    
420  // Refreshener.  // Refreshener.

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

  ViewVC Help
Powered by ViewVC