📄 devicemanagerdialog.cpp
字号:
return ; } QDataStream reply(replyData, IO_ReadOnly); unsigned int connections = 0; if (replyType == "unsigned int") reply >> connections; for (unsigned int i = 0; i < connections; ++i) { QByteArray data; QByteArray replyData; QCString replyType; QDataStream arg(data, IO_WriteOnly); arg << (int)Device::Midi; arg << direction; arg << i; if (!rgapp->sequencerCall("getConnection(int, unsigned int, unsigned int)", replyType, replyData, data)) { RG_DEBUG << "DeviceManagerDialog: can't call Sequencer" << endl; list.append(i18n("No connection")); return ; } QDataStream reply(replyData, IO_ReadOnly); QString connection; if (replyType == "QString") { reply >> connection; list.append(connection); } } list.append(i18n("No connection")); } void DeviceManagerDialog::closeEvent(QCloseEvent *e) { emit closing(); KMainWindow::closeEvent(e); } DeviceId DeviceManagerDialog::getPlayDeviceIdAt(int row) { if (row < 0 || row > (int)m_playDevices.size()) return Device::NO_DEVICE; return m_playDevices[row]->getId(); } DeviceId DeviceManagerDialog::getRecordDeviceIdAt(int row) { if (row < 0 || row > (int)m_recordDevices.size()) return Device::NO_DEVICE; return m_recordDevices[row]->getId(); } void DeviceManagerDialog::slotAddPlayDevice() { QString connection = ""; if (m_playConnections.size() > 0) connection = m_playConnections[m_playConnections.size() - 1]; CreateOrDeleteDeviceCommand *command = new CreateOrDeleteDeviceCommand (m_studio, qstrtostr(i18n("New Device")), Device::Midi, MidiDevice::Play, qstrtostr(connection)); m_document->getCommandHistory()->addCommand(command); } void DeviceManagerDialog::slotAddRecordDevice() { QString connection = ""; if (m_recordConnections.size() > 0) connection = m_recordConnections[m_recordConnections.size() - 1]; CreateOrDeleteDeviceCommand *command = new CreateOrDeleteDeviceCommand (m_studio, qstrtostr(i18n("New Device")), Device::Midi, MidiDevice::Record, qstrtostr(connection)); m_document->getCommandHistory()->addCommand(command); } void DeviceManagerDialog::slotDeletePlayDevice() { // should really grey out if nothing current DeviceId id = getPlayDeviceIdAt(m_playTable->currentRow()); if (id == Device::NO_DEVICE) return ; CreateOrDeleteDeviceCommand *command = new CreateOrDeleteDeviceCommand (m_studio, id); m_document->getCommandHistory()->addCommand(command); QByteArray data; QDataStream arg(data, IO_WriteOnly); arg << (unsigned int)id; rgapp->sequencerSend("removeDevice(unsigned int)", data); } void DeviceManagerDialog::slotDeleteRecordDevice() { DeviceId id = getRecordDeviceIdAt(m_recordTable->currentRow()); if (id == Device::NO_DEVICE) return ; CreateOrDeleteDeviceCommand *command = new CreateOrDeleteDeviceCommand (m_studio, id); m_document->getCommandHistory()->addCommand(command); } void DeviceManagerDialog::slotPlayValueChanged(int row, int col) { if (!m_document) return ; // closing DeviceId id = getPlayDeviceIdAt(row); if (id == Device::NO_DEVICE) return ; Device *device = m_studio->getDevice(id); if (!device) { std::cerr << "WARNING: DeviceManagerDialog::slotPlayValueChanged(): device at row " << row << " (id " << id << ") not found in studio" << std::endl; return ; } switch (col) { case PLAY_NAME_COL: { std::string name = qstrtostr(m_playTable->text(row, col)); if (device->getName() != name) { m_document->getCommandHistory()->addCommand (new RenameDeviceCommand(m_studio, id, name)); emit deviceNamesChanged(); QByteArray data; QDataStream arg(data, IO_WriteOnly); arg << (unsigned int)id; arg << m_playTable->text(row, col); rgapp->sequencerSend("renameDevice(unsigned int, QString)", data); } } break; case PLAY_CONNECTION_COL: { std::string connection = qstrtostr(m_playTable->text(row, col)); if (connection == qstrtostr(m_noConnectionString)) connection = ""; if (device->getConnection() != connection) { m_document->getCommandHistory()->addCommand (new ReconnectDeviceCommand(m_studio, id, connection)); } } break; } } void DeviceManagerDialog::slotRecordValueChanged(int row, int col) { if (!m_document) return ; // closing DeviceId id = getRecordDeviceIdAt(row); if (id == Device::NO_DEVICE) return ; Device *device = m_studio->getDevice(id); if (!device) { std::cerr << "WARNING: DeviceManagerDialog::slotRecordValueChanged(): device at row " << row << " (id " << id << ") not found in studio" << std::endl; return ; } switch (col) { case RECORD_NAME_COL: { std::string name = qstrtostr(m_recordTable->text(row, col)); if (device->getName() != name) { m_document->getCommandHistory()->addCommand (new RenameDeviceCommand(m_studio, id, name)); emit deviceNamesChanged(); QByteArray data; QDataStream arg(data, IO_WriteOnly); arg << (unsigned int)id; arg << m_recordTable->text(row, col); rgapp->sequencerSend("renameDevice(unsigned int, QString)", data); } } break; case RECORD_CONNECTION_COL: { std::string connection = qstrtostr(m_recordTable->text(row, col)); if (device->getConnection() != connection) { m_document->getCommandHistory()->addCommand (new ReconnectDeviceCommand(m_studio, id, connection)); } } break; case RECORD_CURRENT_COL: { m_recordTable->blockSignals(true); QCheckTableItem *check = dynamic_cast<QCheckTableItem *>(m_recordTable->item(row, col)); if (!check) return ; bool actionConnect = check->isChecked(); // The following lines are not strictly needed, but give the checkboxes // a smoother behavior while waiting a confirmation from the sequencer. // check->setText(actionConnect ? i18n("Yes") : i18n("No")); MidiDevice *device = dynamic_cast<MidiDevice*>(m_studio->getDevice(id)); device->setRecording(actionConnect); m_recordTable->setCurrentCell(row, 0); m_document->getCommandHistory()->addCommand (new ChangeRecordDeviceCommand(id, actionConnect)); m_recordTable->blockSignals(false); } break; } } void DeviceManagerDialog::slotPlayDeviceSelected(int row, int col) { RG_DEBUG << "slotPlayDeviceSelected(" << row << "," << col << ")" << endl; bool enable = (row >= 0 && row < (int)m_playDevices.size()); m_deletePlayButton->setEnabled(enable); m_importButton->setEnabled(enable); m_exportButton->setEnabled(enable); m_banksButton->setEnabled(enable); m_controllersButton->setEnabled(enable); } void DeviceManagerDialog::slotRecordDeviceSelected(int row, int col) { RG_DEBUG << "slotRecordDeviceSelected(" << row << "," << col << ")" << endl; bool enable = (row >= 0 && row < (int)m_recordDevices.size()); m_deleteRecordButton->setEnabled(enable); } void DeviceManagerDialog::slotImport() { DeviceId id = getPlayDeviceIdAt(m_playTable->currentRow()); if (id == Device::NO_DEVICE) return ; 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 from Device in File")); if (url.isEmpty()) return ; ImportDeviceDialog *dialog = new ImportDeviceDialog(this, url); if (dialog->doImport() && dialog->exec() == QDialog::Accepted) { 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, id, 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()); m_document->getCommandHistory()->addCommand(command); if (dialog->shouldRename()) emit deviceNamesChanged(); } delete dialog; } void DeviceManagerDialog::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 ; } std::vector<DeviceId> devices; DeviceId id = getPlayDeviceIdAt(m_playTable->currentRow()); MidiDevice *md = 0; if (id != Device::NO_DEVICE) { md = dynamic_cast<MidiDevice *>(m_studio->getDevice(id)); } if (md) { ExportDeviceDialog ed(this, strtoqstr(md->getName())); if (ed.exec() != QDialog::Accepted) return ; if (ed.getExportType() == ExportDeviceDialog::ExportOne) { devices.push_back(id); } } m_document->exportStudio(name, devices); } void DeviceManagerDialog::slotSetBanks() { DeviceId id = getPlayDeviceIdAt(m_playTable->currentRow()); emit editBanks(id); } void DeviceManagerDialog::slotSetControllers() { DeviceId id = getPlayDeviceIdAt(m_playTable->currentRow()); emit editControllers(id); } }#include "DeviceManagerDialog.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -