Commit 732c42eb authored by Sashmita Raghav's avatar Sashmita Raghav
Browse files

Add functions to add the start time of each subtitle line as snaps

parent 36d6121f
......@@ -6,6 +6,7 @@
SubtitleModel::SubtitleModel(std::weak_ptr<DocUndoStack> undo_stack, QObject *parent)
: QAbstractListModel(parent)
, m_undoStack(std::move(undo_stack))
, m_lock(QReadWriteLock::Recursive)
{
}
......@@ -190,6 +191,7 @@ void SubtitleModel::addSubtitle(GenTime start, GenTime end, QString str)
model->beginInsertRows(QModelIndex(), insertRow, insertRow);
model->m_subtitleList[start] = {str, end};
model->endInsertRows();
model->addSnapPoint(start);
}
QHash<int, QByteArray> SubtitleModel::roleNames() const
......@@ -243,4 +245,34 @@ QList<SubtitledTime> SubtitleModel::getAllSubtitles() const
subtitle << s;
}
return subtitle;
}
void SubtitleModel::registerSnap(const std::weak_ptr<SnapInterface> &snapModel)
{
// make sure ptr is valid
if (auto ptr = snapModel.lock()) {
// ptr is valid, we store it
m_regSnaps.push_back(snapModel);
for (const auto &subtitle : m_subtitleList) {
qDebug() << " REGISTERING SUBTITLE: " << subtitle.first.frames(pCore->getCurrentFps());
ptr->addPoint(subtitle.first.frames(pCore->getCurrentFps()));
}
} else {
qDebug() << "Error: added snapmodel for subtitle is null";
Q_ASSERT(false);
}
}
void SubtitleModel::addSnapPoint(GenTime startpos)
{
std::vector<std::weak_ptr<SnapInterface>> validSnapModels;
for (const auto &snapModel : m_regSnaps) {
if (auto ptr = snapModel.lock()) {
validSnapModels.push_back(snapModel);
ptr->addPoint(startpos.frames(pCore->getCurrentFps()));
}
}
// Update the list of snapModel known to be valid
std::swap(m_regSnaps, validSnapModels);
}
\ No newline at end of file
......@@ -15,6 +15,7 @@
#include <mlt++/MltProperties.h>
class DocUndoStack;
class SnapInterface;
class AssetParameterModel;
/* @brief This class is the model for a list of subtitles.
......@@ -39,18 +40,26 @@ public:
/** @brief Returns all subtitles in the model */
QList<SubtitledTime> getAllSubtitles() const;
/** @brief Registers a snap model to the subtitle model */
void registerSnap(const std::weak_ptr<SnapInterface> &snapModel);
private:
std::weak_ptr<DocUndoStack> m_undoStack;
std::map<GenTime, std::pair<QString, GenTime>> m_subtitleList;
//To get subtitle file from effects parameter:
//std::unique_ptr<Mlt::Properties> m_asset;
//std::shared_ptr<AssetParameterModel> m_model;
std::vector<std::weak_ptr<SnapInterface>> m_regSnaps;
mutable QReadWriteLock m_lock;
protected:
/** @brief Helper function that retrieves a pointer to the subtitle model*/
static std::shared_ptr<SubtitleModel> getModel();
/** @brief Add start time as snap in the registered snap model */
void addSnapPoint(GenTime startpos);
};
Q_DECLARE_METATYPE(SubtitleModel *)
#endif // SUBTITLEMODEL_HPP
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment