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