/[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 971 by capela, Thu Dec 7 10:36:26 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 25  Line 25 
25  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
26  #include "qsamplerInstrumentForm.h"  #include "qsamplerInstrumentForm.h"
27    
28    #include "qsamplerOptions.h"
29  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
30    
31    #include <qmessagebox.h>
32  #include <qaction.h>  #include <qaction.h>
33  #include <qfileinfo.h>  #include <qfileinfo.h>
34  #include <qpopupmenu.h>  #include <qpopupmenu.h>
# Line 34  Line 36 
36  // Needed for lroundf()  // Needed for lroundf()
37  #include <math.h>  #include <math.h>
38    
39  #ifdef __BORLANDC__  #ifndef CONFIG_ROUND
40  static long lroundf ( float fval )  static inline long lroundf ( float x )
41  {  {
42          double fint = 0.0;          if (x >= 0.0f)
43      float  frac = float(::modf(fval, &fint));                  return long(x + 0.5f);
44      long   lint = long(fint);          else
45      if (frac >= +0.5f)                  return long(x - 0.5f);
         lint++;  
     else  
     if (frac <= -0.5f)  
         lint--;  
     return lint;  
46  }  }
47  #endif  #endif
48    
# Line 192  void qsamplerInstrumentItem::update (voi Line 189  void qsamplerInstrumentItem::update (voi
189          const QString s = "-";          const QString s = "-";
190          if (m_pInstrument) {          if (m_pInstrument) {
191                  setText(0, m_pInstrument->name());                  setText(0, m_pInstrument->name());
192                  setText(1, QString::number(m_pInstrument->bank()));                  setText(1, QString::number(m_pInstrument->map()));
193                  setText(2, QString::number(m_pInstrument->program() + 1));                  setText(2, QString::number(m_pInstrument->bank()));
194                  setText(3, m_pInstrument->engineName());                  setText(3, QString::number(m_pInstrument->prog() + 1));
195                  setText(4, QFileInfo(m_pInstrument->instrumentFile()).fileName());                  setText(4, m_pInstrument->engineName());
196                  setText(5, QString::number(m_pInstrument->instrumentNr()));                  setText(5, QFileInfo(m_pInstrument->instrumentFile()).fileName());
197                  setText(6, QString::number(::lroundf(100.0f * m_pInstrument->volume())));                  setText(6, QString::number(m_pInstrument->instrumentNr()));
198                    setText(7, QString::number(::lroundf(100.0f * m_pInstrument->volume())));
199                  QString sLoadMode = s;                  QString sLoadMode = s;
200                  switch (m_pInstrument->loadMode()) {                  switch (m_pInstrument->loadMode()) {
201                  case 3:                  case 3:
# Line 210  void qsamplerInstrumentItem::update (voi Line 208  void qsamplerInstrumentItem::update (voi
208                          sLoadMode = QObject::tr("On Demand");                          sLoadMode = QObject::tr("On Demand");
209                          break;                          break;
210                  }                  }
211                  setText(7, sLoadMode);                  setText(8, sLoadMode);
212          } else {          } else {
213                  for (int i = 0; i < listView()->columns(); i++)                  for (int i = 0; i < listView()->columns(); i++)
214                          setText(i, s);                          setText(i, s);
# Line 227  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 237  qsamplerInstrumentList::qsamplerInstrume Line 238  qsamplerInstrumentList::qsamplerInstrume
238          QListView::setSortColumn(-1);          QListView::setSortColumn(-1);
239    
240          QListView::addColumn(tr("Name"));          QListView::addColumn(tr("Name"));
241            QListView::addColumn(tr("Map"));
242          QListView::addColumn(tr("Bank"));          QListView::addColumn(tr("Bank"));
243          QListView::addColumn(tr("Prog"));          QListView::addColumn(tr("Prog"));
244          QListView::addColumn(tr("Engine"));          QListView::addColumn(tr("Engine"));
# Line 245  qsamplerInstrumentList::qsamplerInstrume Line 247  qsamplerInstrumentList::qsamplerInstrume
247          QListView::addColumn(tr("Vol"));          QListView::addColumn(tr("Vol"));
248          QListView::addColumn(tr("Mode"));          QListView::addColumn(tr("Mode"));
249    
250          QListView::setColumnAlignment(1, Qt::AlignHCenter);     // Bank          QListView::setColumnAlignment(1, Qt::AlignHCenter);     // Map
251          QListView::setColumnAlignment(2, Qt::AlignHCenter);     // Prog          QListView::setColumnAlignment(2, Qt::AlignHCenter);     // Bank
252          QListView::setColumnAlignment(5, Qt::AlignHCenter);     // Nr          QListView::setColumnAlignment(3, Qt::AlignHCenter);     // Prog
253          QListView::setColumnAlignment(6, Qt::AlignHCenter);     // Vol          QListView::setColumnAlignment(6, Qt::AlignHCenter);     // Nr
254            QListView::setColumnAlignment(7, Qt::AlignHCenter);     // Vol
255          QListView::setColumnWidth(0, 60);       // Name  
256          QListView::setColumnWidth(0, 120);      // File          QListView::setColumnWidth(0, 120);      // Name
257            QListView::setColumnWidth(5, 240);      // File
258          m_pNewGroupAction = new QAction(tr("New &Group"), tr("Ctrl+G"), this);  
259          m_pNewItemAction  = new QAction(tr("New &Instrument..."), tr("Ctrl+I"), this);          m_pNewGroupAction = new QAction(
260          m_pEditItemAction = new QAction(tr("&Edit..."), tr("Ctrl+E"), this);                  QIconSet(QPixmap::fromMimeSource("itemGroupNew.png")),
261          m_pRenameAction   = new QAction(tr("&Rename"), tr("Ctrl+R"), this);                  tr("New &Group"), tr("Ctrl+G"), this);
262          m_pDeleteAction   = new QAction(tr("&Delete"), tr("Ctrl+D"), this);          m_pNewItemAction  = new QAction(
263          m_pRefreshAction  = new QAction(tr("Re&fresh"), tr("Ctrl+F"), this);                  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);
269            m_pDeleteAction   = new QAction(
270                    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 372  qsamplerInstrumentItem *qsamplerInstrume Line 404  qsamplerInstrumentItem *qsamplerInstrume
404                          qsamplerInstrumentItem *pItem                          qsamplerInstrumentItem *pItem
405                                  = static_cast<qsamplerInstrumentItem *> (pListItem);                                  = static_cast<qsamplerInstrumentItem *> (pListItem);
406                          if (pItem && pItem->instrument()                          if (pItem && pItem->instrument()
407                                    && pItem->instrument()->map()  == pInstrument->map()
408                                  && pItem->instrument()->bank() == pInstrument->bank()                                  && pItem->instrument()->bank() == pInstrument->bank()
409                                  && pItem->instrument()->program() == pInstrument->program())                                  && pItem->instrument()->prog() == pInstrument->prog())
410                                  return pItem;                                  return pItem;
411                  }                  }
412                  ++iter;                  ++iter;
# Line 396  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 409  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 421  void qsamplerInstrumentList::newItemSlot Line 497  void qsamplerInstrumentList::newItemSlot
497                  return;                  return;
498          }          }
499    
500          // Check it there's already one instrument item          // Commit...
501          // with the very same key (bank, program);          pInstrument->mapInstrument();
502          // if yes, just remove it without prejudice...          // add new item to the tree...
503          qsamplerInstrumentItem *pItem = findItem(pInstrument);          addItem(pInstrument, groupItem(QListView::selectedItem()));
504          if (pItem)          // Notify we've changes...
                 delete pItem;  
   
         pInstrument->map();  
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 448  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()->map();                                  // 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 480  void qsamplerInstrumentList::renameSlot Line 572  void qsamplerInstrumentList::renameSlot
572  void qsamplerInstrumentList::deleteSlot (void)  void qsamplerInstrumentList::deleteSlot (void)
573  {  {
574          QListViewItem *pListItem = QListView::selectedItem();          QListViewItem *pListItem = QListView::selectedItem();
575          if (pListItem) {          if (pListItem == NULL)
576                  if (pListItem->rtti() == Item) {                  return;
577                          qsamplerInstrumentItem *pItem  
578                                  = static_cast<qsamplerInstrumentItem *> (pListItem);          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
579                          if (pItem && pItem->instrument()) {          if (pMainForm == NULL)
580                                  pItem->instrument()->unmap();                  return;
581                                  emit instrumentsChanged();  
582                          }          // Prompt user if this is for real...
583            qsamplerOptions *pOptions = pMainForm->options();
584            if (pOptions && pOptions->bConfirmRemove) {
585                    if (QMessageBox::warning(this,
586                            QSAMPLER_TITLE ": " + tr("Warning"),
587                            tr("Delete %1:\n\n"
588                            "%2\n\n"
589                            "Are you sure?")
590                            .arg(pListItem->rtti() == Item ? tr("instrument") : tr("group"))
591                            .arg(pListItem->text(0)),
592                            tr("OK"), tr("Cancel")) > 0)
593                            return;
594            }
595    
596            // Unmap instrument entry...
597            if (pListItem->rtti() == Item) {
598                    qsamplerInstrumentItem *pItem
599                            = static_cast<qsamplerInstrumentItem *> (pListItem);
600                    if (pItem && pItem->instrument()) {
601                            pItem->instrument()->unmapInstrument();
602                            emit instrumentsChanged();
603                  }                  }
                 delete pListItem;  
604          }          }
605    
606            // Do it for real...
607            delete pListItem;
608    
609          selectionChangedSlot();          selectionChangedSlot();
610  }  }
611    
# Line 527  void qsamplerInstrumentList::renamedSlot Line 641  void qsamplerInstrumentList::renamedSlot
641                          = static_cast<qsamplerInstrumentItem *> (pListItem);                          = static_cast<qsamplerInstrumentItem *> (pListItem);
642                  if (pItem && pItem->instrument()) {                  if (pItem && pItem->instrument()) {
643                          pItem->instrument()->setName(pListItem->text(0));                          pItem->instrument()->setName(pListItem->text(0));
644                          pItem->instrument()->map();                          pItem->instrument()->mapInstrument();
645                          emit instrumentsChanged();                          emit instrumentsChanged();
646                          pItem->update();                          pItem->update();
647                  }                  }
# Line 571  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_list_midi_instruments(pMainForm->client(), m_iMidiMap);
689          for (int iInstr = 0; pInstrs && pInstrs[iInstr].program >= 0; ++iInstr) {          for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {
690                  int iBank = (pInstrs[iInstr].bank_msb << 7) | pInstrs[iInstr].bank_lsb;                  int iMap  = pInstrs[iInstr].map;
691                  int iProgram = pInstrs[iInstr].program;                  int iBank = pInstrs[iInstr].bank;
692                    int iProg = pInstrs[iInstr].prog;
693                  qsamplerInstrument *pInstrument                  qsamplerInstrument *pInstrument
694                          = new qsamplerInstrument(iBank, iProgram);                          = new qsamplerInstrument(iMap, iBank, iProg);
695                  if (pInstrument->get())                  if (pInstrument->getInstrument())
696                          pItem = new qsamplerInstrumentItem(this, pInstrument, pItem);                          pItem = new qsamplerInstrumentItem(this, pInstrument, pItem);
697          }          }
698    

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

  ViewVC Help
Powered by ViewVC