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);
136 QFileInfo projectFileLocation(sDestFileLocation);
140 if (info.canonicalFilePath() != projectFileLocation.canonicalFilePath())
142 if (QFile::exists(sDestFileLocation))
143 QFile::remove(sDestFileLocation);
145 bool ok = QFile::copy(key->fileName(), sDestFileLocation);
148 key->setFileName(
"");
151 dd <<
"LayerSound::saveKeyFrameFile";
152 dd <<
QString(
" KeyFrame.pos() = %1").
arg(key->pos());
153 dd <<
QString(
" Key->fileName() = %1").
arg(key->fileName());
154 dd <<
QString(
" FilePath = %1").
arg(sDestFileLocation);
155 dd <<
QString(
"Error: Failed to save SoundClip");
156 return Status(Status::FAIL, dd);
159 key->setFileName(sDestFileLocation);
163KeyFrame* LayerSound::createKeyFrame(
int position)
170SoundClip* LayerSound::getSoundClipWhichCovers(
int frameNumber)
172 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