/[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 2065 by capela, Sat Mar 13 12:44:15 2010 UTC revision 2071 by capela, Mon Mar 15 18:21:28 2010 UTC
# Line 41  namespace QSampler { Line 41  namespace QSampler {
41  InstrumentListModel::InstrumentListModel ( QObject *pParent )  InstrumentListModel::InstrumentListModel ( QObject *pParent )
42          : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL)          : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL)
43  {  {
44          QAbstractItemModel::reset();  //      QAbstractItemModel::reset();
45  }  }
46    
47  InstrumentListModel::~InstrumentListModel (void)  InstrumentListModel::~InstrumentListModel (void)
# Line 79  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 130  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 192  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 202  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 223  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 243  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 339  InstrumentListView::InstrumentListView ( Line 341  InstrumentListView::InstrumentListView (
341          QTreeView::setAlternatingRowColors(true);          QTreeView::setAlternatingRowColors(true);
342          QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows);          QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows);
343          QTreeView::setSelectionMode(QAbstractItemView::SingleSelection);          QTreeView::setSelectionMode(QAbstractItemView::SingleSelection);
344                    QTreeView::setItemsExpandable(false);
345    
346          QHeaderView *pHeader = QTreeView::header();          QHeaderView *pHeader = QTreeView::header();
347          pHeader->setDefaultAlignment(Qt::AlignLeft);          pHeader->setDefaultAlignment(Qt::AlignLeft);
348          pHeader->setMovable(false);          pHeader->setMovable(false);
# Line 386  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 394  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.2065  
changed lines
  Added in v.2071

  ViewVC Help
Powered by ViewVC