1 |
// qsamplerInstrumentList.cpp |
// qsamplerInstrumentList.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
25 |
#include "qsamplerInstrument.h" |
#include "qsamplerInstrument.h" |
26 |
#include "qsamplerInstrumentForm.h" |
#include "qsamplerInstrumentForm.h" |
27 |
|
|
28 |
|
#include "qsamplerOptions.h" |
29 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
30 |
|
|
31 |
|
#include <qmessagebox.h> |
32 |
#include <qaction.h> |
#include <qaction.h> |
33 |
#include <qfileinfo.h> |
#include <qfileinfo.h> |
34 |
#include <qpopupmenu.h> |
#include <qpopupmenu.h> |
225 |
QWidget *pParent, const char *pszName ) |
QWidget *pParent, const char *pszName ) |
226 |
: QListView(pParent, pszName) |
: QListView(pParent, pszName) |
227 |
{ |
{ |
228 |
|
m_iMidiMap = LSCP_MIDI_MAP_ALL; |
229 |
|
|
230 |
// QListView::setRootIsDecorated(true); |
// QListView::setRootIsDecorated(true); |
231 |
|
QListView::setAllColumnsShowFocus(true); |
232 |
QListView::setResizeMode(QListView::NoColumn); |
QListView::setResizeMode(QListView::NoColumn); |
233 |
// QListView::setAcceptDrops(true); |
// QListView::setAcceptDrops(true); |
234 |
QListView::setDragAutoScroll(true); |
QListView::setDragAutoScroll(true); |
256 |
QListView::setColumnWidth(0, 120); // Name |
QListView::setColumnWidth(0, 120); // Name |
257 |
QListView::setColumnWidth(5, 240); // File |
QListView::setColumnWidth(5, 240); // File |
258 |
|
|
259 |
m_pNewGroupAction = new QAction(tr("New &Group"), tr("Ctrl+G"), this); |
m_pNewGroupAction = new QAction( |
260 |
m_pNewItemAction = new QAction(tr("New &Instrument..."), tr("Ctrl+I"), this); |
QIconSet(QPixmap::fromMimeSource("itemGroupNew.png")), |
261 |
m_pEditItemAction = new QAction(tr("&Edit..."), tr("Ctrl+E"), this); |
tr("New &Group"), tr("Ctrl+G"), this); |
262 |
m_pRenameAction = new QAction(tr("&Rename"), tr("Ctrl+R"), this); |
m_pNewItemAction = new QAction( |
263 |
m_pDeleteAction = new QAction(tr("&Delete"), tr("Ctrl+D"), this); |
QIconSet(QPixmap::fromMimeSource("itemNew.png")), |
264 |
m_pRefreshAction = new QAction(tr("Re&fresh"), tr("Ctrl+F"), this); |
tr("New &Instrument..."), tr("Ins"), this); |
265 |
|
m_pEditItemAction = new QAction( |
266 |
|
QIconSet(QPixmap::fromMimeSource("formEdit.png")), |
267 |
|
tr("&Edit..."), tr("Enter"), this); |
268 |
|
m_pRenameAction = new QAction(tr("&Rename"), tr("F2"), this); |
269 |
|
m_pDeleteAction = new QAction( |
270 |
|
QIconSet(QPixmap::fromMimeSource("formRemove.png")), |
271 |
|
tr("&Delete"), tr("Del"), this); |
272 |
|
m_pRefreshAction = new QAction( |
273 |
|
QIconSet(QPixmap::fromMimeSource("formRefresh.png")), |
274 |
|
tr("Re&fresh"), tr("F5"), this); |
275 |
|
|
276 |
|
m_pNewGroupAction->setToolTip(tr("New Group")); |
277 |
|
m_pNewItemAction->setToolTip(tr("New Instrument")); |
278 |
|
m_pEditItemAction->setToolTip(tr("Edit")); |
279 |
|
m_pRenameAction->setToolTip(tr("Rename")); |
280 |
|
m_pDeleteAction->setToolTip(tr("Delete")); |
281 |
|
m_pRefreshAction->setToolTip(tr("Refresh")); |
282 |
|
|
283 |
QObject::connect(m_pNewGroupAction, |
QObject::connect(m_pNewGroupAction, |
284 |
SIGNAL(activated()), |
SIGNAL(activated()), |
332 |
qsamplerInstrument *pInstrument, |
qsamplerInstrument *pInstrument, |
333 |
qsamplerInstrumentGroup *pParentGroup ) |
qsamplerInstrumentGroup *pParentGroup ) |
334 |
{ |
{ |
335 |
|
// Check it there's already one instrument item |
336 |
|
// with the very same key (bank, program); |
337 |
|
// if yes, just remove it without prejudice... |
338 |
qsamplerInstrumentItem *pItem = findItem(pInstrument); |
qsamplerInstrumentItem *pItem = findItem(pInstrument); |
339 |
if (pItem == NULL) { |
if (pItem) |
340 |
if (pParentGroup) |
delete pItem; |
341 |
pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument); |
|
342 |
else |
// Add the new item under proper group one, if any... |
343 |
pItem = new qsamplerInstrumentItem(this, pInstrument); |
if (pParentGroup) { |
344 |
|
pParentGroup->setOpen(true); |
345 |
|
pItem = new qsamplerInstrumentItem(pParentGroup, pInstrument); |
346 |
|
} else { |
347 |
|
pItem = new qsamplerInstrumentItem(this, pInstrument); |
348 |
} |
} |
349 |
|
|
350 |
|
// Set it as current selection... |
351 |
QListView::setSelected(pItem, true); |
QListView::setSelected(pItem, true); |
352 |
|
|
353 |
return pItem; |
return pItem; |
354 |
} |
} |
355 |
|
|
360 |
{ |
{ |
361 |
qsamplerInstrumentGroup *pGroup = findGroup(sName); |
qsamplerInstrumentGroup *pGroup = findGroup(sName); |
362 |
if (pGroup == NULL) { |
if (pGroup == NULL) { |
363 |
if (pParentGroup) |
if (pParentGroup) { |
364 |
|
pParentGroup->setOpen(true); |
365 |
pGroup = new qsamplerInstrumentGroup(pParentGroup, sName); |
pGroup = new qsamplerInstrumentGroup(pParentGroup, sName); |
366 |
else |
} else { |
367 |
pGroup = new qsamplerInstrumentGroup(this, sName); |
pGroup = new qsamplerInstrumentGroup(this, sName); |
368 |
|
} |
369 |
} |
} |
370 |
QListView::setSelected(pGroup, true); |
QListView::setSelected(pGroup, true); |
371 |
return pGroup; |
return pGroup; |
429 |
// Add a new group item below the current one. |
// Add a new group item below the current one. |
430 |
void qsamplerInstrumentList::newGroupSlot (void) |
void qsamplerInstrumentList::newGroupSlot (void) |
431 |
{ |
{ |
|
qsamplerInstrumentGroup *pParentGroup |
|
|
= groupItem(QListView::selectedItem()); |
|
432 |
qsamplerInstrumentGroup *pNewGroup |
qsamplerInstrumentGroup *pNewGroup |
433 |
= addGroup(tr("New Group"), pParentGroup); |
= addGroup(tr("New Group"), groupItem(QListView::selectedItem())); |
|
if (pParentGroup) |
|
|
pParentGroup->setOpen(true); |
|
434 |
if (pNewGroup) |
if (pNewGroup) |
435 |
pNewGroup->startRename(0); |
pNewGroup->startRename(0); |
436 |
|
|
438 |
} |
} |
439 |
|
|
440 |
|
|
441 |
|
// Map selector. |
442 |
|
void qsamplerInstrumentList::setMidiMap ( int iMidiMap ) |
443 |
|
{ |
444 |
|
if (iMidiMap < 0) |
445 |
|
iMidiMap = LSCP_MIDI_MAP_ALL; |
446 |
|
|
447 |
|
m_iMidiMap = iMidiMap; |
448 |
|
} |
449 |
|
|
450 |
|
int qsamplerInstrumentList::midiMap (void) const |
451 |
|
{ |
452 |
|
return m_iMidiMap; |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
|
// List actions accessors. |
457 |
|
QAction *qsamplerInstrumentList::newGroupAction (void) const |
458 |
|
{ |
459 |
|
return m_pNewGroupAction; |
460 |
|
} |
461 |
|
|
462 |
|
QAction *qsamplerInstrumentList::newItemAction (void) const |
463 |
|
{ |
464 |
|
return m_pNewItemAction; |
465 |
|
} |
466 |
|
|
467 |
|
QAction *qsamplerInstrumentList::editItemAction (void) const |
468 |
|
{ |
469 |
|
return m_pEditItemAction; |
470 |
|
} |
471 |
|
|
472 |
|
QAction *qsamplerInstrumentList::renameAction (void) const |
473 |
|
{ |
474 |
|
return m_pRenameAction; |
475 |
|
} |
476 |
|
|
477 |
|
QAction *qsamplerInstrumentList::deleteAction (void) const |
478 |
|
{ |
479 |
|
return m_pDeleteAction; |
480 |
|
} |
481 |
|
|
482 |
|
QAction *qsamplerInstrumentList::refreshAction (void) const |
483 |
|
{ |
484 |
|
return m_pRefreshAction; |
485 |
|
} |
486 |
|
|
487 |
|
|
488 |
// Add a new instrument item below the current one. |
// Add a new instrument item below the current one. |
489 |
void qsamplerInstrumentList::newItemSlot (void) |
void qsamplerInstrumentList::newItemSlot (void) |
490 |
{ |
{ |
497 |
return; |
return; |
498 |
} |
} |
499 |
|
|
500 |
// Check it there's already one instrument item |
// Commit... |
|
// with the very same key (bank, program); |
|
|
// if yes, just remove it without prejudice... |
|
|
qsamplerInstrumentItem *pItem = findItem(pInstrument); |
|
|
if (pItem) |
|
|
delete pItem; |
|
|
|
|
501 |
pInstrument->mapInstrument(); |
pInstrument->mapInstrument(); |
502 |
|
// add new item to the tree... |
503 |
|
addItem(pInstrument, groupItem(QListView::selectedItem())); |
504 |
|
// Notify we've changes... |
505 |
emit instrumentsChanged(); |
emit instrumentsChanged(); |
506 |
|
|
|
qsamplerInstrumentGroup *pParentGroup |
|
|
= groupItem(QListView::selectedItem()); |
|
|
addItem(pInstrument, pParentGroup); |
|
|
if (pParentGroup) |
|
|
pParentGroup->setOpen(true); |
|
|
|
|
507 |
selectionChangedSlot(); |
selectionChangedSlot(); |
508 |
} |
} |
509 |
|
|
515 |
if (pListItem == NULL) |
if (pListItem == NULL) |
516 |
return; |
return; |
517 |
if (pListItem->rtti() == Item) { |
if (pListItem->rtti() == Item) { |
518 |
|
qsamplerInstrument *pInstrument = NULL; |
519 |
qsamplerInstrumentItem *pItem |
qsamplerInstrumentItem *pItem |
520 |
= static_cast<qsamplerInstrumentItem *> (pListItem); |
= static_cast<qsamplerInstrumentItem *> (pListItem); |
521 |
if (pItem && pItem->instrument()) { |
if (pItem) |
522 |
|
pInstrument = pItem->instrument(); |
523 |
|
if (pInstrument) { |
524 |
|
// Save current key values... |
525 |
|
int iMap = pInstrument->map(); |
526 |
|
int iBank = pInstrument->bank(); |
527 |
|
int iProg = pInstrument->prog(); |
528 |
|
// Do the edit dance... |
529 |
qsamplerInstrumentForm form(this); |
qsamplerInstrumentForm form(this); |
530 |
form.setup(pItem->instrument()); |
form.setup(pInstrument); |
531 |
if (form.exec()) { |
if (form.exec()) { |
532 |
pItem->instrument()->mapInstrument(); |
// Commit... |
533 |
|
pInstrument->mapInstrument(); |
534 |
|
// Check whether we changed instrument key... |
535 |
|
if (iMap == pInstrument->map() && |
536 |
|
iBank == pInstrument->bank() && |
537 |
|
iProg == pInstrument->prog()) { |
538 |
|
// just update tree item... |
539 |
|
pItem->update(); |
540 |
|
} else { |
541 |
|
// Change item tree, whether applicable... |
542 |
|
if (m_iMidiMap < 0 || m_iMidiMap == pInstrument->map()) { |
543 |
|
// Add new brand item into view... |
544 |
|
addItem(pInstrument, groupItem(pListItem)); |
545 |
|
} else { |
546 |
|
// Just remove/hide old one. |
547 |
|
delete pItem; |
548 |
|
} |
549 |
|
} |
550 |
|
// Notify we've changes... |
551 |
emit instrumentsChanged(); |
emit instrumentsChanged(); |
|
pItem->update(); |
|
552 |
} |
} |
553 |
} |
} |
554 |
} |
} |
572 |
void qsamplerInstrumentList::deleteSlot (void) |
void qsamplerInstrumentList::deleteSlot (void) |
573 |
{ |
{ |
574 |
QListViewItem *pListItem = QListView::selectedItem(); |
QListViewItem *pListItem = QListView::selectedItem(); |
575 |
if (pListItem) { |
if (pListItem == NULL) |
576 |
if (pListItem->rtti() == Item) { |
return; |
577 |
qsamplerInstrumentItem *pItem |
|
578 |
= static_cast<qsamplerInstrumentItem *> (pListItem); |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
579 |
if (pItem && pItem->instrument()) { |
if (pMainForm == NULL) |
580 |
pItem->instrument()->unmapInstrument(); |
return; |
581 |
emit instrumentsChanged(); |
|
582 |
} |
// Prompt user if this is for real... |
583 |
|
qsamplerOptions *pOptions = pMainForm->options(); |
584 |
|
if (pOptions && pOptions->bConfirmRemove) { |
585 |
|
if (QMessageBox::warning(this, |
586 |
|
QSAMPLER_TITLE ": " + tr("Warning"), |
587 |
|
tr("Delete %1:\n\n" |
588 |
|
"%2\n\n" |
589 |
|
"Are you sure?") |
590 |
|
.arg(pListItem->rtti() == Item ? tr("instrument") : tr("group")) |
591 |
|
.arg(pListItem->text(0)), |
592 |
|
tr("OK"), tr("Cancel")) > 0) |
593 |
|
return; |
594 |
|
} |
595 |
|
|
596 |
|
// Unmap instrument entry... |
597 |
|
if (pListItem->rtti() == Item) { |
598 |
|
qsamplerInstrumentItem *pItem |
599 |
|
= static_cast<qsamplerInstrumentItem *> (pListItem); |
600 |
|
if (pItem && pItem->instrument()) { |
601 |
|
pItem->instrument()->unmapInstrument(); |
602 |
|
emit instrumentsChanged(); |
603 |
} |
} |
|
delete pListItem; |
|
604 |
} |
} |
605 |
|
|
606 |
|
// Do it for real... |
607 |
|
delete pListItem; |
608 |
|
|
609 |
selectionChangedSlot(); |
selectionChangedSlot(); |
610 |
} |
} |
611 |
|
|
685 |
|
|
686 |
qsamplerInstrumentItem *pItem = NULL; |
qsamplerInstrumentItem *pItem = NULL; |
687 |
lscp_midi_instrument_t *pInstrs |
lscp_midi_instrument_t *pInstrs |
688 |
= ::lscp_list_midi_instruments(pMainForm->client(), LSCP_MIDI_MAP_ALL); |
= ::lscp_list_midi_instruments(pMainForm->client(), m_iMidiMap); |
689 |
for (int iInstr = 0; pInstrs && pInstrs[iInstr].prog >= 0; ++iInstr) { |
for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; ++iInstr) { |
690 |
int iMap = pInstrs[iInstr].map; |
int iMap = pInstrs[iInstr].map; |
691 |
int iBank = pInstrs[iInstr].bank; |
int iBank = pInstrs[iInstr].bank; |
692 |
int iProg = pInstrs[iInstr].prog; |
int iProg = pInstrs[iInstr].prog; |