18 #include "soundmanager.h"
24 #include "layersound.h"
25 #include "soundclip.h"
26 #include "soundplayer.h"
27 #include "layermanager.h"
33 SoundManager::~SoundManager()
37 bool SoundManager::init()
44 int count = obj->getLayerCount();
45 for (
int i = 0; i < count; ++i)
47 Layer* layer = obj->getLayer(i);
48 if (layer->type() != Layer::SOUND)
55 soundLayer->foreachKeyFrame([
this](
KeyFrame* key)
60 createMediaPlayer(clip);
71 Status SoundManager::loadSound(
Layer* soundLayer,
int frameNumber,
QString strSoundFile)
74 if (soundLayer->type() != Layer::SOUND)
76 return Status::ERROR_INVALID_LAYER_TYPE;
81 return Status::ERROR_INVALID_FRAME_NUMBER;
86 return Status::FILE_NOT_FOUND;
89 KeyFrame* key = soundLayer->getKeyFrameAt(frameNumber);
93 soundLayer->addKeyFrame(frameNumber, key);
103 QString strCopyFile = soundLayer->object()->copyFileToDataFolder(strSoundFile);
104 Q_ASSERT(!strCopyFile.
isEmpty());
109 soundClip->init(strCopyFile);
110 soundClip->setSoundClipName(sOriginalName);
112 Status st = createMediaPlayer(soundClip);
128 return Status::FILE_NOT_FOUND;
136 QString strCopyFile = editor()->object()->copyFileToDataFolder(strSoundFile);
137 Q_ASSERT(!strCopyFile.
isEmpty());
139 soundClip->init(strCopyFile);
140 soundClip->setSoundClipName(
QFileInfo(strSoundFile).fileName());
142 Status st = createMediaPlayer(soundClip);
149 editor()->layers()->notifyAnimationLengthChanged();
160 return Status::FILE_NOT_FOUND;
162 soundClip->init(soundClip->fileName());
164 Status st = createMediaPlayer(soundClip);
172 void SoundManager::onDurationChanged(
SoundPlayer* player, int64_t duration)
176 double fps =
static_cast<double>(editor()->fps());
178 double frameLength = duration * fps / 1000.0;
179 clip->setLength(static_cast<int>(frameLength));
180 clip->setDuration(duration);
182 editor()->layers()->notifyAnimationLengthChanged();
184 emit soundClipDurationChanged();
190 newPlayer->init(clip);
192 connect(newPlayer, &SoundPlayer::durationChanged,
this, &SoundManager::onDurationChanged);
bool exists() const const
QString fileName() const const
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)