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" |
29 |
|
|
|
#include <QToolTip> |
|
30 |
|
|
31 |
namespace QSampler { |
namespace QSampler { |
32 |
|
|
33 |
InstrumentListForm::InstrumentListForm(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { |
InstrumentListForm::InstrumentListForm ( |
34 |
|
QWidget* pParent, Qt::WindowFlags wflags ) |
35 |
|
: QMainWindow(pParent, wflags) |
36 |
|
{ |
37 |
ui.setupUi(this); |
ui.setupUi(this); |
38 |
|
|
|
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); |
|
|
|
|
39 |
// Setup toolbar widgets. |
// Setup toolbar widgets. |
40 |
InstrumentToolbar = addToolBar(tr("MIDI Instruments")); |
m_pMapComboBox = new QComboBox(ui.InstrumentToolbar); |
|
m_pMapComboBox = new QComboBox(InstrumentToolbar); |
|
41 |
m_pMapComboBox->setMinimumWidth(120); |
m_pMapComboBox->setMinimumWidth(120); |
42 |
m_pMapComboBox->setEnabled(false); |
m_pMapComboBox->setEnabled(false); |
43 |
QToolTip::add(m_pMapComboBox, tr("Instrument Map")); |
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
44 |
|
ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
45 |
|
|
46 |
InstrumentToolbar->addSeparator(); |
ui.InstrumentToolbar->addSeparator(); |
47 |
ui.newInstrumentAction->addTo(InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.newInstrumentAction); |
48 |
ui.editInstrumentAction->addTo(InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.editInstrumentAction); |
49 |
ui.deleteInstrumentAction->addTo(InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.deleteInstrumentAction); |
50 |
InstrumentToolbar->addSeparator(); |
ui.InstrumentToolbar->addSeparator(); |
51 |
ui.refreshInstrumentsAction->addTo(InstrumentToolbar); |
ui.InstrumentToolbar->addAction(ui.refreshInstrumentsAction); |
52 |
|
|
53 |
ui.InstrumentTable->setModel(&model); |
ui.InstrumentTable->setModel(&model); |
54 |
//ui.InstrumentTable->setDelegate(delegate); |
ui.InstrumentTable->setItemDelegate(&delegate); |
55 |
|
|
56 |
QObject::connect(m_pMapComboBox, |
QObject::connect(m_pMapComboBox, |
57 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
58 |
SLOT(activateMap(int))); |
SLOT(activateMap(int))); |
59 |
|
|
60 |
connect( |
QObject::connect( |
61 |
ui.refreshInstrumentsAction, |
ui.refreshInstrumentsAction, |
62 |
SIGNAL(triggered()), SLOT(refreshInstruments(void)) |
SIGNAL(triggered()), |
63 |
|
SLOT(refreshInstruments(void)) |
64 |
); |
); |
65 |
|
|
66 |
|
QObject::connect( |
67 |
|
ui.InstrumentTable, |
68 |
|
SIGNAL(activated(const QModelIndex&)), |
69 |
|
SLOT(editInstrument(const QModelIndex&)) |
70 |
|
); |
71 |
|
QObject::connect( |
72 |
|
ui.newInstrumentAction, |
73 |
|
SIGNAL(triggered()), |
74 |
|
SLOT(newInstrument()) |
75 |
|
); |
76 |
|
QObject::connect( |
77 |
|
ui.deleteInstrumentAction, |
78 |
|
SIGNAL(triggered()), |
79 |
|
SLOT(deleteInstrument()) |
80 |
|
); |
81 |
|
QObject::connect( |
82 |
|
ui.editInstrumentAction, |
83 |
|
SIGNAL(triggered()), |
84 |
|
SLOT(editInstrument()) |
85 |
|
); |
86 |
} |
} |
87 |
|
|
88 |
InstrumentListForm::~InstrumentListForm() { |
|
89 |
|
InstrumentListForm::~InstrumentListForm (void) |
90 |
|
{ |
91 |
delete m_pMapComboBox; |
delete m_pMapComboBox; |
92 |
} |
} |
93 |
|
|
95 |
// Notify our parent that we're emerging. |
// Notify our parent that we're emerging. |
96 |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
97 |
{ |
{ |
98 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
99 |
//if (pMainForm) |
if (pMainForm) |
100 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
101 |
|
|
102 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
103 |
} |
} |
108 |
{ |
{ |
109 |
QWidget::hideEvent(pHideEvent); |
QWidget::hideEvent(pHideEvent); |
110 |
|
|
111 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
112 |
//if (pMainForm) |
if (pMainForm) |
113 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
// Just about to notify main-window that we're closing. |
118 |
|
void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ ) |
119 |
|
{ |
120 |
|
QWidget::hide(); |
121 |
|
|
122 |
|
MainForm *pMainForm = MainForm::getInstance(); |
123 |
|
if (pMainForm) |
124 |
|
pMainForm->stabilizeForm(); |
125 |
} |
} |
126 |
|
|
127 |
|
|
137 |
return; |
return; |
138 |
|
|
139 |
// Get/save current map selection... |
// Get/save current map selection... |
140 |
int iMap = m_pMapComboBox->currentItem(); |
int iMap = m_pMapComboBox->currentIndex(); |
141 |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
142 |
iMap = pOptions->iMidiMap + 1; |
iMap = pOptions->iMidiMap + 1; |
143 |
|
|
144 |
// Populate maps list. |
// Populate maps list. |
145 |
m_pMapComboBox->clear(); |
m_pMapComboBox->clear(); |
146 |
m_pMapComboBox->insertItem(tr("(All)")); |
m_pMapComboBox->addItem(tr("(All)")); |
147 |
m_pMapComboBox->insertStringList(qsamplerInstrument::getMapNames()); |
m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames()); |
148 |
|
|
149 |
// Adjust to saved selection... |
// Adjust to saved selection... |
150 |
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
151 |
iMap = 0; |
iMap = 0; |
152 |
m_pMapComboBox->setCurrentItem(iMap); |
m_pMapComboBox->setCurrentIndex(iMap); |
153 |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
154 |
|
|
155 |
activateMap(iMap); |
activateMap(iMap); |
175 |
model.refresh(); |
model.refresh(); |
176 |
} |
} |
177 |
|
|
178 |
|
|
179 |
|
void InstrumentListForm::editInstrument (void) |
180 |
|
{ |
181 |
|
editInstrument(ui.InstrumentTable->currentIndex()); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
186 |
|
{ |
187 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
188 |
|
return; |
189 |
|
|
190 |
|
qsamplerInstrument* pInstrument |
191 |
|
= static_cast<qsamplerInstrument *> ( |
192 |
|
index.data(Qt::UserRole).value<void *> ()); |
193 |
|
|
194 |
|
if (pInstrument == NULL) |
195 |
|
return; |
196 |
|
|
197 |
|
// Save current key values... |
198 |
|
qsamplerInstrument oldInstrument(*pInstrument); |
199 |
|
// Do the edit dance... |
200 |
|
InstrumentForm form(this); |
201 |
|
form.setup(pInstrument); |
202 |
|
if (form.exec()) { |
203 |
|
// Commit... |
204 |
|
pInstrument->mapInstrument(); |
205 |
|
// Check whether we changed instrument key... |
206 |
|
if (oldInstrument.map() == pInstrument->map() && |
207 |
|
oldInstrument.bank() == pInstrument->bank() && |
208 |
|
oldInstrument.prog() == pInstrument->prog()) { |
209 |
|
// just update tree item... |
210 |
|
//pItem->update(); |
211 |
|
} else { |
212 |
|
// Unmap old instance... |
213 |
|
oldInstrument.unmapInstrument(); |
214 |
|
// correct the position of the instrument in the model |
215 |
|
model.resort(*pInstrument); |
216 |
|
} |
217 |
|
// Notify we've changes... |
218 |
|
emit model.reset(); |
219 |
|
} |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
void InstrumentListForm::newInstrument (void) |
224 |
|
{ |
225 |
|
qsamplerInstrument instrument; |
226 |
|
|
227 |
|
InstrumentForm form(this); |
228 |
|
form.setup(&instrument); |
229 |
|
if (!form.exec()) |
230 |
|
return; |
231 |
|
|
232 |
|
// Commit... |
233 |
|
instrument.mapInstrument(); |
234 |
|
// add new item to the table model |
235 |
|
model.resort(instrument); |
236 |
|
// Notify we've changes... |
237 |
|
//emit model.reset(); |
238 |
|
//FIXME: call above didnt really refresh, so we use this for now ... |
239 |
|
refreshInstruments(); |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
|
void InstrumentListForm::deleteInstrument (void) |
244 |
|
{ |
245 |
|
const QModelIndex& index = ui.InstrumentTable->currentIndex(); |
246 |
|
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
247 |
|
return; |
248 |
|
|
249 |
|
qsamplerInstrument* pInstrument = |
250 |
|
static_cast<qsamplerInstrument*> ( |
251 |
|
index.data(Qt::UserRole).value<void *> ()); |
252 |
|
|
253 |
|
if (pInstrument == NULL) |
254 |
|
return; |
255 |
|
|
256 |
|
pInstrument->unmapInstrument(); |
257 |
|
// let the instrument vanish from the table model |
258 |
|
model.removeInstrument(*pInstrument); |
259 |
|
// Notify we've changes... |
260 |
|
emit model.reset(); |
261 |
|
} |
262 |
|
|
263 |
} // namespace QSampler |
} // namespace QSampler |
264 |
|
|
265 |
|
|