1 |
// qsamplerInstrumentListForm.cpp |
// qsamplerInstrumentListForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2009, 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 |
23 |
#include "qsamplerAbout.h" |
#include "qsamplerAbout.h" |
24 |
#include "qsamplerInstrumentListForm.h" |
#include "qsamplerInstrumentListForm.h" |
25 |
|
|
26 |
|
#include "qsamplerInstrumentList.h" |
27 |
|
|
28 |
#include "qsamplerInstrumentForm.h" |
#include "qsamplerInstrumentForm.h" |
29 |
|
|
30 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
33 |
|
|
34 |
#include <QHeaderView> |
#include <QHeaderView> |
35 |
#include <QMessageBox> |
#include <QMessageBox> |
36 |
|
#include <QContextMenuEvent> |
37 |
|
|
38 |
|
|
39 |
namespace QSampler { |
namespace QSampler { |
48 |
{ |
{ |
49 |
m_ui.setupUi(this); |
m_ui.setupUi(this); |
50 |
|
|
51 |
|
m_pInstrumentListView = new InstrumentListView(this); |
52 |
|
QMainWindow::setCentralWidget(m_pInstrumentListView); |
53 |
|
|
54 |
// Setup toolbar widgets. |
// Setup toolbar widgets. |
55 |
m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar); |
m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar); |
56 |
m_pMapComboBox->setMinimumWidth(120); |
m_pMapComboBox->setMinimumWidth(120); |
57 |
m_pMapComboBox->setEnabled(false); |
m_pMapComboBox->setEnabled(false); |
58 |
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
59 |
m_ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
|
60 |
|
m_ui.instrumentToolbar->addWidget(m_pMapComboBox); |
61 |
m_ui.InstrumentToolbar->addSeparator(); |
m_ui.instrumentToolbar->addSeparator(); |
62 |
m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction); |
m_ui.instrumentToolbar->addAction(m_ui.newInstrumentAction); |
63 |
m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction); |
m_ui.instrumentToolbar->addAction(m_ui.editInstrumentAction); |
64 |
m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
m_ui.instrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
65 |
m_ui.InstrumentToolbar->addSeparator(); |
m_ui.instrumentToolbar->addSeparator(); |
66 |
m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
m_ui.instrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
|
|
|
|
int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4; |
|
|
m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight); |
|
|
|
|
|
m_ui.InstrumentTable->setModel(&m_model); |
|
|
m_ui.InstrumentTable->setItemDelegate(&m_delegate); |
|
|
m_ui.InstrumentTable->verticalHeader()->hide(); |
|
|
|
|
|
QHeaderView *pHeader = m_ui.InstrumentTable->horizontalHeader(); |
|
|
pHeader->setDefaultAlignment(Qt::AlignLeft); |
|
|
pHeader->setMovable(false); |
|
|
pHeader->setStretchLastSection(true); |
|
|
pHeader->resizeSection(0, 120); // Name |
|
|
m_ui.InstrumentTable->resizeColumnToContents(1); // Map |
|
|
m_ui.InstrumentTable->resizeColumnToContents(2); // Bank |
|
|
m_ui.InstrumentTable->resizeColumnToContents(3); // Prog |
|
|
m_ui.InstrumentTable->resizeColumnToContents(4); // Engine |
|
|
pHeader->resizeSection(5, 240); // File |
|
|
m_ui.InstrumentTable->resizeColumnToContents(6); // Nr |
|
|
pHeader->resizeSection(7, 60); // Vol |
|
|
|
|
|
// Enable custom context menu... |
|
|
m_ui.InstrumentTable->setContextMenuPolicy(Qt::CustomContextMenu); |
|
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( |
QObject::connect(m_pInstrumentListView->selectionModel(), |
72 |
m_ui.InstrumentTable, |
SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)), |
|
SIGNAL(customContextMenuRequested(const QPoint&)), |
|
|
SLOT(contextMenu(const QPoint&))); |
|
|
QObject::connect( |
|
|
m_ui.InstrumentTable, |
|
|
SIGNAL(pressed(const QModelIndex&)), |
|
73 |
SLOT(stabilizeForm())); |
SLOT(stabilizeForm())); |
74 |
QObject::connect( |
QObject::connect( |
75 |
m_ui.InstrumentTable, |
m_pInstrumentListView, |
76 |
SIGNAL(activated(const QModelIndex&)), |
SIGNAL(activated(const QModelIndex&)), |
77 |
SLOT(editInstrument(const QModelIndex&))); |
SLOT(editInstrument(const QModelIndex&))); |
78 |
QObject::connect( |
QObject::connect( |
92 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
93 |
SLOT(refreshInstruments())); |
SLOT(refreshInstruments())); |
94 |
|
|
|
MainForm *pMainForm = MainForm::getInstance(); |
|
|
if (pMainForm) { |
|
|
QObject::connect(&m_model, |
|
|
SIGNAL(instrumentsChanged()), |
|
|
pMainForm, SLOT(sessionDirty())); |
|
|
} |
|
|
|
|
95 |
// Things must be stable from the start. |
// Things must be stable from the start. |
96 |
stabilizeForm(); |
stabilizeForm(); |
97 |
} |
} |
100 |
InstrumentListForm::~InstrumentListForm (void) |
InstrumentListForm::~InstrumentListForm (void) |
101 |
{ |
{ |
102 |
delete m_pMapComboBox; |
delete m_pMapComboBox; |
103 |
|
delete m_pInstrumentListView; |
104 |
} |
} |
105 |
|
|
106 |
|
|
183 |
if (iMidiMap >= 0) |
if (iMidiMap >= 0) |
184 |
pOptions->iMidiMap = iMidiMap; |
pOptions->iMidiMap = iMidiMap; |
185 |
|
|
186 |
m_model.setMidiMap(iMidiMap); |
m_pInstrumentListView->setMidiMap(iMidiMap); |
187 |
m_model.refresh(); |
m_pInstrumentListView->refresh(); |
188 |
|
|
189 |
|
stabilizeForm(); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
void InstrumentListForm::newInstrument (void) |
194 |
|
{ |
195 |
|
Instrument instrument; |
196 |
|
|
197 |
|
InstrumentForm form(this); |
198 |
|
form.setup(&instrument); |
199 |
|
if (!form.exec()) |
200 |
|
return; |
201 |
|
|
202 |
|
// Commit... |
203 |
|
instrument.mapInstrument(); |
204 |
|
|
205 |
|
// add new item to the table model |
206 |
|
m_pInstrumentListView->addInstrument( |
207 |
|
instrument.map(), |
208 |
|
instrument.bank(), |
209 |
|
instrument.prog()); |
210 |
|
|
211 |
stabilizeForm(); |
stabilizeForm(); |
212 |
} |
} |
214 |
|
|
215 |
void InstrumentListForm::editInstrument (void) |
void InstrumentListForm::editInstrument (void) |
216 |
{ |
{ |
217 |
editInstrument(m_ui.InstrumentTable->currentIndex()); |
editInstrument(m_pInstrumentListView->currentIndex()); |
218 |
} |
} |
219 |
|
|
220 |
|
|
221 |
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
222 |
{ |
{ |
223 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
if (!index.isValid()) |
224 |
return; |
return; |
225 |
|
|
226 |
Instrument* pInstrument |
Instrument *pInstrument |
227 |
= static_cast<Instrument *> ( |
= static_cast<Instrument *> (index.internalPointer()); |
|
index.data(Qt::UserRole).value<void *> ()); |
|
|
|
|
228 |
if (pInstrument == NULL) |
if (pInstrument == NULL) |
229 |
return; |
return; |
230 |
|
|
231 |
// Save current key values... |
// Save current key values... |
232 |
Instrument oldInstrument(*pInstrument); |
int iMap = pInstrument->map(); |
233 |
// Do the edit dance... |
int iBank = pInstrument->bank(); |
234 |
InstrumentForm form(this); |
int iProg = pInstrument->prog(); |
|
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(); |
|
|
// correct the position of the instrument in the model |
|
|
m_model.resort(*pInstrument); |
|
|
} |
|
|
// Notify we've changes... |
|
|
emit m_model.reset(); |
|
|
} |
|
|
} |
|
235 |
|
|
236 |
|
Instrument instrument(iMap, iBank, iProg); |
237 |
|
|
238 |
void InstrumentListForm::newInstrument (void) |
// Do the edit dance... |
|
{ |
|
|
Instrument instrument; |
|
|
|
|
239 |
InstrumentForm form(this); |
InstrumentForm form(this); |
240 |
form.setup(&instrument); |
form.setup(pInstrument); |
241 |
if (!form.exec()) |
if (!form.exec()) |
242 |
return; |
return; |
243 |
|
|
244 |
// Commit... |
// Commit... |
245 |
instrument.mapInstrument(); |
pInstrument->mapInstrument(); |
246 |
// add new item to the table model |
|
247 |
m_model.resort(instrument); |
// Check whether we changed instrument key... |
248 |
// Notify we've changes... |
if (pInstrument->map() == iMap && |
249 |
//emit model.reset(); |
pInstrument->bank() == iBank && |
250 |
//FIXME: call above didnt really refresh, so we use this for now ... |
pInstrument->prog() == iProg) { |
251 |
refreshInstruments(); |
// Just update tree item... |
252 |
|
m_pInstrumentListView->updateInstrument(pInstrument); |
253 |
|
} else { |
254 |
|
// Unmap old instance... |
255 |
|
instrument.unmapInstrument(); |
256 |
|
// Correct the position of the instrument in the model |
257 |
|
m_pInstrumentListView->resortInstrument(pInstrument); |
258 |
|
} |
259 |
|
|
260 |
|
stabilizeForm(); |
261 |
} |
} |
262 |
|
|
263 |
|
|
264 |
void InstrumentListForm::deleteInstrument (void) |
void InstrumentListForm::deleteInstrument (void) |
265 |
{ |
{ |
266 |
const QModelIndex& index = m_ui.InstrumentTable->currentIndex(); |
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
267 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
if (!index.isValid()) |
268 |
return; |
return; |
269 |
|
|
270 |
Instrument *pInstrument = |
Instrument *pInstrument |
271 |
static_cast<Instrument*> ( |
= static_cast<Instrument *> (index.internalPointer()); |
|
index.data(Qt::UserRole).value<void *> ()); |
|
|
|
|
272 |
if (pInstrument == NULL) |
if (pInstrument == NULL) |
273 |
return; |
return; |
274 |
|
|
291 |
} |
} |
292 |
|
|
293 |
pInstrument->unmapInstrument(); |
pInstrument->unmapInstrument(); |
294 |
// let the instrument vanish from the table model |
|
295 |
m_model.removeInstrument(*pInstrument); |
// Let the instrument vanish from the table model... |
296 |
// Notify we've changes... |
m_pInstrumentListView->removeInstrument(pInstrument); |
297 |
emit m_model.reset(); |
|
298 |
|
stabilizeForm(); |
299 |
} |
} |
300 |
|
|
301 |
|
|
306 |
|
|
307 |
bool bEnabled = (pMainForm && pMainForm->client()); |
bool bEnabled = (pMainForm && pMainForm->client()); |
308 |
m_ui.newInstrumentAction->setEnabled(bEnabled); |
m_ui.newInstrumentAction->setEnabled(bEnabled); |
309 |
const QModelIndex& index = m_ui.InstrumentTable->currentIndex(); |
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
310 |
bEnabled = (bEnabled && index.isValid()); |
bEnabled = (bEnabled && index.isValid()); |
311 |
m_ui.editInstrumentAction->setEnabled(bEnabled); |
m_ui.editInstrumentAction->setEnabled(bEnabled); |
312 |
m_ui.deleteInstrumentAction->setEnabled(bEnabled); |
m_ui.deleteInstrumentAction->setEnabled(bEnabled); |
313 |
} |
} |
314 |
|
|
315 |
|
|
316 |
// Handle custom context menu here... |
// Context menu request. |
317 |
void InstrumentListForm::contextMenu ( const QPoint& pos ) |
void InstrumentListForm::contextMenuEvent ( |
318 |
{ |
QContextMenuEvent *pContextMenuEvent ) |
319 |
if (!m_ui.newInstrumentAction->isEnabled()) |
{ |
320 |
return; |
QMenu menu(this); |
321 |
|
|
322 |
|
menu.addAction(m_ui.newInstrumentAction); |
323 |
|
menu.addSeparator(); |
324 |
|
menu.addAction(m_ui.editInstrumentAction); |
325 |
|
menu.addAction(m_ui.deleteInstrumentAction); |
326 |
|
menu.addSeparator(); |
327 |
|
menu.addAction(m_ui.refreshInstrumentsAction); |
328 |
|
|
329 |
m_ui.contextMenu->exec( |
menu.exec(pContextMenuEvent->globalPos()); |
|
(m_ui.InstrumentTable->viewport())->mapToGlobal(pos)); |
|
330 |
} |
} |
331 |
|
|
332 |
|
|