20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
#include "qsamplerInstrumentListForm.h" |
#include "qsamplerInstrumentListForm.h" |
25 |
|
|
26 |
#include "qsamplerInstrumentForm.h" |
#include "qsamplerInstrumentForm.h" |
27 |
#include "qsamplerMainForm.h" |
|
28 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
29 |
#include "qsamplerInstrument.h" |
#include "qsamplerInstrument.h" |
30 |
|
#include "qsamplerMainForm.h" |
31 |
|
|
32 |
|
#include <QHeaderView> |
33 |
|
|
34 |
|
|
35 |
namespace QSampler { |
namespace QSampler { |
36 |
|
|
37 |
InstrumentListForm::InstrumentListForm ( QWidget* parent, Qt::WindowFlags flags ) |
InstrumentListForm::InstrumentListForm ( |
38 |
: QMainWindow(parent, flags) |
QWidget* pParent, Qt::WindowFlags wflags ) |
39 |
|
: QMainWindow(pParent, wflags) |
40 |
{ |
{ |
41 |
ui.setupUi(this); |
m_ui.setupUi(this); |
|
|
|
|
ui.newInstrumentAction->setText(tr("New &Instrument...")); |
|
|
ui.newInstrumentAction->setShortcut(Qt::Key_Insert); |
|
|
ui.editInstrumentAction->setText(tr("&Edit...")); |
|
|
ui.editInstrumentAction->setShortcut(Qt::Key_Enter); |
|
|
ui.deleteInstrumentAction->setText(tr("&Delete")); |
|
|
ui.deleteInstrumentAction->setShortcut(Qt::Key_Delete); |
|
|
ui.refreshInstrumentsAction->setText(tr("&Refresh")); |
|
|
ui.refreshInstrumentsAction->setShortcut(Qt::Key_F5); |
|
|
|
|
|
// Setup toolbar widgets. |
|
|
m_pMapComboBox = new QComboBox(ui.InstrumentToolbar); |
|
|
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); |
|
42 |
|
|
43 |
ui.InstrumentTable->setModel(&model); |
// Setup toolbar widgets. |
44 |
ui.InstrumentTable->setItemDelegate(&delegate); |
m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar); |
45 |
|
m_pMapComboBox->setMinimumWidth(120); |
46 |
|
m_pMapComboBox->setEnabled(false); |
47 |
|
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
48 |
|
m_ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
49 |
|
|
50 |
|
m_ui.InstrumentToolbar->addSeparator(); |
51 |
|
m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction); |
52 |
|
m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction); |
53 |
|
m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
54 |
|
m_ui.InstrumentToolbar->addSeparator(); |
55 |
|
m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
56 |
|
|
57 |
|
int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4; |
58 |
|
m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight); |
59 |
|
|
60 |
|
m_ui.InstrumentTable->setModel(&m_model); |
61 |
|
m_ui.InstrumentTable->setItemDelegate(&m_delegate); |
62 |
|
m_ui.InstrumentTable->verticalHeader()->hide(); |
63 |
|
|
64 |
|
QHeaderView *pHeader = m_ui.InstrumentTable->horizontalHeader(); |
65 |
|
pHeader->setDefaultAlignment(Qt::AlignLeft); |
66 |
|
pHeader->setMovable(false); |
67 |
|
pHeader->setStretchLastSection(true); |
68 |
|
pHeader->resizeSection(0, 120); // Name |
69 |
|
m_ui.InstrumentTable->resizeColumnToContents(1); // Map |
70 |
|
m_ui.InstrumentTable->resizeColumnToContents(2); // Bank |
71 |
|
m_ui.InstrumentTable->resizeColumnToContents(3); // Prog |
72 |
|
m_ui.InstrumentTable->resizeColumnToContents(4); // Engine |
73 |
|
pHeader->resizeSection(5, 240); // File |
74 |
|
m_ui.InstrumentTable->resizeColumnToContents(6); // Nr |
75 |
|
pHeader->resizeSection(7, 60); // vol |
76 |
|
|
77 |
QObject::connect(m_pMapComboBox, |
QObject::connect(m_pMapComboBox, |
78 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
79 |
SLOT(activateMap(int))); |
SLOT(activateMap(int))); |
|
|
|
80 |
QObject::connect( |
QObject::connect( |
81 |
ui.refreshInstrumentsAction, |
m_ui.refreshInstrumentsAction, |
82 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
83 |
SLOT(refreshInstruments(void)) |
SLOT(refreshInstruments(void))); |
84 |
); |
QObject::connect( |
85 |
|
m_ui.InstrumentTable, |
|
connect( |
|
|
ui.InstrumentTable, |
|
86 |
SIGNAL(activated(const QModelIndex&)), |
SIGNAL(activated(const QModelIndex&)), |
87 |
SLOT(editInstrument(const QModelIndex&)) |
SLOT(editInstrument(const QModelIndex&))); |
88 |
); |
QObject::connect( |
89 |
connect( |
m_ui.newInstrumentAction, |
|
ui.newInstrumentAction, |
|
90 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
91 |
SLOT(newInstrument()) |
SLOT(newInstrument())); |
92 |
); |
QObject::connect( |
93 |
connect( |
m_ui.deleteInstrumentAction, |
|
ui.deleteInstrumentAction, |
|
94 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
95 |
SLOT(deleteInstrument()) |
SLOT(deleteInstrument())); |
96 |
); |
QObject::connect( |
97 |
connect( |
m_ui.editInstrumentAction, |
|
ui.editInstrumentAction, |
|
98 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
99 |
SLOT(editInstrument()) |
SLOT(editInstrument())); |
100 |
); |
|
101 |
|
MainForm *pMainForm = MainForm::getInstance(); |
102 |
|
if (pMainForm) { |
103 |
|
QObject::connect(&m_model, |
104 |
|
SIGNAL(instrumentsChanged()), |
105 |
|
pMainForm, SLOT(sessionDirty())); |
106 |
|
} |
107 |
} |
} |
108 |
|
|
109 |
InstrumentListForm::~InstrumentListForm() { |
|
110 |
|
InstrumentListForm::~InstrumentListForm (void) |
111 |
|
{ |
112 |
delete m_pMapComboBox; |
delete m_pMapComboBox; |
113 |
} |
} |
114 |
|
|
116 |
// Notify our parent that we're emerging. |
// Notify our parent that we're emerging. |
117 |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
118 |
{ |
{ |
119 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
120 |
//if (pMainForm) |
if (pMainForm) |
121 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
122 |
|
|
123 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
124 |
} |
} |
129 |
{ |
{ |
130 |
QWidget::hideEvent(pHideEvent); |
QWidget::hideEvent(pHideEvent); |
131 |
|
|
132 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
133 |
//if (pMainForm) |
if (pMainForm) |
134 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
// Just about to notify main-window that we're closing. |
139 |
|
void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ ) |
140 |
|
{ |
141 |
|
QWidget::hide(); |
142 |
|
|
143 |
|
MainForm *pMainForm = MainForm::getInstance(); |
144 |
|
if (pMainForm) |
145 |
|
pMainForm->stabilizeForm(); |
146 |
} |
} |
147 |
|
|
148 |
|
|
192 |
if (iMidiMap >= 0) |
if (iMidiMap >= 0) |
193 |
pOptions->iMidiMap = iMidiMap; |
pOptions->iMidiMap = iMidiMap; |
194 |
|
|
195 |
model.setMidiMap(iMidiMap); |
m_model.setMidiMap(iMidiMap); |
196 |
model.refresh(); |
m_model.refresh(); |
197 |
} |
} |
198 |
|
|
199 |
void InstrumentListForm::editInstrument() { |
|
200 |
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
void InstrumentListForm::editInstrument (void) |
201 |
editInstrument(index); |
{ |
202 |
|
editInstrument(m_ui.InstrumentTable->currentIndex()); |
203 |
} |
} |
204 |
|
|
205 |
void InstrumentListForm::editInstrument(const QModelIndex& index) { |
|
206 |
|
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
207 |
|
{ |
208 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
209 |
return; |
return; |
210 |
|
|
211 |
qsamplerInstrument* pInstrument = |
qsamplerInstrument* pInstrument |
212 |
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
= static_cast<qsamplerInstrument *> ( |
213 |
|
index.data(Qt::UserRole).value<void *> ()); |
214 |
|
|
215 |
if (!pInstrument) return; |
if (pInstrument == NULL) |
216 |
|
return; |
217 |
|
|
218 |
// Save current key values... |
// Save current key values... |
219 |
qsamplerInstrument oldInstrument(*pInstrument); |
qsamplerInstrument oldInstrument(*pInstrument); |
227 |
if (oldInstrument.map() == pInstrument->map() && |
if (oldInstrument.map() == pInstrument->map() && |
228 |
oldInstrument.bank() == pInstrument->bank() && |
oldInstrument.bank() == pInstrument->bank() && |
229 |
oldInstrument.prog() == pInstrument->prog()) { |
oldInstrument.prog() == pInstrument->prog()) { |
230 |
// just update tree item... |
// Just update tree item... |
231 |
//pItem->update(); |
//pItem->update(); |
232 |
} else { |
} else { |
233 |
// Unmap old instance... |
// Unmap old instance... |
234 |
oldInstrument.unmapInstrument(); |
oldInstrument.unmapInstrument(); |
235 |
// correct the position of the instrument in the model |
// correct the position of the instrument in the model |
236 |
model.resort(*pInstrument); |
m_model.resort(*pInstrument); |
237 |
} |
} |
238 |
// Notify we've changes... |
// Notify we've changes... |
239 |
emit model.reset(); |
emit m_model.reset(); |
240 |
} |
} |
241 |
} |
} |
242 |
|
|
243 |
void InstrumentListForm::newInstrument() { |
|
244 |
|
void InstrumentListForm::newInstrument (void) |
245 |
|
{ |
246 |
qsamplerInstrument instrument; |
qsamplerInstrument instrument; |
247 |
|
|
248 |
InstrumentForm form(this); |
InstrumentForm form(this); |
249 |
form.setup(&instrument); |
form.setup(&instrument); |
250 |
if (!form.exec()) return; |
if (!form.exec()) |
251 |
|
return; |
252 |
|
|
253 |
// Commit... |
// Commit... |
254 |
instrument.mapInstrument(); |
instrument.mapInstrument(); |
255 |
// add new item to the table model |
// add new item to the table model |
256 |
model.resort(instrument); |
m_model.resort(instrument); |
257 |
// Notify we've changes... |
// Notify we've changes... |
258 |
//emit model.reset(); |
//emit model.reset(); |
259 |
//FIXME: call above didnt really refresh, so we use this for now ... |
//FIXME: call above didnt really refresh, so we use this for now ... |
260 |
refreshInstruments(); |
refreshInstruments(); |
261 |
} |
} |
262 |
|
|
263 |
void InstrumentListForm::deleteInstrument() { |
|
264 |
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
void InstrumentListForm::deleteInstrument (void) |
265 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) return; |
{ |
266 |
|
const QModelIndex& index = m_ui.InstrumentTable->currentIndex(); |
267 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
268 |
|
return; |
269 |
|
|
270 |
qsamplerInstrument* pInstrument = |
qsamplerInstrument* pInstrument = |
271 |
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
static_cast<qsamplerInstrument*> ( |
272 |
|
index.data(Qt::UserRole).value<void *> ()); |
273 |
|
|
274 |
if (!pInstrument) return; |
if (pInstrument == NULL) |
275 |
|
return; |
276 |
|
|
277 |
pInstrument->unmapInstrument(); |
pInstrument->unmapInstrument(); |
278 |
// let the instrument vanish from the table model |
// let the instrument vanish from the table model |
279 |
model.removeInstrument(*pInstrument); |
m_model.removeInstrument(*pInstrument); |
280 |
// Notify we've changes... |
// Notify we've changes... |
281 |
emit model.reset(); |
emit m_model.reset(); |
282 |
} |
} |
283 |
|
|
284 |
} // namespace QSampler |
} // namespace QSampler |