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