📄 bankeditordialog.cpp
字号:
MidiKeyMapListViewItem *keyItem = dynamic_cast<MidiKeyMapListViewItem*>(item); if (bankItem) { // renaming a bank item RG_DEBUG << "BankEditorDialog::slotModifyDeviceOrBankName - " << "modify bank name to " << label << endl; if (m_bankList[bankItem->getBank()].getName() != qstrtostr(label)) { m_bankList[bankItem->getBank()].setName(qstrtostr(label)); setModified(true); } } else if (keyItem) { RG_DEBUG << "BankEditorDialog::slotModifyDeviceOrBankName - " << "modify key mapping name to " << label << endl; QString oldName = keyItem->getName(); QListViewItem* currentItem = m_listView->currentItem(); MidiDevice *device = getMidiDevice(currentItem); if (device) { ModifyDeviceCommand *command = new ModifyDeviceCommand (m_studio, device->getId(), device->getName(), device->getLibrarianName(), device->getLibrarianEmail()); KeyMappingList kml = device->getKeyMappings(); for (KeyMappingList::iterator i = kml.begin(); i != kml.end(); ++i) { if (i->getName() == qstrtostr(oldName)) { i->setName(qstrtostr(label)); break; } } command->setKeyMappingList(kml); command->setOverwrite(true); addCommandToHistory(command); updateDialog(); } } else if (deviceItem) { // must be last, as the others are subclasses // renaming a device item RG_DEBUG << "BankEditorDialog::slotModifyDeviceOrBankName - " << "modify device name to " << label << endl; if (m_deviceNameMap[deviceItem->getDeviceId()] != qstrtostr(label)) { m_deviceNameMap[deviceItem->getDeviceId()] = qstrtostr(label); setModified(true); m_updateDeviceList = true; } }}voidBankEditorDialog::selectDeviceItem(MidiDevice *device){ QListViewItem *child = m_listView->firstChild(); MidiDeviceListViewItem *midiDeviceItem; MidiDevice *midiDevice; do { midiDeviceItem = dynamic_cast<MidiDeviceListViewItem*>(child); if (midiDeviceItem) { midiDevice = getMidiDevice(midiDeviceItem); if (midiDevice == device) { m_listView->setSelected(child, true); return ; } } } while ((child = child->nextSibling()));}voidBankEditorDialog::selectDeviceBankItem(DeviceId deviceId, int bank){ QListViewItem *deviceChild = m_listView->firstChild(); QListViewItem *bankChild; int deviceCount = 0, bankCount = 0; do { bankChild = deviceChild->firstChild(); MidiDeviceListViewItem *midiDeviceItem = dynamic_cast<MidiDeviceListViewItem*>(deviceChild); if (midiDeviceItem && bankChild) { do { if (deviceId == midiDeviceItem->getDeviceId() & bank == bankCount) { m_listView->setSelected(bankChild, true); return ; } bankCount++; } while ((bankChild = bankChild->nextSibling())); } deviceCount++; bankCount = 0; } while ((deviceChild = deviceChild->nextSibling()));}voidBankEditorDialog::slotVariationToggled(){ setModified(true); m_variationCombo->setEnabled(m_variationToggle->isChecked());}voidBankEditorDialog::slotVariationChanged(int){ setModified(true);}voidBankEditorDialog::setModified(bool modified){ RG_DEBUG << "BankEditorDialog::setModified(" << modified << ")" << endl; if (modified) { m_applyButton->setEnabled(true); m_resetButton->setEnabled(true); m_closeButton->setEnabled(false); m_listView->setEnabled(false); } else { m_applyButton->setEnabled(false); m_resetButton->setEnabled(false); m_closeButton->setEnabled(true); m_listView->setEnabled(true); } m_modified = modified;}voidBankEditorDialog::addCommandToHistory(KCommand *command){ getCommandHistory()->addCommand(command); setModified(false);}MultiViewCommandHistory*BankEditorDialog::getCommandHistory(){ return m_doc->getCommandHistory();}voidBankEditorDialog::slotImport(){ QString deviceDir = KGlobal::dirs()->findResource("appdata", "library/"); QDir dir(deviceDir); if (!dir.exists()) { deviceDir = ":ROSEGARDENDEVICE"; } else { deviceDir = "file://" + deviceDir; } KURL url = KFileDialog::getOpenURL (deviceDir, "audio/x-rosegarden-device audio/x-rosegarden audio/x-soundfont", this, i18n("Import Banks from Device in File")); if (url.isEmpty()) return ; ImportDeviceDialog *dialog = new ImportDeviceDialog(this, url); if (dialog->doImport() && dialog->exec() == QDialog::Accepted) { MidiDeviceListViewItem* deviceItem = dynamic_cast<MidiDeviceListViewItem*> (m_listView->selectedItem()); if (!deviceItem) { KMessageBox::error(this, "Some internal error: cannot locate selected device"); return ; } ModifyDeviceCommand *command = 0; BankList banks(dialog->getBanks()); ProgramList programs(dialog->getPrograms()); ControlList controls(dialog->getControllers()); KeyMappingList keyMappings(dialog->getKeyMappings()); MidiDevice::VariationType variation(dialog->getVariationType()); std::string librarianName(dialog->getLibrarianName()); std::string librarianEmail(dialog->getLibrarianEmail()); // don't record the librarian when // merging banks -- it's misleading. // (also don't use variation type) if (!dialog->shouldOverwriteBanks()) { librarianName = ""; librarianEmail = ""; } command = new ModifyDeviceCommand(m_studio, deviceItem->getDeviceId(), dialog->getDeviceName(), librarianName, librarianEmail); if (dialog->shouldOverwriteBanks()) { command->setVariation(variation); } if (dialog->shouldImportBanks()) { command->setBankList(banks); command->setProgramList(programs); } if (dialog->shouldImportControllers()) { command->setControlList(controls); } if (dialog->shouldImportKeyMappings()) { command->setKeyMappingList(keyMappings); } command->setOverwrite(dialog->shouldOverwriteBanks()); command->setRename(dialog->shouldRename()); addCommandToHistory(command); // No need to redraw the dialog, this is done by // slotUpdate, signalled by the MultiViewCommandHistory MidiDevice *device = getMidiDevice(deviceItem); if (device) selectDeviceItem(device); } delete dialog; updateDialog();}voidBankEditorDialog::slotEditCopy(){ MidiBankListViewItem* bankItem = dynamic_cast<MidiBankListViewItem*>(m_listView->currentItem()); if (bankItem) { m_copyBank = std::pair<DeviceId, int>(bankItem->getDeviceId(), bankItem->getBank()); m_pastePrograms->setEnabled(true); }}voidBankEditorDialog::slotEditPaste(){ MidiBankListViewItem* bankItem = dynamic_cast<MidiBankListViewItem*>(m_listView->currentItem()); if (bankItem) { // Get the full program and bank list for the source device // MidiDevice *device = getMidiDevice(m_copyBank.first); std::vector<MidiBank> tempBank = device->getBanks(); ProgramList::iterator it; std::vector<MidiProgram> tempProg; // Remove programs that will be overwritten // for (it = m_programList.begin(); it != m_programList.end(); it++) { if (!(it->getBank() == m_lastBank)) tempProg.push_back(*it); } m_programList = tempProg; // Now get source list and msb/lsb // tempProg = device->getPrograms(); MidiBank sourceBank = tempBank[m_copyBank.second]; // Add the new programs // for (it = tempProg.begin(); it != tempProg.end(); it++) { if (it->getBank() == sourceBank) { // Insert with new MSB and LSB // MidiProgram copyProgram(m_lastBank, it->getProgram(), it->getName()); m_programList.push_back(copyProgram); } } // Save these for post-apply // DeviceId devPos = bankItem->getDeviceId(); int bankPos = bankItem->getBank(); slotApply(); // Select same bank // selectDeviceBankItem(devPos, bankPos); }}voidBankEditorDialog::slotExport(){ QString extension = "rgd"; QString name = KFileDialog::getSaveFileName(":ROSEGARDEN", (extension.isEmpty() ? QString("*") : ("*." + extension)), this, i18n("Export Device as...")); // Check for the existence of the name if (name.isEmpty()) return ; // Append extension if we don't have one // if (!extension.isEmpty()) { if (!name.endsWith("." + extension)) { name += "." + extension; } } QFileInfo info(name); if (info.isDir()) { KMessageBox::sorry(this, i18n("You have specified a directory")); return ; } if (info.exists()) { int overwrite = KMessageBox::questionYesNo (this, i18n("The specified file exists. Overwrite?")); if (overwrite != KMessageBox::Yes) return ; } MidiDeviceListViewItem* deviceItem = dynamic_cast<MidiDeviceListViewItem*> (m_listView->selectedItem()); std::vector<DeviceId> devices; MidiDevice *md = getMidiDevice(deviceItem); if (md) { ExportDeviceDialog *ed = new ExportDeviceDialog (this, strtoqstr(md->getName())); if (ed->exec() != QDialog::Accepted) return ; if (ed->getExportType() == ExportDeviceDialog::ExportOne) { devices.push_back(md->getId()); } } m_doc->exportStudio(name, devices);}voidBankEditorDialog::slotFileClose(){ RG_DEBUG << "BankEditorDialog::slotFileClose()\n"; // We need to do this because we might be here due to a // documentAboutToChange signal, in which case the document won't // be valid by the time we reach the dtor, since it will be // triggered when the closeEvent is actually processed. // m_doc->getCommandHistory()->detachView(actionCollection()); m_doc = 0; close();}voidBankEditorDialog::closeEvent(QCloseEvent *e){ if (m_modified) { int res = KMessageBox::warningYesNoCancel(this, i18n("There are unsaved changes.\n" "Do you want to apply the changes before exiting " "the Bank Editor or discard the changes ?"), i18n("Unsaved Changes"), i18n("&Apply"), i18n("&Discard")); if (res == KMessageBox::Yes) { slotApply(); } else if (res == KMessageBox::Cancel) return ; } emit closing(); KMainWindow::closeEvent(e);}}#include "BankEditorDialog.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -