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

Legend:
Removed from v.980  
changed lines
  Added in v.1499

  ViewVC Help
Powered by ViewVC