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" |
60 |
ui.refreshInstrumentsAction->addTo(ui.InstrumentToolbar); |
ui.refreshInstrumentsAction->addTo(ui.InstrumentToolbar); |
61 |
|
|
62 |
ui.InstrumentTable->setModel(&model); |
ui.InstrumentTable->setModel(&model); |
63 |
//ui.InstrumentTable->setDelegate(delegate); |
ui.InstrumentTable->setItemDelegate(&delegate); |
64 |
|
|
65 |
QObject::connect(m_pMapComboBox, |
QObject::connect(m_pMapComboBox, |
66 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
71 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
72 |
SLOT(refreshInstruments(void)) |
SLOT(refreshInstruments(void)) |
73 |
); |
); |
74 |
|
|
75 |
|
connect( |
76 |
|
ui.InstrumentTable, |
77 |
|
SIGNAL(activated(const QModelIndex&)), |
78 |
|
SLOT(editInstrument(const QModelIndex&)) |
79 |
|
); |
80 |
|
connect( |
81 |
|
ui.newInstrumentAction, |
82 |
|
SIGNAL(triggered()), |
83 |
|
SLOT(newInstrument()) |
84 |
|
); |
85 |
|
connect( |
86 |
|
ui.deleteInstrumentAction, |
87 |
|
SIGNAL(triggered()), |
88 |
|
SLOT(deleteInstrument()) |
89 |
|
); |
90 |
|
connect( |
91 |
|
ui.editInstrumentAction, |
92 |
|
SIGNAL(triggered()), |
93 |
|
SLOT(editInstrument()) |
94 |
|
); |
95 |
} |
} |
96 |
|
|
97 |
InstrumentListForm::~InstrumentListForm() { |
InstrumentListForm::~InstrumentListForm() { |
171 |
model.refresh(); |
model.refresh(); |
172 |
} |
} |
173 |
|
|
174 |
|
void InstrumentListForm::editInstrument() { |
175 |
|
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
176 |
|
editInstrument(index); |
177 |
|
} |
178 |
|
|
179 |
|
void InstrumentListForm::editInstrument(const QModelIndex& index) { |
180 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
181 |
|
return; |
182 |
|
|
183 |
|
qsamplerInstrument* pInstrument = |
184 |
|
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
185 |
|
|
186 |
|
if (!pInstrument) return; |
187 |
|
|
188 |
|
// Save current key values... |
189 |
|
qsamplerInstrument oldInstrument(*pInstrument); |
190 |
|
// Do the edit dance... |
191 |
|
InstrumentForm form(this); |
192 |
|
form.setup(pInstrument); |
193 |
|
if (form.exec()) { |
194 |
|
// Commit... |
195 |
|
pInstrument->mapInstrument(); |
196 |
|
// Check whether we changed instrument key... |
197 |
|
if (oldInstrument.map() == pInstrument->map() && |
198 |
|
oldInstrument.bank() == pInstrument->bank() && |
199 |
|
oldInstrument.prog() == pInstrument->prog()) { |
200 |
|
// just update tree item... |
201 |
|
//pItem->update(); |
202 |
|
} else { |
203 |
|
// Unmap old instance... |
204 |
|
oldInstrument.unmapInstrument(); |
205 |
|
// correct the position of the instrument in the model |
206 |
|
model.resort(*pInstrument); |
207 |
|
} |
208 |
|
// Notify we've changes... |
209 |
|
emit model.reset(); |
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
|
void InstrumentListForm::newInstrument() { |
214 |
|
qsamplerInstrument instrument; |
215 |
|
|
216 |
|
InstrumentForm form(this); |
217 |
|
form.setup(&instrument); |
218 |
|
if (!form.exec()) return; |
219 |
|
|
220 |
|
// Commit... |
221 |
|
instrument.mapInstrument(); |
222 |
|
// add new item to the table model |
223 |
|
model.resort(instrument); |
224 |
|
// Notify we've changes... |
225 |
|
//emit model.reset(); |
226 |
|
//FIXME: call above didnt really refresh, so we use this for now ... |
227 |
|
refreshInstruments(); |
228 |
|
} |
229 |
|
|
230 |
|
void InstrumentListForm::deleteInstrument() { |
231 |
|
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
232 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) return; |
233 |
|
|
234 |
|
qsamplerInstrument* pInstrument = |
235 |
|
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
236 |
|
|
237 |
|
if (!pInstrument) return; |
238 |
|
|
239 |
|
pInstrument->unmapInstrument(); |
240 |
|
// let the instrument vanish from the table model |
241 |
|
model.removeInstrument(*pInstrument); |
242 |
|
// Notify we've changes... |
243 |
|
emit model.reset(); |
244 |
|
} |
245 |
|
|
246 |
} // namespace QSampler |
} // namespace QSampler |
247 |
|
|
248 |
|
|