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

📄 audiomanagerdialog.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 "AudioManagerDialog.h"#include <kapplication.h>#include "base/Event.h"#include "misc/Debug.h"#include "misc/Strings.h"#include "AudioPlayingDialog.h"#include "base/Composition.h"#include "base/Exception.h"#include "base/Instrument.h"#include "base/MidiProgram.h"#include "base/NotationTypes.h"#include "base/RealTime.h"#include "base/Segment.h"#include "base/Selection.h"#include "base/Studio.h"#include "base/Track.h"#include "document/MultiViewCommandHistory.h"#include "document/RosegardenGUIDoc.h"#include "document/ConfigGroups.h"#include "gui/application/RosegardenGUIView.h"#include "gui/application/RosegardenApplication.h"#include "gui/widgets/AudioListItem.h"#include "gui/widgets/AudioListView.h"#include "gui/widgets/CurrentProgressDialog.h"#include "gui/widgets/ProgressDialog.h"#include "sound/AudioFile.h"#include "sound/AudioFileManager.h"#include "sound/WAVAudioFile.h"#include "UnusedAudioSelectionDialog.h"#include <klocale.h>#include <kstddirs.h>#include <kaction.h>#include <kcommand.h>#include <kfiledialog.h>#include <kglobal.h>#include <klineeditdlg.h>#include <klistview.h>#include <kmainwindow.h>#include <kmessagebox.h>#include <kstdaction.h>#include <kurl.h>#include <kxmlguiclient.h>#include <kio/netaccess.h>#include <qaccel.h>#include <qcstring.h>#include <qdatastream.h>#include <qdialog.h>#include <qdragobject.h>#include <qfile.h>#include <qfileinfo.h>#include <qiconset.h>#include <qlabel.h>#include <qlistview.h>#include <qpainter.h>#include <qpixmap.h>#include <qstring.h>#include <qstrlist.h>#include <qtimer.h>#include <qvbox.h>#include <qwidget.h>namespace Rosegarden{const int AudioManagerDialog::m_maxPreviewWidth            = 100;const int AudioManagerDialog::m_previewHeight              = 30;const char* const AudioManagerDialog::m_listViewLayoutName = "AudioManagerDialog Layout";AudioManagerDialog::AudioManagerDialog(QWidget *parent,                                       RosegardenGUIDoc *doc):        KMainWindow(parent, "audioManagerDialog"),        m_doc(doc),        m_playingAudioFile(0),        m_audioPlayingDialog(0),        m_playTimer(new QTimer(this)),        m_audiblePreview(true){    setCaption(i18n("Audio File Manager"));    setWFlags(WDestructiveClose);    QVBox *box = new QVBox(this);    setCentralWidget(box);    box->setMargin(10);    box->setSpacing(5);    m_sampleRate = 0;    QCString replyType;    QByteArray replyData;    if (rgapp->sequencerCall("getSampleRate()", replyType, replyData)) {        QDataStream streamIn(replyData, IO_ReadOnly);        unsigned int result;        streamIn >> result;        m_sampleRate = result;    }    m_fileList = new AudioListView(box);    m_wrongSampleRates = new QLabel(i18n("* Some audio files are encoded at a sample rate different from that of the JACK audio server.\nRosegarden will play them at the correct speed, but they will sound terrible.\nPlease consider resampling such files externally, or adjusting the sample rate of the JACK server."), box);    m_wrongSampleRates->hide();    QString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/");    QIconSet icon(QPixmap(pixmapDir + "/toolbar/transport-play.xpm"));    new KAction(i18n("&Add Audio File..."), "fileopen", 0, this,                SLOT(slotAdd()), actionCollection(), "add_audio");    new KAction(i18n("&Unload Audio File"), "editdelete", 0, this,                SLOT(slotRemove()),                actionCollection(), "remove_audio");    icon = QIconSet(QPixmap(pixmapDir + "/toolbar/transport-play.xpm"));    new KAction(i18n("&Play Preview"), icon, 0, this,                SLOT(slotPlayPreview()),                actionCollection(), "preview_audio");    /*!!! Not actually implemented -- this never worked right!        new KAction(i18n("Re&label"), 0, 0, this,    		SLOT(slotRename()),     		actionCollection(), "rename_audio");    */    icon = QIconSet(QPixmap(pixmapDir + "/toolbar/insert_audio_into_track.xpm"));    new KAction(i18n("&Insert into Selected Audio Track"),                icon, 0, this, SLOT(slotInsert()),                actionCollection(), "insert_audio");    new KAction(i18n("Unload &all Audio Files"), 0, 0, this,                SLOT(slotRemoveAll()),                actionCollection(), "remove_all_audio");    new KAction(i18n("Unload all &Unused Audio Files"), 0, 0, this,                SLOT(slotRemoveAllUnused()),                actionCollection(), "remove_all_unused_audio");    new KAction(i18n("&Delete Unused Audio Files..."), 0, 0, this,                SLOT(slotDeleteUnused()),                actionCollection(), "delete_unused_audio");    new KAction(i18n("&Export Audio File..."), "fileexport", 0, this,                SLOT(slotExportAudio()),                actionCollection(), "export_audio");/*    new KAction(i18n("Distribute Audio on &MIDI"),                0, 0, this,                SLOT(slotDistributeOnMidiSegment()),                actionCollection(),                "distribute_audio");*/    // Set the column names    //    m_fileList->addColumn(i18n("Name"));           // 0    m_fileList->addColumn(i18n("Duration"));       // 1    m_fileList->addColumn(i18n("Envelope"));       // 2    m_fileList->addColumn(i18n("Sample rate"));    // 3    m_fileList->addColumn(i18n("Channels"));       // 4    m_fileList->addColumn(i18n("Resolution"));     // 5    m_fileList->addColumn(i18n("File"));           // 6    m_fileList->setColumnAlignment(1, Qt::AlignHCenter);    m_fileList->setColumnAlignment(2, Qt::AlignHCenter);    m_fileList->setColumnAlignment(3, Qt::AlignHCenter);    m_fileList->setColumnAlignment(4, Qt::AlignHCenter);    m_fileList->setColumnAlignment(5, Qt::AlignHCenter);    m_fileList->restoreLayout(kapp->config(), m_listViewLayoutName);    // a minimum width for the list box    //m_fileList->setMinimumWidth(300);    // show focus across all columns    m_fileList->setAllColumnsShowFocus(true);    // show tooltips when columns are partially hidden    m_fileList->setShowToolTips(true);    // connect selection mechanism    connect(m_fileList, SIGNAL(selectionChanged(QListViewItem*)),            SLOT(slotSelectionChanged(QListViewItem*)));    connect(m_fileList, SIGNAL(dropped(QDropEvent*, QListViewItem*)),            SLOT(slotDropped(QDropEvent*, QListViewItem*)));    // setup local accelerators    //    m_accelerators = new QAccel(this);    // delete    //    m_accelerators->connectItem(m_accelerators->insertItem(Key_Delete),                                this,                                SLOT(slotRemove()));    slotPopulateFileList();    // Connect command history for updates    //    connect(getCommandHistory(), SIGNAL(commandExecuted(KCommand *)),            this, SLOT(slotCommandExecuted(KCommand *)));    //setInitialSize(configDialogSize(AudioManagerDialogConfigGroup));    connect(m_playTimer, SIGNAL(timeout()),            this, SLOT(slotCancelPlayingAudio()));    KStdAction::close(this,                      SLOT(slotClose()),                      actionCollection());    createGUI("audiomanager.rc");    updateActionState(false);}AudioManagerDialog::~AudioManagerDialog(){    RG_DEBUG << "\n*** AudioManagerDialog::~AudioManagerDialog\n" << endl;    m_fileList->saveLayout(kapp->config(), m_listViewLayoutName);    //saveDialogSize(AudioManagerDialogConfigGroup);}voidAudioManagerDialog::slotPopulateFileList(){    // create pixmap of given size    QPixmap *audioPixmap = new QPixmap(m_maxPreviewWidth, m_previewHeight);    // Store last selected item if we have one    //    AudioListItem *selectedItem =        dynamic_cast<AudioListItem*>(m_fileList->selectedItem());    AudioFileId lastId = 0;    Segment *lastSegment = 0;    bool findSelection = false;    bool foundSelection = false;    if (selectedItem) {        lastId = selectedItem->getId();        lastSegment = selectedItem->getSegment();        findSelection = true;    }    // We don't want the selection changes to be propagated    // to the main view    //    m_fileList->blockSignals(true);    // clear file list and disable associated action buttons    m_fileList->clear();    if (m_doc->getAudioFileManager().begin() ==            m_doc->getAudioFileManager().end()) {        // Turn off selection and report empty list        //        new AudioListItem(m_fileList, i18n("<no audio files>"), 0);        m_fileList->setSelectionMode(QListView::NoSelection);        m_fileList->setRootIsDecorated(false);        m_fileList->blockSignals(false);        updateActionState(false);        return ;    }    // show tree hierarchy    m_fileList->setRootIsDecorated(true);    // enable selection    m_fileList->setSelectionMode(QListView::Single);    // for the sample file length    QString msecs, sRate;    RealTime length;    // Create a vector of audio Segments only    //    std::vector<Segment*> segments;    std::vector<Segment*>::const_iterator iit;    for (Composition::iterator it = m_doc->getComposition().begin();            it != m_doc->getComposition().end(); ++it) {        if ((*it)->getType() == Segment::Audio)            segments.push_back(*it);    }    // duration    RealTime segmentDuration;    bool wrongSampleRates = false;    for (std::vector<AudioFile*>::const_iterator            it = m_doc->getAudioFileManager().begin();            it != m_doc->getAudioFileManager().end();            ++it) {        try {            m_doc->getAudioFileManager().            drawPreview((*it)->getId(),                        RealTime::zeroTime,                        (*it)->getLength(),                        audioPixmap);        } catch (Exception e) {            audioPixmap->fill(); // white            QPainter p(audioPixmap);            p.setPen(Qt::black);            p.drawText(10, m_previewHeight / 2, QString("<no preview>"));        }        //!!! Why isn't the label the label the user assigned to the file?        // Why do we allow the user to assign a label at all, then?        QString label = QString((*it)->getShortFilename().c_str());        // Set the label, duration, envelope pixmap and filename        //        AudioListItem *item = new AudioListItem(m_fileList, label,                                                (*it)->getId());        // Duration        //        length = (*it)->getLength();        msecs.sprintf("%03d", length.nsec / 1000000);        item->setText(1, QString("%1.%2s").arg(length.sec).arg(msecs));        // set start time and duration        item->setStartTime(RealTime::zeroTime);        item->setDuration(length);        // Envelope pixmap        //        item->setPixmap(2, *audioPixmap);        // File location        //        item->setText(6, QString(                          m_doc->getAudioFileManager().                          substituteHomeForTilde((*it)->getFilename()).c_str()));        // Resolution        //        item->setText(5, QString("%1 bits").arg((*it)->getBitsPerSample()));        // Channels        //        item->setText(4, QString("%1").arg((*it)->getChannels()));        // Sample rate        //        if (m_sampleRate != 0 && (*it)->getSampleRate() != m_sampleRate) {            sRate.sprintf("%.1f KHz *", float((*it)->getSampleRate()) / 1000.0);            wrongSampleRates = true;        } else {            sRate.sprintf("%.1f KHz", float((*it)->getSampleRate()) / 1000.0);        }        item->setText(3, sRate);        // Test audio file element for selection criteria        //        if (findSelection && lastSegment == 0 && lastId == (*it)->getId()) {            m_fileList->setSelected(item, true);            findSelection = false;        }        // Add children        //        for (iit = segments.begin(); iit != segments.end(); iit++) {            if ((*iit)->getAudioFileId() == (*it)->getId()) {                AudioListItem *childItem =                    new AudioListItem(item,                                      QString((*iit)->getLabel().c_str()),                                      (*it)->getId());                segmentDuration = (*iit)->getAudioEndTime() -                                  (*iit)->getAudioStartTime();                // store the start time                //                childItem->setStartTime((*iit)->getAudioStartTime());                childItem->setDuration(segmentDuration);                // Write segment duration                //                msecs.sprintf("%03d", segmentDuration.nsec / 1000000);                childItem->setText(1, QString("%1.%2s")                                   .arg(segmentDuration.sec)                                   .arg(msecs));                try {                    m_doc->getAudioFileManager().                    drawHighlightedPreview((*it)->getId(),                                           RealTime::zeroTime,                                           (*it)->getLength(),                                           (*iit)->getAudioStartTime(),                                           (*iit)->getAudioEndTime(),                                           audioPixmap);                } catch (Exception e) {                    // should already be set to "no file"                }

⌨️ 快捷键说明

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