Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
e8c67715
Commit
e8c67715
authored
Jun 30, 2020
by
Sashmita Raghav
Browse files
Add functions to add the start time of each subtitle line as snaps
parent
7fe395a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/bin/model/subtitlemodel.cpp
View file @
e8c67715
...
...
@@ -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
src/bin/model/subtitlemodel.hpp
View file @
e8c67715
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment