/[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 1234 by capela, Wed Jun 13 21:54:07 2007 UTC revision 1463 by capela, Thu Nov 1 13:01:27 2007 UTC
# Line 34  Line 34 
34  #include <qaction.h>  #include <qaction.h>
35  #include <qcursor.h>  #include <qcursor.h>
36  #include <qfileinfo.h>  #include <qfileinfo.h>
37  #include <qpopupmenu.h>  
38    #include <QMenu>
39    
40  // Needed for lroundf()  // Needed for lroundf()
41  #include <math.h>  #include <math.h>
# Line 49  static inline long lroundf ( float x ) Line 50  static inline long lroundf ( float x )
50  }  }
51  #endif  #endif
52    
53    using namespace QSampler;
54    
55  //----------------------------------------------------------------------  //----------------------------------------------------------------------
56  // class qsamplerInstrumentGroup -- custom group list view item.  // class qsamplerInstrumentGroup -- custom group list view item.
57  //  //
58    
59    #if 0
60  // Constructors.  // Constructors.
61  qsamplerInstrumentGroup::qsamplerInstrumentGroup (  qsamplerInstrumentGroup::qsamplerInstrumentGroup (
62          qsamplerInstrumentList *pListView, const QString& sName,          qsamplerInstrumentList *pListView, const QString& sName,
# Line 62  qsamplerInstrumentGroup::qsamplerInstrum Line 65  qsamplerInstrumentGroup::qsamplerInstrum
65  {  {
66          QListViewItem::setRenameEnabled(0, true);          QListViewItem::setRenameEnabled(0, true);
67    
68          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png"));          QListViewItem::setPixmap(0, QPixmap(":/icons/itemGroup.png"));
69          QListViewItem::setText(0, sName);          QListViewItem::setText(0, sName);
70  }  }
71    
# Line 73  qsamplerInstrumentGroup::qsamplerInstrum Line 76  qsamplerInstrumentGroup::qsamplerInstrum
76  {  {
77          QListViewItem::setRenameEnabled(0, true);          QListViewItem::setRenameEnabled(0, true);
78    
79          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemGroup.png"));          QListViewItem::setPixmap(0, QPixmap(":/icons/itemGroup.png"));
80  }  }
81    
82    
# Line 116  void qsamplerInstrumentGroup::setOpen ( Line 119  void qsamplerInstrumentGroup::setOpen (
119  {  {
120          // Set the proper pixmap of this...          // Set the proper pixmap of this...
121          if (rtti() == qsamplerInstrumentList::Group) {          if (rtti() == qsamplerInstrumentList::Group) {
122                  QListViewItem::setPixmap(0, QPixmap::fromMimeSource(                  QListViewItem::setPixmap(0, QPixmap(bOpen ?
123                          bOpen ? "itemGroupOpen.png" : "itemGroup.png"));                          ":/icons/itemGroupOpen.png" : ":/icons/itemGroup.png"));
124          }          }
125          // Open it up...          // Open it up...
126          QListViewItem::setOpen(bOpen);          QListViewItem::setOpen(bOpen);
# Line 187  qsamplerInstrument *qsamplerInstrumentIt Line 190  qsamplerInstrument *qsamplerInstrumentIt
190  // Item refreshment.  // Item refreshment.
191  void qsamplerInstrumentItem::update (void)  void qsamplerInstrumentItem::update (void)
192  {  {
193          QListViewItem::setPixmap(0, QPixmap::fromMimeSource("itemFile.png"));          QListViewItem::setPixmap(0, QPixmap(":/icons/itemFile.png"));
194    
195          const QString s = "-";          const QString s = "-";
196          if (m_pInstrument) {          if (m_pInstrument) {
# Line 260  qsamplerInstrumentList::qsamplerInstrume Line 263  qsamplerInstrumentList::qsamplerInstrume
263          QListView::setColumnWidth(5, 240);      // File          QListView::setColumnWidth(5, 240);      // File
264    
265          m_pNewGroupAction = new QAction(          m_pNewGroupAction = new QAction(
266                  QIconSet(QPixmap::fromMimeSource("itemGroupNew.png")),                  QIcon(":/icons/itemGroupNew.png"),
267                  tr("New &Group"), tr("Ctrl+G"), this);                  tr("New &Group"), tr("Ctrl+G"), this);
268          m_pNewItemAction  = new QAction(          m_pNewItemAction  = new QAction(
269                  QIconSet(QPixmap::fromMimeSource("itemNew.png")),                  QIcon(":/icons/itemNew.png"),
270                  tr("New &Instrument..."), tr("Ins"), this);                  tr("New &Instrument..."), tr("Ins"), this);
271          m_pEditItemAction = new QAction(          m_pEditItemAction = new QAction(
272                  QIconSet(QPixmap::fromMimeSource("formEdit.png")),                  QIcon(":/icons/formEdit.png"),
273                  tr("&Edit..."), tr("Enter"), this);                  tr("&Edit..."), tr("Enter"), this);
274          m_pRenameAction   = new QAction(tr("&Rename"), tr("F2"), this);          m_pRenameAction   = new QAction(tr("&Rename"), tr("F2"), this);
275          m_pDeleteAction   = new QAction(          m_pDeleteAction   = new QAction(
276                  QIconSet(QPixmap::fromMimeSource("formRemove.png")),                  QIcon(":/icons/formRemove.png"),
277                  tr("&Delete"), tr("Del"), this);                  tr("&Delete"), tr("Del"), this);
278          m_pRefreshAction  = new QAction(          m_pRefreshAction  = new QAction(
279                  QIconSet(QPixmap::fromMimeSource("formRefresh.png")),                  QIcon(":/icons/formRefresh.png"),
280                  tr("Re&fresh"), tr("F5"), this);                  tr("Re&fresh"), tr("F5"), this);
281    
282          m_pNewGroupAction->setToolTip(tr("New Group"));          m_pNewGroupAction->setToolTip(tr("New Group"));
# Line 720  void qsamplerInstrumentList::refresh (vo Line 723  void qsamplerInstrumentList::refresh (vo
723    
724          selectionChangedSlot();          selectionChangedSlot();
725  }  }
726    #endif
727    
728    MidiInstrumentsModel::MidiInstrumentsModel(QObject* parent) : QAbstractTableModel(parent) {
729        m_iMidiMap = LSCP_MIDI_MAP_ALL;
730    }
731    
732    int MidiInstrumentsModel::rowCount(const QModelIndex& /*parent*/) const {
733        if (m_iMidiMap == LSCP_MIDI_MAP_ALL) {
734            int n = 0;
735            for (InstrumentsMap::const_iterator itMap = instruments.begin(); itMap != instruments.end(); ++itMap)
736                n += (*itMap).size();
737            return n;
738        }
739        InstrumentsMap::const_iterator itMap = instruments.find(m_iMidiMap);
740        if (itMap == instruments.end()) return 0;
741        return (*itMap).size();
742    }
743    
744    int MidiInstrumentsModel::columnCount(const QModelIndex& /*parent*/) const {
745        return 9;
746    }
747    
748    QVariant MidiInstrumentsModel::data(const QModelIndex &index, int role) const {
749        if (!index.isValid() || role != Qt::DisplayRole) return QVariant();
750    
751        if (m_iMidiMap == LSCP_MIDI_MAP_ALL) {
752            int n = 0;
753            for (InstrumentsMap::const_iterator itMap = instruments.begin(); itMap != instruments.end(); ++itMap) {
754                n += (*itMap).size();
755                if (index.row() < n)
756                    return QVariant::fromValue(
757                        (*itMap)[index.row() + (*itMap).size() - n]
758                    );
759            }
760        } else {
761            // resolve MIDI instrument map
762            InstrumentsMap::const_iterator itMap = instruments.find(m_iMidiMap);
763            if (itMap == instruments.end()) return QVariant();
764            // resolve instrument in that map
765            if (index.row() >= (*itMap).size()) return QVariant();
766            return QVariant::fromValue(
767                (*itMap)[index.row()]
768            );
769        }
770    
771        return QVariant();
772    }
773    
774    QVariant MidiInstrumentsModel::headerData(int section, Qt::Orientation orientation, int role) const {
775        if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
776            return QVariant();
777    
778        switch (section) {
779            case 0: return tr("Name");
780            case 1: return tr("Map");
781            case 2: return tr("Bank");
782            case 3: return tr("Prog");
783            case 4: return tr("Engine");
784            case 5: return tr("File");
785            case 6: return tr("Nr");
786            case 7: return tr("Vol");
787            case 8: return tr("Mode");
788            default: return QVariant();
789        }
790    }
791    
792    qsamplerInstrument* MidiInstrumentsModel::addInstrument(int iMap, int iBank, int iProg) {
793        // Check it there's already one instrument item
794        // with the very same key (bank, program);
795        // if yes, just remove it without prejudice...
796        for (int i = 0; i < instruments[iMap].size(); i++) {
797            if (
798                instruments[iMap][i].bank() == iBank &&
799                instruments[iMap][i].prog() == iProg
800            ) {
801                instruments[iMap].removeAt(i);
802                break;
803            }
804        }
805    
806        // resolve the appropriate place, we keep the list sorted that way ...
807        int i = 0;
808        for (; i < instruments[iMap].size(); i++)
809            if (
810                iBank > instruments[iMap][i].bank() ||
811                ( iBank == instruments[iMap][i].bank() &&
812                  iProg > instruments[iMap][i].prog() )
813            ) break;
814    
815        qsamplerInstrument& instr = instruments[iMap][i] = qsamplerInstrument(iMap, iBank, iProg);
816    
817        return &instr;
818    }
819    
820    void MidiInstrumentsModel::setMidiMap(int iMidiMap) {
821        if (iMidiMap < 0)
822            iMidiMap = LSCP_MIDI_MAP_ALL;
823    
824        m_iMidiMap = iMidiMap;
825    }
826    
827    int MidiInstrumentsModel::midiMap() const {
828        return m_iMidiMap;
829    }
830    
831    void MidiInstrumentsModel::refresh() {
832            instruments.clear();
833    
834            MainForm* pMainForm = MainForm::getInstance();
835            if (pMainForm == NULL)
836                    return;
837            if (pMainForm->client() == NULL)
838                    return;
839    
840            QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
841    
842            // Load the whole bunch of instrument items...
843            lscp_midi_instrument_t* pInstrs
844                    = ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap);
845            for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) {
846                    const int iMap  = pInstrs[iInstr].map;
847                    const int iBank = pInstrs[iInstr].bank;
848                    const int iProg = pInstrs[iInstr].prog;
849                    addInstrument(iMap, iBank, iProg);
850                    // Try to keep it snappy :)
851                    QApplication::processEvents(QEventLoop::ExcludeUserInput);
852            }
853    
854            QApplication::restoreOverrideCursor();
855    
856            if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) {
857                    pMainForm->appendMessagesClient("lscp_list_midi_instruments");
858                    pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry."));
859            }
860    
861            //selectionChangedSlot();
862    }
863    
864    
865    MidiInstrumentsDelegate::MidiInstrumentsDelegate(QObject* parent) : QItemDelegate(parent) {
866    }
867    
868    QWidget* MidiInstrumentsDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const {
869        return new QLabel(index.model()->data(index, Qt::DisplayRole).toString(), parent);
870    }
871    
872    void MidiInstrumentsDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const {
873    }
874    
875    void MidiInstrumentsDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
876    }
877    
878    void MidiInstrumentsDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const {
879        if (editor) editor->setGeometry(option.rect);
880    }
881    
882  // end of qsamplerInstrumentList.cpp  // end of qsamplerInstrumentList.cpp
883    

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

  ViewVC Help
Powered by ViewVC