📄 bankeditordialog.cpp
字号:
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: *//* Rosegarden A MIDI and audio sequencer and musical notation editor. This program is Copyright 2000-2007 Guillaume Laurent <glaurent@telegraph-road.org>, Chris Cannam <cannam@all-day-breakfast.com>, Richard Bown <richard.bown@ferventsoftware.com> The moral rights of Guillaume Laurent, Chris Cannam, and Richard Bown to claim authorship of this work have been asserted. Other copyrights also apply to some parts of this work. Please see the AUTHORS file and individual file headers for details. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information.*/#include "BankEditorDialog.h"#include <qlayout.h>#include <kapplication.h>#include <klocale.h>#include <kstddirs.h>#include "misc/Debug.h"#include "misc/Strings.h"#include "base/Device.h"#include "base/MidiDevice.h"#include "base/MidiProgram.h"#include "base/NotationTypes.h"#include "base/Studio.h"#include "commands/studio/ModifyDeviceCommand.h"#include "document/MultiViewCommandHistory.h"#include "document/RosegardenGUIDoc.h"#include "document/ConfigGroups.h"#include "gui/dialogs/ExportDeviceDialog.h"#include "gui/dialogs/ImportDeviceDialog.h"#include "MidiBankListViewItem.h"#include "MidiDeviceListViewItem.h"#include "MidiKeyMapListViewItem.h"#include "MidiKeyMappingEditor.h"#include "MidiProgramsEditor.h"#include <kaction.h>#include <kcombobox.h>#include <kcommand.h>#include <kfiledialog.h>#include <kglobal.h>#include <klistview.h>#include <kmainwindow.h>#include <kmessagebox.h>#include <kstdaccel.h>#include <kstdaction.h>#include <kxmlguiclient.h>#include <qcheckbox.h>#include <qdialog.h>#include <qdir.h>#include <qfileinfo.h>#include <qframe.h>#include <qgroupbox.h>#include <qhbox.h>#include <qpushbutton.h>#include <qsizepolicy.h>#include <qsplitter.h>#include <qstring.h>#include <qtooltip.h>#include <qvbox.h>#include <qvgroupbox.h>#include <qwidget.h>namespace Rosegarden{BankEditorDialog::BankEditorDialog(QWidget *parent, RosegardenGUIDoc *doc, DeviceId defaultDevice): KMainWindow(parent, "bankeditordialog"), m_studio(&doc->getStudio()), m_doc(doc), m_copyBank(Device::NO_DEVICE, -1), m_modified(false), m_keepBankList(false), m_deleteAllReally(false), m_lastDevice(Device::NO_DEVICE), m_updateDeviceList(false){ QVBox* mainFrame = new QVBox(this); setCentralWidget(mainFrame); setCaption(i18n("Manage MIDI Banks and Programs")); QSplitter* splitter = new QSplitter(mainFrame); QFrame* btnBox = new QFrame(mainFrame); btnBox->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed)); QHBoxLayout* layout = new QHBoxLayout(btnBox, 4, 10); m_closeButton = new QPushButton(btnBox); m_applyButton = new QPushButton(i18n("Apply"), btnBox); m_resetButton = new QPushButton(i18n("Reset"), btnBox); layout->addStretch(10); layout->addWidget(m_applyButton); layout->addWidget(m_resetButton); layout->addSpacing(15); layout->addWidget(m_closeButton); layout->addSpacing(5); connect(m_applyButton, SIGNAL(clicked()), this, SLOT(slotApply())); connect(m_resetButton, SIGNAL(clicked()), this, SLOT(slotReset())); // // Left-side list view // QVBox* leftPart = new QVBox(splitter); m_listView = new KListView(leftPart); m_listView->addColumn(i18n("MIDI Device")); m_listView->addColumn(i18n("Type")); m_listView->addColumn(i18n("MSB")); m_listView->addColumn(i18n("LSB")); m_listView->setRootIsDecorated(true); m_listView->setShowSortIndicator(true); m_listView->setItemsRenameable(true); m_listView->restoreLayout(kapp->config(), BankEditorConfigGroup); QFrame *bankBox = new QFrame(leftPart); QGridLayout *gridLayout = new QGridLayout(bankBox, 4, 2, 6, 6); m_addBank = new QPushButton(i18n("Add Bank"), bankBox); m_addKeyMapping = new QPushButton(i18n("Add Key Mapping"), bankBox); m_delete = new QPushButton(i18n("Delete"), bankBox); m_deleteAll = new QPushButton(i18n("Delete All"), bankBox); gridLayout->addWidget(m_addBank, 0, 0); gridLayout->addWidget(m_addKeyMapping, 0, 1); gridLayout->addWidget(m_delete, 1, 0); gridLayout->addWidget(m_deleteAll, 1, 1); // Tips // QToolTip::add (m_addBank, i18n("Add a Bank to the current device")); QToolTip::add (m_addKeyMapping, i18n("Add a Percussion Key Mapping to the current device")); QToolTip::add (m_delete, i18n("Delete the current Bank or Key Mapping")); QToolTip::add (m_deleteAll, i18n("Delete all Banks and Key Mappings from the current Device")); m_importBanks = new QPushButton(i18n("Import..."), bankBox); m_exportBanks = new QPushButton(i18n("Export..."), bankBox); gridLayout->addWidget(m_importBanks, 2, 0); gridLayout->addWidget(m_exportBanks, 2, 1); // Tips // QToolTip::add (m_importBanks, i18n("Import Bank and Program data from a Rosegarden file to the current Device")); QToolTip::add (m_exportBanks, i18n("Export all Device and Bank information to a Rosegarden format interchange file")); m_copyPrograms = new QPushButton(i18n("Copy"), bankBox); m_pastePrograms = new QPushButton(i18n("Paste"), bankBox); gridLayout->addWidget(m_copyPrograms, 3, 0); gridLayout->addWidget(m_pastePrograms, 3, 1); // Tips // QToolTip::add (m_copyPrograms, i18n("Copy all Program names from current Bank to clipboard")); QToolTip::add (m_pastePrograms, i18n("Paste Program names from clipboard to current Bank")); connect(m_listView, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(slotPopulateDevice(QListViewItem*))); QFrame *vbox = new QFrame(splitter); QVBoxLayout *vboxLayout = new QVBoxLayout(vbox, 8, 6); m_programEditor = new MidiProgramsEditor(this, vbox); vboxLayout->addWidget(m_programEditor); m_keyMappingEditor = new MidiKeyMappingEditor(this, vbox); vboxLayout->addWidget(m_keyMappingEditor); m_keyMappingEditor->hide(); m_programEditor->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred)); m_keyMappingEditor->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred)); m_optionBox = new QVGroupBox(i18n("Options"), vbox); vboxLayout->addWidget(m_optionBox); QHBox *variationBox = new QHBox(m_optionBox); m_variationToggle = new QCheckBox(i18n("Show Variation list based on "), variationBox); m_variationCombo = new KComboBox(variationBox); m_variationCombo->insertItem(i18n("LSB")); m_variationCombo->insertItem(i18n("MSB")); // device/bank modification connect(m_listView, SIGNAL(itemRenamed (QListViewItem*, const QString&, int)), this, SLOT(slotModifyDeviceOrBankName(QListViewItem*, const QString&, int))); connect(m_addBank, SIGNAL(clicked()), this, SLOT(slotAddBank())); connect(m_addKeyMapping, SIGNAL(clicked()), this, SLOT(slotAddKeyMapping())); connect(m_delete, SIGNAL(clicked()), this, SLOT(slotDelete())); connect(m_deleteAll, SIGNAL(clicked()), this, SLOT(slotDeleteAll())); connect(m_importBanks, SIGNAL(clicked()), this, SLOT(slotImport())); connect(m_exportBanks, SIGNAL(clicked()), this, SLOT(slotExport())); connect(m_copyPrograms, SIGNAL(clicked()), this, SLOT(slotEditCopy())); connect(m_pastePrograms, SIGNAL(clicked()), this, SLOT(slotEditPaste())); connect(m_variationToggle, SIGNAL(clicked()), this, SLOT(slotVariationToggled())); connect(m_variationCombo, SIGNAL(activated(int)), this, SLOT(slotVariationChanged(int))); setupActions(); m_doc->getCommandHistory()->attachView(actionCollection()); connect(m_doc->getCommandHistory(), SIGNAL(commandExecuted()), this, SLOT(slotUpdate())); // Initialise the dialog // initDialog(); setModified(false); // Check for no Midi devices and disable everything // DeviceList *devices = m_studio->getDevices(); DeviceListIterator it; bool haveMidiPlayDevice = false; for (it = devices->begin(); it != devices->end(); ++it) { MidiDevice *md = dynamic_cast<MidiDevice *>(*it); if (md && md->getDirection() == MidiDevice::Play) { haveMidiPlayDevice = true; break; } } if (!haveMidiPlayDevice) { leftPart->setDisabled(true); m_programEditor->setDisabled(true); m_keyMappingEditor->setDisabled(true); m_optionBox->setDisabled(true); } if (defaultDevice != Device::NO_DEVICE) { setCurrentDevice(defaultDevice); } setAutoSaveSettings(BankEditorConfigGroup, true);}BankEditorDialog::~BankEditorDialog(){ RG_DEBUG << "~BankEditorDialog()\n"; m_listView->saveLayout(kapp->config(), BankEditorConfigGroup); if (m_doc) // see slotFileClose() for an explanation on why we need to test m_doc m_doc->getCommandHistory()->detachView(actionCollection());}voidBankEditorDialog::setupActions(){ KAction* close = KStdAction::close (this, SLOT(slotFileClose()), actionCollection()); m_closeButton->setText(close->text()); connect(m_closeButton, SIGNAL(clicked()), this, SLOT(slotFileClose())); KStdAction::copy (this, SLOT(slotEditCopy()), actionCollection()); KStdAction::paste (this, SLOT(slotEditPaste()), actionCollection()); // some adjustments new KToolBarPopupAction(i18n("Und&o"), "undo", KStdAccel::key(KStdAccel::Undo), actionCollection(), KStdAction::stdName(KStdAction::Undo)); new KToolBarPopupAction(i18n("Re&do"), "redo", KStdAccel::key(KStdAccel::Redo), actionCollection(), KStdAction::stdName(KStdAction::Redo)); createGUI("bankeditor.rc");}voidBankEditorDialog::initDialog(){ // Clear down // m_deviceNameMap.clear(); m_listView->clear(); // Fill list view // DeviceList *devices = m_studio->getDevices(); DeviceListIterator it; for (it = devices->begin(); it != devices->end(); ++it) { if ((*it)->getType() == Device::Midi) { MidiDevice* midiDevice = dynamic_cast<MidiDevice*>(*it); if (!midiDevice) continue; // skip read-only devices if (midiDevice->getDirection() == MidiDevice::Record) continue; m_deviceNameMap[midiDevice->getId()] = midiDevice->getName(); QString itemName = strtoqstr(midiDevice->getName()); RG_DEBUG << "BankEditorDialog::initDialog - adding " << itemName << endl; QListViewItem* deviceItem = new MidiDeviceListViewItem (midiDevice->getId(), m_listView, itemName); deviceItem->setOpen(true); populateDeviceItem(deviceItem, midiDevice); } } // Select the first Device // populateDevice(m_listView->firstChild()); m_listView->setSelected(m_listView->firstChild(), true);}voidBankEditorDialog::updateDialog(){ // Update list view // DeviceList *devices = m_studio->getDevices(); DeviceListIterator it; bool deviceLabelUpdate = false; for (it = devices->begin(); it != devices->end(); ++it) { if ((*it)->getType() != Device::Midi) continue; MidiDevice* midiDevice = dynamic_cast<MidiDevice*>(*it); if (!midiDevice) continue; // skip read-only devices if (midiDevice->getDirection() == MidiDevice::Record) continue; if (m_deviceNameMap.find(midiDevice->getId()) != m_deviceNameMap.end()) { // Device already displayed but make sure the label is up to date // QListViewItem* currentItem = m_listView->currentItem(); if (currentItem) { MidiDeviceListViewItem* deviceItem = getParentDeviceItem(currentItem); if (deviceItem && deviceItem->getDeviceId() == midiDevice->getId()) { if (deviceItem->text(0) != strtoqstr(midiDevice->getName())) { deviceItem->setText(0, strtoqstr(midiDevice->getName())); m_deviceNameMap[midiDevice->getId()] = midiDevice->getName(); /* cout << "NEW TEXT FOR DEVICE " << midiDevice->getId() << " IS " << midiDevice->getName() << endl; cout << "LIST ITEM ID = " << deviceItem->getDeviceId() << endl; */ deviceLabelUpdate = true; } QListViewItem *child = deviceItem->firstChild();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -