/[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 2387 by capela, Sat Dec 29 00:21:11 2012 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-2012, 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 41  namespace QSampler { Line 42  namespace QSampler {
42  InstrumentListModel::InstrumentListModel ( QObject *pParent )  InstrumentListModel::InstrumentListModel ( QObject *pParent )
43          : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL)          : QAbstractItemModel(pParent), m_iMidiMap(LSCP_MIDI_MAP_ALL)
44  {  {
45          QAbstractItemModel::reset();  //      QAbstractItemModel::reset();
46  }  }
47    
48  InstrumentListModel::~InstrumentListModel (void)  InstrumentListModel::~InstrumentListModel (void)
# Line 79  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 130  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 192  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 202  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 223  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 243  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 339  InstrumentListView::InstrumentListView ( Line 342  InstrumentListView::InstrumentListView (
342          QTreeView::setAlternatingRowColors(true);          QTreeView::setAlternatingRowColors(true);
343          QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows);          QTreeView::setSelectionBehavior(QAbstractItemView::SelectRows);
344          QTreeView::setSelectionMode(QAbstractItemView::SingleSelection);          QTreeView::setSelectionMode(QAbstractItemView::SingleSelection);
345                    QTreeView::setItemsExpandable(false);
346    
347          QHeaderView *pHeader = QTreeView::header();          QHeaderView *pHeader = QTreeView::header();
348          pHeader->setDefaultAlignment(Qt::AlignLeft);          pHeader->setDefaultAlignment(Qt::AlignLeft);
349    #if QT_VERSION < 0x050000
350          pHeader->setMovable(false);          pHeader->setMovable(false);
351    #endif
352          pHeader->setStretchLastSection(true);          pHeader->setStretchLastSection(true);
353          pHeader->resizeSection(0, 120);                 // Name          pHeader->resizeSection(0, 120);                 // Name
354          QTreeView::resizeColumnToContents(1);   // Map          QTreeView::resizeColumnToContents(1);   // Map
# Line 386  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 394  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.2065  
changed lines
  Added in v.2387

  ViewVC Help
Powered by ViewVC