📄 midiprogramseditor.cpp
字号:
int msb; try { msb = ensureUniqueMSB(value, value > getCurrentBank()->getMSB()); } catch (bool) { msb = getCurrentBank()->getMSB(); } MidiBank newBank(m_percussion->isChecked(), msb, m_lsb->value()); modifyCurrentPrograms(*getCurrentBank(), newBank); m_msb->setValue(msb); *getCurrentBank() = newBank; m_msb->blockSignals(false); m_bankEditor->setModified(true);}voidMidiProgramsEditor::slotNewLSB(int value){ RG_DEBUG << "MidiProgramsEditor::slotNewLSB(" << value << ")\n"; m_lsb->blockSignals(true); int lsb; try { lsb = ensureUniqueLSB(value, value > getCurrentBank()->getLSB()); } catch (bool) { lsb = getCurrentBank()->getLSB(); } MidiBank newBank(m_percussion->isChecked(), m_msb->value(), lsb); modifyCurrentPrograms(*getCurrentBank(), newBank); m_lsb->setValue(lsb); *getCurrentBank() = newBank; m_lsb->blockSignals(false); m_bankEditor->setModified(true);}struct ProgramCmp{ bool operator()(const Rosegarden::MidiProgram &p1, const Rosegarden::MidiProgram &p2) { if (p1.getProgram() == p2.getProgram()) { const Rosegarden::MidiBank &b1(p1.getBank()); const Rosegarden::MidiBank &b2(p2.getBank()); if (b1.getMSB() == b2.getMSB()) if (b1.getLSB() == b2.getLSB()) return ((b1.isPercussion() ? 1 : 0) < (b2.isPercussion() ? 1 : 0)); else return (b1.getLSB() < b2.getLSB()); else return (b1.getMSB() < b2.getMSB()); } else return (p1.getProgram() < p2.getProgram()); }};voidMidiProgramsEditor::slotNameChanged(const QString& programName){ const KLineEdit* lineEdit = dynamic_cast<const KLineEdit*>(sender()); if (!lineEdit) { RG_DEBUG << "MidiProgramsEditor::slotProgramChanged() : %%% ERROR - signal sender is not a KLineEdit\n"; return ; } QString senderName = sender()->name(); // Adjust value back to zero rated // unsigned int id = senderName.toUInt() - 1; RG_DEBUG << "MidiProgramsEditor::slotNameChanged(" << programName << ") : id = " << id << endl; MidiProgram *program = getProgram(*getCurrentBank(), id); if (program == 0) { // Do nothing if program name is empty if (programName.isEmpty()) return ; program = new MidiProgram(*getCurrentBank(), id); m_programList.push_back(*program); // Sort the program list by id std::sort(m_programList.begin(), m_programList.end(), ProgramCmp()); // Now, get with the program // program = getProgram(*getCurrentBank(), id); } else { // If we've found a program and the label is now empty // then remove it from the program list. // if (programName.isEmpty()) { ProgramList::iterator it = m_programList.begin(); ProgramList tmpProg; for (; it != m_programList.end(); it++) { if (((unsigned int)it->getProgram()) == id) { m_programList.erase(it); m_bankEditor->setModified(true); RG_DEBUG << "deleting empty program (" << id << ")" << endl; return ; } } } } if (qstrtostr(programName) != program->getName()) { program->setName(qstrtostr(programName)); m_bankEditor->setModified(true); }}voidMidiProgramsEditor::slotEntryButtonPressed(){ QPushButton* button = dynamic_cast<QPushButton*>(const_cast<QObject *>(sender())); if (!button) { RG_DEBUG << "MidiProgramsEditor::slotEntryButtonPressed() : %%% ERROR - signal sender is not a QPushButton\n"; return ; } QString senderName = button->name(); if (!m_device) return ; const KeyMappingList &kml = m_device->getKeyMappings(); if (kml.empty()) return ; // Adjust value back to zero rated // unsigned int id = senderName.toUInt() - 1; MidiProgram *program = getProgram(*getCurrentBank(), id); if (!program) return ; m_currentMenuProgram = id; RosegardenPopupMenu *menu = new RosegardenPopupMenu(button); const MidiKeyMapping *currentMapping = m_device->getKeyMappingForProgram(*program); int currentEntry = 0; menu->insertItem(i18n("<no key mapping>"), this, SLOT(slotEntryMenuItemSelected(int)), 0, 0); menu->setItemParameter(0, 0); for (int i = 0; i < kml.size(); ++i) { menu->insertItem(strtoqstr(kml[i].getName()), this, SLOT(slotEntryMenuItemSelected(int)), 0, i + 1); menu->setItemParameter(i + 1, i + 1); if (currentMapping && (kml[i] == *currentMapping)) currentEntry = i + 1; } int itemHeight = menu->itemHeight(0) + 2; QPoint pos = QCursor::pos(); pos.rx() -= 10; pos.ry() -= (itemHeight / 2 + currentEntry * itemHeight); menu->popup(pos);}voidMidiProgramsEditor::slotEntryMenuItemSelected(int i){ if (!m_device) return ; const KeyMappingList &kml = m_device->getKeyMappings(); if (kml.empty()) return ; MidiProgram *program = getProgram(*getCurrentBank(), m_currentMenuProgram); if (!program) return ; std::string newMapping; if (i == 0) { // no key mapping newMapping = ""; } else { --i; if (i < kml.size()) { newMapping = kml[i].getName(); } } m_device->setKeyMappingForProgram(*program, newMapping); QString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/"); bool haveKeyMappings = (m_device->getKeyMappings().size() > 0); QPushButton *btn = getEntryButton(m_currentMenuProgram); if (newMapping.empty()) { QString file = pixmapDir + "/toolbar/key-white.png"; if (QFile(file).exists()) { btn->setPixmap(QPixmap(file)); } QToolTip::remove (btn); } else { QString file = pixmapDir + "/toolbar/key-green.png"; if (QFile(file).exists()) { btn->setPixmap(QPixmap(file)); } QToolTip::add (btn, i18n("Key Mapping: %1").arg(strtoqstr(newMapping))); } btn->setEnabled(haveKeyMappings);}intMidiProgramsEditor::ensureUniqueMSB(int msb, bool ascending){ int newMSB = msb; while (banklistContains(MidiBank(m_percussion->isChecked(), newMSB, m_lsb->value())) && newMSB < 128 && newMSB > -1) if (ascending) newMSB++; else newMSB--; if (newMSB == -1 || newMSB == 128) throw false; return newMSB;}intMidiProgramsEditor::ensureUniqueLSB(int lsb, bool ascending){ int newLSB = lsb; while (banklistContains(MidiBank(m_percussion->isChecked(), m_msb->value(), newLSB)) && newLSB < 128 && newLSB > -1) if (ascending) newLSB++; else newLSB--; if (newLSB == -1 || newLSB == 128) throw false; return newLSB;}boolMidiProgramsEditor::banklistContains(const MidiBank &bank){ BankList::iterator it; for (it = m_bankList.begin(); it != m_bankList.end(); it++) if (*it == bank) return true; return false;}MidiProgram*MidiProgramsEditor::getProgram(const MidiBank &bank, int programNo){ ProgramList::iterator it = m_programList.begin(); for (; it != m_programList.end(); it++) { if (it->getBank() == bank && it->getProgram() == programNo) return &(*it); } return 0;}voidMidiProgramsEditor::setBankName(const QString& s){ setTitle(s);}void MidiProgramsEditor::blockAllSignals(bool block){ const QObjectList* allChildren = queryList("KLineEdit", "[0-9]+"); QObjectListIt it(*allChildren); QObject *obj; while ( (obj = it.current()) != 0 ) { obj->blockSignals(block); ++it; } m_msb->blockSignals(block); m_lsb->blockSignals(block);}}#include "MidiProgramsEditor.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -