From 13cfef9144a245876a806507b417cf99fd3dc789 Mon Sep 17 00:00:00 2001 From: "Martijn van Berkel (Flitskikker)" Date: Fri, 18 Oct 2024 22:24:59 +0200 Subject: [PATCH 1/3] Handle subtitles as connected that turn out to be so when chaining --- src/libse/Forms/TimeCodesBeautifier.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/libse/Forms/TimeCodesBeautifier.cs b/src/libse/Forms/TimeCodesBeautifier.cs index 8eb8d03de..4a75105e5 100644 --- a/src/libse/Forms/TimeCodesBeautifier.cs +++ b/src/libse/Forms/TimeCodesBeautifier.cs @@ -111,7 +111,7 @@ namespace Nikse.SubtitleEdit.Core.Forms } } - private bool FixConnectedSubtitles(Paragraph leftParagraph = null, Paragraph rightParagraph = null) + private bool FixConnectedSubtitles(Paragraph leftParagraph = null, Paragraph rightParagraph = null, bool checkConnected = true) { if (leftParagraph == null || rightParagraph == null) { @@ -140,7 +140,7 @@ namespace Nikse.SubtitleEdit.Core.Forms var subtitlesAreConnected = distance < Configuration.Settings.BeautifyTimeCodes.Profile.ConnectedSubtitlesTreatConnected; - if (subtitlesAreConnected) + if (subtitlesAreConnected || !checkConnected) { var newLeftOutCueFrame = MillisecondsToFrames(leftParagraph.EndTime.TotalMilliseconds); var newRightInCueFrame = MillisecondsToFrames(rightParagraph.StartTime.TotalMilliseconds); @@ -545,7 +545,17 @@ namespace Nikse.SubtitleEdit.Core.Forms var performGeneralChaining = false; - if (isRightInCueOnShotChange) + if (isLeftOutCueOnShotChange && isRightInCueOnShotChange + && bestLeftOutCueFrameInfo.result == FindBestCueResult.SnappedToRedZone && bestRightInCueFrameInfo.result == FindBestCueResult.SnappedToRedZone + && bestLeftOutCueFrame == bestRightInCueFrame) + { + // If both cues are being snapped to the exact same shot change, the subtitles really are connected + // So, handle using the designated function, ignoring the "treat connected" value (because otherwise it would have handled it before going into this function) + FixConnectedSubtitles(leftParagraph, rightParagraph, checkConnected: false); + + return true; + } + else if (isRightInCueOnShotChange) { // The right in cue is on a shot change // Try to chain the subtitles From c13db1f4a7ecd49272e0e0f11b4fb8b34f74889d Mon Sep 17 00:00:00 2001 From: "Martijn van Berkel (Flitskikker)" Date: Sun, 20 Oct 2024 12:23:57 +0200 Subject: [PATCH 2/3] More general approach --- src/libse/Forms/TimeCodesBeautifier.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/libse/Forms/TimeCodesBeautifier.cs b/src/libse/Forms/TimeCodesBeautifier.cs index 4a75105e5..dd54056da 100644 --- a/src/libse/Forms/TimeCodesBeautifier.cs +++ b/src/libse/Forms/TimeCodesBeautifier.cs @@ -539,23 +539,24 @@ namespace Nikse.SubtitleEdit.Core.Forms bestRightInCueFrame = newRightInCueFrame; } - // Check cases - var isLeftOutCueOnShotChange = IsCueOnShotChange(bestLeftOutCueFrame, false); - var isRightInCueOnShotChange = IsCueOnShotChange(bestRightInCueFrame, true); - - var performGeneralChaining = false; - - if (isLeftOutCueOnShotChange && isRightInCueOnShotChange - && bestLeftOutCueFrameInfo.result == FindBestCueResult.SnappedToRedZone && bestRightInCueFrameInfo.result == FindBestCueResult.SnappedToRedZone - && bestLeftOutCueFrame == bestRightInCueFrame) + // Re-check if, with the new cues, the subtitles are actually connected + var newDistance = FramesToMilliseconds(bestRightInCueFrame) - FramesToMilliseconds(bestLeftOutCueFrame); + if (newDistance < Configuration.Settings.BeautifyTimeCodes.Profile.ConnectedSubtitlesTreatConnected) { - // If both cues are being snapped to the exact same shot change, the subtitles really are connected - // So, handle using the designated function, ignoring the "treat connected" value (because otherwise it would have handled it before going into this function) + // Yes, so handle using the designated function, ignoring its check connected check + // (because otherwise it would have handled it before going into the FixChainableSubtitles function) FixConnectedSubtitles(leftParagraph, rightParagraph, checkConnected: false); return true; } - else if (isRightInCueOnShotChange) + + // Check cases + var isLeftOutCueOnShotChange = IsCueOnShotChange(bestLeftOutCueFrame, false); + var isRightInCueOnShotChange = IsCueOnShotChange(bestRightInCueFrame, true); + + var performGeneralChaining = false; + + if (isRightInCueOnShotChange) { // The right in cue is on a shot change // Try to chain the subtitles From f378bf8def7c2cc47b90a4b4d9cb39c45b798837 Mon Sep 17 00:00:00 2001 From: "Martijn van Berkel (Flitskikker)" Date: Sun, 20 Oct 2024 12:38:46 +0200 Subject: [PATCH 3/3] Remove weird spaces --- src/libse/Forms/TimeCodesBeautifier.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libse/Forms/TimeCodesBeautifier.cs b/src/libse/Forms/TimeCodesBeautifier.cs index dd54056da..a8411ebfa 100644 --- a/src/libse/Forms/TimeCodesBeautifier.cs +++ b/src/libse/Forms/TimeCodesBeautifier.cs @@ -554,7 +554,7 @@ namespace Nikse.SubtitleEdit.Core.Forms var isLeftOutCueOnShotChange = IsCueOnShotChange(bestLeftOutCueFrame, false); var isRightInCueOnShotChange = IsCueOnShotChange(bestRightInCueFrame, true); - var performGeneralChaining = false; + var performGeneralChaining = false; if (isRightInCueOnShotChange) {