29 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
30 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
31 |
|
|
32 |
#include <qapplication.h> |
#include <QApplication> |
33 |
#include <qmessagebox.h> |
#include <QMessageBox> |
|
#include <qeventloop.h> |
|
|
#include <qaction.h> |
|
|
#include <qcursor.h> |
|
|
#include <qfileinfo.h> |
|
|
|
|
34 |
#include <QMenu> |
#include <QMenu> |
35 |
|
#include <QAction> |
36 |
|
#include <QCursor> |
37 |
|
#include <QFileInfo> |
38 |
|
|
39 |
// Needed for lroundf() |
// Needed for lroundf() |
40 |
#include <math.h> |
#include <math.h> |
51 |
|
|
52 |
using namespace QSampler; |
using namespace QSampler; |
53 |
|
|
|
//---------------------------------------------------------------------- |
|
|
// class qsamplerInstrumentGroup -- custom group list view item. |
|
|
// |
|
|
|
|
|
#if 0 |
|
|
// Constructors. |
|
|
qsamplerInstrumentGroup::qsamplerInstrumentGroup ( |
|
|
qsamplerInstrumentList *pListView, const QString& sName, |
|
|
QListViewItem *pItemAfter ) |
|
|
: QListViewItem(pListView, pItemAfter ? pItemAfter : pListView->lastItem()) |
|
|
{ |
|
|
QListViewItem::setRenameEnabled(0, true); |
|
|
|
|
|
QListViewItem::setPixmap(0, QPixmap(":/icons/itemGroup.png")); |
|
|
QListViewItem::setText(0, sName); |
|
|
} |
|
|
|
|
|
|
|
|
qsamplerInstrumentGroup::qsamplerInstrumentGroup ( |
|
|
qsamplerInstrumentGroup *pGroupItem, const QString& sName ) |
|
|
: QListViewItem(pGroupItem, sName) |
|
|
{ |
|
|
QListViewItem::setRenameEnabled(0, true); |
|
|
|
|
|
QListViewItem::setPixmap(0, QPixmap(":/icons/itemGroup.png")); |
|
|
} |
|
|
|
|
|
|
|
|
// Default destructor. |
|
|
qsamplerInstrumentGroup::~qsamplerInstrumentGroup (void) |
|
|
{ |
|
|
} |
|
|
|
|
|
|
|
|
// Instance accessors. |
|
|
void qsamplerInstrumentGroup::setName ( const QString& sName ) |
|
|
{ |
|
|
QListViewItem::setText(0, sName); |
|
|
} |
|
|
|
|
|
|
|
|
QString qsamplerInstrumentGroup::name (void) const |
|
|
{ |
|
|
return QListViewItem::text(0); |
|
|
} |
|
|
|
|
|
|
|
|
qsamplerInstrumentGroup *qsamplerInstrumentGroup::groupItem (void) const |
|
|
{ |
|
|
QListViewItem *pParent = QListViewItem::parent(); |
|
|
while (pParent && pParent->rtti() != qsamplerInstrumentList::Group) |
|
|
pParent = pParent->parent(); |
|
|
return static_cast<qsamplerInstrumentGroup *> (pParent); |
|
|
} |
|
54 |
|
|
55 |
|
//------------------------------------------------------------------------- |
56 |
|
// MidiInstrumentsModel - data model for MIDI prog mappings (used for QTableView) |
57 |
|
// |
58 |
|
|
59 |
qsamplerInstrumentList *qsamplerInstrumentGroup::listView (void) const |
MidiInstrumentsModel::MidiInstrumentsModel ( QObject* pParent) |
60 |
|
: QAbstractTableModel(pParent) |
61 |
{ |
{ |
62 |
return static_cast<qsamplerInstrumentList *> (QListViewItem::listView()); |
m_iMidiMap = LSCP_MIDI_MAP_ALL; |
63 |
} |
} |
64 |
|
|
65 |
|
|
66 |
// To show up whether its open or not. |
int MidiInstrumentsModel::rowCount ( const QModelIndex& /*parent*/) const |
|
void qsamplerInstrumentGroup::setOpen ( bool bOpen ) |
|
67 |
{ |
{ |
68 |
// Set the proper pixmap of this... |
if (m_iMidiMap == LSCP_MIDI_MAP_ALL) { |
69 |
if (rtti() == qsamplerInstrumentList::Group) { |
int n = 0; |
70 |
QListViewItem::setPixmap(0, QPixmap(bOpen ? |
for (InstrumentsMap::const_iterator itMap = m_instruments.begin(); |
71 |
":/icons/itemGroupOpen.png" : ":/icons/itemGroup.png")); |
itMap != m_instruments.end(); ++itMap) |
72 |
|
n += (*itMap).size(); |
73 |
|
return n; |
74 |
} |
} |
75 |
// Open it up... |
InstrumentsMap::const_iterator itMap = m_instruments.find(m_iMidiMap); |
76 |
QListViewItem::setOpen(bOpen); |
if (itMap == m_instruments.end()) return 0; |
77 |
|
return (*itMap).size(); |
|
// All ancestors should be also visible. |
|
|
if (bOpen && QListViewItem::parent()) |
|
|
QListViewItem::parent()->setOpen(true); |
|
78 |
} |
} |
79 |
|
|
80 |
|
|
81 |
// To virtually distinguish between list view items. |
int MidiInstrumentsModel::columnCount ( const QModelIndex& /*parent*/) const |
|
int qsamplerInstrumentGroup::rtti (void) const |
|
82 |
{ |
{ |
83 |
return qsamplerInstrumentList::Group; |
return 9; |
84 |
} |
} |
85 |
|
|
86 |
|
|
87 |
//---------------------------------------------------------------------- |
QVariant MidiInstrumentsModel::data ( const QModelIndex &index, int role ) const |
|
// class qsamplerInstrumentItem -- custom file list view item. |
|
|
// |
|
|
|
|
|
// Constructors. |
|
|
qsamplerInstrumentItem::qsamplerInstrumentItem ( |
|
|
qsamplerInstrumentList *pListView, |
|
|
qsamplerInstrument *pInstrument, |
|
|
QListViewItem *pItemAfter ) |
|
|
: qsamplerInstrumentGroup(pListView, pInstrument->name(), pItemAfter) |
|
88 |
{ |
{ |
89 |
m_pInstrument = pInstrument; |
if (!index.isValid()) |
90 |
|
return QVariant(); |
91 |
|
|
92 |
update(); |
const qsamplerInstrument* pInstr = NULL; |
|
} |
|
|
|
|
|
qsamplerInstrumentItem::qsamplerInstrumentItem ( |
|
|
qsamplerInstrumentGroup *pGroupItem, |
|
|
qsamplerInstrument *pInstrument ) |
|
|
: qsamplerInstrumentGroup(pGroupItem, pInstrument->name()) |
|
|
{ |
|
|
m_pInstrument = pInstrument; |
|
|
|
|
|
update(); |
|
|
} |
|
|
|
|
|
|
|
|
// Default destructor. |
|
|
qsamplerInstrumentItem::~qsamplerInstrumentItem (void) |
|
|
{ |
|
|
if (m_pInstrument) |
|
|
delete m_pInstrument; |
|
|
} |
|
93 |
|
|
94 |
|
if (m_iMidiMap == LSCP_MIDI_MAP_ALL) { |
95 |
|
int n = 0; |
96 |
|
for (InstrumentsMap::const_iterator itMap = m_instruments.begin(); |
97 |
|
itMap != m_instruments.end(); ++itMap) { |
98 |
|
n += (*itMap).size(); |
99 |
|
if (index.row() < n) |
100 |
|
pInstr = &(*itMap)[index.row() + (*itMap).size() - n]; |
101 |
|
} |
102 |
|
} else { |
103 |
|
// resolve MIDI instrument map |
104 |
|
InstrumentsMap::const_iterator itMap = m_instruments.find(m_iMidiMap); |
105 |
|
if (itMap == m_instruments.end()) return QVariant(); |
106 |
|
// resolve instrument in that map |
107 |
|
if (index.row() >= (*itMap).size()) return QVariant(); |
108 |
|
pInstr = &(*itMap)[index.row()]; |
109 |
|
} |
110 |
|
|
111 |
|
if (!pInstr) |
112 |
|
return QVariant(); |
113 |
|
|
114 |
|
if (role == Qt::UserRole) |
115 |
|
return QVariant::fromValue((void *) pInstr); |
116 |
|
|
117 |
|
if (role == Qt::DisplayRole) { |
118 |
|
switch (index.column()) { |
119 |
|
case 0: return pInstr->name(); |
120 |
|
case 1: return QVariant::fromValue(pInstr->map()); |
121 |
|
case 2: return QVariant::fromValue(pInstr->bank()); |
122 |
|
case 3: return QVariant::fromValue(pInstr->prog()); |
123 |
|
case 4: return pInstr->engineName(); |
124 |
|
case 5: return pInstr->instrumentFile(); |
125 |
|
case 6: return QVariant::fromValue(pInstr->instrumentNr()); |
126 |
|
case 7: return QString::number(pInstr->volume() * 100.0) + " %"; |
127 |
|
case 8: { |
128 |
|
switch (pInstr->loadMode()) { |
129 |
|
case 3: return QObject::tr("Persistent"); |
130 |
|
case 2: return QObject::tr("On Demand Hold"); |
131 |
|
case 1: return QObject::tr("On Demand"); |
132 |
|
default: return QVariant(); |
133 |
|
} |
134 |
|
} |
135 |
|
default: return QVariant(); |
136 |
|
} |
137 |
|
} |
138 |
|
|
139 |
// To virtually distinguish between list view items. |
return QVariant(); |
|
int qsamplerInstrumentItem::rtti (void) const |
|
|
{ |
|
|
return qsamplerInstrumentList::Item; |
|
140 |
} |
} |
141 |
|
|
142 |
|
|
143 |
// Payload accessor. |
QVariant MidiInstrumentsModel::headerData ( |
144 |
qsamplerInstrument *qsamplerInstrumentItem::instrument (void) const |
int section, Qt::Orientation orientation, int role ) const |
145 |
{ |
{ |
146 |
return m_pInstrument; |
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) |
147 |
} |
return QVariant(); |
|
|
|
148 |
|
|
149 |
// Item refreshment. |
switch (section) { |
150 |
void qsamplerInstrumentItem::update (void) |
case 0: return tr("Name"); |
151 |
{ |
case 1: return tr("Map"); |
152 |
QListViewItem::setPixmap(0, QPixmap(":/icons/itemFile.png")); |
case 2: return tr("Bank"); |
153 |
|
case 3: return tr("Prog"); |
154 |
const QString s = "-"; |
case 4: return tr("Engine"); |
155 |
if (m_pInstrument) { |
case 5: return tr("File"); |
156 |
setText(0, m_pInstrument->name()); |
case 6: return tr("Nr"); |
157 |
setText(1, QString::number(m_pInstrument->map())); |
case 7: return tr("Vol"); |
158 |
setText(2, QString::number(m_pInstrument->bank())); |
case 8: return tr("Mode"); |
159 |
setText(3, QString::number(m_pInstrument->prog() + 1)); |
default: return QVariant(); |
|
setText(4, m_pInstrument->engineName()); |
|
|
setText(5, QFileInfo(m_pInstrument->instrumentFile()).fileName()); |
|
|
setText(6, QString::number(m_pInstrument->instrumentNr())); |
|
|
setText(7, QString::number(::lroundf(100.0f * m_pInstrument->volume()))); |
|
|
QString sLoadMode = s; |
|
|
switch (m_pInstrument->loadMode()) { |
|
|
case 3: |
|
|
sLoadMode = QObject::tr("Persistent"); |
|
|
break; |
|
|
case 2: |
|
|
sLoadMode = QObject::tr("On Demand Hold"); |
|
|
break; |
|
|
case 1: |
|
|
sLoadMode = QObject::tr("On Demand"); |
|
|
break; |
|
|
} |
|
|
setText(8, sLoadMode); |
|
|
} else { |
|
|
for (int i = 0; i < listView()->columns(); i++) |
|
|
setText(i, s); |
|
160 |
} |
} |
161 |
} |
} |
162 |
|
|
163 |
|
|
164 |
//---------------------------------------------------------------------------- |
qsamplerInstrument* MidiInstrumentsModel::addInstrument ( |
165 |
// qsamplerInstrumentList -- MIDI instrument list view. |
int iMap, int iBank, int iProg ) |
|
// |
|
|
|
|
|
// Constructor. |
|
|
qsamplerInstrumentList::qsamplerInstrumentList ( |
|
|
QWidget *pParent, const char *pszName ) |
|
|
: QListView(pParent, pszName) |
|
|
{ |
|
|
m_iMidiMap = LSCP_MIDI_MAP_ALL; |
|
|
|
|
|
// QListView::setRootIsDecorated(true); |
|
|
QListView::setAllColumnsShowFocus(true); |
|
|
QListView::setResizeMode(QListView::NoColumn); |
|
|
// QListView::setAcceptDrops(true); |
|
|
QListView::setDragAutoScroll(true); |
|
|
QListView::setSizePolicy( |
|
|
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
|
|
// QListView::setShowToolTips(false); |
|
|
QListView::setSortColumn(-1); |
|
|
|
|
|
QListView::addColumn(tr("Name")); |
|
|
QListView::addColumn(tr("Map")); |
|
|
QListView::addColumn(tr("Bank")); |
|
|
QListView::addColumn(tr("Prog")); |
|
|
QListView::addColumn(tr("Engine")); |
|
|
QListView::addColumn(tr("File")); |
|
|
QListView::addColumn(tr("Nr")); |
|
|
QListView::addColumn(tr("Vol")); |
|
|
QListView::addColumn(tr("Mode")); |
|
|
|
|
|
QListView::setColumnAlignment(1, Qt::AlignHCenter); // Map |
|
|
QListView::setColumnAlignment(2, Qt::AlignHCenter); // Bank |
|
|
QListView::setColumnAlignment(3, Qt::AlignHCenter); // Prog |
|
|
QListView::setColumnAlignment(6, Qt::AlignHCenter); // Nr |
|
|
QListView::setColumnAlignment(7, Qt::AlignHCenter); // Vol |
|
|
|
|
|
QListView::setColumnWidth(0, 120); // Name |
|
|
QListView::setColumnWidth(5, 240); // File |
|
|
|
|
|
m_pNewGroupAction = new QAction( |
|
|
QIcon(":/icons/itemGroupNew.png"), |
|
|
tr("New &Group"), tr("Ctrl+G"), this); |
|
|
m_pNewItemAction = new QAction( |
|
|
QIcon(":/icons/itemNew.png"), |
|
|
tr("New &Instrument..."), tr("Ins"), this); |
|
|
m_pEditItemAction = new QAction( |
|
|
QIcon(":/icons/formEdit.png"), |
|
|
tr("&Edit..."), tr("Enter"), this); |
|
|
m_pRenameAction = new QAction(tr("&Rename"), tr("F2"), this); |
|
|
m_pDeleteAction = new QAction( |
|
|
QIcon(":/icons/formRemove.png"), |
|
|
tr("&Delete"), tr("Del"), this); |
|
|
m_pRefreshAction = new QAction( |
|
|
QIcon(":/icons/formRefresh.png"), |
|
|
tr("Re&fresh"), tr("F5"), this); |
|
|
|
|
|
m_pNewGroupAction->setToolTip(tr("New Group")); |
|
|
m_pNewItemAction->setToolTip(tr("New Instrument")); |
|
|
m_pEditItemAction->setToolTip(tr("Edit")); |
|
|
m_pRenameAction->setToolTip(tr("Rename")); |
|
|
m_pDeleteAction->setToolTip(tr("Delete")); |
|
|
m_pRefreshAction->setToolTip(tr("Refresh")); |
|
|
|
|
|
QObject::connect(m_pNewGroupAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(newGroupSlot())); |
|
|
QObject::connect(m_pNewItemAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(newItemSlot())); |
|
|
QObject::connect(m_pEditItemAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(editItemSlot())); |
|
|
QObject::connect(m_pRenameAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(renameSlot())); |
|
|
QObject::connect(m_pDeleteAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(deleteSlot())); |
|
|
QObject::connect(m_pRefreshAction, |
|
|
SIGNAL(activated()), |
|
|
SLOT(refresh())); |
|
|
|
|
|
QObject::connect(this, |
|
|
SIGNAL(selectionChanged()), |
|
|
SLOT(selectionChangedSlot())); |
|
|
QObject::connect(this, |
|
|
SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)), |
|
|
SLOT(activatedSlot(QListViewItem*))); |
|
|
QObject::connect(this, |
|
|
SIGNAL(returnPressed(QListViewItem*)), |
|
|
SLOT(activatedSlot(QListViewItem*))); |
|
|
QObject::connect(this, |
|
|
SIGNAL(itemRenamed(QListViewItem*,int)), |
|
|
SLOT(renamedSlot(QListViewItem*))); |
|
|
|
|
|
selectionChangedSlot(); |
|
|
} |
|
|
|
|
|
|
|
|
// Default destructor. |
|
|
qsamplerInstrumentList::~qsamplerInstrumentList (void) |
|
|
{ |
|
|
delete m_pNewGroupAction; |
|
|
delete m_pNewItemAction; |
|
|
delete m_pEditItemAction; |
|
|
delete m_pRenameAction; |
|
|
delete m_pDeleteAction; |
|
|
} |
|
|
|
|
|
|
|
|
// Add a new instrument item, optionally under a given group. |
|
|
qsamplerInstrumentItem *qsamplerInstrumentList::addItem ( |
|
|
qsamplerInstrument *pInstrument, |
|
|
qsamplerInstrumentGroup *pParentGroup ) |
|
166 |
{ |
{ |
167 |
// Check it there's already one instrument item |
// Check it there's already one instrument item |
168 |
// with the very same key (bank, program); |
// with the very same key (bank, program); |
169 |
// if yes, just remove it without prejudice... |
// if yes, just remove it without prejudice... |
170 |
qsamplerInstrumentItem *pItem = findItem(pInstrument); |
for (int i = 0; i < m_instruments[iMap].size(); i++) { |
171 |
if (pItem) { |
if (m_instruments[iMap][i].bank() == iBank && |
172 |
// If exactly the same, just update view and bail out... |
m_instruments[iMap][i].prog() == iProg) { |
173 |
if (pItem->instrument() == pInstrument) { |
m_instruments[iMap].removeAt(i); |
174 |
pItem->update(); |
break; |
|
return pItem; |
|
175 |
} |
} |
|
// Remove it, as instrument keys must be unique. |
|
|
delete pItem; |
|
176 |
} |
} |
177 |
|
|
178 |
// Add the new item under proper group one, if any... |
// Resolve the appropriate place, we keep the list sorted that way ... |
179 |
if (pParentGroup) { |
int i = 0; |
180 |
pParentGroup->setOpen(true); |
for (; i < m_instruments[iMap].size(); ++i) { |
181 |
pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument); |
if (iBank < m_instruments[iMap][i].bank() |
182 |
} else { |
|| (iBank == m_instruments[iMap][i].bank() && |
183 |
pItem = new qsamplerInstrumentItem(this, pInstrument); |
iProg < m_instruments[iMap][i].prog())) { |
184 |
} |
break; |
|
|
|
|
// Set it as current selection... |
|
|
QListView::setSelected(pItem, true); |
|
|
|
|
|
return pItem; |
|
|
} |
|
|
|
|
|
|
|
|
// Add a new instrument group, optionally under another group. |
|
|
qsamplerInstrumentGroup *qsamplerInstrumentList::addGroup ( |
|
|
const QString& sName, qsamplerInstrumentGroup *pParentGroup ) |
|
|
{ |
|
|
qsamplerInstrumentGroup *pGroup = findGroup(sName); |
|
|
if (pGroup == NULL) { |
|
|
if (pParentGroup) { |
|
|
pParentGroup->setOpen(true); |
|
|
pGroup = new qsamplerInstrumentGroup(pParentGroup, sName); |
|
|
} else { |
|
|
pGroup = new qsamplerInstrumentGroup(this, sName); |
|
185 |
} |
} |
186 |
} |
} |
|
QListView::setSelected(pGroup, true); |
|
|
return pGroup; |
|
|
} |
|
187 |
|
|
188 |
|
m_instruments[iMap].insert(i, qsamplerInstrument(iMap, iBank, iProg)); |
189 |
|
qsamplerInstrument& instr = m_instruments[iMap][i]; |
190 |
|
if (!instr.getInstrument()) |
191 |
|
m_instruments[iMap].removeAt(i); |
192 |
|
|
193 |
// Find a group item, given its name. |
return &instr; |
|
qsamplerInstrumentGroup *qsamplerInstrumentList::findGroup ( |
|
|
const QString& sName ) const |
|
|
{ |
|
|
// Iterate all over the place to search for the group. |
|
|
QListViewItemIterator iter((QListView *) this); |
|
|
while (iter.current()) { |
|
|
QListViewItem *pItem = iter.current(); |
|
|
if (pItem->rtti() == Group && pItem->text(0) == sName) |
|
|
return static_cast<qsamplerInstrumentGroup *> (pItem); |
|
|
++iter; |
|
|
} |
|
|
// Not found. |
|
|
return NULL; |
|
194 |
} |
} |
195 |
|
|
196 |
|
|
197 |
// Find a file item, given its name. |
void MidiInstrumentsModel::removeInstrument ( |
198 |
qsamplerInstrumentItem *qsamplerInstrumentList::findItem ( |
const qsamplerInstrument& instrument ) |
199 |
qsamplerInstrument *pInstrument ) const |
{ |
200 |
{ |
const int iMap = instrument.map(); |
201 |
if (pInstrument == NULL) |
const int iBank = instrument.bank(); |
202 |
return NULL; |
const int iProg = instrument.prog(); |
203 |
|
for (int i = 0; i < m_instruments[iMap].size(); i++) { |
204 |
// Iterate all over the place to search for the group. |
if (m_instruments[iMap][i].bank() == iBank && |
205 |
QListViewItemIterator iter((QListView *) this); |
m_instruments[iMap][i].prog() == iProg) { |
206 |
while (iter.current()) { |
m_instruments[iMap].removeAt(i); |
207 |
QListViewItem *pListItem = iter.current(); |
break; |
|
if (pListItem->rtti() == Item) { |
|
|
qsamplerInstrumentItem *pItem |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
|
|
if (pItem && pItem->instrument() |
|
|
&& pItem->instrument()->map() == pInstrument->map() |
|
|
&& pItem->instrument()->bank() == pInstrument->bank() |
|
|
&& pItem->instrument()->prog() == pInstrument->prog()) |
|
|
return pItem; |
|
208 |
} |
} |
|
++iter; |
|
209 |
} |
} |
|
// Not found. |
|
|
return NULL; |
|
210 |
} |
} |
211 |
|
|
212 |
|
|
213 |
// Find and return the nearest group item... |
// Reposition the instrument in the model (called when map/bank/prg changed) |
214 |
qsamplerInstrumentGroup *qsamplerInstrumentList::groupItem ( |
void MidiInstrumentsModel::resort ( const qsamplerInstrument& instrument ) |
|
QListViewItem *pItem ) const |
|
215 |
{ |
{ |
216 |
while (pItem && pItem->rtti() != Group) |
const int iMap = instrument.map(); |
217 |
pItem = pItem->parent(); |
const int iBank = instrument.bank(); |
218 |
return static_cast<qsamplerInstrumentGroup *> (pItem); |
const int iProg = instrument.prog(); |
219 |
|
// Remove given instrument from its current list |
220 |
|
removeInstrument(instrument); |
221 |
|
// Re-add the instrument |
222 |
|
addInstrument(iMap, iBank, iProg); |
223 |
} |
} |
224 |
|
|
225 |
|
|
226 |
// Add a new group item below the current one. |
void MidiInstrumentsModel::setMidiMap ( int iMidiMap ) |
|
void qsamplerInstrumentList::newGroupSlot (void) |
|
|
{ |
|
|
qsamplerInstrumentGroup *pNewGroup |
|
|
= addGroup(tr("New Group"), groupItem(QListView::selectedItem())); |
|
|
if (pNewGroup) |
|
|
pNewGroup->startRename(0); |
|
|
|
|
|
selectionChangedSlot(); |
|
|
} |
|
|
|
|
|
|
|
|
// Map selector. |
|
|
void qsamplerInstrumentList::setMidiMap ( int iMidiMap ) |
|
227 |
{ |
{ |
228 |
if (iMidiMap < 0) |
if (iMidiMap < 0) |
229 |
iMidiMap = LSCP_MIDI_MAP_ALL; |
iMidiMap = LSCP_MIDI_MAP_ALL; |
231 |
m_iMidiMap = iMidiMap; |
m_iMidiMap = iMidiMap; |
232 |
} |
} |
233 |
|
|
|
int qsamplerInstrumentList::midiMap (void) const |
|
|
{ |
|
|
return m_iMidiMap; |
|
|
} |
|
|
|
|
|
|
|
|
// List actions accessors. |
|
|
QAction *qsamplerInstrumentList::newGroupAction (void) const |
|
|
{ |
|
|
return m_pNewGroupAction; |
|
|
} |
|
|
|
|
|
QAction *qsamplerInstrumentList::newItemAction (void) const |
|
|
{ |
|
|
return m_pNewItemAction; |
|
|
} |
|
|
|
|
|
QAction *qsamplerInstrumentList::editItemAction (void) const |
|
|
{ |
|
|
return m_pEditItemAction; |
|
|
} |
|
|
|
|
|
QAction *qsamplerInstrumentList::renameAction (void) const |
|
|
{ |
|
|
return m_pRenameAction; |
|
|
} |
|
|
|
|
|
QAction *qsamplerInstrumentList::deleteAction (void) const |
|
|
{ |
|
|
return m_pDeleteAction; |
|
|
} |
|
|
|
|
|
QAction *qsamplerInstrumentList::refreshAction (void) const |
|
|
{ |
|
|
return m_pRefreshAction; |
|
|
} |
|
|
|
|
|
|
|
|
// Add a new instrument item below the current one. |
|
|
void qsamplerInstrumentList::newItemSlot (void) |
|
|
{ |
|
|
qsamplerInstrument *pInstrument = new qsamplerInstrument(); |
|
|
|
|
|
qsamplerInstrumentForm form(this); |
|
|
form.setup(pInstrument); |
|
|
if (!form.exec()) { |
|
|
delete pInstrument; |
|
|
return; |
|
|
} |
|
|
|
|
|
// Commit... |
|
|
pInstrument->mapInstrument(); |
|
|
// add new item to the tree... |
|
|
addItem(pInstrument, groupItem(QListView::selectedItem())); |
|
|
// Notify we've changes... |
|
|
emit instrumentsChanged(); |
|
|
|
|
|
selectionChangedSlot(); |
|
|
} |
|
|
|
|
|
|
|
|
// Edit current item below the current one. |
|
|
void qsamplerInstrumentList::editItemSlot (void) |
|
|
{ |
|
|
QListViewItem *pListItem = QListView::selectedItem(); |
|
|
if (pListItem == NULL) |
|
|
return; |
|
|
if (pListItem->rtti() == Item) { |
|
|
qsamplerInstrument *pInstrument = NULL; |
|
|
qsamplerInstrumentItem *pItem |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
|
|
if (pItem) |
|
|
pInstrument = pItem->instrument(); |
|
|
if (pInstrument) { |
|
|
// Save current key values... |
|
|
qsamplerInstrument oldInstrument(*pInstrument); |
|
|
// Do the edit dance... |
|
|
qsamplerInstrumentForm form(this); |
|
|
form.setup(pInstrument); |
|
|
if (form.exec()) { |
|
|
// Commit... |
|
|
pInstrument->mapInstrument(); |
|
|
// Check whether we changed instrument key... |
|
|
if (oldInstrument.map() == pInstrument->map() && |
|
|
oldInstrument.bank() == pInstrument->bank() && |
|
|
oldInstrument.prog() == pInstrument->prog()) { |
|
|
// just update tree item... |
|
|
pItem->update(); |
|
|
} else { |
|
|
// Unmap old instance... |
|
|
oldInstrument.unmapInstrument(); |
|
|
// Change item tree, whether applicable... |
|
|
if (m_iMidiMap < 0 || m_iMidiMap == pInstrument->map()) { |
|
|
// Add new brand item into view... |
|
|
addItem(pInstrument, groupItem(pListItem)); |
|
|
} else { |
|
|
// Just remove/hide old one. |
|
|
delete pItem; |
|
|
} |
|
|
} |
|
|
// Notify we've changes... |
|
|
emit instrumentsChanged(); |
|
|
} |
|
|
} |
|
|
} |
|
234 |
|
|
235 |
selectionChangedSlot(); |
int MidiInstrumentsModel::midiMap (void) const |
|
} |
|
|
|
|
|
|
|
|
// Rename current group/item. |
|
|
void qsamplerInstrumentList::renameSlot (void) |
|
236 |
{ |
{ |
237 |
QListViewItem *pListItem = QListView::selectedItem(); |
return m_iMidiMap; |
|
if (pListItem) |
|
|
pListItem->startRename(0); |
|
|
|
|
|
selectionChangedSlot(); |
|
|
} |
|
|
|
|
|
|
|
|
// Remove current group/item. |
|
|
void qsamplerInstrumentList::deleteSlot (void) |
|
|
{ |
|
|
QListViewItem *pListItem = QListView::selectedItem(); |
|
|
if (pListItem == NULL) |
|
|
return; |
|
|
|
|
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
|
|
if (pMainForm == NULL) |
|
|
return; |
|
|
|
|
|
// Prompt user if this is for real... |
|
|
qsamplerOptions *pOptions = pMainForm->options(); |
|
|
if (pOptions && pOptions->bConfirmRemove) { |
|
|
if (QMessageBox::warning(this, |
|
|
QSAMPLER_TITLE ": " + tr("Warning"), |
|
|
tr("Delete %1:\n\n" |
|
|
"%2\n\n" |
|
|
"Are you sure?") |
|
|
.arg(pListItem->rtti() == Item ? tr("instrument") : tr("group")) |
|
|
.arg(pListItem->text(0)), |
|
|
tr("OK"), tr("Cancel")) > 0) |
|
|
return; |
|
|
} |
|
|
|
|
|
// Unmap instrument entry... |
|
|
if (pListItem->rtti() == Item) { |
|
|
qsamplerInstrumentItem *pItem |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
|
|
if (pItem && pItem->instrument()) { |
|
|
pItem->instrument()->unmapInstrument(); |
|
|
emit instrumentsChanged(); |
|
|
} |
|
|
} |
|
|
|
|
|
// Do it for real... |
|
|
delete pListItem; |
|
|
|
|
|
selectionChangedSlot(); |
|
|
} |
|
|
|
|
|
|
|
|
// In-place selection slot. |
|
|
void qsamplerInstrumentList::selectionChangedSlot (void) |
|
|
{ |
|
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
|
|
QListViewItem *pListItem = QListView::selectedItem(); |
|
|
bool bEnabled = (pMainForm && pMainForm->client()); |
|
|
m_pNewItemAction->setEnabled(bEnabled); |
|
|
bEnabled = (bEnabled && pListItem != NULL); |
|
|
m_pEditItemAction->setEnabled(bEnabled && pListItem->rtti() == Item); |
|
|
m_pRenameAction->setEnabled(bEnabled); |
|
|
m_pDeleteAction->setEnabled(bEnabled); |
|
|
} |
|
|
|
|
|
|
|
|
// In-place activation slot. |
|
|
void qsamplerInstrumentList::activatedSlot ( QListViewItem *pListItem ) |
|
|
{ |
|
|
// FIXME: Hope the list view item is the one selected. |
|
|
if (pListItem && pListItem->rtti() == Item) |
|
|
editItemSlot(); |
|
|
} |
|
|
|
|
|
|
|
|
// In-place aliasing slot. |
|
|
void qsamplerInstrumentList::renamedSlot ( QListViewItem *pListItem ) |
|
|
{ |
|
|
if (pListItem->rtti() == Item) { |
|
|
qsamplerInstrumentItem *pItem |
|
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
|
|
if (pItem && pItem->instrument()) { |
|
|
pItem->instrument()->setName(pListItem->text(0)); |
|
|
pItem->instrument()->mapInstrument(); |
|
|
emit instrumentsChanged(); |
|
|
pItem->update(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Context menu request event handler. |
|
|
void qsamplerInstrumentList::contextMenuEvent ( |
|
|
QContextMenuEvent *pContextMenuEvent ) |
|
|
{ |
|
|
if (!m_pNewItemAction->isEnabled()) |
|
|
return; |
|
|
|
|
|
QPopupMenu menu(this); |
|
|
|
|
|
// Construct context menu. |
|
|
m_pNewItemAction->addTo(&menu); |
|
|
// m_pNewGroupAction->addTo(&menu); |
|
|
menu.insertSeparator(); |
|
|
m_pEditItemAction->addTo(&menu); |
|
|
m_pRenameAction->addTo(&menu); |
|
|
m_pDeleteAction->addTo(&menu); |
|
|
menu.insertSeparator(); |
|
|
m_pRefreshAction->addTo(&menu); |
|
|
|
|
|
menu.exec(pContextMenuEvent->globalPos()); |
|
238 |
} |
} |
239 |
|
|
240 |
|
void MidiInstrumentsModel::refresh (void) |
|
// General reloader. |
|
|
void qsamplerInstrumentList::refresh (void) |
|
241 |
{ |
{ |
242 |
clear(); |
m_instruments.clear(); |
|
|
|
|
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
|
|
if (pMainForm == NULL) |
|
|
return; |
|
|
if (pMainForm->client() == NULL) |
|
|
return; |
|
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
|
|
|
|
|
// Load the whole bunch of instrument items... |
|
|
qsamplerInstrumentItem *pItem = NULL; |
|
|
lscp_midi_instrument_t *pInstrs |
|
|
= ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap); |
|
|
for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) { |
|
|
int iMap = pInstrs[iInstr].map; |
|
|
int iBank = pInstrs[iInstr].bank; |
|
|
int iProg = pInstrs[iInstr].prog; |
|
|
qsamplerInstrument *pInstrument |
|
|
= new qsamplerInstrument(iMap, iBank, iProg); |
|
|
if (pInstrument->getInstrument()) |
|
|
pItem = new qsamplerInstrumentItem(this, pInstrument, pItem); |
|
|
// Try to keep it snappy :) |
|
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
|
|
} |
|
|
|
|
|
QApplication::restoreOverrideCursor(); |
|
|
|
|
|
if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) { |
|
|
pMainForm->appendMessagesClient("lscp_list_midi_instruments"); |
|
|
pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry.")); |
|
|
} |
|
|
|
|
|
selectionChangedSlot(); |
|
|
} |
|
|
#endif |
|
|
|
|
|
MidiInstrumentsModel::MidiInstrumentsModel(QObject* parent) : QAbstractTableModel(parent) { |
|
|
m_iMidiMap = LSCP_MIDI_MAP_ALL; |
|
|
} |
|
|
|
|
|
int MidiInstrumentsModel::rowCount(const QModelIndex& /*parent*/) const { |
|
|
if (m_iMidiMap == LSCP_MIDI_MAP_ALL) { |
|
|
int n = 0; |
|
|
for (InstrumentsMap::const_iterator itMap = instruments.begin(); itMap != instruments.end(); ++itMap) |
|
|
n += (*itMap).size(); |
|
|
return n; |
|
|
} |
|
|
InstrumentsMap::const_iterator itMap = instruments.find(m_iMidiMap); |
|
|
if (itMap == instruments.end()) return 0; |
|
|
return (*itMap).size(); |
|
|
} |
|
|
|
|
|
int MidiInstrumentsModel::columnCount(const QModelIndex& /*parent*/) const { |
|
|
return 9; |
|
|
} |
|
|
|
|
|
QVariant MidiInstrumentsModel::data(const QModelIndex &index, int role) const { |
|
|
if (!index.isValid() || role != Qt::DisplayRole) return QVariant(); |
|
|
|
|
|
if (m_iMidiMap == LSCP_MIDI_MAP_ALL) { |
|
|
int n = 0; |
|
|
for (InstrumentsMap::const_iterator itMap = instruments.begin(); itMap != instruments.end(); ++itMap) { |
|
|
n += (*itMap).size(); |
|
|
if (index.row() < n) |
|
|
return QVariant::fromValue( |
|
|
(*itMap)[index.row() + (*itMap).size() - n] |
|
|
); |
|
|
} |
|
|
} else { |
|
|
// resolve MIDI instrument map |
|
|
InstrumentsMap::const_iterator itMap = instruments.find(m_iMidiMap); |
|
|
if (itMap == instruments.end()) return QVariant(); |
|
|
// resolve instrument in that map |
|
|
if (index.row() >= (*itMap).size()) return QVariant(); |
|
|
return QVariant::fromValue( |
|
|
(*itMap)[index.row()] |
|
|
); |
|
|
} |
|
|
|
|
|
return QVariant(); |
|
|
} |
|
|
|
|
|
QVariant MidiInstrumentsModel::headerData(int section, Qt::Orientation orientation, int role) const { |
|
|
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) |
|
|
return QVariant(); |
|
|
|
|
|
switch (section) { |
|
|
case 0: return tr("Name"); |
|
|
case 1: return tr("Map"); |
|
|
case 2: return tr("Bank"); |
|
|
case 3: return tr("Prog"); |
|
|
case 4: return tr("Engine"); |
|
|
case 5: return tr("File"); |
|
|
case 6: return tr("Nr"); |
|
|
case 7: return tr("Vol"); |
|
|
case 8: return tr("Mode"); |
|
|
default: return QVariant(); |
|
|
} |
|
|
} |
|
|
|
|
|
qsamplerInstrument* MidiInstrumentsModel::addInstrument(int iMap, int iBank, int iProg) { |
|
|
// Check it there's already one instrument item |
|
|
// with the very same key (bank, program); |
|
|
// if yes, just remove it without prejudice... |
|
|
for (int i = 0; i < instruments[iMap].size(); i++) { |
|
|
if ( |
|
|
instruments[iMap][i].bank() == iBank && |
|
|
instruments[iMap][i].prog() == iProg |
|
|
) { |
|
|
instruments[iMap].removeAt(i); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
// resolve the appropriate place, we keep the list sorted that way ... |
|
|
int i = 0; |
|
|
for (; i < instruments[iMap].size(); i++) |
|
|
if ( |
|
|
iBank > instruments[iMap][i].bank() || |
|
|
( iBank == instruments[iMap][i].bank() && |
|
|
iProg > instruments[iMap][i].prog() ) |
|
|
) break; |
|
|
|
|
|
qsamplerInstrument& instr = instruments[iMap][i] = qsamplerInstrument(iMap, iBank, iProg); |
|
|
|
|
|
return &instr; |
|
|
} |
|
|
|
|
|
void MidiInstrumentsModel::setMidiMap(int iMidiMap) { |
|
|
if (iMidiMap < 0) |
|
|
iMidiMap = LSCP_MIDI_MAP_ALL; |
|
|
|
|
|
m_iMidiMap = iMidiMap; |
|
|
} |
|
|
|
|
|
int MidiInstrumentsModel::midiMap() const { |
|
|
return m_iMidiMap; |
|
|
} |
|
|
|
|
|
void MidiInstrumentsModel::refresh() { |
|
|
instruments.clear(); |
|
243 |
|
|
244 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
245 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
258 |
const int iProg = pInstrs[iInstr].prog; |
const int iProg = pInstrs[iInstr].prog; |
259 |
addInstrument(iMap, iBank, iProg); |
addInstrument(iMap, iBank, iProg); |
260 |
// Try to keep it snappy :) |
// Try to keep it snappy :) |
261 |
QApplication::processEvents(QEventLoop::ExcludeUserInput); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
262 |
} |
} |
263 |
|
|
264 |
QApplication::restoreOverrideCursor(); |
QApplication::restoreOverrideCursor(); |
265 |
|
|
266 |
if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) { |
if (pInstrs == NULL && ::lscp_client_get_errno(pMainForm->client())) { |
267 |
pMainForm->appendMessagesClient("lscp_list_midi_instruments"); |
pMainForm->appendMessagesClient("lscp_list_midi_instruments"); |
268 |
pMainForm->appendMessagesError(tr("Could not get current list of MIDI instrument mappings.\n\nSorry.")); |
pMainForm->appendMessagesError( |
269 |
|
tr("Could not get current list of MIDI instrument mappings.\n\nSorry.")); |
270 |
} |
} |
271 |
|
|
272 |
//selectionChangedSlot(); |
// inform the outer world (QTableView) that our data changed |
273 |
|
QAbstractTableModel::reset(); |
274 |
} |
} |
275 |
|
|
276 |
|
|
277 |
MidiInstrumentsDelegate::MidiInstrumentsDelegate(QObject* parent) : QItemDelegate(parent) { |
//------------------------------------------------------------------------- |
278 |
|
// MidiInstrumentsDelegate - table cell renderer for MIDI prog mappings |
279 |
|
// (doesn't actually do anything ATM, but is already there for a future |
280 |
|
// cell editor widget implementation) |
281 |
|
|
282 |
|
MidiInstrumentsDelegate::MidiInstrumentsDelegate ( QObject* pParent ) |
283 |
|
: QItemDelegate(pParent) |
284 |
|
{ |
285 |
} |
} |
286 |
|
|
287 |
QWidget* MidiInstrumentsDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { |
|
288 |
return new QLabel(index.model()->data(index, Qt::DisplayRole).toString(), parent); |
QWidget* MidiInstrumentsDelegate::createEditor ( QWidget* pParent, |
289 |
|
const QStyleOptionViewItem& option, const QModelIndex& index ) const |
290 |
|
{ |
291 |
|
return QItemDelegate::createEditor(pParent, option, index); |
292 |
|
// return new QLabel(index.model()->data(index, Qt::DisplayRole).toString(), parent); |
293 |
} |
} |
294 |
|
|
295 |
void MidiInstrumentsDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const { |
|
296 |
|
void MidiInstrumentsDelegate::setEditorData ( QWidget */*pEditor*/, |
297 |
|
const QModelIndex& /*index*/) const |
298 |
|
{ |
299 |
} |
} |
300 |
|
|
301 |
void MidiInstrumentsDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
|
302 |
|
void MidiInstrumentsDelegate::setModelData ( QWidget */*pEditor*/, |
303 |
|
QAbstractItemModel* /*model*/, const QModelIndex& /*index*/) const |
304 |
|
{ |
305 |
} |
} |
306 |
|
|
307 |
void MidiInstrumentsDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const { |
|
308 |
if (editor) editor->setGeometry(option.rect); |
void MidiInstrumentsDelegate::updateEditorGeometry ( QWidget *pEditor, |
309 |
|
const QStyleOptionViewItem& option, const QModelIndex& index) const |
310 |
|
{ |
311 |
|
QItemDelegate::updateEditorGeometry(pEditor, option, index); |
312 |
|
// if (pEditor) pEditor->setGeometry(option.rect); |
313 |
} |
} |
314 |
|
|
315 |
|
|