22 |
|
|
23 |
#include "qsamplerInstrumentListForm.h" |
#include "qsamplerInstrumentListForm.h" |
24 |
|
|
25 |
|
#include "qsamplerInstrumentForm.h" |
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
28 |
#include "qsamplerInstrument.h" |
#include "qsamplerInstrument.h" |
29 |
|
|
|
#include <QToolTip> |
|
30 |
|
|
31 |
namespace QSampler { |
namespace QSampler { |
32 |
|
|
33 |
InstrumentListForm::InstrumentListForm(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { |
InstrumentListForm::InstrumentListForm ( QWidget* parent, Qt::WindowFlags flags ) |
34 |
|
: QMainWindow(parent, flags) |
35 |
|
{ |
36 |
ui.setupUi(this); |
ui.setupUi(this); |
37 |
|
|
38 |
ui.newInstrumentAction->setText(tr("New &Instrument...")); |
ui.newInstrumentAction->setText(tr("New &Instrument...")); |
48 |
m_pMapComboBox = new QComboBox(ui.InstrumentToolbar); |
m_pMapComboBox = new QComboBox(ui.InstrumentToolbar); |
49 |
m_pMapComboBox->setMinimumWidth(120); |
m_pMapComboBox->setMinimumWidth(120); |
50 |
m_pMapComboBox->setEnabled(false); |
m_pMapComboBox->setEnabled(false); |
51 |
QToolTip::add(m_pMapComboBox, tr("Instrument Map")); |
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
52 |
|
ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
53 |
|
|
54 |
ui.InstrumentToolbar->addSeparator(); |
ui.InstrumentToolbar->addSeparator(); |
55 |
ui.newInstrumentAction->addTo(ui.InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.newInstrumentAction); |
56 |
ui.editInstrumentAction->addTo(ui.InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.editInstrumentAction); |
57 |
ui.deleteInstrumentAction->addTo(ui.InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.deleteInstrumentAction); |
58 |
ui.InstrumentToolbar->addSeparator(); |
ui.InstrumentToolbar->addSeparator(); |
59 |
ui.refreshInstrumentsAction->addTo(ui.InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.refreshInstrumentsAction); |
60 |
|
|
61 |
ui.InstrumentTable->setModel(&model); |
ui.InstrumentTable->setModel(&model); |
62 |
//ui.InstrumentTable->setDelegate(delegate); |
ui.InstrumentTable->setItemDelegate(&delegate); |
63 |
|
|
64 |
QObject::connect(m_pMapComboBox, |
QObject::connect(m_pMapComboBox, |
65 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
70 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
71 |
SLOT(refreshInstruments(void)) |
SLOT(refreshInstruments(void)) |
72 |
); |
); |
73 |
|
|
74 |
|
connect( |
75 |
|
ui.InstrumentTable, |
76 |
|
SIGNAL(activated(const QModelIndex&)), |
77 |
|
SLOT(editInstrument(const QModelIndex&)) |
78 |
|
); |
79 |
|
connect( |
80 |
|
ui.newInstrumentAction, |
81 |
|
SIGNAL(triggered()), |
82 |
|
SLOT(newInstrument()) |
83 |
|
); |
84 |
|
connect( |
85 |
|
ui.deleteInstrumentAction, |
86 |
|
SIGNAL(triggered()), |
87 |
|
SLOT(deleteInstrument()) |
88 |
|
); |
89 |
|
connect( |
90 |
|
ui.editInstrumentAction, |
91 |
|
SIGNAL(triggered()), |
92 |
|
SLOT(editInstrument()) |
93 |
|
); |
94 |
} |
} |
95 |
|
|
96 |
InstrumentListForm::~InstrumentListForm() { |
InstrumentListForm::~InstrumentListForm() { |
132 |
return; |
return; |
133 |
|
|
134 |
// Get/save current map selection... |
// Get/save current map selection... |
135 |
int iMap = m_pMapComboBox->currentItem(); |
int iMap = m_pMapComboBox->currentIndex(); |
136 |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
137 |
iMap = pOptions->iMidiMap + 1; |
iMap = pOptions->iMidiMap + 1; |
138 |
|
|
139 |
// Populate maps list. |
// Populate maps list. |
140 |
m_pMapComboBox->clear(); |
m_pMapComboBox->clear(); |
141 |
m_pMapComboBox->insertItem(tr("(All)")); |
m_pMapComboBox->addItem(tr("(All)")); |
142 |
m_pMapComboBox->insertStringList(qsamplerInstrument::getMapNames()); |
m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames()); |
143 |
|
|
144 |
// Adjust to saved selection... |
// Adjust to saved selection... |
145 |
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
146 |
iMap = 0; |
iMap = 0; |
147 |
m_pMapComboBox->setCurrentItem(iMap); |
m_pMapComboBox->setCurrentIndex(iMap); |
148 |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
149 |
|
|
150 |
activateMap(iMap); |
activateMap(iMap); |
170 |
model.refresh(); |
model.refresh(); |
171 |
} |
} |
172 |
|
|
173 |
|
void InstrumentListForm::editInstrument() { |
174 |
|
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
175 |
|
editInstrument(index); |
176 |
|
} |
177 |
|
|
178 |
|
void InstrumentListForm::editInstrument(const QModelIndex& index) { |
179 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
180 |
|
return; |
181 |
|
|
182 |
|
qsamplerInstrument* pInstrument = |
183 |
|
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
184 |
|
|
185 |
|
if (!pInstrument) return; |
186 |
|
|
187 |
|
// Save current key values... |
188 |
|
qsamplerInstrument oldInstrument(*pInstrument); |
189 |
|
// Do the edit dance... |
190 |
|
InstrumentForm form(this); |
191 |
|
form.setup(pInstrument); |
192 |
|
if (form.exec()) { |
193 |
|
// Commit... |
194 |
|
pInstrument->mapInstrument(); |
195 |
|
// Check whether we changed instrument key... |
196 |
|
if (oldInstrument.map() == pInstrument->map() && |
197 |
|
oldInstrument.bank() == pInstrument->bank() && |
198 |
|
oldInstrument.prog() == pInstrument->prog()) { |
199 |
|
// just update tree item... |
200 |
|
//pItem->update(); |
201 |
|
} else { |
202 |
|
// Unmap old instance... |
203 |
|
oldInstrument.unmapInstrument(); |
204 |
|
// correct the position of the instrument in the model |
205 |
|
model.resort(*pInstrument); |
206 |
|
} |
207 |
|
// Notify we've changes... |
208 |
|
emit model.reset(); |
209 |
|
} |
210 |
|
} |
211 |
|
|
212 |
|
void InstrumentListForm::newInstrument() { |
213 |
|
qsamplerInstrument instrument; |
214 |
|
|
215 |
|
InstrumentForm form(this); |
216 |
|
form.setup(&instrument); |
217 |
|
if (!form.exec()) return; |
218 |
|
|
219 |
|
// Commit... |
220 |
|
instrument.mapInstrument(); |
221 |
|
// add new item to the table model |
222 |
|
model.resort(instrument); |
223 |
|
// Notify we've changes... |
224 |
|
//emit model.reset(); |
225 |
|
//FIXME: call above didnt really refresh, so we use this for now ... |
226 |
|
refreshInstruments(); |
227 |
|
} |
228 |
|
|
229 |
|
void InstrumentListForm::deleteInstrument() { |
230 |
|
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
231 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) return; |
232 |
|
|
233 |
|
qsamplerInstrument* pInstrument = |
234 |
|
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
235 |
|
|
236 |
|
if (!pInstrument) return; |
237 |
|
|
238 |
|
pInstrument->unmapInstrument(); |
239 |
|
// let the instrument vanish from the table model |
240 |
|
model.removeInstrument(*pInstrument); |
241 |
|
// Notify we've changes... |
242 |
|
emit model.reset(); |
243 |
|
} |
244 |
|
|
245 |
} // namespace QSampler |
} // namespace QSampler |
246 |
|
|
247 |
|
|