Пример #1
0
void Engine::startPlayback()
{
    if (m_audioOutput) {
        if (QAudio::AudioOutput == m_mode &&
                QAudio::SuspendedState == m_state) {
            m_audioOutput->resume();
        } else {
            m_spectrumAnalyser.cancelCalculation();
            spectrumChanged(0, 0, FrequencySpectrum());
            setPlayPosition(0, true);
            m_mode = QAudio::AudioOutput;
            CHECKED_CONNECT(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
                            this, SLOT(audioStateChanged(QAudio::State)));
            CHECKED_CONNECT(m_audioOutput, SIGNAL(notify()),
                            this, SLOT(audioNotify()));
            m_count = 0;
            if (m_file) {
                m_file->seek(0);
                m_bufferPosition = 0;
                m_dataLength = 0;
                m_audioOutput->start(m_file);
            } else {
                m_audioOutputIODevice.close();
                m_audioOutputIODevice.setBuffer(&m_buffer);
                m_audioOutputIODevice.open(QIODevice::ReadOnly);
                m_audioOutput->start(&m_audioOutputIODevice);
            }
        }
    }
}
Пример #2
0
/**
  * Creating needed connections
  */
void MainWindow::createConnections()
{
    connect(ui->leSearch, SIGNAL(returnPressed()), this, SLOT(searchAudio()));

    connect(playerControls, SIGNAL(play()), player, SLOT(play()));
    connect(playerControls, SIGNAL(pause()), player, SLOT(pause()));
    connect(playerControls, SIGNAL(volumeChanged(int)), player, SLOT(setVolume(int)));
    connect(playerControls, SIGNAL(playPositionChanged(qint64)), player, SLOT(setPosition(qint64)));

    connect(player, SIGNAL(positionChanged(qint64)), playerControls, SLOT(setPlayPosition(qint64)));
    connect(player, SIGNAL(durationChanged(qint64)), playerControls, SLOT(setAudioLength(qint64)));
    connect(player, SIGNAL(volumeChanged(int)), playerControls, SLOT(setVolume(int)));
    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), playerControls, SLOT(setState(QMediaPlayer::State)));
    connect(playlist, SIGNAL(titleChange(QString)), playerControls, SLOT(setTitle(QString)));

    connect(playerControls, SIGNAL(previous()), playlist, SLOT(previous()));
    connect(playerControls, SIGNAL(next()), playlist, SLOT(next()));

    connect(playerControls, SIGNAL(configure()), this, SLOT(showSettingsDialog()));

    connect(vkaudio, SIGNAL(statusChanged(QString, int)), this->statusBar(), SLOT(showMessage(QString,int)));

    connect(ui->tvSongs, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(playAudio()));
    connect(ui->tvSongs, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showSongsContextMenu(QPoint)));
    connect(ui->tvPlaylists, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showPlaylistsContextMenu(QPoint)));
}
Пример #3
0
void Engine::resetAudioDevices()
{
    delete m_audioOutput;
    m_audioOutput = 0;
    setPlayPosition(0);
    m_spectrumPosition = 0;
    setLevel(0.0, 0.0, 0);
}
Пример #4
0
	/*/////////////////////////////////////////////////////////////////*/
	void OgreOggISound::setCuePoint(unsigned short index)
	{
		if ( mCuePoints.empty() || ((int)mCuePoints.size()<=index) )
			return;

		// set cue point
		setPlayPosition(mCuePoints.at(index));
	}
