⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 midiprogramseditor.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* -*- 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 "MidiProgramsEditor.h"#include "MidiBankListViewItem.h"#include "NameSetEditor.h"#include "misc/Debug.h"#include "misc/Strings.h"#include "BankEditorDialog.h"#include "base/Device.h"#include "base/MidiDevice.h"#include "base/MidiProgram.h"#include "gui/widgets/RosegardenPopupMenu.h"#include <kcompletion.h>#include <kglobal.h>#include <klineedit.h>#include <klocale.h>#include <kstddirs.h>#include <qcheckbox.h>#include <qcursor.h>#include <qfile.h>#include <qframe.h>#include <qlabel.h>#include <qlayout.h>#include <qobjectlist.h>#include <qpixmap.h>#include <qpoint.h>#include <qpopupmenu.h>#include <qpushbutton.h>#include <qspinbox.h>#include <qstring.h>#include <qtooltip.h>#include <qvgroupbox.h>#include <qwidget.h>#include <algorithm>namespace Rosegarden{MidiProgramsEditor::MidiProgramsEditor(BankEditorDialog* bankEditor,                                       QWidget* parent,                                       const char* name)        : NameSetEditor(bankEditor,                        i18n("Bank and Program details"),                        parent, name, i18n("Programs"), true),        m_device(0),        m_bankList(bankEditor->getBankList()),        m_programList(bankEditor->getProgramList()),        m_oldBank(false, 0, 0){    QWidget *additionalWidget = makeAdditionalWidget(m_mainFrame);    if (additionalWidget) {        m_mainLayout->addMultiCellWidget(additionalWidget, 0, 2, 0, 2);    }}QWidget *MidiProgramsEditor::makeAdditionalWidget(QWidget *parent){    QFrame *frame = new QFrame(parent);    m_percussion = new QCheckBox(frame);    m_msb = new QSpinBox(frame);    m_lsb = new QSpinBox(frame);    QGridLayout *gridLayout = new QGridLayout(frame,                              3,   // rows                              2,   // cols                              2); // margin    gridLayout->addWidget(new QLabel(i18n("Percussion"), frame),                          0, 0, AlignLeft);    gridLayout->addWidget(m_percussion, 0, 1, AlignLeft);    connect(m_percussion, SIGNAL(clicked()),            this, SLOT(slotNewPercussion()));    gridLayout->addWidget(new QLabel(i18n("MSB Value"), frame),                          1, 0, AlignLeft);    m_msb->setMinValue(0);    m_msb->setMaxValue(127);    gridLayout->addWidget(m_msb, 1, 1, AlignLeft);    QToolTip::add        (m_msb,                i18n("Selects a MSB controller Bank number (MSB/LSB pairs are always unique for any Device)"));    QToolTip::add        (m_lsb,                i18n("Selects a LSB controller Bank number (MSB/LSB pairs are always unique for any Device)"));    connect(m_msb, SIGNAL(valueChanged(int)),            this, SLOT(slotNewMSB(int)));    gridLayout->addWidget(new QLabel(i18n("LSB Value"), frame),                          2, 0, AlignLeft);    m_lsb->setMinValue(0);    m_lsb->setMaxValue(127);    gridLayout->addWidget(m_lsb, 2, 1, AlignLeft);    connect(m_lsb, SIGNAL(valueChanged(int)),            this, SLOT(slotNewLSB(int)));    return frame;}ProgramListMidiProgramsEditor::getBankSubset(const MidiBank &bank){    ProgramList program;    ProgramList::iterator it;    for (it = m_programList.begin(); it != m_programList.end(); it++) {        if (it->getBank() == bank)            program.push_back(*it);    }    return program;}MidiBank*MidiProgramsEditor::getCurrentBank(){    return m_currentBank;}voidMidiProgramsEditor::modifyCurrentPrograms(const MidiBank &oldBank,        const MidiBank &newBank){    ProgramList::iterator it;    for (it = m_programList.begin(); it != m_programList.end(); it++) {        if (it->getBank() == oldBank) {            *it = MidiProgram(newBank, it->getProgram(), it->getName());        }    }}voidMidiProgramsEditor::clearAll(){    blockAllSignals(true);    for (unsigned int i = 0; i < m_names.size(); ++i)        m_names[i]->clear();    setTitle(i18n("Bank and Program details"));    m_percussion->setChecked(false);    m_msb->setValue(0);    m_lsb->setValue(0);    m_librarian->clear();    m_librarianEmail->clear();    m_currentBank = 0;    setEnabled(false);    blockAllSignals(false);}voidMidiProgramsEditor::populate(QListViewItem* item){    RG_DEBUG << "MidiProgramsEditor::populate\n";    MidiBankListViewItem* bankItem = dynamic_cast<MidiBankListViewItem*>(item);    if (!bankItem) {        RG_DEBUG << "MidiProgramsEditor::populate : not a bank item - returning\n";        return ;    }    DeviceId deviceId = bankItem->getDeviceId();    m_device = m_bankEditor->getMidiDevice(deviceId);    if (!m_device)        return ;    setEnabled(true);    setBankName(item->text(0));    RG_DEBUG << "MidiProgramsEditor::populate : bankItem->getBank = "    << bankItem->getBank() << endl;    m_currentBank = &(m_bankList[bankItem->getBank()]); // m_device->getBankByIndex(bankItem->getBank());    blockAllSignals(true);    // set the bank values    m_percussion->setChecked(m_currentBank->isPercussion());    m_msb->setValue(m_currentBank->getMSB());    m_lsb->setValue(m_currentBank->getLSB());    m_oldBank = *m_currentBank;    // Librarian details    //    m_librarian->setText(strtoqstr(m_device->getLibrarianName()));    m_librarianEmail->setText(strtoqstr(m_device->getLibrarianEmail()));    ProgramList programSubset = getBankSubset(*m_currentBank);    ProgramList::iterator it;    QPixmap noKeyPixmap, keyPixmap;    QString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/");    QString file = pixmapDir + "/toolbar/key-white.png";    if (QFile(file).exists())        noKeyPixmap = QPixmap(file);    file = pixmapDir + "/toolbar/key-green.png";    if (QFile(file).exists())        keyPixmap = QPixmap(file);    bool haveKeyMappings = m_currentBank->isPercussion()                           && (m_device->getKeyMappings().size() > 0);    for (unsigned int i = 0; i < m_names.size(); i++) {        m_names[i]->clear();        getEntryButton(i)->setEnabled(haveKeyMappings);        getEntryButton(i)->setPixmap(noKeyPixmap);        QToolTip::remove            ( getEntryButton(i) );        for (it = programSubset.begin(); it != programSubset.end(); it++) {            if (it->getProgram() == i) {                QString programName = strtoqstr(it->getName());                m_completion.addItem(programName);                m_names[i]->setText(programName);                if (m_device->getKeyMappingForProgram(*it)) {                    getEntryButton(i)->setPixmap(keyPixmap);                    QToolTip::add                        (getEntryButton(i),                                i18n("Key Mapping: %1").arg(                                    strtoqstr(m_device->getKeyMappingForProgram(*it)->getName())));                }                break;            }        }        // show start of label        m_names[i]->setCursorPosition(0);    }    blockAllSignals(false);}voidMidiProgramsEditor::reset(){    m_percussion->blockSignals(true);    m_msb->blockSignals(true);    m_lsb->blockSignals(true);    m_percussion->setChecked(m_oldBank.isPercussion());    m_msb->setValue(m_oldBank.getMSB());    m_lsb->setValue(m_oldBank.getLSB());    if (m_currentBank) {        modifyCurrentPrograms(*m_currentBank, m_oldBank);        *m_currentBank = m_oldBank;    }    m_percussion->blockSignals(false);    m_msb->blockSignals(false);    m_lsb->blockSignals(false);}voidMidiProgramsEditor::slotNewPercussion(){    RG_DEBUG << "MidiProgramsEditor::slotNewPercussion" << endl;    bool percussion = m_percussion->isChecked();    m_percussion->blockSignals(true);    if (banklistContains(MidiBank(percussion, m_msb->value(), m_lsb->value()))) {        RG_DEBUG << "MidiProgramsEditor::slotNewPercussion: calling setChecked(" << !percussion << ")" << endl;        m_percussion->setChecked(!percussion);    } else {        MidiBank newBank(percussion,                         m_msb->value(),                         m_lsb->value());        modifyCurrentPrograms(*getCurrentBank(), newBank);        *getCurrentBank() = newBank;    }    m_percussion->blockSignals(false);    m_bankEditor->setModified(true);}voidMidiProgramsEditor::slotNewMSB(int value){    RG_DEBUG << "MidiProgramsEditor::slotNewMSB(" << value << ")\n";    m_msb->blockSignals(true);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -