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 "qsamplerMainForm.h" |
#include "qsamplerInstrumentList.h" |
27 |
|
|
28 |
|
#include "qsamplerInstrumentForm.h" |
29 |
|
|
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 |
|
|
|
#include <QToolTip> |
|
38 |
|
|
39 |
namespace QSampler { |
namespace QSampler { |
40 |
|
|
41 |
InstrumentListForm::InstrumentListForm(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { |
//------------------------------------------------------------------------- |
42 |
ui.setupUi(this); |
// QSampler::InstrumentListForm -- Instrument map list form implementation. |
43 |
|
// |
44 |
|
|
45 |
|
InstrumentListForm::InstrumentListForm ( |
46 |
|
QWidget* pParent, Qt::WindowFlags wflags ) |
47 |
|
: QMainWindow(pParent, wflags) |
48 |
|
{ |
49 |
|
m_ui.setupUi(this); |
50 |
|
|
51 |
ui.newInstrumentAction->setText(tr("New &Instrument...")); |
m_pInstrumentListView = new InstrumentListView(this); |
52 |
ui.newInstrumentAction->setShortcut(Qt::Key_Insert); |
QMainWindow::setCentralWidget(m_pInstrumentListView); |
|
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. |
|
|
InstrumentToolbar = addToolBar(tr("MIDI Instruments")); |
|
|
m_pMapComboBox = new QComboBox(InstrumentToolbar); |
|
|
m_pMapComboBox->setMinimumWidth(120); |
|
|
m_pMapComboBox->setEnabled(false); |
|
|
QToolTip::add(m_pMapComboBox, tr("Instrument Map")); |
|
|
|
|
|
InstrumentToolbar->addSeparator(); |
|
|
ui.newInstrumentAction->addTo(InstrumentToolbar); |
|
|
ui.editInstrumentAction->addTo(InstrumentToolbar); |
|
|
ui.deleteInstrumentAction->addTo(InstrumentToolbar); |
|
|
InstrumentToolbar->addSeparator(); |
|
|
ui.refreshInstrumentsAction->addTo(InstrumentToolbar); |
|
53 |
|
|
54 |
ui.InstrumentTable->setModel(&model); |
// Setup toolbar widgets. |
55 |
//ui.InstrumentTable->setDelegate(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( |
75 |
|
m_pInstrumentListView, |
76 |
|
SIGNAL(activated(const QModelIndex&)), |
77 |
|
SLOT(editInstrument(const QModelIndex&))); |
78 |
|
QObject::connect( |
79 |
|
m_ui.newInstrumentAction, |
80 |
|
SIGNAL(triggered()), |
81 |
|
SLOT(newInstrument())); |
82 |
|
QObject::connect( |
83 |
|
m_ui.deleteInstrumentAction, |
84 |
|
SIGNAL(triggered()), |
85 |
|
SLOT(deleteInstrument())); |
86 |
|
QObject::connect( |
87 |
|
m_ui.editInstrumentAction, |
88 |
|
SIGNAL(triggered()), |
89 |
|
SLOT(editInstrument())); |
90 |
|
QObject::connect( |
91 |
|
m_ui.refreshInstrumentsAction, |
92 |
|
SIGNAL(triggered()), |
93 |
|
SLOT(refreshInstruments())); |
94 |
|
|
95 |
connect( |
// Things must be stable from the start. |
96 |
ui.refreshInstrumentsAction, |
stabilizeForm(); |
|
SIGNAL(triggered()), SLOT(refreshInstruments(void)) |
|
|
); |
|
97 |
} |
} |
98 |
|
|
99 |
InstrumentListForm::~InstrumentListForm() { |
|
100 |
|
InstrumentListForm::~InstrumentListForm (void) |
101 |
|
{ |
102 |
delete m_pMapComboBox; |
delete m_pMapComboBox; |
103 |
|
delete m_pInstrumentListView; |
104 |
} |
} |
105 |
|
|
106 |
|
|
107 |
// Notify our parent that we're emerging. |
// Notify our parent that we're emerging. |
108 |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
109 |
{ |
{ |
110 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
111 |
//if (pMainForm) |
if (pMainForm) |
112 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
113 |
|
|
114 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
115 |
} |
} |
120 |
{ |
{ |
121 |
QWidget::hideEvent(pHideEvent); |
QWidget::hideEvent(pHideEvent); |
122 |
|
|
123 |
//MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
124 |
//if (pMainForm) |
if (pMainForm) |
125 |
// pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
// Just about to notify main-window that we're closing. |
130 |
|
void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ ) |
131 |
|
{ |
132 |
|
QWidget::hide(); |
133 |
|
|
134 |
|
MainForm *pMainForm = MainForm::getInstance(); |
135 |
|
if (pMainForm) |
136 |
|
pMainForm->stabilizeForm(); |
137 |
} |
} |
138 |
|
|
139 |
|
|
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 |
|
|
151 |
// Get/save current map selection... |
// Get/save current map selection... |
152 |
int iMap = m_pMapComboBox->currentItem(); |
int iMap = m_pMapComboBox->currentIndex(); |
153 |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
154 |
iMap = pOptions->iMidiMap + 1; |
iMap = pOptions->iMidiMap + 1; |
155 |
|
|
156 |
// Populate maps list. |
// Populate maps list. |
157 |
m_pMapComboBox->clear(); |
m_pMapComboBox->clear(); |
158 |
m_pMapComboBox->insertItem(tr("(All)")); |
m_pMapComboBox->addItem(tr("(All)")); |
159 |
m_pMapComboBox->insertStringList(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()) |
163 |
iMap = 0; |
iMap = 0; |
164 |
m_pMapComboBox->setCurrentItem(iMap); |
m_pMapComboBox->setCurrentIndex(iMap); |
165 |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
166 |
|
|
167 |
activateMap(iMap); |
activateMap(iMap); |
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::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(); |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
void InstrumentListForm::editInstrument (void) |
216 |
|
{ |
217 |
|
editInstrument(m_pInstrumentListView->currentIndex()); |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
222 |
|
{ |
223 |
|
if (!index.isValid()) |
224 |
|
return; |
225 |
|
|
226 |
|
Instrument *pInstrument |
227 |
|
= static_cast<Instrument *> (index.internalPointer()); |
228 |
|
if (pInstrument == NULL) |
229 |
|
return; |
230 |
|
|
231 |
|
// Save current key values... |
232 |
|
int iMap = pInstrument->map(); |
233 |
|
int iBank = pInstrument->bank(); |
234 |
|
int iProg = pInstrument->prog(); |
235 |
|
|
236 |
|
Instrument instrument(iMap, iBank, iProg); |
237 |
|
|
238 |
|
// Do the edit dance... |
239 |
|
InstrumentForm form(this); |
240 |
|
form.setup(&instrument); |
241 |
|
if (!form.exec()) |
242 |
|
return; |
243 |
|
|
244 |
|
// Commit... |
245 |
|
instrument.mapInstrument(); |
246 |
|
|
247 |
|
// Check whether we changed instrument key... |
248 |
|
if (instrument.map() == iMap && |
249 |
|
instrument.bank() == iBank && |
250 |
|
instrument.prog() == iProg) { |
251 |
|
// Just update tree item... |
252 |
|
//pItem->update(); |
253 |
|
} else { |
254 |
|
// Unmap old instance... |
255 |
|
Instrument(iMap, iBank, iProg).unmapInstrument(); |
256 |
|
// correct the position of the instrument in the model |
257 |
|
m_pInstrumentListView->updateInstrument(pInstrument); |
258 |
|
} |
259 |
|
|
260 |
|
stabilizeForm(); |
261 |
|
} |
262 |
|
|
263 |
|
|
264 |
|
void InstrumentListForm::deleteInstrument (void) |
265 |
|
{ |
266 |
|
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
267 |
|
if (!index.isValid()) |
268 |
|
return; |
269 |
|
|
270 |
|
Instrument *pInstrument |
271 |
|
= static_cast<Instrument *> (index.internalPointer()); |
272 |
|
if (pInstrument == NULL) |
273 |
|
return; |
274 |
|
|
275 |
|
MainForm *pMainForm = MainForm::getInstance(); |
276 |
|
if (pMainForm == NULL) |
277 |
|
return; |
278 |
|
|
279 |
|
// Prompt user if this is for real... |
280 |
|
Options *pOptions = pMainForm->options(); |
281 |
|
if (pOptions && pOptions->bConfirmRemove) { |
282 |
|
if (QMessageBox::warning(this, |
283 |
|
QSAMPLER_TITLE ": " + tr("Warning"), |
284 |
|
tr("About to delete instrument map entry:\n\n" |
285 |
|
"%1\n\n" |
286 |
|
"Are you sure?") |
287 |
|
.arg(pInstrument->name()), |
288 |
|
QMessageBox::Ok | QMessageBox::Cancel) |
289 |
|
== QMessageBox::Cancel) |
290 |
|
return; |
291 |
|
} |
292 |
|
|
293 |
|
pInstrument->unmapInstrument(); |
294 |
|
|
295 |
|
// let the instrument vanish from the table model |
296 |
|
m_pInstrumentListView->removeInstrument(pInstrument); |
297 |
|
|
298 |
|
stabilizeForm(); |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
// Update form actions enablement... |
303 |
|
void InstrumentListForm::stabilizeForm (void) |
304 |
|
{ |
305 |
|
MainForm *pMainForm = MainForm::getInstance(); |
306 |
|
|
307 |
|
bool bEnabled = (pMainForm && pMainForm->client()); |
308 |
|
m_ui.newInstrumentAction->setEnabled(bEnabled); |
309 |
|
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
310 |
|
bEnabled = (bEnabled && index.isValid()); |
311 |
|
m_ui.editInstrumentAction->setEnabled(bEnabled); |
312 |
|
m_ui.deleteInstrumentAction->setEnabled(bEnabled); |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
// Context menu request. |
317 |
|
void InstrumentListForm::contextMenuEvent ( |
318 |
|
QContextMenuEvent *pContextMenuEvent ) |
319 |
|
{ |
320 |
|
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 |
|
menu.exec(pContextMenuEvent->globalPos()); |
330 |
|
} |
331 |
|
|
332 |
|
|
333 |
} // namespace QSampler |
} // namespace QSampler |
334 |
|
|
335 |
|
|