17#include "layersound.h"
20#include <QMediaPlayer>
26LayerSound::LayerSound(
int id) :
Layer(id,
Layer::SOUND)
28 setName(tr(
"Sound Layer"));
31LayerSound::~LayerSound()
35Status LayerSound::loadSoundClipAtFrame(
const QString& sSoundClipName,
41 return Status::FILE_NOT_FOUND;
47 return Status::ERROR_LOAD_SOUND_FILE;
51 clip->setSoundClipName(sSoundClipName);
52 clip->init(strFilePath);
53 clip->setPos(frameNumber);
58void LayerSound::updateFrameLengths(
int fps)
60 foreachKeyFrame([&fps](
KeyFrame* pKeyFrame)
62 auto soundClip =
dynamic_cast<SoundClip *
>(pKeyFrame);
63 soundClip->updateLength(fps);
71 foreachKeyFrame([&doc, &layerElem](
KeyFrame* pKeyFrame)
88void LayerSound::loadDomElement(
const QDomElement& element,
QString dataDirPath, ProgressCallback progressStep)
90 this->loadBaseDomElement(element);
101 if (soundElement.
tagName() ==
"sound")
104 const QString sSoundClipName = soundElement.
attribute(
"name",
"My Sound Clip");
112 Status st = loadSoundClipAtFrame(sSoundClipName, sFullPath, position);
134 if (sDestFileLocation != key->fileName())
139 bool ok =
QFile::copy(key->fileName(), sDestFileLocation);
142 key->setFileName(
"");
146 dd <<
QString(
" KeyFrame.pos() = %1").
arg(key->pos());
147 dd <<
QString(
" Key->fileName() = %1").
arg(key->fileName());
148 dd <<
QString(
" FilePath = %1").
arg(sDestFileLocation);
149 dd <<
QString(
"Couldn't save the sound clip");
150 return Status(Status::FAIL, dd);
152 key->setFileName(sDestFileLocation);
157KeyFrame* LayerSound::createKeyFrame(
int position)
164SoundClip* LayerSound::getSoundClipWhichCovers(
int frameNumber)
166 KeyFrame* key = getKeyFrameWhichCovers(frameNumber);
QString filePath(const QString &fileName) const const
QDomElement createElement(const QString &tagName)
QString attribute(const QString &name, const QString &defValue) const const
void setAttribute(const QString &name, const QString &value)
QString tagName() const const
QDomNode appendChild(const QDomNode &newChild)
QDomNode firstChild() const const
bool isNull() const const
QDomNode nextSibling() const const
QDomElement toElement() const const
bool copy(const QString &newName)
bool exists() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
int toInt(bool *ok, int base) const const