Пример #5
0
void Engine::audioNotify()
{
    switch (m_mode) {
    case QAudio::AudioInput: {
            const qint64 recordPosition = qMin(m_bufferLength, audioLength(m_format, m_audioInput->processedUSecs()));
            setRecordPosition(recordPosition);
            const qint64 levelPosition = m_dataLength - m_levelBufferLength;
            if (levelPosition >= 0)
                calculateLevel(levelPosition, m_levelBufferLength);
            if (m_dataLength >= m_spectrumBufferLength) {
                const qint64 spectrumPosition = m_dataLength - m_spectrumBufferLength;
                calculateSpectrum(spectrumPosition);
            }
            emit bufferChanged(0, m_dataLength, m_buffer);
        }
        break;
    case QAudio::AudioOutput: {
            const qint64 playPosition = audioLength(m_format, m_audioOutput->processedUSecs());
            setPlayPosition(qMin(bufferLength(), playPosition));
            const qint64 levelPosition = playPosition - m_levelBufferLength;
            const qint64 spectrumPosition = playPosition - m_spectrumBufferLength;
            if (m_file) {
                if (levelPosition > m_bufferPosition ||
                    spectrumPosition > m_bufferPosition ||
                    qMax(m_levelBufferLength, m_spectrumBufferLength) > m_dataLength) {
                    m_bufferPosition = 0;
                    m_dataLength = 0;
                    // Data needs to be read into m_buffer in order to be analysed
                    const qint64 readPos = qMax(qint64(0), qMin(levelPosition, spectrumPosition));
                    const qint64 readEnd = qMin(m_analysisFile->size(), qMax(levelPosition + m_levelBufferLength, spectrumPosition + m_spectrumBufferLength));
                    const qint64 readLen = readEnd - readPos + audioLength(m_format, WaveformWindowDuration);
                    qDebug() << "Engine::audioNotify [1]"
                             << "analysisFileSize" << m_analysisFile->size()
                             << "readPos" << readPos
                             << "readLen" << readLen;
                    if (m_analysisFile->seek(readPos + m_analysisFile->headerLength())) {
                        m_buffer.resize(readLen);
                        m_bufferPosition = readPos;
                        m_dataLength = m_analysisFile->read(m_buffer.data(), readLen);
                        qDebug() << "Engine::audioNotify [2]" << "bufferPosition" << m_bufferPosition << "dataLength" << m_dataLength;
                    } else {
                        qDebug() << "Engine::audioNotify [2]" << "file seek error";
                    }
                    emit bufferChanged(m_bufferPosition, m_dataLength, m_buffer);
                }
            } else {
                if (playPosition >= m_dataLength)
                    stopPlayback();
            }
            if (levelPosition >= 0 && levelPosition + m_levelBufferLength < m_bufferPosition + m_dataLength)
                calculateLevel(levelPosition, m_levelBufferLength);
            if (spectrumPosition >= 0 && spectrumPosition + m_spectrumBufferLength < m_bufferPosition + m_dataLength)
                calculateSpectrum(spectrumPosition);
        }
        break;
    }
}
Пример #6
0
MusicWindow::MusicWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MusicWindow)
{
    ui->setupUi(this);
    playNum = 1;
    last_PlayNum = 0;
    search_Last = 0;
    player = new QMediaPlayer;
    lyric = new MyLyric(this);
    playMode = "order";
    ui->volumeSlider->setValue(player->volume());
    thread = new Thread(this); //线程实例化
    //窗口初始化
    setElement_BackGround();

    //检测音乐播放进度,同时调整播放滑块
    connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(updateTime(qint64))); 
    connect(player, SIGNAL(durationChanged(qint64)), this, SLOT(setPlayRange(qint64)));
    connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(setPlayPosition(qint64)));
    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(lyric_Sync(QMediaPlayer::State)));

    //调整播放进程
    connect(ui->timeSlider, SIGNAL(sliderMoved(int)), this, SLOT(setSliderPosition()));
    connect(ui->volumeSlider, SIGNAL(sliderMoved(int)), this, SLOT(adjustVolume()));
    connect(ui->browserHideButton, SIGNAL(clicked()), this, SLOT(browserSet()));
    connect(ui->setApearenceButton, SIGNAL(clicked()), this, SLOT(setApearence()));
    connect(ui->addButton, SIGNAL(clicked()), this, SLOT(load_again()));
    connect(ui->lyricButton, SIGNAL(clicked()), this, SLOT(show_Hide_Lyric()));
    connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(nextSong()));
    connect(ui->lastButton, SIGNAL(clicked()), this, SLOT(lastSong()));
    connect(ui->playButton, SIGNAL(clicked()), this, SLOT(playEvent()));
    connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(doubleClickedPlay(QListWidgetItem *)));
    connect(ui->quitButton, SIGNAL(clicked()), this, SLOT(warning()));
    connect(ui->markButton, SIGNAL(clicked()), this, SLOT(markSong()));
    connect(ui->setApearenceButton, SIGNAL(clicked()), this, SLOT(setApearence()));
    connect(ui->muteButton, SIGNAL(clicked()), this, SLOT(set_Mute()));
    connect(ui->storeButton, SIGNAL(clicked()), this, SLOT(store_Show()));
    connect(ui->favoriteButton, SIGNAL(clicked()), this, SLOT(favoriteSongs_Show()));
    connect(ui->browserButton, SIGNAL(clicked()), this, SLOT(browser_Show()));
    connect(ui->loginButton, SIGNAL(clicked()), this, SLOT(user_login()));
    connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(download_File()));
    connect(ui->modeButton, SIGNAL(clicked()), this, SLOT(playMode_Change()));
    connect(ui->smallButton, SIGNAL(clicked()), this, SLOT(showMinimized()));
    connect(ui->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(songs_Search(QString)));

    //子线程
    connect(thread, SIGNAL(upgrade_Signal(int, QStringList, QStringList, QFileInfoList)), this,
            SLOT(upgradeData(int, QStringList, QStringList, QFileInfoList)), Qt::DirectConnection );

    //载入音乐
    musicLoad();
    Sleep(1000);
}
Пример #7
0
void
LoopRuler::mouseDoubleClickEvent(QMouseEvent *mE)
{
    double x = mouseEventToSceneX(mE);
    if (x < 0)
        x = 0;

    RG_DEBUG << "LoopRuler::mouseDoubleClickEvent: x = " << x << ", looping = " << m_loopingMode << endl;

	if (mE->button() == Qt::LeftButton && !m_loopingMode)
        emit setPlayPosition(m_grid->snapX(x));
}
Пример #8
0
/*/////////////////////////////////////////////////////////////////*/
void OgreOggStaticSound::_playImpl() {
    if(isPlaying())
        return;

    if(mSource == AL_NONE)
        if(!OgreOggSoundManager::getSingleton()._requestSoundSource(this))
            return;

    // Pick up playback position change..
    if(mPlayPosChanged)
        setPlayPosition(mPlayPos);

    alSourcePlay(mSource);
    mPlay = true;

    // Notify listener
    if(mSoundListener) mSoundListener->soundPlayed(this);
}
Пример #9
0
void Engine::startPlayback()
{
    if (m_audioOutput) {
        if (QAudio::AudioOutput == m_mode &&
            QAudio::SuspendedState == m_state) {
#ifdef Q_OS_WIN
            // The Windows backend seems to internally go back into ActiveState
            // while still returning SuspendedState, so to ensure that it doesn't
            // ignore the resume() call, we first re-suspend
            m_audioOutput->suspend();
#endif
            m_audioOutput->resume();
        } else {
            m_spectrumAnalyser.cancelCalculation();
            spectrumChanged(0, 0, FrequencySpectrum());
            setPlayPosition(0, true);
            stopRecording();
            m_mode = QAudio::AudioOutput;
            CHECKED_CONNECT(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
                            this, SLOT(audioStateChanged(QAudio::State)));
            CHECKED_CONNECT(m_audioOutput, SIGNAL(notify()),
                            this, SLOT(audioNotify()));
            m_count = 0;
            if (m_file) {
                m_file->seek(0);
                m_bufferPosition = 0;
                m_dataLength = 0;
                m_audioOutput->start(m_file);
            } else {
                m_audioOutputIODevice.close();
                m_audioOutputIODevice.setBuffer(&m_buffer);
                m_audioOutputIODevice.open(QIODevice::ReadOnly);
                m_audioOutput->start(&m_audioOutputIODevice);
            }
        }
    }
}
Пример #10
0
StandardRuler::StandardRuler(RosegardenDocument *doc,
                             RulerScale *rulerScale,
                             double xorigin,
                             int barHeight,
                             bool invert,
                             bool isForMainWindow,
                             QWidget* parent) :
        QWidget(parent),
        m_invert(invert),
        m_isForMainWindow(isForMainWindow),
        m_loopRulerHeight(10),
        m_currentXOffset(0),
        m_doc(doc),
        m_rulerScale(rulerScale),
        m_markerRuler(0)
{
//    QString localStyle("QWidget { background-color: #EEEEEE; color: #000000; }");

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->setSpacing(0);
    setLayout(layout);
	
    if (!m_invert) {
        m_markerRuler = new MarkerRuler
                       (m_doc, m_rulerScale, barHeight - m_loopRulerHeight, xorigin, this);
        layout->addWidget(m_markerRuler);
    }

    m_loopRuler = new LoopRuler
                  (m_doc, m_rulerScale, m_loopRulerHeight, xorigin, m_invert, m_isForMainWindow, this);
    layout->addWidget(m_loopRuler);

    if (m_invert) {
        m_markerRuler = new MarkerRuler
                       (m_doc, m_rulerScale, barHeight - m_loopRulerHeight, xorigin, this);
        layout->addWidget(m_markerRuler);
    }

//    m_markerRuler->setStyleSheet(localStyle);
//    m_loopRuler->setStyleSheet(localStyle);
//    m_markerRuler->setToolTip(QString("I am m_markerRuler. My style is: %1").arg(localStyle));


    QObject::connect
        (CommandHistory::getInstance(), SIGNAL(commandExecuted()),
         this, SLOT(update()));

    if (RosegardenMainWindow::self()) {
        QObject::connect
                (m_markerRuler, SIGNAL(editMarkers()),
                 RosegardenMainWindow::self(), SLOT(slotEditMarkers()));

        QObject::connect
                (m_markerRuler, SIGNAL(addMarker(timeT)),
                 RosegardenMainWindow::self(), SLOT(slotAddMarker(timeT)));

        QObject::connect
                (m_markerRuler, SIGNAL(deleteMarker(int, timeT, QString, QString)),
                 RosegardenMainWindow::self(), SLOT(slotDeleteMarker(int, timeT, QString, QString)));

        QObject::connect
                (m_loopRuler, SIGNAL(setPlayPosition(timeT)),
                 RosegardenMainWindow::self(), SLOT(slotSetPlayPosition(timeT)));
    }
}