@@ -5,6 +5,9 @@ import { runJobWithPlayoutModel } from './lock'
55import { updateTimeline } from './timeline/generate'
66import { selectNextPart } from './selectNextPart'
77import { setNextPart } from './setNext'
8+ import { resetPartInstancesWithPieceInstances } from './lib'
9+ import { QuickLoopMarker , QuickLoopMarkerType } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
10+ import { SegmentId } from '@sofie-automation/corelib/dist/dataModel/Ids'
811
912export async function handleSetQuickLoopMarker ( context : JobContext , data : SetQuickLoopMarkerProps ) : Promise < void > {
1013 return runJobWithPlayoutModel (
@@ -17,9 +20,74 @@ export async function handleSetQuickLoopMarker(context: JobContext, data: SetQui
1720 async ( playoutModel ) => {
1821 const playlist = playoutModel . playlist
1922 if ( ! playlist . activationId ) throw new Error ( `Playlist has no activationId!` )
20- const wasQuickLoopRunning = playoutModel . playlist . quickLoop ?. running
23+ const oldProps = playoutModel . playlist . quickLoop
24+ const wasQuickLoopRunning = oldProps ?. running
2125 playoutModel . setQuickLoopMarker ( data . type , data . marker )
2226
27+ const markerChanged = (
28+ markerA : QuickLoopMarker | undefined ,
29+ markerB : QuickLoopMarker | undefined
30+ ) : boolean => {
31+ if ( ! markerA || ! markerB ) return false
32+
33+ if (
34+ ( markerA . type === QuickLoopMarkerType . RUNDOWN ||
35+ markerA . type === QuickLoopMarkerType . SEGMENT ||
36+ markerA . type === QuickLoopMarkerType . PART ) &&
37+ ( markerB . type === QuickLoopMarkerType . RUNDOWN ||
38+ markerB . type === QuickLoopMarkerType . SEGMENT ||
39+ markerB . type === QuickLoopMarkerType . PART )
40+ ) {
41+ return markerA . id !== markerB . id
42+ }
43+
44+ return false
45+ }
46+
47+ if ( playlist . currentPartInfo ) {
48+ // rundown is on air
49+ let segmentsToReset : SegmentId [ ] = [ ]
50+
51+ if (
52+ playlist . quickLoop ?. start &&
53+ oldProps ?. start &&
54+ markerChanged ( oldProps . start , playlist . quickLoop . start )
55+ ) {
56+ // start marker changed
57+ segmentsToReset = playoutModel . getSegmentsBetweenQuickLoopMarker (
58+ playlist . quickLoop . start ,
59+ oldProps . start
60+ )
61+ } else if (
62+ playlist . quickLoop ?. end &&
63+ oldProps ?. end &&
64+ markerChanged ( oldProps . end , playlist . quickLoop . end )
65+ ) {
66+ // end marker changed
67+ segmentsToReset = playoutModel . getSegmentsBetweenQuickLoopMarker (
68+ oldProps . end ,
69+ playlist . quickLoop . end
70+ )
71+ } else if ( playlist . quickLoop ?. start && playlist . quickLoop . end && ! ( oldProps ?. start && oldProps . end ) ) {
72+ // a new loop was created
73+ segmentsToReset = playoutModel . getSegmentsBetweenQuickLoopMarker (
74+ playlist . quickLoop . start ,
75+ playlist . quickLoop . end
76+ )
77+ }
78+
79+ // reset segments that have been added to the loop and are not on-air
80+ resetPartInstancesWithPieceInstances ( context , playoutModel , {
81+ segmentId : {
82+ $in : segmentsToReset . filter (
83+ ( segmentId ) =>
84+ segmentId !== playoutModel . currentPartInstance ?. partInstance . segmentId &&
85+ segmentId !== playoutModel . nextPartInstance ?. partInstance . segmentId
86+ ) ,
87+ } ,
88+ } )
89+ }
90+
2391 if ( wasQuickLoopRunning ) {
2492 const nextPart = selectNextPart (
2593 context ,
0 commit comments