Skip to content

Commit 0f06f6a

Browse files
authored
Merge pull request #1666 from nrkno/contribute/fix/sofie-4336/endRelativeToPart
2 parents 7cc9ab5 + 52b41f3 commit 0f06f6a

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

packages/job-worker/src/playout/__tests__/timeline.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,11 +1893,11 @@ describe('Timeline', () => {
18931893
currentInfinitePieces: {
18941894
piece002: {
18951895
// Should still be based on the time of previousPart
1896-
partGroup: { start: firstPartTakeTime },
18971896
pieceGroup: {
18981897
controlObj: { start: 500 },
18991898
childGroup: { preroll: 0, postroll: 0 },
19001899
},
1900+
partGroup: { start: firstPartTakeTime - 500 }, // this is Piece plannedStartedPlayback minus pieceGroup.controlObj.start
19011901
},
19021902
},
19031903
previousOutTransition: undefined,
@@ -1973,7 +1973,7 @@ describe('Timeline', () => {
19731973
},
19741974
},
19751975
partGroup: {
1976-
start: plannedStartedPlayback,
1976+
start: plannedStartedPlayback - 500, // this is plannedStartedPlayback minus pieceGroup.controlObj.start
19771977
},
19781978
},
19791979
},

packages/job-worker/src/playout/timeline/multi-gateway.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { PlayoutModel } from '../model/PlayoutModel.js'
88
import { RundownTimelineTimingContext, getInfinitePartGroupId } from './rundown.js'
99
import { PlayoutPartInstanceModel } from '../model/PlayoutPartInstanceModel.js'
1010
import { PlayoutPieceInstanceModel } from '../model/PlayoutPieceInstanceModel.js'
11+
import { getPieceControlObjectId } from '@sofie-automation/corelib/dist/playout/ids'
1112

1213
/**
1314
* We want it to be possible to generate a timeline without it containing any `start: 'now'`.
@@ -297,7 +298,7 @@ function setPlannedTimingsOnPieceInstance(
297298

298299
const userDurationEnd =
299300
pieceInstance.pieceInstance.userDuration && 'endRelativeToPart' in pieceInstance.pieceInstance.userDuration
300-
? pieceInstance.pieceInstance.userDuration.endRelativeToPart
301+
? partPlannedStart + pieceInstance.pieceInstance.userDuration.endRelativeToPart
301302
: null
302303

303304
let plannedEnd: number | undefined = userDurationEnd ?? undefined
@@ -334,14 +335,27 @@ function preserveOrTrackInfiniteTimings(
334335
// Update the timeline group
335336
const startedPlayback = plannedStartedPlayback ?? pieceInstance.pieceInstance.plannedStartedPlayback
336337
if (startedPlayback) {
338+
const pieceControlObjectId = getPieceControlObjectId(pieceInstance.pieceInstance)
339+
const pieceControlObj = timelineObjsMap[pieceControlObjectId]
340+
341+
// this replicates what generateCurrentInfinitePieceObjects() does
342+
let pieceEnableStartOffset = 0
343+
if (
344+
pieceControlObj &&
345+
!Array.isArray(pieceControlObj.enable) &&
346+
typeof pieceControlObj.enable?.start === 'number'
347+
) {
348+
pieceEnableStartOffset = pieceControlObj.enable.start
349+
}
350+
337351
const infinitePartGroupId = getInfinitePartGroupId(pieceInstance.pieceInstance._id)
338352
const infinitePartGroupObj = timelineObjsMap[infinitePartGroupId]
339353
if (
340354
infinitePartGroupObj &&
341355
!Array.isArray(infinitePartGroupObj.enable) &&
342356
typeof infinitePartGroupObj.enable.start === 'string'
343357
) {
344-
infinitePartGroupObj.enable.start = startedPlayback
358+
infinitePartGroupObj.enable.start = startedPlayback - pieceEnableStartOffset
345359
}
346360
}
347361
}

packages/job-worker/src/playout/timeline/rundown.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ function generateCurrentInfinitePieceObjects(
282282
return []
283283
}
284284

285+
/*
286+
Notes on the "Infinite Part Group":
287+
Infinite pieces are put into a parent "infinite Part Group" object instead of the usual Part Group,
288+
because their lifetime can be outside of their Part.
289+
290+
The Infinite Part Group's start time is set to be the start time of the Piece, but this is then complicated by
291+
the Piece.enable.start assuming that it is relative to the PartGroup it is in. This is being factored in if an
292+
absolute start time is known for the piece.
293+
*/
294+
285295
const { infiniteGroupEnable, pieceEnable, nowInParent } = calculateInfinitePieceEnable(
286296
currentPartInfo,
287297
timingContext,
@@ -350,7 +360,12 @@ function calculateInfinitePieceEnable(
350360
)
351361

352362
let infiniteGroupEnable: PartEnable = {
353-
start: `#${timingContext.currentPartGroup.id}.start`, // This gets overriden with a concrete time if the original piece is known to have already started
363+
/*
364+
This gets overridden with a concrete time if the original piece is known to have already started
365+
but if not, allows the pieceEnable to be relative to the currentPartInstance's part group as normal
366+
and `nowInParent` to be correct for the piece objects inside
367+
*/
368+
start: `#${timingContext.currentPartGroup.id}.start`,
354369
}
355370

356371
let nowInParent = currentPartInfo.partTimes.nowInPart // Where is 'now' inside of the infiniteGroup?

0 commit comments

Comments
 (0)