/[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 987 by capela, Tue Dec 19 11:19:55 2006 UTC revision 1013 by capela, Mon Jan 8 16:52:48 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    
6     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 225  qsamplerInstrumentList::qsamplerInstrume Line 225  qsamplerInstrumentList::qsamplerInstrume
225          QWidget *pParent, const char *pszName )          QWidget *pParent, const char *pszName )
226          : QListView(pParent, pszName)          : QListView(pParent, pszName)
227  {  {
228            m_iMidiMap = LSCP_MIDI_MAP_ALL;
229    
230  //  QListView::setRootIsDecorated(true);  //  QListView::setRootIsDecorated(true);
231            QListView::setAllColumnsShowFocus(true);
232          QListView::setResizeMode(QListView::NoColumn);          QListView::setResizeMode(QListView::NoColumn);
233  //      QListView::setAcceptDrops(true);  //      QListView::setAcceptDrops(true);
234          QListView::setDragAutoScroll(true);          QListView::setDragAutoScroll(true);
# Line 253  qsamplerInstrumentList::qsamplerInstrume Line 256  qsamplerInstrumentList::qsamplerInstrume
256          QListView::setColumnWidth(0, 120);      // Name          QListView::setColumnWidth(0, 120);      // Name
257          QListView::setColumnWidth(5, 240);      // File          QListView::setColumnWidth(5, 240);      // File
258    
259          m_pNewGroupAction = new QAction(tr("New &Group"), tr("Ctrl+G"), this);          m_pNewGroupAction = new QAction(
260          m_pNewItemAction  = new QAction(tr("New &Instrument..."), tr("Ins"), this);                  QIconSet(QPixmap::fromMimeSource("itemGroupNew.png")),
261          m_pEditItemAction = new QAction(tr("&Edit..."), tr("Enter"), this);                  tr("New &Group"), tr("Ctrl+G"), this);
262            m_pNewItemAction  = new QAction(
263                    QIconSet(QPixmap::fromMimeSource("itemNew.png")),
264                    tr("New &Instrument..."), tr("Ins"), this);
265            m_pEditItemAction = new QAction(
266                    QIconSet(QPixmap::fromMimeSource("formEdit.png")),
267                    tr("&Edit..."), tr("Enter"), this);
268          m_pRenameAction   = new QAction(tr("&Rename"), tr("F2"), this);          m_pRenameAction   = new QAction(tr("&Rename"), tr("F2"), this);
269          m_pDeleteAction   = new QAction(tr("&Delete"), tr("Del"), this);          m_pDeleteAction   = new QAction(
270          m_pRefreshAction  = new QAction(tr("Re&fresh"), tr("F5"), this);                  QIconSet(QPixmap::fromMimeSource("formRemove.png")),
271                    tr("&Delete"), tr("Del"), this);
272            m_pRefreshAction  = new QAction(
273                    QIconSet(QPixmap::fromMimeSource("formRefresh.png")),
274                    tr("Re&fresh"), tr("F5"), this);
275    
276            m_pNewGroupAction->setToolTip(tr("New Group"));
277            m_pNewItemAction->setToolTip(tr("New Instrument"));
278            m_pEditItemAction->setToolTip(tr("Edit"));
279            m_pRenameAction->setToolTip(tr("Rename"));
280            m_pDeleteAction->setToolTip(tr("Delete"));
281            m_pRefreshAction->setToolTip(tr("Refresh"));
282    
283          QObject::connect(m_pNewGroupAction,          QObject::connect(m_pNewGroupAction,
284                  SIGNAL(activated()),                  SIGNAL(activated()),
# Line 312  qsamplerInstrumentItem *qsamplerInstrume Line 332  qsamplerInstrumentItem *qsamplerInstrume
332          qsamplerInstrument *pInstrument,          qsamplerInstrument *pInstrument,
333          qsamplerInstrumentGroup *pParentGroup )          qsamplerInstrumentGroup *pParentGroup )
334  {  {
335            // Check it there's already one instrument item
336            // with the very same key (bank, program);
337            // if yes, just remove it without prejudice...
338          qsamplerInstrumentItem *pItem = findItem(pInstrument);          qsamplerInstrumentItem *pItem = findItem(pInstrument);
339          if (pItem == NULL) {          if (pItem)
340                  if (pParentGroup)                  delete pItem;
341                          pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument);  
342                  else          // Add the new item under proper group one, if any...
343                          pItem = new qsamplerInstrumentItem(this, pInstrument);          if (pParentGroup) {
344                    pParentGroup->setOpen(true);
345                    pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument);
346            } else {
347                    pItem = new qsamplerInstrumentItem(this, pInstrument);
348          }          }
349    
350            // Set it as current selection...
351          QListView::setSelected(pItem, true);          QListView::setSelected(pItem, true);
352    
353          return pItem;          return pItem;
354  }  }
355    
# Line 330  qsamplerInstrumentGroup *qsamplerInstrum Line 360  qsamplerInstrumentGroup *qsamplerInstrum
360  {  {
361          qsamplerInstrumentGroup *pGroup = findGroup(sName);          qsamplerInstrumentGroup *pGroup = findGroup(sName);
362          if (pGroup == NULL) {          if (pGroup == NULL) {
363                  if (pParentGroup)                  if (pParentGroup) {
364                            pParentGroup->setOpen(true);
365                          pGroup = new qsamplerInstrumentGroup(pParentGroup, sName);                          pGroup = new qsamplerInstrumentGroup(pParentGroup, sName);
366                  else                  } else {
367                          pGroup = new qsamplerInstrumentGroup(this, sName);                          pGroup = new qsamplerInstrumentGroup(this, sName);
368                    }
369          }          }
370          QListView::setSelected(pGroup, true);          QListView::setSelected(pGroup, true);
371          return pGroup;          return pGroup;
# Line 397  qsamplerInstrumentGroup *qsamplerInstrum Line 429  qsamplerInstrumentGroup *qsamplerInstrum
429  // Add a new group item below the current one.  // Add a new group item below the current one.
430  void qsamplerInstrumentList::newGroupSlot (void)  void qsamplerInstrumentList::newGroupSlot (void)
431  {  {
         qsamplerInstrumentGroup *pParentGroup  
                 = groupItem(QListView::selectedItem());  
432          qsamplerInstrumentGroup *pNewGroup          qsamplerInstrumentGroup *pNewGroup
433                  = addGroup(tr("New Group"), pParentGroup);                  = addGroup(tr("New Group"), groupItem(QListView::selectedItem()));
         if (pParentGroup)  
                 pParentGroup->setOpen(true);  
434          if (pNewGroup)          if (pNewGroup)
435                  pNewGroup->startRename(0);                  pNewGroup->startRename(0);
436    
# Line 410  void qsamplerInstrumentList::newGroupSlo Line 438  void qsamplerInstrumentList::newGroupSlo
438  }  }
439    
440    
441    // Map selector.
442    void qsamplerInstrumentList::setMidiMap ( int iMidiMap )
443    {
444            if (iMidiMap < 0)
445                    iMidiMap = LSCP_MIDI_MAP_ALL;
446    
447            m_iMidiMap = iMidiMap;
448    }
449    
450    int qsamplerInstrumentList::midiMap (void) const
451    {
452            return m_iMidiMap;
453    }
454    
455    
456    // List actions accessors.
457    QAction *qsamplerInstrumentList::newGroupAction (void) const
458    {
459            return m_pNewGroupAction;
460    }
461    
462    QAction *qsamplerInstrumentList::newItemAction (void) const
463    {
464            return m_pNewItemAction;
465    }
466    
467    QAction *qsamplerInstrumentList::editItemAction (void) const
468    {
469            return m_pEditItemAction;
470    }
471    
472    QAction *qsamplerInstrumentList::renameAction (void) const
473    {
474            return m_pRenameAction;
475    }
476    
477    QAction *qsamplerInstrumentList::deleteAction (void) const
478    {
479            return m_pDeleteAction;
480    }
481    
482    QAction *qsamplerInstrumentList::refreshAction (void) const
483    {
484            return m_pRefreshAction;
485    }
486    
487    
488  // Add a new instrument item below the current one.  // Add a new instrument item below the current one.
489  void qsamplerInstrumentList::newItemSlot (void)  void qsamplerInstrumentList::newItemSlot (void)
490  {  {
# Line 422  void qsamplerInstrumentList::newItemSlot Line 497  void qsamplerInstrumentList::newItemSlot
497                  return;                  return;
498          }          }
499    
500          // Check it there's already one instrument item          // Commit...
         // with the very same key (bank, program);  
         // if yes, just remove it without prejudice...  
         qsamplerInstrumentItem *pItem = findItem(pInstrument);  
         if (pItem)  
                 delete pItem;  
   
501          pInstrument->mapInstrument();          pInstrument->mapInstrument();
502            // add new item to the tree...
503            addItem(pInstrument, groupItem(QListView::selectedItem()));
504            // Notify we've changes...
505          emit instrumentsChanged();          emit instrumentsChanged();
506    
         qsamplerInstrumentGroup *pParentGroup  
                 = groupItem(QListView::selectedItem());  
         addItem(pInstrument, pParentGroup);  
         if (pParentGroup)  
                 pParentGroup->setOpen(true);  
   
507          selectionChangedSlot();          selectionChangedSlot();
508  }  }
509    
# Line 449  void qsamplerInstrumentList::editItemSlo Line 515  void qsamplerInstrumentList::editItemSlo
515          if (pListItem == NULL)          if (pListItem == NULL)
516                  return;                  return;
517          if (pListItem->rtti() == Item) {          if (pListItem->rtti() == Item) {
518                    qsamplerInstrument *pInstrument = NULL;
519                  qsamplerInstrumentItem *pItem                  qsamplerInstrumentItem *pItem
520                          = static_cast<qsamplerInstrumentItem *> (pListItem);                          = static_cast<qsamplerInstrumentItem *> (pListItem);
521                  if (pItem && pItem->instrument()) {                  if (pItem)
522                            pInstrument = pItem->instrument();
523                    if (pInstrument) {
524                            // Save current key values...
525                            int iMap  = pInstrument->map();
526                            int iBank = pInstrument->bank();
527                            int iProg = pInstrument->prog();
528                            // Do the edit dance...
529                          qsamplerInstrumentForm form(this);                          qsamplerInstrumentForm form(this);
530                          form.setup(pItem->instrument());                          form.setup(pInstrument);
531                          if (form.exec()) {                          if (form.exec()) {
532                                  pItem->instrument()->mapInstrument();                                  // Commit...
533                                    pInstrument->mapInstrument();
534                                    // Check whether we changed instrument key...
535                                    if (iMap  == pInstrument->map()  &&
536                                            iBank == pInstrument->bank() &&
537                                            iProg == pInstrument->prog()) {
538                                            // just update tree item...
539                                            pItem->update();
540                                    } else {
541                                            // Change item tree, whether applicable...
542                                            if (m_iMidiMap < 0 || m_iMidiMap == pInstrument->map()) {
543                                                    // Add new brand item into view...
544                                                    addItem(pInstrument, groupItem(pListItem));
545                                            } else {
546                                                    // Just remove/hide old one.
547                                                    delete pItem;
548                                            }
549                                    }
550                                    // Notify we've changes...
551                                  emit instrumentsChanged();                                  emit instrumentsChanged();
                                 pItem->update();  
552                          }                          }
553                  }                  }
554          }          }
# Line 594  void qsamplerInstrumentList::refresh (vo Line 685  void qsamplerInstrumentList::refresh (vo
685    
686          qsamplerInstrumentItem *pItem = NULL;          qsamplerInstrumentItem *pItem = NULL;
687          lscp_midi_instrument_t *pInstrs          lscp_midi_instrument_t *pInstrs
688                  = ::lscp_list_midi_instruments(pMainForm->client(), LSCP_MIDI_MAP_ALL);                  = ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap);
689          for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {          for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {
690                  int iMap  = pInstrs[iInstr].map;                  int iMap  = pInstrs[iInstr].map;
691                  int iBank = pInstrs[iInstr].bank;                  int iBank = pInstrs[iInstr].bank;

Legend:
Removed from v.987  
changed lines
  Added in v.1013

  ViewVC Help
Powered by ViewVC