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

📄 midiinstrumentparameterpanel.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* -*- 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 "MIDIInstrumentParameterPanel.h"#include <qlayout.h>#include "sound/Midi.h"#include <klocale.h>#include "misc/Debug.h"#include "misc/Strings.h"#include "base/Colour.h"#include "base/Composition.h"#include "base/ControlParameter.h"#include "base/Instrument.h"#include "base/MidiDevice.h"#include "base/MidiProgram.h"#include "document/RosegardenGUIDoc.h"#include "gui/studio/StudioControl.h"#include "gui/widgets/Rotary.h"#include "InstrumentParameterPanel.h"#include "sound/MappedEvent.h"#include "sound/MappedInstrument.h"#include <kcombobox.h>#include <ksqueezedtextlabel.h>#include <qcheckbox.h>#include <qcolor.h>#include <qfontmetrics.h>#include <qframe.h>#include <qhbox.h>#include <qlabel.h>#include <qregexp.h>#include <qsignalmapper.h>#include <qstring.h>#include <qwidget.h>#include <algorithm>namespace Rosegarden{MIDIInstrumentParameterPanel::MIDIInstrumentParameterPanel(RosegardenGUIDoc *doc, QWidget* parent):        InstrumentParameterPanel(doc, parent),        m_rotaryFrame(0),        m_rotaryMapper(new QSignalMapper(this)){    m_mainGrid = new QGridLayout(this, 10, 3, 2, 1);    m_connectionLabel = new KSqueezedTextLabel(this);    m_bankValue = new KComboBox(this);    m_channelValue = new KComboBox(this);    m_programValue = new KComboBox(this);    m_variationValue = new KComboBox(this);    m_bankCheckBox = new QCheckBox(this);    m_programCheckBox = new QCheckBox(this);    m_variationCheckBox = new QCheckBox(this);    m_percussionCheckBox = new QCheckBox(this);    m_bankValue->setSizeLimit(20);    m_programValue->setSizeLimit(20);    m_variationValue->setSizeLimit(20);    m_bankLabel = new QLabel(i18n("Bank"), this);    m_variationLabel = new QLabel(i18n("Variation"), this);    m_programLabel = new QLabel(i18n("Program"), this);    QLabel *channelLabel = new QLabel(i18n("Channel out"), this);    QLabel *percussionLabel = new QLabel(i18n("Percussion"), this);    // Ensure a reasonable amount of space in the program dropdowns even    // if no instrument initially selected    QFontMetrics metrics(m_programValue->font());    int width22 = metrics.width("1234567890123456789012");    int width25 = metrics.width("1234567890123456789012345");    m_bankValue->setMinimumWidth(width22);    m_programValue->setMinimumWidth(width22);    m_variationValue->setMinimumWidth(width22);    m_connectionLabel->setFixedWidth(width25);    m_connectionLabel->setAlignment(Qt::AlignCenter);    // Configure the empty final row to accomodate any extra vertical space.    m_mainGrid->setRowStretch(m_mainGrid->numRows() - 1, 1);    m_mainGrid->setColStretch(2, 1);    m_mainGrid->addMultiCellWidget(m_instrumentLabel, 0, 0, 0, 2, AlignCenter);    m_mainGrid->addMultiCellWidget(m_connectionLabel, 1, 1, 0, 2, AlignCenter);    m_mainGrid->addMultiCellWidget(channelLabel, 2, 2, 0, 1, AlignLeft);    m_mainGrid->addWidget(m_channelValue, 2, 2, AlignRight);    m_mainGrid->addMultiCellWidget(percussionLabel, 3, 3, 0, 1, AlignLeft);    m_mainGrid->addWidget(m_percussionCheckBox, 3, 2, AlignRight);    m_mainGrid->addWidget(m_bankLabel, 4, 0, AlignLeft);    m_mainGrid->addWidget(m_bankCheckBox, 4, 1, AlignRight);    m_mainGrid->addWidget(m_bankValue, 4, 2, AlignRight);    m_mainGrid->addWidget(m_programLabel, 5, 0, AlignLeft);    m_mainGrid->addWidget(m_programCheckBox, 5, 1, AlignRight);    m_mainGrid->addWidget(m_programValue, 5, 2, AlignRight);    m_mainGrid->addWidget(m_variationLabel, 6, 0);    m_mainGrid->addWidget(m_variationCheckBox, 6, 1);    m_mainGrid->addWidget(m_variationValue, 6, 2, AlignRight);    // Populate channel lists    //    for (int i = 0; i < 16; i++) {        m_channelValue->insertItem(QString("%1").arg(i + 1));    }    m_channelValue->setSizeLimit(16);    // Disable these by default - they are activate by their    // checkboxes    //    m_programValue->setDisabled(true);    m_bankValue->setDisabled(true);    m_variationValue->setDisabled(true);    // Only active if we have an Instrument selected    //    m_percussionCheckBox->setDisabled(true);    m_programCheckBox->setDisabled(true);    m_bankCheckBox->setDisabled(true);    m_variationCheckBox->setDisabled(true);    // Connect up the toggle boxes    //    connect(m_percussionCheckBox, SIGNAL(toggled(bool)),            this, SLOT(slotTogglePercussion(bool)));    connect(m_programCheckBox, SIGNAL(toggled(bool)),            this, SLOT(slotToggleProgramChange(bool)));    connect(m_bankCheckBox, SIGNAL(toggled(bool)),            this, SLOT(slotToggleBank(bool)));    connect(m_variationCheckBox, SIGNAL(toggled(bool)),            this, SLOT(slotToggleVariation(bool)));    // Connect activations    //    connect(m_bankValue, SIGNAL(activated(int)),            this, SLOT(slotSelectBank(int)));    connect(m_variationValue, SIGNAL(activated(int)),            this, SLOT(slotSelectVariation(int)));    connect(m_programValue, SIGNAL(activated(int)),            this, SLOT(slotSelectProgram(int)));    connect(m_channelValue, SIGNAL(activated(int)),            this, SLOT(slotSelectChannel(int)));    // don't select any of the options in any dropdown    m_programValue->setCurrentItem( -1);    m_bankValue->setCurrentItem( -1);    m_channelValue->setCurrentItem( -1);    m_variationValue->setCurrentItem( -1);    connect(m_rotaryMapper, SIGNAL(mapped(int)),            this, SLOT(slotControllerChanged(int)));}voidMIDIInstrumentParameterPanel::setupForInstrument(Instrument *instrument){    RG_DEBUG << "MIDIInstrumentParameterPanel::setupForInstrument" << endl;    MidiDevice *md = dynamic_cast<MidiDevice*>                     (instrument->getDevice());    if (!md) {        RG_DEBUG << "WARNING: MIDIInstrumentParameterPanel::setupForInstrument:"        << " No MidiDevice for Instrument "        << instrument->getId() << endl;        return ;    }    m_selectedInstrument = instrument;    // Set instrument name    //    m_instrumentLabel->setText(strtoqstr(instrument->getPresentationName()));    // Set Studio Device name    //    QString connection(strtoqstr(md->getConnection()));    if (connection == "") {        m_connectionLabel->setText(i18n("[ %1 ]").arg(i18n("No connection")));    } else {        // remove trailing "(duplex)", "(read only)", "(write only)" etc        connection.replace(QRegExp("\\s*\\([^)0-9]+\\)\\s*$"), "");        QString text = i18n("[ %1 ]").arg(connection);        /*QString origText(text);        QFontMetrics metrics(m_connectionLabel->fontMetrics());        int maxwidth = metrics.width            ("Program: [X]   Acoustic Grand Piano 123");// kind of arbitrary!        int hlen = text.length() / 2;        while (metrics.width(text) > maxwidth && text.length() > 10) {            --hlen;            text = origText.left(hlen) + "..." + origText.right(hlen);        }        if (text.length() > origText.length() - 7) text = origText;*/        m_connectionLabel->setText(text);    }    // Enable all check boxes    //    m_percussionCheckBox->setDisabled(false);    m_programCheckBox->setDisabled(false);    m_bankCheckBox->setDisabled(false);    m_variationCheckBox->setDisabled(false);    // Activate all checkboxes    //    m_percussionCheckBox->setChecked(instrument->isPercussion());    m_programCheckBox->setChecked(instrument->sendsProgramChange());    m_bankCheckBox->setChecked(instrument->sendsBankSelect());    m_variationCheckBox->setChecked(instrument->sendsBankSelect());    // Basic parameters    //    m_channelValue->setCurrentItem((int)instrument->getMidiChannel());    // Check for program change    //    populateBankList();    populateProgramList();    populateVariationList();    // Setup the ControlParameters    //    setupControllers(md);    // Set all the positions by controller number    //    for (RotaryMap::iterator it = m_rotaries.begin() ;            it != m_rotaries.end(); ++it) {        MidiByte value = 0;        // Special cases        //        if (it->first == MIDI_CONTROLLER_PAN)            value = int(instrument->getPan());        else if (it->first == MIDI_CONTROLLER_VOLUME)            value = int(instrument->getVolume());        else {            try {                value = instrument->getControllerValue(                            MidiByte(it->first));            } catch (...) {                continue;            }        }        setRotaryToValue(it->first, int(value));    }}voidMIDIInstrumentParameterPanel::setupControllers(MidiDevice *md){    if (!m_rotaryFrame) {        m_rotaryFrame = new QFrame(this);        m_mainGrid->addMultiCellWidget(m_rotaryFrame, 8, 8, 0, 2, Qt::AlignHCenter);        m_rotaryGrid = new QGridLayout(m_rotaryFrame, 10, 3, 8, 1);        m_rotaryGrid->addItem(new QSpacerItem(10, 4), 0, 1);    }    // To cut down on flicker, we avoid destroying and recreating    // widgets as far as possible here.  If a label already exists,    // we just set its text; if a rotary exists, we only replace it    // if we actually need a different one.    Composition &comp = m_doc->getComposition();    ControlList list = md->getControlParameters();    // sort by IPB position    //    std::sort(list.begin(), list.end(),              ControlParameter::ControlPositionCmp());    int count = 0;    RotaryMap::iterator rmi = m_rotaries.begin();    for (ControlList::iterator it = list.begin();            it != list.end(); ++it) {        if (it->getIPBPosition() == -1)            continue;        // Get the knob colour - only if the colour is non-default (>0)        //        QColor knobColour = Qt::black; // special case for Rotary        if (it->getColourIndex() > 0) {            Colour c =                comp.getGeneralColourMap().getColourByIndex                (it->getColourIndex());            knobColour = QColor(c.getRed(), c.getGreen(), c.getBlue());        }        Rotary *rotary = 0;        if (rmi != m_rotaries.end()) {            // Update the controller number that is associated with the            // existing rotary widget.            rmi->first = it->getControllerValue();            // Update the properties of the existing rotary widget.            rotary = rmi->second.first;            int redraw = 0; // 1 -> position, 2 -> all            if (rotary->getMinValue() != it->getMin()) {                rotary->setMinValue(it->getMin());                redraw = 1;            }            if (rotary->getMaxValue() != it->getMax()) {                rotary->setMaxValue(it->getMax());                redraw = 1;            }            if (rotary->getKnobColour() != knobColour) {                rotary->setKnobColour(knobColour);                redraw = 2;            }            if (redraw == 1 || rotary->getPosition() != it->getDefault()) {                rotary->setPosition(it->getDefault());                if (redraw == 1)                    redraw = 0;            }            if (redraw == 2) {                rotary->repaint();            }            // Update the controller name that is associated with            // with the existing rotary widget.            QLabel *label = rmi->second.second;            label->setText(strtoqstr(it->getName()));            ++rmi;        } else {            QHBox *hbox = new QHBox(m_rotaryFrame);            hbox->setSpacing(8);            float smallStep = 1.0;            float bigStep = 5.0;            if (it->getMax() - it->getMin() < 10)                bigStep = 1.0;            else if (it->getMax() - it->getMin() < 20)                bigStep = 2.0;            rotary = new Rotary                     (hbox,                      it->getMin(),                      it->getMax(),                      smallStep,

⌨️ 快捷键说明

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