Skip to content

Commit f422e7f

Browse files
committed
wip: cleanip
1 parent 1b4fc54 commit f422e7f

File tree

12 files changed

+58
-62
lines changed

12 files changed

+58
-62
lines changed

packages/blueprints-integration/src/documents/pieceInstance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { IBlueprintPieceDB } from './piece'
44
export interface IBlueprintPieceInstance<TPrivateData = unknown, TPublicData = unknown> {
55
_id: string
66
/** The part instace this piece belongs to */
7-
partInstanceId: string | null
7+
partInstanceId: string
88

99
/** If this piece has been created play-time using an AdLibPiece, this should be set to it's source piece */
1010
adLibSourceId?: string

packages/corelib/src/dataModel/PieceInstance.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export interface PieceInstance {
3434
_id: PieceInstanceId
3535
/** The rundown this piece belongs to */
3636
rundownId: RundownId
37-
/**
38-
* The part instance this piece belongs to.
39-
*/
37+
/** The part instance this piece belongs to. */
4038
partInstanceId: PartInstanceId
4139

4240
/** Whether this PieceInstance is a temprorary wrapping of a Piece */

packages/corelib/src/dataModel/RundownPlaylist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface ABSessionInfo {
2626
/** Set if the session is being used by an infinite PieceInstance */
2727
infiniteInstanceId?: PieceInstanceInfiniteId
2828
/** Set to the PartInstances this session is used by, if not just used for lookahead */
29-
partInstanceIds?: Array<PartInstanceId | null>
29+
partInstanceIds?: Array<PartInstanceId>
3030
}
3131

3232
export interface ABSessionAssignment {

packages/job-worker/src/blueprints/__tests__/context-events.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,19 @@ describe('Test blueprint api context', () => {
277277

278278
// Check what was generated
279279
const context = await getContext(rundown, undefined, partInstance, undefined)
280-
await expect(context.getPieceInstances(unprotectString(partInstance._id))).resolves.toHaveLength(3)
280+
await expect(
281+
context.getPieceInstances(unprotectString(pieceInstance.partInstanceId))
282+
).resolves.toHaveLength(3)
281283

282284
// mark one of the piece as different activation
283285
await jobContext.mockCollections.PieceInstances.update(pieceInstance._id, {
284286
$set: { playlistActivationId: protectString('another activation') },
285287
})
286288

287289
// should now be less
288-
await expect(context.getPieceInstances(unprotectString(partInstance._id))).resolves.toHaveLength(2)
290+
await expect(
291+
context.getPieceInstances(unprotectString(pieceInstance.partInstanceId))
292+
).resolves.toHaveLength(2)
289293
})
290294

291295
test('getSegment - no id', async () => {

packages/job-worker/src/blueprints/context/services/__tests__/PartAndPieceInstanceActionService.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ describe('Test blueprint api context', () => {
240240
if (!info) {
241241
return null
242242
} else if ('partInstanceId' in info) {
243-
if (!info.partInstanceId) return null
244243
return {
245244
partInstanceId: info.partInstanceId,
246245
rundownId: info.rundownId,

packages/job-worker/src/playout/model/implementation/LoadPlayoutModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ async function loadPartInstances(
260260
context: JobContext,
261261
playlist: ReadonlyDeep<DBRundownPlaylist>,
262262
rundownIds: RundownId[]
263-
): Promise<{ partInstances: DBPartInstance[]; groupedPieceInstances: Map<PartInstanceId | null, PieceInstance[]> }> {
263+
): Promise<{ partInstances: DBPartInstance[]; groupedPieceInstances: Map<PartInstanceId, PieceInstance[]> }> {
264264
const selectedPartInstanceIds = _.compact([
265265
playlist.currentPartInfo?.partInstanceId,
266266
playlist.nextPartInfo?.partInstanceId,

packages/job-worker/src/playout/model/implementation/PlayoutModelImpl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class PlayoutModelReadonlyImpl implements PlayoutModelReadonly {
9494
peripheralDevices: ReadonlyDeep<PeripheralDevice[]>,
9595
playlist: DBRundownPlaylist,
9696
partInstances: DBPartInstance[],
97-
groupedPieceInstances: Map<PartInstanceId | null, PieceInstance[]>,
97+
groupedPieceInstances: Map<PartInstanceId, PieceInstance[]>,
9898
rundowns: PlayoutRundownModelImpl[],
9999
timeline: TimelineComplete | undefined
100100
) {
@@ -118,7 +118,7 @@ export class PlayoutModelReadonlyImpl implements PlayoutModelReadonly {
118118

119119
private createPartInstanceModelImpls(
120120
partInstances: DBPartInstance[],
121-
groupedPieceInstances: Map<PartInstanceId | null, PieceInstance[]>
121+
groupedPieceInstances: Map<PartInstanceId, PieceInstance[]>
122122
) {
123123
const allPartInstances: PlayoutPartInstanceModelImpl[] = []
124124
for (const partInstance of partInstances) {
@@ -297,7 +297,7 @@ export class PlayoutModelImpl extends PlayoutModelReadonlyImpl implements Playou
297297
peripheralDevices: ReadonlyDeep<PeripheralDevice[]>,
298298
playlist: DBRundownPlaylist,
299299
partInstances: DBPartInstance[],
300-
groupedPieceInstances: Map<PartInstanceId | null, PieceInstance[]>,
300+
groupedPieceInstances: Map<PartInstanceId, PieceInstance[]>,
301301
rundowns: PlayoutRundownModelImpl[],
302302
timeline: TimelineComplete | undefined
303303
) {

packages/job-worker/src/playout/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export async function handleRestorePlaylistSnapshot(
375375
T extends {
376376
_id: ProtectedString<any>
377377
rundownId?: RundownId
378-
partInstanceId?: PartInstanceId | null
378+
partInstanceId?: PartInstanceId
379379
partId?: PartId
380380
segmentId?: SegmentId
381381
part?: unknown

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

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BlueprintId, TimelineHash } from '@sofie-automation/corelib/dist/dataModel/Ids'
1+
import { BlueprintId, RundownPlaylistId, TimelineHash } from '@sofie-automation/corelib/dist/dataModel/Ids'
22
import { JobContext, JobStudio } from '../../jobs'
33
import { ReadonlyDeep } from 'type-fest'
44
import {
@@ -388,37 +388,8 @@ async function getTimelineRundown(
388388
timelineObjs = timelineObjs.concat(rundownTimelineResult.timeline)
389389
timelineObjs = timelineObjs.concat(await pLookaheadObjs)
390390

391-
let regenerateTimelineToken: string | undefined
392-
const regenerateTimelineAt = Math.min(
393-
partInstancesInfo.current?.regenerateTimelineAt ?? Number.POSITIVE_INFINITY,
394-
partInstancesInfo.next?.regenerateTimelineAt ?? Number.POSITIVE_INFINITY
395-
)
396-
if (regenerateTimelineAt < Number.POSITIVE_INFINITY) {
397-
// The timeline has requested a regeneration at a specific time
398-
regenerateTimelineToken = getHash(`regenerate-${playoutModel.playlistId}-${getCurrentTime()}`)
399-
timelineObjs.push(
400-
literal<TimelineObjRegenerateTrigger & OnGenerateTimelineObjExt>({
401-
id: `regenerate_${regenerateTimelineToken}`,
402-
enable: {
403-
start: regenerateTimelineAt,
404-
},
405-
layer: '__timeline_regeneration_trigger__', // Some unique name, as callbacks need to be on a layer
406-
priority: 1,
407-
content: {
408-
deviceType: TSR.DeviceType.ABSTRACT,
409-
type: 'callback',
410-
callBack: PlayoutChangedType.TRIGGER_REGENERATION,
411-
callBackData: {
412-
rundownPlaylistId: playoutModel.playlistId,
413-
regenerationToken: regenerateTimelineToken,
414-
},
415-
},
416-
objectType: TimelineObjType.RUNDOWN,
417-
metaData: undefined,
418-
partInstanceId: null,
419-
})
420-
)
421-
}
391+
const regenerateTimelineObj = createRegenerateTimelineObj(playoutModel.playlistId, partInstancesInfo)
392+
if (regenerateTimelineObj) timelineObjs.push(regenerateTimelineObj.obj)
422393

423394
const blueprint = await context.getShowStyleBlueprint(showStyle._id)
424395
timelineVersions = generateTimelineVersions(
@@ -517,7 +488,7 @@ async function getTimelineRundown(
517488
}),
518489
versions: timelineVersions ?? generateTimelineVersions(context.studio, undefined, '-'),
519490
timingContext: rundownTimelineResult.timingContext,
520-
regenerateTimelineToken,
491+
regenerateTimelineToken: regenerateTimelineObj?.token,
521492
}
522493
} else {
523494
if (span) span.end()
@@ -541,6 +512,44 @@ async function getTimelineRundown(
541512
}
542513
}
543514

515+
function createRegenerateTimelineObj(
516+
playlistId: RundownPlaylistId,
517+
partInstancesInfo: SelectedPartInstancesTimelineInfo
518+
) {
519+
const regenerateTimelineAt = Math.min(
520+
partInstancesInfo.current?.regenerateTimelineAt ?? Number.POSITIVE_INFINITY,
521+
partInstancesInfo.next?.regenerateTimelineAt ?? Number.POSITIVE_INFINITY
522+
)
523+
if (regenerateTimelineAt < Number.POSITIVE_INFINITY) {
524+
// The timeline has requested a regeneration at a specific time
525+
const token = getHash(`regenerate-${playlistId}-${getCurrentTime()}`)
526+
const obj = literal<TimelineObjRegenerateTrigger & OnGenerateTimelineObjExt>({
527+
id: `regenerate_${token}`,
528+
enable: {
529+
start: regenerateTimelineAt,
530+
},
531+
layer: '__timeline_regeneration_trigger__', // Some unique name, as callbacks need to be on a layer
532+
priority: 1,
533+
content: {
534+
deviceType: TSR.DeviceType.ABSTRACT,
535+
type: 'callback',
536+
callBack: PlayoutChangedType.TRIGGER_REGENERATION,
537+
callBackData: {
538+
rundownPlaylistId: playlistId,
539+
regenerationToken: token,
540+
},
541+
},
542+
objectType: TimelineObjType.RUNDOWN,
543+
metaData: undefined,
544+
partInstanceId: null,
545+
})
546+
547+
return { token, obj }
548+
} else {
549+
return null
550+
}
551+
}
552+
544553
/**
545554
* Process the timeline objects, to provide some basic validation. Also flattens the nested objects into a single array
546555
* Note: Input array is mutated in place

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,13 @@ import { logger } from '../../logging'
3333
* Fields are populated as it progresses through generation, and consumed during the finalisation
3434
*/
3535
export interface RundownTimelineTimingContext {
36-
/**
37-
* How long an absolute timed piece should be on the timeline before it is played
38-
* This is a constant derived from the settings
39-
*/
40-
// readonly absolutePiecePrepareTime: number
41-
4236
currentPartGroup: TimelineObjGroupPart
4337
currentPartDuration: number | undefined
4438

4539
previousPartOverlap?: number
4640

4741
nextPartGroup?: TimelineObjGroupPart
4842
nextPartOverlap?: number
49-
50-
/**
51-
* The timeline can request to be regenerated at a specific time, this allows for things to be added to the timeline nearer to when they will be played
52-
*/
53-
// regenerateTimelineAt?: Time
5443
}
5544
export interface RundownTimelineResult {
5645
timeline: (TimelineObjRundown & OnGenerateTimelineObjExt)[]
@@ -146,8 +135,6 @@ export function buildTimelineObjsForRundown(
146135
const currentPartGroup = createPartGroup(partInstancesInfo.current.partInstance, currentPartEnable)
147136

148137
const timingContext: RundownTimelineTimingContext = {
149-
// absolutePiecePrepareTime:
150-
// context.studio.settings.rundownGlobalPiecesPrepareTime || DEFAULT_ABSOLUTE_PIECE_PREPARE_TIME,
151138
currentPartGroup,
152139
currentPartDuration: currentPartEnable.duration,
153140
}

0 commit comments

Comments
 (0)