18 #include <QMediaPlayer>
20 #include "layersound.h"
21 #include "soundclip.h"
26 mName = QString( tr(
"Sound Layer" ) );
29 LayerSound::~LayerSound()
33 Status LayerSound::loadSoundClipAtFrame(
const QString& sSoundClipName,
34 const QString& strFilePath,
37 if ( !QFile::exists( strFilePath ) )
39 return Status::FILE_NOT_FOUND;
42 QFileInfo info( strFilePath );
45 return Status::ERROR_LOAD_SOUND_FILE;
49 clip->setSoundClipName( sSoundClipName );
50 clip->init( strFilePath );
51 clip->setPos( frameNumber );
56 void LayerSound::updateFrameLengths(
int fps)
58 foreachKeyFrame( [&fps] (
KeyFrame* pKeyFrame)
60 auto soundClip =
dynamic_cast<SoundClip *
>(pKeyFrame);
61 soundClip->updateLength(fps);
65 QDomElement LayerSound::createDomElement( QDomDocument& doc )
67 QDomElement layerTag = doc.createElement(
"layer" );
69 layerTag.setAttribute(
"id",
id() );
70 layerTag.setAttribute(
"name", name() );
71 layerTag.setAttribute(
"visibility", visible() );
72 layerTag.setAttribute(
"type", type() );
74 foreachKeyFrame( [ &doc, &layerTag ](
KeyFrame* pKeyFrame )
78 QDomElement imageTag = doc.createElement(
"sound" );
79 imageTag.setAttribute(
"frame", clip->pos() );
80 imageTag.setAttribute(
"name", clip->soundClipName() );
82 QFileInfo info( clip->fileName() );
84 imageTag.setAttribute(
"src", info.fileName() );
85 layerTag.appendChild( imageTag );
91 void LayerSound::loadDomElement( QDomElement element, QString dataDirPath )
93 if ( !element.attribute(
"id" ).isNull() )
95 int myId = element.attribute(
"id" ).toInt();
98 mName = element.attribute(
"name" );
99 mVisible = ( element.attribute(
"visibility" ).toInt() == 1 );
101 QDomNode soundTag = element.firstChild();
102 while ( !soundTag.isNull() )
104 QDomElement soundElement = soundTag.toElement();
105 if ( soundElement.isNull() )
110 if ( soundElement.tagName() ==
"sound" )
112 const QString soundFile = soundElement.attribute(
"src" );
113 const QString sSoundClipName = soundElement.attribute(
"name",
"My Sound Clip" );
116 const QString sFullPath = QDir( dataDirPath ).filePath( soundFile );
118 int position = soundElement.attribute(
"frame" ).toInt();
119 Status st = loadSoundClipAtFrame( sSoundClipName, sFullPath, position );
123 soundTag = soundTag.nextSibling();