/[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 1234 by capela, Wed Jun 13 21:54:07 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 28  Line 28 
28  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
29  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
30    
31    #include <qapplication.h>
32  #include <qmessagebox.h>  #include <qmessagebox.h>
33    #include <qeventloop.h>
34  #include <qaction.h>  #include <qaction.h>
35    #include <qcursor.h>
36  #include <qfileinfo.h>  #include <qfileinfo.h>
37  #include <qpopupmenu.h>  #include <qpopupmenu.h>
38    
# Line 225  qsamplerInstrumentList::qsamplerInstrume Line 228  qsamplerInstrumentList::qsamplerInstrume
228          QWidget *pParent, const char *pszName )          QWidget *pParent, const char *pszName )
229          : QListView(pParent, pszName)          : QListView(pParent, pszName)
230  {  {
231            m_iMidiMap = LSCP_MIDI_MAP_ALL;
232    
233  //  QListView::setRootIsDecorated(true);  //  QListView::setRootIsDecorated(true);
234            QListView::setAllColumnsShowFocus(true);
235          QListView::setResizeMode(QListView::NoColumn);          QListView::setResizeMode(QListView::NoColumn);
236  //      QListView::setAcceptDrops(true);  //      QListView::setAcceptDrops(true);
237          QListView::setDragAutoScroll(true);          QListView::setDragAutoScroll(true);
# Line 253  qsamplerInstrumentList::qsamplerInstrume Line 259  qsamplerInstrumentList::qsamplerInstrume
259          QListView::setColumnWidth(0, 120);      // Name          QListView::setColumnWidth(0, 120);      // Name
260          QListView::setColumnWidth(5, 240);      // File          QListView::setColumnWidth(5, 240);      // File
261    
262          m_pNewGroupAction = new QAction(tr("New &Group"), tr("Ctrl+G"), this);          m_pNewGroupAction = new QAction(
263          m_pNewItemAction  = new QAction(tr("New &Instrument..."), tr("Ins"), this);                  QIconSet(QPixmap::fromMimeSource("itemGroupNew.png")),
264          m_pEditItemAction = new QAction(tr("&Edit..."), tr("Enter"), this);                  tr("New &Group"), tr("Ctrl+G"), this);
265            m_pNewItemAction  = new QAction(
266                    QIconSet(QPixmap::fromMimeSource("itemNew.png")),
267                    tr("New &Instrument..."), tr("Ins"), this);
268            m_pEditItemAction = new QAction(
269                    QIconSet(QPixmap::fromMimeSource("formEdit.png")),
270                    tr("&Edit..."), tr("Enter"), this);
271          m_pRenameAction   = new QAction(tr("&Rename"), tr("F2"), this);          m_pRenameAction   = new QAction(tr("&Rename"), tr("F2"), this);
272          m_pDeleteAction   = new QAction(tr("&Delete"), tr("Del"), this);          m_pDeleteAction   = new QAction(
273          m_pRefreshAction  = new QAction(tr("Re&fresh"), tr("F5"), this);                  QIconSet(QPixmap::fromMimeSource("formRemove.png")),
274                    tr("&Delete"), tr("Del"), this);
275            m_pRefreshAction  = new QAction(
276                    QIconSet(QPixmap::fromMimeSource("formRefresh.png")),
277                    tr("Re&fresh"), tr("F5"), this);
278    
279            m_pNewGroupAction->setToolTip(tr("New Group"));
280            m_pNewItemAction->setToolTip(tr("New Instrument"));
281            m_pEditItemAction->setToolTip(tr("Edit"));
282            m_pRenameAction->setToolTip(tr("Rename"));
283            m_pDeleteAction->setToolTip(tr("Delete"));
284            m_pRefreshAction->setToolTip(tr("Refresh"));
285    
286          QObject::connect(m_pNewGroupAction,          QObject::connect(m_pNewGroupAction,
287                  SIGNAL(activated()),                  SIGNAL(activated()),
# Line 312  qsamplerInstrumentItem *qsamplerInstrume Line 335  qsamplerInstrumentItem *qsamplerInstrume
335          qsamplerInstrument *pInstrument,          qsamplerInstrument *pInstrument,
336          qsamplerInstrumentGroup *pParentGroup )          qsamplerInstrumentGroup *pParentGroup )
337  {  {
338            // Check it there's already one instrument item
339            // with the very same key (bank, program);
340            // if yes, just remove it without prejudice...
341          qsamplerInstrumentItem *pItem = findItem(pInstrument);          qsamplerInstrumentItem *pItem = findItem(pInstrument);
342          if (pItem == NULL) {          if (pItem) {
343                  if (pParentGroup)                  // If exactly the same, just update view and bail out...
344                          pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument);                  if (pItem->instrument() == pInstrument) {
345                  else                          pItem->update();
346                          pItem = new qsamplerInstrumentItem(this, pInstrument);                          return pItem;
347                    }
348                    // Remove it, as instrument keys must be unique.
349                    delete pItem;
350          }          }
351    
352            // Add the new item under proper group one, if any...
353            if (pParentGroup) {
354                    pParentGroup->setOpen(true);
355                    pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument);
356            } else {
357                    pItem = new qsamplerInstrumentItem(this, pInstrument);
358            }
359    
360            // Set it as current selection...
361          QListView::setSelected(pItem, true);          QListView::setSelected(pItem, true);
362    
363          return pItem;          return pItem;
364  }  }
365    
# Line 330  qsamplerInstrumentGroup *qsamplerInstrum Line 370  qsamplerInstrumentGroup *qsamplerInstrum
370  {  {
371          qsamplerInstrumentGroup *pGroup = findGroup(sName);          qsamplerInstrumentGroup *pGroup = findGroup(sName);
372          if (pGroup == NULL) {          if (pGroup == NULL) {
373                  if (pParentGroup)                  if (pParentGroup) {
374                            pParentGroup->setOpen(true);
375                          pGroup = new qsamplerInstrumentGroup(pParentGroup, sName);                          pGroup = new qsamplerInstrumentGroup(pParentGroup, sName);
376                  else                  } else {
377                          pGroup = new qsamplerInstrumentGroup(this, sName);                          pGroup = new qsamplerInstrumentGroup(this, sName);
378                    }
379          }          }
380          QListView::setSelected(pGroup, true);          QListView::setSelected(pGroup, true);
381          return pGroup;          return pGroup;
# Line 397  qsamplerInstrumentGroup *qsamplerInstrum Line 439  qsamplerInstrumentGroup *qsamplerInstrum
439  // Add a new group item below the current one.  // Add a new group item below the current one.
440  void qsamplerInstrumentList::newGroupSlot (void)  void qsamplerInstrumentList::newGroupSlot (void)
441  {  {
         qsamplerInstrumentGroup *pParentGroup  
                 = groupItem(QListView::selectedItem());  
442          qsamplerInstrumentGroup *pNewGroup          qsamplerInstrumentGroup *pNewGroup
443                  = addGroup(tr("New Group"), pParentGroup);                  = addGroup(tr("New Group"), groupItem(QListView::selectedItem()));
         if (pParentGroup)  
                 pParentGroup->setOpen(true);  
444          if (pNewGroup)          if (pNewGroup)
445                  pNewGroup->startRename(0);                  pNewGroup->startRename(0);
446    
# Line 410  void qsamplerInstrumentList::newGroupSlo Line 448  void qsamplerInstrumentList::newGroupSlo
448  }  }
449    
450    
451    // Map selector.
452    void qsamplerInstrumentList::setMidiMap ( int iMidiMap )
453    {
454            if (iMidiMap < 0)
455                    iMidiMap = LSCP_MIDI_MAP_ALL;
456    
457            m_iMidiMap = iMidiMap;
458    }
459    
460    int qsamplerInstrumentList::midiMap (void) const
461    {
462            return m_iMidiMap;
463    }
464    
465    
466    // List actions accessors.
467    QAction *qsamplerInstrumentList::newGroupAction (void) const
468    {
469            return m_pNewGroupAction;
470    }
471    
472    QAction *qsamplerInstrumentList::newItemAction (void) const
473    {
474            return m_pNewItemAction;
475    }
476    
477    QAction *qsamplerInstrumentList::editItemAction (void) const
478    {
479            return m_pEditItemAction;
480    }
481    
482    QAction *qsamplerInstrumentList::renameAction (void) const
483    {
484            return m_pRenameAction;
485    }
486    
487    QAction *qsamplerInstrumentList::deleteAction (void) const
488    {
489            return m_pDeleteAction;
490    }
491    
492    QAction *qsamplerInstrumentList::refreshAction (void) const
493    {
494            return m_pRefreshAction;
495    }
496    
497    
498  // Add a new instrument item below the current one.  // Add a new instrument item below the current one.
499  void qsamplerInstrumentList::newItemSlot (void)  void qsamplerInstrumentList::newItemSlot (void)
500  {  {
# Line 422  void qsamplerInstrumentList::newItemSlot Line 507  void qsamplerInstrumentList::newItemSlot
507                  return;                  return;
508          }          }
509    
510          // 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;  
   
511          pInstrument->mapInstrument();          pInstrument->mapInstrument();
512            // add new item to the tree...
513            addItem(pInstrument, groupItem(QListView::selectedItem()));
514            // Notify we've changes...
515          emit instrumentsChanged();          emit instrumentsChanged();
516    
         qsamplerInstrumentGroup *pParentGroup  
                 = groupItem(QListView::selectedItem());  
         addItem(pInstrument, pParentGroup);  
         if (pParentGroup)  
                 pParentGroup->setOpen(true);  
   
517          selectionChangedSlot();          selectionChangedSlot();
518  }  }
519    
# Line 449  void qsamplerInstrumentList::editItemSlo Line 525  void qsamplerInstrumentList::editItemSlo
525          if (pListItem == NULL)          if (pListItem == NULL)
526                  return;                  return;
527          if (pListItem->rtti() == Item) {          if (pListItem->rtti() == Item) {
528                    qsamplerInstrument *pInstrument = NULL;
529                  qsamplerInstrumentItem *pItem                  qsamplerInstrumentItem *pItem
530                          = static_cast<qsamplerInstrumentItem *> (pListItem);                          = static_cast<qsamplerInstrumentItem *> (pListItem);
531                  if (pItem && pItem->instrument()) {                  if (pItem)
532                            pInstrument = pItem->instrument();
533                    if (pInstrument) {
534                            // Save current key values...
535                            qsamplerInstrument oldInstrument(*pInstrument);
536                            // Do the edit dance...
537                          qsamplerInstrumentForm form(this);                          qsamplerInstrumentForm form(this);
538                          form.setup(pItem->instrument());                          form.setup(pInstrument);
539                          if (form.exec()) {                          if (form.exec()) {
540                                  pItem->instrument()->mapInstrument();                                  // Commit...
541                                    pInstrument->mapInstrument();
542                                    // Check whether we changed instrument key...
543                                    if (oldInstrument.map()  == pInstrument->map()  &&
544                                            oldInstrument.bank() == pInstrument->bank() &&
545                                            oldInstrument.prog() == pInstrument->prog()) {
546                                            // just update tree item...
547                                            pItem->update();
548                                    } else {
549                                            // Unmap old instance...
550                                            oldInstrument.unmapInstrument();
551                                            // Change item tree, whether applicable...
552                                            if (m_iMidiMap < 0 || m_iMidiMap == pInstrument->map()) {
553                                                    // Add new brand item into view...
554                                                    addItem(pInstrument, groupItem(pListItem));
555                                            } else {
556                                                    // Just remove/hide old one.
557                                                    delete pItem;
558                                            }
559                                    }
560                                    // Notify we've changes...
561                                  emit instrumentsChanged();                                  emit instrumentsChanged();
                                 pItem->update();  
562                          }                          }
563                  }                  }
564          }          }
# Line 537  void qsamplerInstrumentList::selectionCh Line 638  void qsamplerInstrumentList::selectionCh
638  void qsamplerInstrumentList::activatedSlot ( QListViewItem *pListItem )  void qsamplerInstrumentList::activatedSlot ( QListViewItem *pListItem )
639  {  {
640          // FIXME: Hope the list view item is the one selected.          // FIXME: Hope the list view item is the one selected.
641          if (pListItem->rtti() == Item)          if (pListItem && pListItem->rtti() == Item)
642                  editItemSlot();                  editItemSlot();
643  }  }
644    
# Line 592  void qsamplerInstrumentList::refresh (vo Line 693  void qsamplerInstrumentList::refresh (vo
693          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
694                  return;                  return;
695    
696            QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
697    
698            // Load the whole bunch of instrument items...
699          qsamplerInstrumentItem *pItem = NULL;          qsamplerInstrumentItem *pItem = NULL;
700          lscp_midi_instrument_t *pInstrs          lscp_midi_instrument_t *pInstrs
701                  = ::lscp_list_midi_instruments(pMainForm->client(), LSCP_MIDI_MAP_ALL);                  = ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap);
702          for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {          for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {
703                  int iMap  = pInstrs[iInstr].map;                  int iMap  = pInstrs[iInstr].map;
704                  int iBank = pInstrs[iInstr].bank;                  int iBank = pInstrs[iInstr].bank;
# Line 603  void qsamplerInstrumentList::refresh (vo Line 707  void qsamplerInstrumentList::refresh (vo
707                          = new qsamplerInstrument(iMap, iBank, iProg);                          = new qsamplerInstrument(iMap, iBank, iProg);
708                  if (pInstrument->getInstrument())                  if (pInstrument->getInstrument())
709                          pItem = new qsamplerInstrumentItem(this, pInstrument, pItem);                          pItem = new qsamplerInstrumentItem(this, pInstrument, pItem);
710                    // Try to keep it snappy :)
711                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
712          }          }
713    
714            QApplication::restoreOverrideCursor();
715    
716          if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) {          if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) {
717                  pMainForm->appendMessagesClient("lscp_list_midi_instruments");                  pMainForm->appendMessagesClient("lscp_list_midi_instruments");
718                  pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry."));                  pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry."));

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

  ViewVC Help
Powered by ViewVC