1 |
// qsamplerInstrumentListForm.cpp |
// qsamplerInstrumentListForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2019, 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 |
35 |
#include <QMessageBox> |
#include <QMessageBox> |
36 |
#include <QContextMenuEvent> |
#include <QContextMenuEvent> |
37 |
|
|
38 |
|
#include <QCheckBox> |
39 |
|
|
40 |
|
|
41 |
namespace QSampler { |
namespace QSampler { |
42 |
|
|
75 |
SLOT(stabilizeForm())); |
SLOT(stabilizeForm())); |
76 |
QObject::connect( |
QObject::connect( |
77 |
m_pInstrumentListView, |
m_pInstrumentListView, |
78 |
SIGNAL(doubleClicked(const QModelIndex&)), |
SIGNAL(activated(const QModelIndex&)), |
79 |
SLOT(editInstrument(const QModelIndex&))); |
SLOT(editInstrument(const QModelIndex&))); |
80 |
QObject::connect( |
QObject::connect( |
81 |
m_ui.newInstrumentAction, |
m_ui.newInstrumentAction, |
143 |
void InstrumentListForm::refreshInstruments (void) |
void InstrumentListForm::refreshInstruments (void) |
144 |
{ |
{ |
145 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
146 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
147 |
return; |
return; |
148 |
|
|
149 |
Options *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
150 |
if (pOptions == NULL) |
if (pOptions == nullptr) |
151 |
return; |
return; |
152 |
|
|
153 |
// Get/save current map selection... |
// Get/save current map selection... |
174 |
void InstrumentListForm::activateMap ( int iMap ) |
void InstrumentListForm::activateMap ( int iMap ) |
175 |
{ |
{ |
176 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
177 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
178 |
return; |
return; |
179 |
|
|
180 |
Options *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
181 |
if (pOptions == NULL) |
if (pOptions == nullptr) |
182 |
return; |
return; |
183 |
|
|
184 |
int iMidiMap = iMap - 1; |
int iMidiMap = iMap - 1; |
192 |
} |
} |
193 |
|
|
194 |
|
|
195 |
|
void InstrumentListForm::newInstrument (void) |
196 |
|
{ |
197 |
|
Instrument instrument; |
198 |
|
|
199 |
|
InstrumentForm form(this); |
200 |
|
form.setup(&instrument); |
201 |
|
if (!form.exec()) |
202 |
|
return; |
203 |
|
|
204 |
|
// Commit... |
205 |
|
instrument.mapInstrument(); |
206 |
|
|
207 |
|
// add new item to the table model |
208 |
|
m_pInstrumentListView->addInstrument( |
209 |
|
instrument.map(), |
210 |
|
instrument.bank(), |
211 |
|
instrument.prog()); |
212 |
|
|
213 |
|
stabilizeForm(); |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
void InstrumentListForm::editInstrument (void) |
void InstrumentListForm::editInstrument (void) |
218 |
{ |
{ |
219 |
editInstrument(m_pInstrumentListView->currentIndex()); |
editInstrument(m_pInstrumentListView->currentIndex()); |
227 |
|
|
228 |
Instrument *pInstrument |
Instrument *pInstrument |
229 |
= static_cast<Instrument *> (index.internalPointer()); |
= static_cast<Instrument *> (index.internalPointer()); |
230 |
if (pInstrument == NULL) |
if (pInstrument == nullptr) |
231 |
return; |
return; |
232 |
|
|
233 |
// Save current key values... |
// Save current key values... |
239 |
|
|
240 |
// Do the edit dance... |
// Do the edit dance... |
241 |
InstrumentForm form(this); |
InstrumentForm form(this); |
242 |
form.setup(&instrument); |
form.setup(pInstrument); |
|
if (form.exec()) { |
|
|
// Commit... |
|
|
instrument.mapInstrument(); |
|
|
// Check whether we changed instrument key... |
|
|
if (instrument.map() == iMap && |
|
|
instrument.bank() == iBank && |
|
|
instrument.prog() == iProg) { |
|
|
// Just update tree item... |
|
|
//pItem->update(); |
|
|
} else { |
|
|
// Unmap old instance... |
|
|
Instrument(iMap, iBank, iProg).unmapInstrument(); |
|
|
// correct the position of the instrument in the model |
|
|
m_pInstrumentListView->updateInstrument(pInstrument); |
|
|
} |
|
|
} |
|
|
|
|
|
stabilizeForm(); |
|
|
} |
|
|
|
|
|
|
|
|
void InstrumentListForm::newInstrument (void) |
|
|
{ |
|
|
Instrument instrument; |
|
|
|
|
|
InstrumentForm form(this); |
|
|
form.setup(&instrument); |
|
243 |
if (!form.exec()) |
if (!form.exec()) |
244 |
return; |
return; |
245 |
|
|
246 |
// Commit... |
// Commit... |
247 |
instrument.mapInstrument(); |
pInstrument->mapInstrument(); |
248 |
|
|
249 |
// add new item to the table model |
// Check whether we changed instrument key... |
250 |
m_pInstrumentListView->addInstrument( |
if (pInstrument->map() == iMap && |
251 |
instrument.map(), |
pInstrument->bank() == iBank && |
252 |
instrument.bank(), |
pInstrument->prog() == iProg) { |
253 |
instrument.prog()); |
// Just update tree item... |
254 |
|
m_pInstrumentListView->updateInstrument(pInstrument); |
255 |
|
} else { |
256 |
|
// Unmap old instance... |
257 |
|
instrument.unmapInstrument(); |
258 |
|
// Correct the position of the instrument in the model |
259 |
|
m_pInstrumentListView->resortInstrument(pInstrument); |
260 |
|
} |
261 |
|
|
262 |
stabilizeForm(); |
stabilizeForm(); |
263 |
} |
} |
271 |
|
|
272 |
Instrument *pInstrument |
Instrument *pInstrument |
273 |
= static_cast<Instrument *> (index.internalPointer()); |
= static_cast<Instrument *> (index.internalPointer()); |
274 |
if (pInstrument == NULL) |
if (pInstrument == nullptr) |
275 |
return; |
return; |
276 |
|
|
277 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
278 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
279 |
return; |
return; |
280 |
|
|
281 |
// Prompt user if this is for real... |
// Prompt user if this is for real... |
282 |
Options *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
283 |
if (pOptions && pOptions->bConfirmRemove) { |
if (pOptions && pOptions->bConfirmRemove) { |
284 |
if (QMessageBox::warning(this, |
const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning"); |
285 |
QSAMPLER_TITLE ": " + tr("Warning"), |
const QString& sText = tr( |
286 |
tr("About to delete instrument map entry:\n\n" |
"About to delete instrument map entry:\n\n" |
287 |
"%1\n\n" |
"%1\n\n" |
288 |
"Are you sure?") |
"Are you sure?") |
289 |
.arg(pInstrument->name()), |
.arg(pInstrument->name()); |
290 |
QMessageBox::Ok | QMessageBox::Cancel) |
#if 0 |
291 |
== QMessageBox::Cancel) |
if (QMessageBox::warning(this, sTitle, sText, |
292 |
return; |
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) |
293 |
|
return; |
294 |
|
#else |
295 |
|
QMessageBox mbox(this); |
296 |
|
mbox.setIcon(QMessageBox::Warning); |
297 |
|
mbox.setWindowTitle(sTitle); |
298 |
|
mbox.setText(sText); |
299 |
|
mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); |
300 |
|
QCheckBox cbox(tr("Don't ask this again")); |
301 |
|
cbox.setChecked(false); |
302 |
|
cbox.blockSignals(true); |
303 |
|
mbox.addButton(&cbox, QMessageBox::ActionRole); |
304 |
|
if (mbox.exec() == QMessageBox::Cancel) |
305 |
|
return; |
306 |
|
if (cbox.isChecked()) |
307 |
|
pOptions->bConfirmRemove = false; |
308 |
|
#endif |
309 |
} |
} |
310 |
|
|
311 |
pInstrument->unmapInstrument(); |
pInstrument->unmapInstrument(); |
312 |
|
|
313 |
// let the instrument vanish from the table model |
// Let the instrument vanish from the table model... |
314 |
m_pInstrumentListView->removeInstrument(pInstrument); |
m_pInstrumentListView->removeInstrument(pInstrument); |
315 |
|
|
316 |
stabilizeForm(); |
stabilizeForm(); |
335 |
void InstrumentListForm::contextMenuEvent ( |
void InstrumentListForm::contextMenuEvent ( |
336 |
QContextMenuEvent *pContextMenuEvent ) |
QContextMenuEvent *pContextMenuEvent ) |
337 |
{ |
{ |
338 |
if (m_ui.newInstrumentAction->isEnabled()) |
QMenu menu(this); |
339 |
m_ui.contextMenu->exec(pContextMenuEvent->globalPos()); |
|
340 |
|
menu.addAction(m_ui.newInstrumentAction); |
341 |
|
menu.addSeparator(); |
342 |
|
menu.addAction(m_ui.editInstrumentAction); |
343 |
|
menu.addAction(m_ui.deleteInstrumentAction); |
344 |
|
menu.addSeparator(); |
345 |
|
menu.addAction(m_ui.refreshInstrumentsAction); |
346 |
|
|
347 |
|
menu.exec(pContextMenuEvent->globalPos()); |
348 |
} |
} |
349 |
|
|
350 |
|
|