Пример #1
0
void WaveformView::playSegment(LipsyncPhrase *fPhrase, LipsyncWord *fWord, LipsyncPhoneme *fPhoneme, int32 fScrubFrame)
{
    bool playSegment = false;
    QMediaPlayer *audioPlayer = fDoc->GetAudioPlayer();
    int32 startFrame;
    fAudioStopFrame = -1;
    if (audioPlayer)
    {
        if (fPhrase)
        {
            playSegment = true;
            startFrame = fPhrase->fStartFrame;
            fAudioStopFrame = fPhrase->fEndFrame + 1;
        }
        else if (fWord)
        {
            playSegment = true;
            startFrame = fWord->fStartFrame;
            fAudioStopFrame = fWord->fEndFrame + 1;
        }
        else if (fPhoneme)
        {
            playSegment = true;
            startFrame = fPhoneme->fFrame;
            fAudioStopFrame = startFrame + 1;
        }
        if (playSegment)
        {
            float f = ((real)startFrame / (real)fDoc->Fps()) * 1000.0f;
            audioPlayer->setPosition(PG_ROUND(f));
            audioPlayer->play();
            emit(frameChanged(fScrubFrame));
        }
    }
}
Пример #2
0
Bullet::Bullet()
    :QObject(),
     QGraphicsPixmapItem()
{
    setPixmap(QPixmap(":/images/rocket.png"));

    QTimer *timer = new QTimer();
    QObject::connect(timer, SIGNAL(timeout()), this, SLOT(move()));

    timer->start(50);

    //sound bullet
    QMediaPlayer *bulletSound = new QMediaPlayer();
    bulletSound->setMedia(QUrl("qrc:/sounds/shoot.wav"));

    //sound
    if (bulletSound->state() == QMediaPlayer::PlayingState)
    {
        bulletSound->setPosition(0); //rewind
    }
    else bulletSound->play(); //it should be in QMediaPlayer::StoppedState
}
Пример #3
0
void WaveformView::mouseMoveEvent(QMouseEvent *event)
{
	if (!fDragging || !fDoc)
		return;

	bool	needUpdate = false;
	real	f = (real)event->x() / (real)fFrameWidth;
	int32	frame = PG_FLOOR(f);

	if (fSelectedPhrase)
	{
		if (fDraggingEnd == 0)
		{
			if (frame != fSelectedPhrase->fStartFrame)
			{
				fDoc->fDirty = true;
				fSelectedPhrase->fStartFrame = frame;
				if (fSelectedPhrase->fStartFrame > fSelectedPhrase->fEndFrame - 1)
					fSelectedPhrase->fStartFrame = fSelectedPhrase->fEndFrame - 1;
				fDoc->fCurrentVoice->RepositionPhrase(fSelectedPhrase, fDoc->Duration());
				needUpdate = true;
			}
		}
		else if (fDraggingEnd == 1)
		{
			if (frame != fSelectedPhrase->fEndFrame)
			{
				fDoc->fDirty = true;
				fSelectedPhrase->fEndFrame = frame;
				if (fSelectedPhrase->fEndFrame < fSelectedPhrase->fStartFrame + 1)
					fSelectedPhrase->fEndFrame = fSelectedPhrase->fStartFrame + 1;
				fDoc->fCurrentVoice->RepositionPhrase(fSelectedPhrase, fDoc->Duration());
				needUpdate = true;
			}
		}
		else if (fDraggingEnd == 2)
		{
			if (frame != fOldFrame)
			{
				fDoc->fDirty = true;
				fSelectedPhrase->fStartFrame += frame - fOldFrame;
				fSelectedPhrase->fEndFrame += frame - fOldFrame;
				if (fSelectedPhrase->fEndFrame < fSelectedPhrase->fStartFrame + 1)
					fSelectedPhrase->fEndFrame = fSelectedPhrase->fStartFrame + 1;
				fDoc->fCurrentVoice->RepositionPhrase(fSelectedPhrase, fDoc->Duration());
				needUpdate = true;
			}
		}
	}
	else if (fSelectedWord)
	{
		if (fDraggingEnd == 0)
		{
			if (frame != fSelectedWord->fStartFrame)
			{
				fDoc->fDirty = true;
				fSelectedWord->fStartFrame = frame;
				if (fSelectedWord->fStartFrame > fSelectedWord->fEndFrame - 1)
					fSelectedWord->fStartFrame = fSelectedWord->fEndFrame - 1;
				fParentPhrase->RepositionWord(fSelectedWord);
				needUpdate = true;
			}
		}
		else if (fDraggingEnd == 1)
		{
			if (frame != fSelectedWord->fEndFrame)
			{
				fDoc->fDirty = true;
				fSelectedWord->fEndFrame = frame;
				if (fSelectedWord->fEndFrame < fSelectedWord->fStartFrame + 1)
					fSelectedWord->fEndFrame = fSelectedWord->fStartFrame + 1;
				fParentPhrase->RepositionWord(fSelectedWord);
				needUpdate = true;
			}
		}
		else if (fDraggingEnd == 2)
		{
			if (frame != fOldFrame)
			{
				fDoc->fDirty = true;
				fSelectedWord->fStartFrame += frame - fOldFrame;
				fSelectedWord->fEndFrame += frame - fOldFrame;
				if (fSelectedWord->fEndFrame < fSelectedWord->fStartFrame + 1)
					fSelectedWord->fEndFrame = fSelectedWord->fStartFrame + 1;
				fParentPhrase->RepositionWord(fSelectedWord);
				needUpdate = true;
			}
		}
	}
	else if (fSelectedPhoneme)
	{
		if (fDraggingEnd == 0)
		{
			if (frame != fSelectedPhoneme->fFrame)
			{
				fDoc->fDirty = true;
				fSelectedPhoneme->fFrame = frame;
				fParentWord->RepositionPhoneme(fSelectedPhoneme);
				needUpdate = true;
			}
		}
	}

	fOldFrame = frame;

	QMediaPlayer *audioPlayer = fDoc->GetAudioPlayer();
	if (frame != fScrubFrame)
	{
		fScrubFrame = frame;
		fCurFrame = fScrubFrame;
		f = ((real)fScrubFrame / (real)fDoc->Fps()) * 1000.0f;
		audioPlayer->setPosition(PG_FLOOR(f));
		audioPlayer->play();
		emit(frameChanged(fScrubFrame));
		needUpdate = true;
	}
	if (needUpdate)
		update();
}