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
eb37dfa6
Commit
eb37dfa6
authored
Feb 18, 2021
by
Jean-Baptiste Mardelle
Browse files
Some fixes for text analysis on clip zones
parent
f13d23a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/dialogs/textbasededit.cpp
View file @
eb37dfa6
...
...
@@ -41,6 +41,7 @@
VideoTextEdit
::
VideoTextEdit
(
QWidget
*
parent
)
:
QTextEdit
(
parent
)
,
clipOffset
(
0
)
,
m_hoveredBlock
(
-
1
)
,
m_lastClickedBlock
(
-
1
)
{
...
...
@@ -66,16 +67,16 @@ void VideoTextEdit::repaintLines()
void
VideoTextEdit
::
cleanup
()
{
m_z
ones
.
clear
();
speechZ
ones
.
clear
();
cutZones
.
clear
();
m_hoveredBlock
=
-
1
;
clear
();
qDebug
()
<<
"===== GOT STRATING BLIBKS: "
<<
document
()
->
blockCount
()
<<
"
\n
:::::::::"
;
}
void
VideoTextEdit
::
rebuildZones
(
double
offset
)
void
VideoTextEdit
::
rebuildZones
()
{
m_z
ones
.
clear
();
speechZ
ones
.
clear
();
QTextCursor
curs
=
textCursor
();
qDebug
()
<<
"===== DOCUMNET BKS: "
<<
document
()
->
blockCount
();
curs
.
movePosition
(
QTextCursor
::
Start
,
QTextCursor
::
MoveAnchor
);
...
...
@@ -88,9 +89,9 @@ void VideoTextEdit::rebuildZones(double offset)
QString
anchorEnd
=
anchorAt
(
cursorRect
(
curs
).
center
());
qDebug
()
<<
"=== END ANCHOR: "
<<
anchorEnd
<<
" AT POS: "
<<
curs
.
position
();
if
(
!
anchorStart
.
isEmpty
()
&&
!
anchorEnd
.
isEmpty
())
{
double
startMs
=
anchorStart
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
()
+
o
ffset
;
double
endMs
=
anchorEnd
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
1
,
1
).
toDouble
()
+
o
ffset
;
m_z
ones
<<
QPair
<
double
,
double
>
(
startMs
,
endMs
);
double
startMs
=
anchorStart
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
()
+
clipO
ffset
;
double
endMs
=
anchorEnd
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
1
,
1
).
toDouble
()
+
clipO
ffset
;
speechZ
ones
<<
QPair
<
double
,
double
>
(
startMs
,
endMs
);
}
curs
.
movePosition
(
QTextCursor
::
NextBlock
,
QTextCursor
::
MoveAnchor
);
}
...
...
@@ -170,7 +171,7 @@ QVector<QPoint> VideoTextEdit::processedZones(QVector<QPoint> sourceZones)
return
resultZones
;
}
QVector
<
QPoint
>
VideoTextEdit
::
getInsertZones
(
double
offset
)
QVector
<
QPoint
>
VideoTextEdit
::
getInsertZones
()
{
if
(
m_selectedBlocks
.
isEmpty
())
{
// return text selection, not blocks
...
...
@@ -183,8 +184,8 @@ QVector<QPoint> VideoTextEdit::getInsertZones(double offset)
cursor2
.
setPosition
(
end
-
1
);
QString
anchorEnd
=
anchorAt
(
cursorRect
(
cursor2
).
center
());
if
(
!
anchorStart
.
isEmpty
()
&&
!
anchorEnd
.
isEmpty
())
{
double
startMs
=
anchorStart
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
()
+
o
ffset
;
double
endMs
=
anchorEnd
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
1
,
1
).
toDouble
()
+
o
ffset
;
double
startMs
=
anchorStart
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
()
+
clipO
ffset
;
double
endMs
=
anchorEnd
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
1
,
1
).
toDouble
()
+
clipO
ffset
;
QPoint
originalZone
(
QPoint
(
GenTime
(
startMs
).
frames
(
pCore
->
getCurrentFps
()),
GenTime
(
endMs
).
frames
(
pCore
->
getCurrentFps
())));
return
processedZones
({
originalZone
});
}
...
...
@@ -198,7 +199,7 @@ QVector<QPoint> VideoTextEdit::getInsertZones(double offset)
int
currentStart
=
-
1
;
qDebug
()
<<
"=== FROM BLOCKS: "
<<
m_selectedBlocks
;
for
(
auto
&
bk
:
m_selectedBlocks
)
{
QPair
<
double
,
double
>
z
=
m_z
ones
.
at
(
bk
);
QPair
<
double
,
double
>
z
=
speechZ
ones
.
at
(
bk
);
currentStart
=
GenTime
(
z
.
first
).
frames
(
pCore
->
getCurrentFps
());
currentEnd
=
GenTime
(
z
.
second
).
frames
(
pCore
->
getCurrentFps
());
if
(
zoneStart
<
0
)
{
...
...
@@ -265,7 +266,7 @@ void VideoTextEdit::checkHoverBlock(int yPos)
void
VideoTextEdit
::
blockClicked
(
Qt
::
KeyboardModifiers
modifiers
,
bool
play
)
{
if
(
m_hoveredBlock
>
-
1
&&
m_hoveredBlock
<
m_z
ones
.
count
())
{
if
(
m_hoveredBlock
>
-
1
&&
m_hoveredBlock
<
speechZ
ones
.
count
())
{
if
(
m_selectedBlocks
.
contains
(
m_hoveredBlock
))
{
if
(
modifiers
&
Qt
::
ControlModifier
)
{
// remove from selection on ctrl+click an already selected block
...
...
@@ -295,7 +296,7 @@ void VideoTextEdit::blockClicked(Qt::KeyboardModifiers modifiers, bool play)
if
(
m_hoveredBlock
>=
0
)
{
m_lastClickedBlock
=
m_hoveredBlock
;
}
QPair
<
double
,
double
>
zone
=
m_z
ones
.
at
(
m_hoveredBlock
);
QPair
<
double
,
double
>
zone
=
speechZ
ones
.
at
(
m_hoveredBlock
);
double
startMs
=
zone
.
first
;
double
endMs
=
zone
.
second
;
pCore
->
getMonitor
(
Kdenlive
::
ClipMonitor
)
->
requestSeek
(
GenTime
(
startMs
).
frames
(
pCore
->
getCurrentFps
()));
...
...
@@ -376,14 +377,14 @@ void VideoTextEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
// Draw the numbers (displaying the current line number in green)
while
(
block
.
isValid
()
&&
top
<=
event
->
rect
().
bottom
())
{
if
(
blockNumber
>=
m_z
ones
.
count
())
{
if
(
blockNumber
>=
speechZ
ones
.
count
())
{
break
;
}
if
(
block
.
isVisible
()
&&
bottom
>=
event
->
rect
().
top
())
{
if
(
m_selectedBlocks
.
contains
(
blockNumber
))
{
painter
.
fillRect
(
QRect
(
0
,
top
,
lineNumberArea
->
width
(),
bottom
-
top
),
palette
().
highlight
().
color
());
}
QString
number
=
pCore
->
timecode
().
getDisplayTimecode
(
GenTime
(
m_z
ones
[
blockNumber
].
first
),
false
);
QString
number
=
pCore
->
timecode
().
getDisplayTimecode
(
GenTime
(
speechZ
ones
[
blockNumber
].
first
),
false
);
painter
.
setPen
(
QColor
(
120
,
120
,
120
));
painter
.
setPen
((
this
->
textCursor
().
blockNumber
()
==
blockNumber
)
?
col_2
:
m_selectedBlocks
.
contains
(
blockNumber
)
?
col_1
:
col_0
);
painter
.
drawText
(
-
5
,
top
,
...
...
@@ -412,7 +413,7 @@ void VideoTextEdit::mousePressEvent(QMouseEvent *e)
if
(
!
link
.
isEmpty
())
{
// Clicked on a word
cursor
.
setPosition
(
pos
+
1
,
QTextCursor
::
KeepAnchor
);
double
startMs
=
link
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
();
double
startMs
=
link
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
()
+
clipOffset
;
pCore
->
getMonitor
(
Kdenlive
::
ClipMonitor
)
->
requestSeek
(
GenTime
(
startMs
).
frames
(
pCore
->
getCurrentFps
()));
}
}
...
...
@@ -490,8 +491,8 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
bool
hasSelection
=
m_visualEditor
->
textCursor
().
selectedText
().
isEmpty
()
==
false
;
button_insert
->
setEnabled
(
hasSelection
);
button_delete
->
setEnabled
(
hasSelection
);
button_up
->
setEnabled
(
!
m_visualEditor
->
m_z
ones
.
isEmpty
());
button_down
->
setEnabled
(
!
m_visualEditor
->
m_z
ones
.
isEmpty
());
button_up
->
setEnabled
(
!
m_visualEditor
->
speechZ
ones
.
isEmpty
());
button_down
->
setEnabled
(
!
m_visualEditor
->
speechZ
ones
.
isEmpty
());
});
connect
(
button_start
,
&
QPushButton
::
clicked
,
this
,
&
TextBasedEdit
::
startRecognition
);
...
...
@@ -701,7 +702,7 @@ void TextBasedEdit::startRecognition()
m_sourceUrl
.
clear
();
QString
clipName
;
m_
o
ffset
=
0
;
m_
visualEditor
->
clipO
ffset
=
0
;
m_lastPosition
=
0
;
double
endPos
=
0
;
if
(
clip
->
itemType
()
==
AbstractProjectItem
::
ClipItem
)
{
...
...
@@ -713,7 +714,7 @@ void TextBasedEdit::startRecognition()
// Analyse clip zone only
QPoint
zone
=
clipItem
->
zone
();
m_lastPosition
=
zone
.
x
();
m_
o
ffset
=
GenTime
(
zone
.
x
(),
pCore
->
getCurrentFps
()).
seconds
();
m_
visualEditor
->
clipO
ffset
=
GenTime
(
zone
.
x
(),
pCore
->
getCurrentFps
()).
seconds
();
m_clipDuration
=
GenTime
(
zone
.
y
()
-
zone
.
x
(),
pCore
->
getCurrentFps
()).
seconds
();
endPos
=
m_clipDuration
;
}
else
{
...
...
@@ -728,7 +729,7 @@ void TextBasedEdit::startRecognition()
clipName
=
master
->
clipName
();
QPoint
zone
=
clipItem
->
zone
();
m_lastPosition
=
zone
.
x
();
m_
o
ffset
=
GenTime
(
zone
.
x
(),
pCore
->
getCurrentFps
()).
seconds
();
m_
visualEditor
->
clipO
ffset
=
GenTime
(
zone
.
x
(),
pCore
->
getCurrentFps
()).
seconds
();
m_clipDuration
=
GenTime
(
zone
.
y
()
-
zone
.
x
(),
pCore
->
getCurrentFps
()).
seconds
();
endPos
=
m_clipDuration
;
}
...
...
@@ -746,8 +747,8 @@ void TextBasedEdit::startRecognition()
connect
(
m_speechJob
.
get
(),
&
QProcess
::
readyReadStandardError
,
this
,
&
TextBasedEdit
::
slotProcessSpeechError
);
connect
(
m_speechJob
.
get
(),
&
QProcess
::
readyReadStandardOutput
,
this
,
&
TextBasedEdit
::
slotProcessSpeech
);
connect
(
m_speechJob
.
get
(),
static_cast
<
void
(
QProcess
::*
)(
int
,
QProcess
::
ExitStatus
)
>
(
&
QProcess
::
finished
),
this
,
&
TextBasedEdit
::
slotProcessSpeechStatus
);
qDebug
()
<<
"=== STARTING RECO: "
<<
speechScript
<<
" / "
<<
modelDirectory
<<
" / "
<<
language
<<
" / "
<<
m_sourceUrl
<<
", START: "
<<
m_
o
ffset
<<
", DUR: "
<<
endPos
;
m_speechJob
->
start
(
pyExec
,
{
speechScript
,
modelDirectory
,
language
,
m_sourceUrl
,
QString
::
number
(
m_
o
ffset
),
QString
::
number
(
endPos
)});
qDebug
()
<<
"=== STARTING RECO: "
<<
speechScript
<<
" / "
<<
modelDirectory
<<
" / "
<<
language
<<
" / "
<<
m_sourceUrl
<<
", START: "
<<
m_
visualEditor
->
clipO
ffset
<<
", DUR: "
<<
endPos
;
m_speechJob
->
start
(
pyExec
,
{
speechScript
,
modelDirectory
,
language
,
m_sourceUrl
,
QString
::
number
(
m_
visualEditor
->
clipO
ffset
),
QString
::
number
(
endPos
)});
speech_progress
->
setValue
(
0
);
frame_progress
->
setVisible
(
true
);
}
...
...
@@ -814,7 +815,7 @@ void TextBasedEdit::slotProcessSpeech()
// Get start time for first word
QJsonValue
val
=
obj2
.
first
();
if
(
val
.
isObject
()
&&
val
.
toObject
().
keys
().
contains
(
"start"
))
{
double
ms
=
val
.
toObject
().
value
(
"start"
).
toDouble
()
+
m_
o
ffset
;
double
ms
=
val
.
toObject
().
value
(
"start"
).
toDouble
()
+
m_
visualEditor
->
clipO
ffset
;
GenTime
startPos
(
ms
);
sentenceZone
.
first
=
ms
;
if
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
>
m_lastPosition
+
1
)
{
...
...
@@ -824,13 +825,13 @@ void TextBasedEdit::slotProcessSpeech()
QString
htmlSpace
=
QString
(
"<a href=
\"
#%1:%2
\"
>%3</a>"
).
arg
(
silenceStart
.
seconds
()).
arg
(
GenTime
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
-
1
,
pCore
->
getCurrentFps
()).
seconds
()).
arg
(
i18n
(
"No speech"
));
m_visualEditor
->
insertHtml
(
htmlSpace
);
m_visualEditor
->
textCursor
().
insertBlock
(
cursor
.
blockFormat
());
m_visualEditor
->
m_z
ones
<<
QPair
<
double
,
double
>
(
silenceStart
.
seconds
(),
GenTime
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
-
1
,
pCore
->
getCurrentFps
()).
seconds
());
m_visualEditor
->
speechZ
ones
<<
QPair
<
double
,
double
>
(
silenceStart
.
seconds
(),
GenTime
(
startPos
.
frames
(
pCore
->
getCurrentFps
())
-
1
,
pCore
->
getCurrentFps
()).
seconds
());
}
val
=
obj2
.
last
();
if
(
val
.
isObject
()
&&
val
.
toObject
().
keys
().
contains
(
"end"
))
{
double
ms
=
val
.
toObject
().
value
(
"end"
).
toDouble
();
sentenceZone
.
second
=
ms
+
m_
o
ffset
;
m_lastPosition
=
GenTime
(
ms
+
m_
o
ffset
).
frames
(
pCore
->
getCurrentFps
());
sentenceZone
.
second
=
ms
+
m_
visualEditor
->
clipO
ffset
;
m_lastPosition
=
GenTime
(
ms
+
m_
visualEditor
->
clipO
ffset
).
frames
(
pCore
->
getCurrentFps
());
if
(
m_clipDuration
>
0.
)
{
speech_progress
->
setValue
(
static_cast
<
int
>
(
100
*
ms
/
m_clipDuration
));
}
...
...
@@ -842,14 +843,14 @@ void TextBasedEdit::slotProcessSpeech()
m_visualEditor
->
moveCursor
(
QTextCursor
::
End
);
QString
htmlSpace
=
QString
(
"<a href=
\"
#%1:%2
\"
>%3</a>"
).
arg
(
silenceStart
.
seconds
()).
arg
(
GenTime
(
m_clipDuration
).
seconds
()).
arg
(
i18n
(
"No speech"
));
m_visualEditor
->
insertHtml
(
htmlSpace
);
m_visualEditor
->
m_z
ones
<<
QPair
<
double
,
double
>
(
silenceStart
.
seconds
(),
GenTime
(
m_clipDuration
).
seconds
());
m_visualEditor
->
speechZ
ones
<<
QPair
<
double
,
double
>
(
silenceStart
.
seconds
(),
GenTime
(
m_clipDuration
).
seconds
());
}
if
(
!
htmlLine
.
isEmpty
())
{
m_visualEditor
->
insertHtml
(
htmlLine
.
simplified
());
if
(
sentenceZone
.
second
<
m_clipDuration
)
{
if
(
sentenceZone
.
second
<
m_visualEditor
->
clipOffset
+
m_clipDuration
)
{
m_visualEditor
->
textCursor
().
insertBlock
(
cursor
.
blockFormat
());
}
m_visualEditor
->
m_z
ones
<<
sentenceZone
;
m_visualEditor
->
speechZ
ones
<<
sentenceZone
;
}
}
}
else
if
(
loadDoc
.
isEmpty
())
{
...
...
@@ -901,8 +902,8 @@ void TextBasedEdit::deleteItem()
end
--
;
anchorEnd
=
m_visualEditor
->
anchorAt
(
m_visualEditor
->
cursorRect
(
cursor
).
center
());
}
double
startMs
=
anchorStart
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
()
+
m_
o
ffset
;
double
endMs
=
anchorEnd
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
1
,
1
).
toDouble
()
+
m_
o
ffset
;
double
startMs
=
anchorStart
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
0
,
0
).
toDouble
()
+
m_
visualEditor
->
clipO
ffset
;
double
endMs
=
anchorEnd
.
section
(
QLatin1Char
(
'#'
),
1
).
section
(
QLatin1Char
(
':'
),
1
,
1
).
toDouble
()
+
m_
visualEditor
->
clipO
ffset
;
if
(
startMs
<
endMs
)
{
m_visualEditor
->
cutZones
<<
QPoint
(
GenTime
(
startMs
).
frames
(
pCore
->
getCurrentFps
()),
GenTime
(
endMs
).
frames
(
pCore
->
getCurrentFps
()));
}
...
...
@@ -926,12 +927,12 @@ void TextBasedEdit::deleteItem()
}
// Reset selection and rebuild line numbers
m_visualEditor
->
rebuildZones
(
m_offset
);
m_visualEditor
->
rebuildZones
();
}
void
TextBasedEdit
::
insertToTimeline
()
{
QVector
<
QPoint
>
zones
=
m_visualEditor
->
getInsertZones
(
m_offset
);
QVector
<
QPoint
>
zones
=
m_visualEditor
->
getInsertZones
();
if
(
zones
.
isEmpty
())
{
return
;
}
...
...
src/dialogs/textbasededit.h
View file @
eb37dfa6
...
...
@@ -49,9 +49,10 @@ public:
void
checkHoverBlock
(
int
yPos
);
void
blockClicked
(
Qt
::
KeyboardModifiers
modifiers
,
bool
play
=
false
);
QVector
<
QPoint
>
processedZones
(
QVector
<
QPoint
>
sourceZones
);
QVector
<
QPoint
>
getInsertZones
(
double
offset
);
void
rebuildZones
(
double
offset
);
QVector
<
QPair
<
double
,
double
>
>
m_zones
;
QVector
<
QPoint
>
getInsertZones
();
void
rebuildZones
();
QVector
<
QPair
<
double
,
double
>
>
speechZones
;
double
clipOffset
;
QVector
<
QPoint
>
cutZones
;
protected:
...
...
@@ -150,7 +151,6 @@ private:
QString
m_binId
;
QString
m_sourceUrl
;
double
m_clipDuration
;
double
m_offset
;
int
m_lastPosition
;
QString
m_errorString
;
QAction
*
m_logAction
;
...
...
Write
Preview
Supports
Markdown
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