88import { MarkerPosition , compareMarkerPositions } from '@sofie-automation/corelib/dist/playout/playlist'
99import { ProtectedString , unprotectString } from '@sofie-automation/corelib/dist/protectedString'
1010import { DEFAULT_FALLBACK_PART_DURATION } from '@sofie-automation/shared-lib/dist/core/constants'
11- import { generateTranslation } from '../../../lib/lib'
11+ import { generateTranslation , getCurrentTime } from '../../../lib/lib'
1212import { DBStudio } from '@sofie-automation/corelib/dist/dataModel/Studio'
1313import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
1414import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
@@ -48,7 +48,8 @@ export function modifyPartForQuickLoop(
4848 playlist : Pick < DBRundownPlaylist , 'quickLoop' > ,
4949 studio : Pick < DBStudio , 'settings' > ,
5050 quickLoopStartPosition : MarkerPosition | undefined ,
51- quickLoopEndPosition : MarkerPosition | undefined
51+ quickLoopEndPosition : MarkerPosition | undefined ,
52+ canSetAutoNext = ( ) => true
5253) : void {
5354 const partPosition = findPartPosition ( part , segmentRanks , rundownRanks )
5455 const isLoopDefined = quickLoopStartPosition && quickLoopEndPosition
@@ -71,9 +72,47 @@ export function modifyPartForQuickLoop(
7172 }
7273 }
7374 }
75+ if ( ! canSetAutoNext ( ) ) return
7476 part . autoNext = part . autoNext || ( isLoopingOverriden && ( part . expectedDuration ?? 0 ) > 0 )
7577}
7678
79+ export function modifyPartInstanceForQuickLoop (
80+ partInstance : Omit < DBPartInstance , 'part.privateData' > ,
81+ segmentRanks : Record < string , number > ,
82+ rundownRanks : Record < string , number > ,
83+ playlist : Pick < DBRundownPlaylist , 'quickLoop' > ,
84+ studio : Pick < DBStudio , 'settings' > ,
85+ quickLoopStartPosition : MarkerPosition | undefined ,
86+ quickLoopEndPosition : MarkerPosition | undefined
87+ ) : void {
88+ // note that the logic for when a part does not do autonext in quickloop should reflect the logic in the QuickLoopService in job worker
89+ const canAutoNext = ( ) => {
90+ const start = partInstance . timings ?. plannedStartedPlayback
91+ if ( start !== undefined && partInstance . part . expectedDuration ) {
92+ // date.now - start = playback duration, duration + offset gives position in part
93+ const playbackDuration = getCurrentTime ( ) - start
94+
95+ // If there is an auto next planned soon or was in the past
96+ if ( partInstance . part . expectedDuration - playbackDuration < 0 ) {
97+ return false
98+ }
99+ }
100+
101+ return true
102+ }
103+
104+ modifyPartForQuickLoop (
105+ partInstance . part ,
106+ segmentRanks ,
107+ rundownRanks ,
108+ playlist ,
109+ studio ,
110+ quickLoopStartPosition ,
111+ quickLoopEndPosition ,
112+ canAutoNext // do not adjust the part instance if we have passed the time where we can still enable auto next
113+ )
114+ }
115+
77116export function findMarkerPosition (
78117 marker : QuickLoopMarker ,
79118 fallback : number ,
0 commit comments