audioplugindialog.cpp

来自「LINUX下的混音软件」· C++ 代码 · 共 899 行 · 第 1/2 页

CPP
899
字号
/* -*- 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 "AudioPluginDialog.h"#include <qlayout.h>#include <klocale.h>#include "misc/Debug.h"#include "misc/Strings.h"#include "base/AudioPluginInstance.h"#include "base/Instrument.h"#include "base/MidiProgram.h"#include "gui/studio/AudioPluginClipboard.h"#include "gui/studio/AudioPlugin.h"#include "gui/studio/AudioPluginManager.h"#include "gui/studio/AudioPluginOSCGUIManager.h"#include "gui/studio/StudioControl.h"#include "gui/widgets/PluginControl.h"#include "sound/MappedStudio.h"#include <kcombobox.h>#include <kdialogbase.h>#include <qaccel.h>#include <qcheckbox.h>#include <qframe.h>#include <qgroupbox.h>#include <qhbox.h>#include <qlabel.h>#include <qpushbutton.h>#include <qsizepolicy.h>#include <qstring.h>#include <qstringlist.h>#include <qtooltip.h>#include <qvbox.h>#include <qwidget.h>#include <set>namespace Rosegarden{AudioPluginDialog::AudioPluginDialog(QWidget *parent,                                     AudioPluginManager *aPM,#ifdef HAVE_LIBLO                                     AudioPluginOSCGUIManager *aGM,#endif                                     PluginContainer *pluginContainer,                                     int index):    KDialogBase(parent, "", false, i18n("Audio Plugin"),#ifdef HAVE_LIBLO                Close | Details | Help),#else                Close | Help),#endif    m_pluginManager(aPM),#ifdef HAVE_LIBLO    m_pluginGUIManager(aGM),#endif    m_pluginContainer(pluginContainer),    m_containerId(pluginContainer->getId()),    m_programLabel(0),    m_index(index),    m_generating(true),    m_guiShown(false){    setHelp("studio-plugins");    setSizePolicy(QSizePolicy(QSizePolicy::Preferred,                              QSizePolicy::Fixed));#ifdef HAVE_LIBLO    setButtonText(Details, i18n("Editor"));#endif    QVBox *vbox = makeVBoxMainWidget();    QGroupBox *pluginSelectionBox = new QGroupBox        (1, Horizontal, i18n("Plugin"), vbox);    makePluginParamsBox(vbox, 0, 10);    m_pluginCategoryBox = new QHBox(pluginSelectionBox);    new QLabel(i18n("Category:"), m_pluginCategoryBox);    m_pluginCategoryList = new KComboBox(m_pluginCategoryBox);    m_pluginCategoryList->setSizeLimit(20);    QHBox *hbox = new QHBox(pluginSelectionBox);    m_pluginLabel = new QLabel(i18n("Plugin:"), hbox);    m_pluginList = new KComboBox(hbox);    m_pluginList->setSizeLimit(20);    QToolTip::add        (m_pluginList, i18n("Select a plugin from this list."));    QHBox *h = new QHBox(pluginSelectionBox);// top line    m_bypass = new QCheckBox(i18n("Bypass"), h);    QToolTip::add        (m_bypass, i18n("Bypass this plugin."));    connect(m_bypass, SIGNAL(toggled(bool)),            this, SLOT(slotBypassChanged(bool)));    m_insOuts = new QLabel(i18n("<ports>"), h);    m_insOuts->setAlignment(AlignRight);    QToolTip::add        (m_insOuts, i18n("Input and output port counts."));    m_pluginId = new QLabel(i18n("<id>"), h);    m_pluginId->setAlignment(AlignRight);    QToolTip::add        (m_pluginId, i18n("Unique ID of plugin."));    connect(m_pluginList, SIGNAL(activated(int)),            this, SLOT(slotPluginSelected(int)));    connect(m_pluginCategoryList, SIGNAL(activated(int)),            this, SLOT(slotCategorySelected(int)));// new line    h = new QHBox(pluginSelectionBox);    m_copyButton = new QPushButton(i18n("Copy"), h);    connect(m_copyButton, SIGNAL(clicked()),            this, SLOT(slotCopy()));    QToolTip::add        (m_copyButton, i18n("Copy plugin parameters"));    m_pasteButton = new QPushButton(i18n("Paste"), h);    connect(m_pasteButton, SIGNAL(clicked()),            this, SLOT(slotPaste()));    QToolTip::add        (m_pasteButton, i18n("Paste plugin parameters"));    m_defaultButton = new QPushButton(i18n("Default"), h);    connect(m_defaultButton, SIGNAL(clicked()),            this, SLOT(slotDefault()));    QToolTip::add        (m_defaultButton, i18n("Set to defaults"));    populatePluginCategoryList();    populatePluginList();    m_generating = false;    m_accelerators = new QAccel(this);}#ifdef HAVE_LIBLOvoidAudioPluginDialog::slotDetails(){    slotShowGUI();}#endifvoidAudioPluginDialog::slotShowGUI(){    emit showPluginGUI(m_containerId, m_index);    m_guiShown = true;    //!!! need to get notification of when a plugin gui exits from the    //gui manager}voidAudioPluginDialog::populatePluginCategoryList(){    AudioPluginInstance *inst = m_pluginContainer->getPlugin(m_index);    std::set        <QString> categories;    QString currentCategory;    for (PluginIterator i = m_pluginManager->begin();         i != m_pluginManager->end(); ++i) {        if (( isSynth() && (*i)->isSynth()) ||            (!isSynth() && (*i)->isEffect())) {            if ((*i)->getCategory() != "") {                categories.insert((*i)->getCategory());            }            if (inst && inst->isAssigned() &&                ((*i)->getIdentifier() == inst->getIdentifier().c_str())) {                currentCategory = (*i)->getCategory();            }        }    }    if (inst) {        RG_DEBUG << "AudioPluginDialog::populatePluginCategoryList: inst id " << inst->getIdentifier() << ", cat " << currentCategory << endl;    }    if (categories.empty()) {        m_pluginCategoryBox->hide();        m_pluginLabel->hide();    }    m_pluginCategoryList->clear();    m_pluginCategoryList->insertItem(i18n("(any)"));    m_pluginCategoryList->insertItem(i18n("(unclassified)"));    m_pluginCategoryList->setCurrentItem(0);    for (std::set             <QString>::iterator i = categories.begin();         i != categories.end(); ++i) {        m_pluginCategoryList->insertItem(*i);        if (*i == currentCategory) {            m_pluginCategoryList->setCurrentItem(m_pluginCategoryList->count() - 1);        }    }}voidAudioPluginDialog::populatePluginList(){    m_pluginList->clear();    m_pluginsInList.clear();    m_pluginList->insertItem(i18n("(none)"));    m_pluginsInList.push_back(0);    QString category;    bool needCategory = false;    if (m_pluginCategoryList->currentItem() > 0) {        needCategory = true;        if (m_pluginCategoryList->currentItem() == 1) {            category = "";        } else {            category = m_pluginCategoryList->currentText();        }    }    // Check for plugin and setup as required    AudioPluginInstance *inst = m_pluginContainer->getPlugin(m_index);    if (inst)        m_bypass->setChecked(inst->isBypassed());    // Use this temporary map to ensure that the plugins are sorted    // by name when they go into the combobox    typedef std::pair<int, AudioPlugin *> PluginPair;    typedef std::map<QString, PluginPair> PluginMap;    PluginMap plugins;    int count = 0;    for (PluginIterator i = m_pluginManager->begin();         i != m_pluginManager->end(); ++i) {        ++count;        if (( isSynth() && (*i)->isSynth()) ||            (!isSynth() && (*i)->isEffect())) {            if (needCategory) {                QString cat = "";                if ((*i)->getCategory())                    cat = (*i)->getCategory();                if (cat != category)                    continue;            }            plugins[(*i)->getName()] = PluginPair(count, *i);        }    }    const char *currentId = 0;    if (inst && inst->isAssigned())        currentId = inst->getIdentifier().c_str();    for (PluginMap::iterator i = plugins.begin(); i != plugins.end(); ++i) {        QString name = i->first;        if (name.endsWith(" VST"))            name = name.left(name.length() - 4);        m_pluginList->insertItem(name);        m_pluginsInList.push_back(i->second.first);        if (currentId && currentId == i->second.second->getIdentifier()) {            m_pluginList->setCurrentItem(m_pluginList->count() - 1);        }    }    slotPluginSelected(m_pluginList->currentItem());}voidAudioPluginDialog::makePluginParamsBox(QWidget *parent, int portCount,                                       int tooManyPorts){    m_pluginParamsBox = new QFrame(parent);    int columns = 2;    if (portCount > tooManyPorts) {        columns = 2;    } else if (portCount > 24) {        if (portCount > 60) {            columns = (portCount - 1) / 16 + 1;        } else {            columns = (portCount - 1) / 12 + 1;        }    }    int perColumn = 4;    if (portCount > 48) { // no bounds will be shown        perColumn = 2;    }    m_gridLayout = new QGridLayout(m_pluginParamsBox,                                   1,   // rows (will expand)                                   columns * perColumn,                                   5); // margin    m_gridLayout->setColStretch(3, 2);    m_gridLayout->setColStretch(7, 2);}voidAudioPluginDialog::slotCategorySelected(int){    populatePluginList();}voidAudioPluginDialog::slotPluginSelected(int i){    bool guiWasShown = m_guiShown;    if (m_guiShown) {        emit stopPluginGUI(m_containerId, m_index);        m_guiShown = false;    }    int number = m_pluginsInList[i];    RG_DEBUG << "AudioPluginDialog::::slotPluginSelected - "             << "setting up plugin from position " << number << " at menu item " << i << endl;    QString caption =        strtoqstr(m_pluginContainer->getName()) +        QString(" [ %1 ] - ").arg(m_index + 1);    if (number == 0) {        setCaption(caption + i18n("<no plugin>"));        m_insOuts->setText(i18n("<ports>"));        m_pluginId->setText(i18n("<id>"));        QToolTip::hide();        QToolTip::remove            (m_pluginList);        QToolTip::add            (m_pluginList, i18n("Select a plugin from this list."));    }    AudioPlugin *plugin = m_pluginManager->getPlugin(number - 1);    // Destroy old param widgets    //    QWidget* parent = dynamic_cast<QWidget*>(m_pluginParamsBox->parent());    delete m_pluginParamsBox;    m_pluginWidgets.clear(); // The widgets are deleted with the parameter box    m_programCombo = 0;    int portCount = 0;    if (plugin) {        for (AudioPlugin::PortIterator it = plugin->begin(); it != plugin->end(); ++it) {            if (((*it)->getType() & PluginPort::Control) &&                ((*it)->getType() & PluginPort::Input))                ++portCount;        }    }    int tooManyPorts = 96;    makePluginParamsBox(parent, portCount, tooManyPorts);    bool showBounds = (portCount <= 48);    if (portCount > tooManyPorts) {        m_gridLayout->addMultiCellWidget(            new QLabel(i18n("This plugin has too many controls to edit here."),                       m_pluginParamsBox),            1, 1, 0, m_gridLayout->numCols() - 1, Qt::AlignCenter);    }    AudioPluginInstance *inst = m_pluginContainer->getPlugin(m_index);    if (!inst)        return ;    if (plugin) {        setCaption(caption + plugin->getName());        m_pluginId->setText(i18n("Id: %1").arg(plugin->getUniqueId()));        QString pluginInfo = plugin->getAuthor() + QString("\n") +            plugin->getCopyright();        QToolTip::hide();        QToolTip::remove            (m_pluginList);        QToolTip::add            (m_pluginList, pluginInfo);        std::string identifier = plugin->getIdentifier().data();        // Only clear ports &c if this method is accessed by user        // action (after the constructor)        //        if (m_generating == false) {            inst->clearPorts();            if (inst->getIdentifier() != identifier) {                inst->clearConfiguration();            }        }        inst->setIdentifier(identifier);        AudioPlugin::PortIterator it = plugin->begin();        int count = 0;        int ins = 0, outs = 0;        for (; it != plugin->end(); ++it) {            if (((*it)->getType() & PluginPort::Control) &&

⌨️ 快捷键说明

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