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 |
|
|
33 |
namespace QSampler { |
namespace QSampler { |
34 |
|
|
35 |
InstrumentListForm::InstrumentListForm ( QWidget* parent, Qt::WindowFlags flags ) |
InstrumentListForm::InstrumentListForm ( |
36 |
: QMainWindow(parent, flags) |
QWidget* pParent, Qt::WindowFlags wflags ) |
37 |
|
: QMainWindow(pParent, wflags) |
38 |
{ |
{ |
39 |
ui.setupUi(this); |
m_ui.setupUi(this); |
40 |
|
|
41 |
ui.newInstrumentAction->setText(tr("New &Instrument...")); |
// Setup toolbar widgets. |
42 |
ui.newInstrumentAction->setShortcut(Qt::Key_Insert); |
m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar); |
43 |
ui.editInstrumentAction->setText(tr("&Edit...")); |
m_pMapComboBox->setMinimumWidth(120); |
44 |
ui.editInstrumentAction->setShortcut(Qt::Key_Enter); |
m_pMapComboBox->setEnabled(false); |
45 |
ui.deleteInstrumentAction->setText(tr("&Delete")); |
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
46 |
ui.deleteInstrumentAction->setShortcut(Qt::Key_Delete); |
m_ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
47 |
ui.refreshInstrumentsAction->setText(tr("&Refresh")); |
|
48 |
ui.refreshInstrumentsAction->setShortcut(Qt::Key_F5); |
m_ui.InstrumentToolbar->addSeparator(); |
49 |
|
m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction); |
50 |
// Setup toolbar widgets. |
m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction); |
51 |
m_pMapComboBox = new QComboBox(ui.InstrumentToolbar); |
m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
52 |
m_pMapComboBox->setMinimumWidth(120); |
m_ui.InstrumentToolbar->addSeparator(); |
53 |
m_pMapComboBox->setEnabled(false); |
m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
|
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); |
|
54 |
|
|
55 |
ui.InstrumentTable->setModel(&model); |
m_ui.InstrumentTable->setModel(&m_model); |
56 |
ui.InstrumentTable->setItemDelegate(&delegate); |
m_ui.InstrumentTable->setItemDelegate(&m_delegate); |
57 |
|
|
58 |
QObject::connect(m_pMapComboBox, |
QObject::connect(m_pMapComboBox, |
59 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
60 |
SLOT(activateMap(int))); |
SLOT(activateMap(int))); |
|
|
|
61 |
QObject::connect( |
QObject::connect( |
62 |
ui.refreshInstrumentsAction, |
m_ui.refreshInstrumentsAction, |
63 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
64 |
SLOT(refreshInstruments(void)) |
SLOT(refreshInstruments(void))); |
65 |
); |
QObject::connect( |
66 |
|
m_ui.InstrumentTable, |
|
connect( |
|
|
ui.InstrumentTable, |
|
67 |
SIGNAL(activated(const QModelIndex&)), |
SIGNAL(activated(const QModelIndex&)), |
68 |
SLOT(editInstrument(const QModelIndex&)) |
SLOT(editInstrument(const QModelIndex&))); |
69 |
); |
QObject::connect( |
70 |
connect( |
m_ui.newInstrumentAction, |
|
ui.newInstrumentAction, |
|
71 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
72 |
SLOT(newInstrument()) |
SLOT(newInstrument())); |
73 |
); |
QObject::connect( |
74 |
connect( |
m_ui.deleteInstrumentAction, |
|
ui.deleteInstrumentAction, |
|
75 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
76 |
SLOT(deleteInstrument()) |
SLOT(deleteInstrument())); |
77 |
); |
QObject::connect( |
78 |
connect( |
m_ui.editInstrumentAction, |
|
ui.editInstrumentAction, |
|
79 |
SIGNAL(triggered()), |
SIGNAL(triggered()), |
80 |
SLOT(editInstrument()) |
SLOT(editInstrument())); |
81 |
); |
|
82 |
|
MainForm *pMainForm = MainForm::getInstance(); |
83 |
|
if (pMainForm) { |
84 |
|
QObject::connect(&m_model, |
85 |
|
SIGNAL(instrumentsChanged()), |
86 |
|
pMainForm, SLOT(sessionDirty())); |
87 |
|
} |
88 |
} |
} |
89 |
|
|
90 |
InstrumentListForm::~InstrumentListForm() { |
|
91 |
|
InstrumentListForm::~InstrumentListForm (void) |
92 |
|
{ |
93 |
delete m_pMapComboBox; |
delete m_pMapComboBox; |
94 |
} |
} |
95 |
|
|
97 |
// Notify our parent that we're emerging. |
// Notify our parent that we're emerging. |
98 |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
99 |
{ |
{ |
100 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
101 |
//if (pMainForm) |
if (pMainForm) |
102 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
103 |
|
|
104 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
105 |
} |
} |
110 |
{ |
{ |
111 |
QWidget::hideEvent(pHideEvent); |
QWidget::hideEvent(pHideEvent); |
112 |
|
|
113 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
114 |
//if (pMainForm) |
if (pMainForm) |
115 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
// Just about to notify main-window that we're closing. |
120 |
|
void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ ) |
121 |
|
{ |
122 |
|
QWidget::hide(); |
123 |
|
|
124 |
|
MainForm *pMainForm = MainForm::getInstance(); |
125 |
|
if (pMainForm) |
126 |
|
pMainForm->stabilizeForm(); |
127 |
} |
} |
128 |
|
|
129 |
|
|
173 |
if (iMidiMap >= 0) |
if (iMidiMap >= 0) |
174 |
pOptions->iMidiMap = iMidiMap; |
pOptions->iMidiMap = iMidiMap; |
175 |
|
|
176 |
model.setMidiMap(iMidiMap); |
m_model.setMidiMap(iMidiMap); |
177 |
model.refresh(); |
m_model.refresh(); |
178 |
} |
} |
179 |
|
|
180 |
void InstrumentListForm::editInstrument() { |
|
181 |
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
void InstrumentListForm::editInstrument (void) |
182 |
editInstrument(index); |
{ |
183 |
|
editInstrument(m_ui.InstrumentTable->currentIndex()); |
184 |
} |
} |
185 |
|
|
186 |
void InstrumentListForm::editInstrument(const QModelIndex& index) { |
|
187 |
|
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
188 |
|
{ |
189 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
190 |
return; |
return; |
191 |
|
|
192 |
qsamplerInstrument* pInstrument = |
qsamplerInstrument* pInstrument |
193 |
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
= static_cast<qsamplerInstrument *> ( |
194 |
|
index.data(Qt::UserRole).value<void *> ()); |
195 |
|
|
196 |
if (!pInstrument) return; |
if (pInstrument == NULL) |
197 |
|
return; |
198 |
|
|
199 |
// Save current key values... |
// Save current key values... |
200 |
qsamplerInstrument oldInstrument(*pInstrument); |
qsamplerInstrument oldInstrument(*pInstrument); |
214 |
// Unmap old instance... |
// Unmap old instance... |
215 |
oldInstrument.unmapInstrument(); |
oldInstrument.unmapInstrument(); |
216 |
// correct the position of the instrument in the model |
// correct the position of the instrument in the model |
217 |
model.resort(*pInstrument); |
m_model.resort(*pInstrument); |
218 |
} |
} |
219 |
// Notify we've changes... |
// Notify we've changes... |
220 |
emit model.reset(); |
emit m_model.reset(); |
221 |
} |
} |
222 |
} |
} |
223 |
|
|
224 |
void InstrumentListForm::newInstrument() { |
|
225 |
|
void InstrumentListForm::newInstrument (void) |
226 |
|
{ |
227 |
qsamplerInstrument instrument; |
qsamplerInstrument instrument; |
228 |
|
|
229 |
InstrumentForm form(this); |
InstrumentForm form(this); |
230 |
form.setup(&instrument); |
form.setup(&instrument); |
231 |
if (!form.exec()) return; |
if (!form.exec()) |
232 |
|
return; |
233 |
|
|
234 |
// Commit... |
// Commit... |
235 |
instrument.mapInstrument(); |
instrument.mapInstrument(); |
236 |
// add new item to the table model |
// add new item to the table model |
237 |
model.resort(instrument); |
m_model.resort(instrument); |
238 |
// Notify we've changes... |
// Notify we've changes... |
239 |
//emit model.reset(); |
//emit model.reset(); |
240 |
//FIXME: call above didnt really refresh, so we use this for now ... |
//FIXME: call above didnt really refresh, so we use this for now ... |
241 |
refreshInstruments(); |
refreshInstruments(); |
242 |
} |
} |
243 |
|
|
244 |
void InstrumentListForm::deleteInstrument() { |
|
245 |
const QModelIndex index = ui.InstrumentTable->currentIndex(); |
void InstrumentListForm::deleteInstrument (void) |
246 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) return; |
{ |
247 |
|
const QModelIndex& index = m_ui.InstrumentTable->currentIndex(); |
248 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
249 |
|
return; |
250 |
|
|
251 |
qsamplerInstrument* pInstrument = |
qsamplerInstrument* pInstrument = |
252 |
(qsamplerInstrument*) index.data(Qt::UserRole).value<void*>(); |
static_cast<qsamplerInstrument*> ( |
253 |
|
index.data(Qt::UserRole).value<void *> ()); |
254 |
|
|
255 |
if (!pInstrument) return; |
if (pInstrument == NULL) |
256 |
|
return; |
257 |
|
|
258 |
pInstrument->unmapInstrument(); |
pInstrument->unmapInstrument(); |
259 |
// let the instrument vanish from the table model |
// let the instrument vanish from the table model |
260 |
model.removeInstrument(*pInstrument); |
m_model.removeInstrument(*pInstrument); |
261 |
// Notify we've changes... |
// Notify we've changes... |
262 |
emit model.reset(); |
emit m_model.reset(); |
263 |
} |
} |
264 |
|
|
265 |
} // namespace QSampler |
} // namespace QSampler |