1 |
// qsamplerInstrumentListForm.cpp |
// qsamplerInstrumentListForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
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 |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
#include "qsamplerInstrumentListForm.h" |
#include "qsamplerInstrumentListForm.h" |
25 |
|
|
26 |
|
#include "qsamplerInstrumentList.h" |
27 |
|
|
28 |
#include "qsamplerInstrumentForm.h" |
#include "qsamplerInstrumentForm.h" |
29 |
#include "qsamplerMainForm.h" |
|
30 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
31 |
#include "qsamplerInstrument.h" |
#include "qsamplerInstrument.h" |
32 |
|
#include "qsamplerMainForm.h" |
33 |
|
|
34 |
|
#include <QHeaderView> |
35 |
|
#include <QMessageBox> |
36 |
|
#include <QContextMenuEvent> |
37 |
|
|
38 |
|
|
39 |
namespace QSampler { |
namespace QSampler { |
40 |
|
|
41 |
|
//------------------------------------------------------------------------- |
42 |
|
// QSampler::InstrumentListForm -- Instrument map list form implementation. |
43 |
|
// |
44 |
|
|
45 |
InstrumentListForm::InstrumentListForm ( |
InstrumentListForm::InstrumentListForm ( |
46 |
QWidget* pParent, Qt::WindowFlags wflags ) |
QWidget* pParent, Qt::WindowFlags wflags ) |
47 |
: QMainWindow(pParent, wflags) |
: QMainWindow(pParent, wflags) |
48 |
{ |
{ |
49 |
ui.setupUi(this); |
m_ui.setupUi(this); |
50 |
|
|
51 |
// Setup toolbar widgets. |
m_pInstrumentListView = new InstrumentListView(this); |
52 |
m_pMapComboBox = new QComboBox(ui.InstrumentToolbar); |
QMainWindow::setCentralWidget(m_pInstrumentListView); |
|
m_pMapComboBox->setMinimumWidth(120); |
|
|
m_pMapComboBox->setEnabled(false); |
|
|
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
|
|
ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
|
|
|
|
|
ui.InstrumentToolbar->addSeparator(); |
|
|
ui.InstrumentToolbar->addAction(ui.newInstrumentAction); |
|
|
ui.InstrumentToolbar->addAction(ui.editInstrumentAction); |
|
|
ui.InstrumentToolbar->addAction(ui.deleteInstrumentAction); |
|
|
ui.InstrumentToolbar->addSeparator(); |
|
|
ui.InstrumentToolbar->addAction(ui.refreshInstrumentsAction); |
|
53 |
|
|
54 |
ui.InstrumentTable->setModel(&model); |
// Setup toolbar widgets. |
55 |
ui.InstrumentTable->setItemDelegate(&delegate); |
m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar); |
56 |
|
m_pMapComboBox->setMinimumWidth(120); |
57 |
|
m_pMapComboBox->setEnabled(false); |
58 |
|
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
59 |
|
|
60 |
|
m_ui.instrumentToolbar->addWidget(m_pMapComboBox); |
61 |
|
m_ui.instrumentToolbar->addSeparator(); |
62 |
|
m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction); |
63 |
|
m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction); |
64 |
|
m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
65 |
|
m_ui.instrumentToolbar->addSeparator(); |
66 |
|
m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
67 |
|
|
68 |
QObject::connect(m_pMapComboBox, |
QObject::connect(m_pMapComboBox, |
69 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
70 |
SLOT(activateMap(int))); |
SLOT(activateMap(int))); |
71 |
|
QObject::connect(m_pInstrumentListView->selectionModel(), |
72 |
|
SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)), |
73 |
|
SLOT(stabilizeForm())); |
74 |
QObject::connect( |
QObject::connect( |
75 |
ui.refreshInstrumentsAction, |
m_pInstrumentListView, |
76 |
SIGNAL(triggered()), |
SIGNAL(doubleClicked(const QModelIndex&)), |
77 |
SLOT(refreshInstruments(void)) |
SLOT(editInstrument(const QModelIndex&))); |
|
); |
|
|
|
|
78 |
QObject::connect( |
QObject::connect( |
79 |
ui.InstrumentTable, |
m_ui.newInstrumentAction, |
80 |
SIGNAL(activated(const QModelIndex&)), |
SIGNAL(triggered()), |
81 |
SLOT(editInstrument(const QModelIndex&)) |
SLOT(newInstrument())); |
|
); |
|
82 |
QObject::connect( |
QObject::connect( |
83 |
ui.newInstrumentAction, |
m_ui.deleteInstrumentAction, |
84 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
85 |
SLOT(newInstrument()) |
SLOT(deleteInstrument())); |
|
); |
|
86 |
QObject::connect( |
QObject::connect( |
87 |
ui.deleteInstrumentAction, |
m_ui.editInstrumentAction, |
88 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
89 |
SLOT(deleteInstrument()) |
SLOT(editInstrument())); |
|
); |
|
90 |
QObject::connect( |
QObject::connect( |
91 |
ui.editInstrumentAction, |
m_ui.refreshInstrumentsAction, |
92 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
93 |
SLOT(editInstrument()) |
SLOT(refreshInstruments())); |
94 |
); |
|
95 |
|
// Things must be stable from the start. |
96 |
|
stabilizeForm(); |
97 |
} |
} |
98 |
|
|
99 |
|
|
100 |
InstrumentListForm::~InstrumentListForm (void) |
InstrumentListForm::~InstrumentListForm (void) |
101 |
{ |
{ |
102 |
delete m_pMapComboBox; |
delete m_pMapComboBox; |
103 |
|
delete m_pInstrumentListView; |
104 |
} |
} |
105 |
|
|
106 |
|
|
144 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
145 |
return; |
return; |
146 |
|
|
147 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
148 |
if (pOptions == NULL) |
if (pOptions == NULL) |
149 |
return; |
return; |
150 |
|
|
156 |
// Populate maps list. |
// Populate maps list. |
157 |
m_pMapComboBox->clear(); |
m_pMapComboBox->clear(); |
158 |
m_pMapComboBox->addItem(tr("(All)")); |
m_pMapComboBox->addItem(tr("(All)")); |
159 |
m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames()); |
m_pMapComboBox->insertItems(1, Instrument::getMapNames()); |
160 |
|
|
161 |
// Adjust to saved selection... |
// Adjust to saved selection... |
162 |
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
175 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
176 |
return; |
return; |
177 |
|
|
178 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
179 |
if (pOptions == NULL) |
if (pOptions == NULL) |
180 |
return; |
return; |
181 |
|
|
183 |
if (iMidiMap >= 0) |
if (iMidiMap >= 0) |
184 |
pOptions->iMidiMap = iMidiMap; |
pOptions->iMidiMap = iMidiMap; |
185 |
|
|
186 |
model.setMidiMap(iMidiMap); |
m_pInstrumentListView->setMidiMap(iMidiMap); |
187 |
model.refresh(); |
m_pInstrumentListView->refresh(); |
188 |
|
|
189 |
|
stabilizeForm(); |
190 |
} |
} |
191 |
|
|
192 |
|
|
193 |
void InstrumentListForm::editInstrument (void) |
void InstrumentListForm::editInstrument (void) |
194 |
{ |
{ |
195 |
editInstrument(ui.InstrumentTable->currentIndex()); |
editInstrument(m_pInstrumentListView->currentIndex()); |
196 |
} |
} |
197 |
|
|
198 |
|
|
199 |
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
200 |
{ |
{ |
201 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
if (!index.isValid()) |
202 |
return; |
return; |
203 |
|
|
204 |
qsamplerInstrument* pInstrument |
Instrument *pInstrument |
205 |
= static_cast<qsamplerInstrument *> ( |
= static_cast<Instrument *> (index.internalPointer()); |
|
index.data(Qt::UserRole).value<void *> ()); |
|
|
|
|
206 |
if (pInstrument == NULL) |
if (pInstrument == NULL) |
207 |
return; |
return; |
208 |
|
|
209 |
// Save current key values... |
// Save current key values... |
210 |
qsamplerInstrument oldInstrument(*pInstrument); |
int iMap = pInstrument->map(); |
211 |
|
int iBank = pInstrument->bank(); |
212 |
|
int iProg = pInstrument->prog(); |
213 |
|
|
214 |
|
Instrument instrument(iMap, iBank, iProg); |
215 |
|
|
216 |
// Do the edit dance... |
// Do the edit dance... |
217 |
InstrumentForm form(this); |
InstrumentForm form(this); |
218 |
form.setup(pInstrument); |
form.setup(&instrument); |
219 |
if (form.exec()) { |
if (form.exec()) { |
220 |
// Commit... |
// Commit... |
221 |
pInstrument->mapInstrument(); |
instrument.mapInstrument(); |
222 |
// Check whether we changed instrument key... |
// Check whether we changed instrument key... |
223 |
if (oldInstrument.map() == pInstrument->map() && |
if (instrument.map() == iMap && |
224 |
oldInstrument.bank() == pInstrument->bank() && |
instrument.bank() == iBank && |
225 |
oldInstrument.prog() == pInstrument->prog()) { |
instrument.prog() == iProg) { |
226 |
// just update tree item... |
// Just update tree item... |
227 |
//pItem->update(); |
//pItem->update(); |
228 |
} else { |
} else { |
229 |
// Unmap old instance... |
// Unmap old instance... |
230 |
oldInstrument.unmapInstrument(); |
Instrument(iMap, iBank, iProg).unmapInstrument(); |
231 |
// correct the position of the instrument in the model |
// correct the position of the instrument in the model |
232 |
model.resort(*pInstrument); |
m_pInstrumentListView->updateInstrument(pInstrument); |
233 |
} |
} |
|
// Notify we've changes... |
|
|
emit model.reset(); |
|
234 |
} |
} |
235 |
|
|
236 |
|
stabilizeForm(); |
237 |
} |
} |
238 |
|
|
239 |
|
|
240 |
void InstrumentListForm::newInstrument (void) |
void InstrumentListForm::newInstrument (void) |
241 |
{ |
{ |
242 |
qsamplerInstrument instrument; |
Instrument instrument; |
243 |
|
|
244 |
InstrumentForm form(this); |
InstrumentForm form(this); |
245 |
form.setup(&instrument); |
form.setup(&instrument); |
248 |
|
|
249 |
// Commit... |
// Commit... |
250 |
instrument.mapInstrument(); |
instrument.mapInstrument(); |
251 |
|
|
252 |
// add new item to the table model |
// add new item to the table model |
253 |
model.resort(instrument); |
m_pInstrumentListView->addInstrument( |
254 |
// Notify we've changes... |
instrument.map(), |
255 |
//emit model.reset(); |
instrument.bank(), |
256 |
//FIXME: call above didnt really refresh, so we use this for now ... |
instrument.prog()); |
257 |
refreshInstruments(); |
|
258 |
|
stabilizeForm(); |
259 |
} |
} |
260 |
|
|
261 |
|
|
262 |
void InstrumentListForm::deleteInstrument (void) |
void InstrumentListForm::deleteInstrument (void) |
263 |
{ |
{ |
264 |
const QModelIndex& index = ui.InstrumentTable->currentIndex(); |
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
265 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
if (!index.isValid()) |
266 |
return; |
return; |
267 |
|
|
268 |
qsamplerInstrument* pInstrument = |
Instrument *pInstrument |
269 |
static_cast<qsamplerInstrument*> ( |
= static_cast<Instrument *> (index.internalPointer()); |
|
index.data(Qt::UserRole).value<void *> ()); |
|
|
|
|
270 |
if (pInstrument == NULL) |
if (pInstrument == NULL) |
271 |
return; |
return; |
272 |
|
|
273 |
|
MainForm *pMainForm = MainForm::getInstance(); |
274 |
|
if (pMainForm == NULL) |
275 |
|
return; |
276 |
|
|
277 |
|
// Prompt user if this is for real... |
278 |
|
Options *pOptions = pMainForm->options(); |
279 |
|
if (pOptions && pOptions->bConfirmRemove) { |
280 |
|
if (QMessageBox::warning(this, |
281 |
|
QSAMPLER_TITLE ": " + tr("Warning"), |
282 |
|
tr("About to delete instrument map entry:\n\n" |
283 |
|
"%1\n\n" |
284 |
|
"Are you sure?") |
285 |
|
.arg(pInstrument->name()), |
286 |
|
QMessageBox::Ok | QMessageBox::Cancel) |
287 |
|
== QMessageBox::Cancel) |
288 |
|
return; |
289 |
|
} |
290 |
|
|
291 |
pInstrument->unmapInstrument(); |
pInstrument->unmapInstrument(); |
292 |
|
|
293 |
// let the instrument vanish from the table model |
// let the instrument vanish from the table model |
294 |
model.removeInstrument(*pInstrument); |
m_pInstrumentListView->removeInstrument(pInstrument); |
295 |
// Notify we've changes... |
|
296 |
emit model.reset(); |
stabilizeForm(); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
// Update form actions enablement... |
301 |
|
void InstrumentListForm::stabilizeForm (void) |
302 |
|
{ |
303 |
|
MainForm *pMainForm = MainForm::getInstance(); |
304 |
|
|
305 |
|
bool bEnabled = (pMainForm && pMainForm->client()); |
306 |
|
m_ui.newInstrumentAction->setEnabled(bEnabled); |
307 |
|
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
308 |
|
bEnabled = (bEnabled && index.isValid()); |
309 |
|
m_ui.editInstrumentAction->setEnabled(bEnabled); |
310 |
|
m_ui.deleteInstrumentAction->setEnabled(bEnabled); |
311 |
} |
} |
312 |
|
|
313 |
|
|
314 |
|
// Context menu request. |
315 |
|
void InstrumentListForm::contextMenuEvent ( |
316 |
|
QContextMenuEvent *pContextMenuEvent ) |
317 |
|
{ |
318 |
|
if (m_ui.newInstrumentAction->isEnabled()) |
319 |
|
m_ui.contextMenu->exec(pContextMenuEvent->globalPos()); |
320 |
|
} |
321 |
|
|
322 |
|
|
323 |
} // namespace QSampler |
} // namespace QSampler |
324 |
|
|
325 |
|
|