17#include "layersound.h"
20#include <QMediaPlayer>
27LayerSound::LayerSound(
int id) :
Layer(id,
Layer::SOUND)
29 setName(tr(
"Sound Layer"));
32LayerSound::~LayerSound()
36Status LayerSound::loadSoundClipAtFrame(
const QString& sSoundClipName,
40 if (!QFile::exists(strFilePath))
42 return Status::FILE_NOT_FOUND;
48 return Status::ERROR_LOAD_SOUND_FILE;
52 clip->setSoundClipName(sSoundClipName);
53 clip->init(strFilePath);
54 clip->setPos(frameNumber);
59void LayerSound::updateFrameLengths(
int fps)
61 foreachKeyFrame([&fps](
KeyFrame* pKeyFrame)
63 auto soundClip =
dynamic_cast<SoundClip *
>(pKeyFrame);
64 soundClip->updateLength(fps);
72 foreachKeyFrame([&doc, &layerElem](
KeyFrame* pKeyFrame)
89void LayerSound::loadDomElement(
const QDomElement& element,
QString dataDirPath, ProgressCallback progressStep)
91 this->loadBaseDomElement(element);
98 if (!soundElement.
isNull() && soundElement.
tagName() ==
"sound")
101 const QString sSoundClipName = soundElement.
attribute(
"name",
"My Sound Clip");
105 QString path = validateDataPath(soundFile, dataDirPath);
109 Status st = loadSoundClipAtFrame(sSoundClipName, path, position);
120void LayerSound::replaceKeyFrame(
const KeyFrame* soundClip)
122 *getSoundClipWhichCovers(soundClip->pos()) = *
static_cast<const SoundClip*
>(soundClip);
137 if (sDestFileLocation != key->fileName())
139 if (QFile::exists(sDestFileLocation))
140 QFile::remove(sDestFileLocation);
142 bool ok = QFile::copy(key->fileName(), sDestFileLocation);
145 key->setFileName(
"");
148 dd <<
"LayerSound::saveKeyFrameFile";
149 dd <<
QString(
" KeyFrame.pos() = %1").
arg(key->pos());
150 dd <<
QString(
" Key->fileName() = %1").
arg(key->fileName());
151 dd <<
QString(
" FilePath = %1").
arg(sDestFileLocation);
152 dd <<
QString(
"Error: Failed to save SoundClip");
153 return Status(Status::FAIL, dd);
155 key->setFileName(sDestFileLocation);
160KeyFrame* LayerSound::createKeyFrame(
int position)
167SoundClip* LayerSound::getSoundClipWhichCovers(
int frameNumber)
169 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
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
int toInt(bool *ok, int base) const const