Skip to content

Commit a64166a

Browse files
committed
Handle drag and drop retime operations
1 parent 9985fd4 commit a64166a

File tree

1 file changed

+29
-36
lines changed

1 file changed

+29
-36
lines changed

packages/blueprints/src/base/studio/userEditOperations/processIngestData.ts

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
DefaultUserOperationEditProperties,
3+
DefaultUserOperationRetimePiece,
34
DefaultUserOperations,
45
DefaultUserOperationsTypes,
56
IngestChangeType,
@@ -118,14 +119,10 @@ async function applyUserOperation(
118119
/**
119120
* Process piece retiming operations from the UI.
120121
*
121-
* This function handles drag-and-drop retime operations on pieces in the Sofie Rundown Editor.
122-
* It modifies the underlying ingest data (objectTime and duration) for pieces within parts.
122+
* This function handles drag-and-drop retime operations from the Sofie UI.
123123
*
124-
* Expected payload formats:
125-
* - { newTime: number, newDuration?: number }
126-
* - { deltaTime: number, deltaDuration?: number }
127-
* - { startTime: number }
128-
* - { timing: { start: number, duration?: number } }
124+
* It updates the piece timing in the ingest data structure based on the new inPoint provided and
125+
* locks the segment/part to prevent NRCS updates.
129126
*
130127
* @param context - The ingest data processing context
131128
* @param mutableIngestRundown - The mutable rundown being processed
@@ -139,7 +136,7 @@ function processRetimePiece(
139136
changes: UserOperationChange<BlueprintsUserOperations | DefaultUserOperations>
140137
) {
141138
// Extract piece timing information from the operation
142-
const operation = changes.operation as any // DefaultUserOperationRetimePiece would be the proper type
139+
const operation = changes.operation as DefaultUserOperationRetimePiece
143140

144141
context.logDebug('Processing piece retime operation: ' + JSON.stringify(changes, null, 2))
145142

@@ -150,12 +147,19 @@ function processRetimePiece(
150147
}
151148

152149
// Find the part containing the piece
153-
const part = mutableIngestRundown.findPart(operationTarget.partExternalId)
150+
const partAndSegment = mutableIngestRundown.findPartAndSegment(operationTarget.partExternalId)
151+
const { part, segment } = partAndSegment || {}
152+
154153
if (!part?.payload) {
155154
context.logError(`Part not found for retime operation: ${operationTarget.partExternalId}`)
156155
return
157156
}
158157

158+
if (!segment) {
159+
context.logError(`Segment not found for retime operation: ${operationTarget.segmentExternalId}`)
160+
return
161+
}
162+
159163
// Parse the part payload to access pieces
160164
const partPayload: any = part.payload
161165
if (!partPayload.pieces || !Array.isArray(partPayload.pieces)) {
@@ -199,7 +203,7 @@ function processRetimePiece(
199203
context.logWarning(`Retime piece operation has unknown keys in payload: ${unknownKeys.join(', ')}`)
200204
}
201205

202-
// Check if there are actually changes to apply (now comparing in the same units)
206+
// Check if there are actually changes to apply
203207
const timeDifference = Math.abs(newTime - originalTime)
204208
if (timeDifference < 0.005) {
205209
// Less than 5ms difference - consider it unchanged
@@ -216,39 +220,27 @@ function processRetimePiece(
216220
objectTime: newTime,
217221
}
218222

223+
// Lock segment to prevent NRCS updates:
224+
segment.setUserEditState(BlueprintUserOperationTypes.LOCK_SEGMENT_NRCS_UPDATES, true)
225+
226+
// Mark both segment and part as user-edited
227+
segment.setUserEditState(BlueprintUserOperationTypes.USER_EDITED, true)
228+
part.setUserEditState(BlueprintUserOperationTypes.USER_EDITED, true)
229+
219230
// Update the piece in the part payload
220231
partPayload.pieces[pieceIndex] = updatedPiece
221232

222233
// Mark the part as modified using replacePayload
223234
part.replacePayload(partPayload)
224235

225-
// Mark the segment/part as having been edited by the user
226-
// This helps track that the content has been modified from the original ingest
227-
const partAndSegment = mutableIngestRundown.findPartAndSegment(operationTarget.partExternalId)
228-
if (partAndSegment?.segment && partAndSegment?.part) {
229-
// Mark both segment and part as user-edited
230-
partAndSegment.segment.setUserEditState(BlueprintUserOperationTypes.USER_EDITED, true)
231-
partAndSegment.part.setUserEditState(BlueprintUserOperationTypes.USER_EDITED, true)
232-
233-
// Create a unique user edit state key for this piece retime operation
234-
// This ensures each retime operation creates a new state change, triggering persistence
235-
const pieceRetimeKey = `${operation.id}_${operationTarget.pieceExternalId}_${Date.now()}`
236-
237-
// Store the retime operation as a user edit state
238-
// Each retime gets a unique key to ensure state changes trigger persistence
239-
partAndSegment.segment.setUserEditState(pieceRetimeKey, true)
240-
partAndSegment.part.setUserEditState(pieceRetimeKey, true)
236+
// Store the retime operation as a user edit state
237+
// Each retime gets a unique key to ensure state changes trigger persistence
238+
// This is a horrible hack.
239+
// segment.setUserEditState(pieceRetimeKey, true)
240+
const pieceRetimeKey = `${operation.id}_${operationTarget.pieceExternalId}_${Date.now()}`
241+
part.setUserEditState(pieceRetimeKey, true)
241242

242-
// Also mark the specific operation that was performed
243-
partAndSegment.segment.setUserEditState(operation.id, true)
244-
partAndSegment.part.setUserEditState(operation.id, true)
245-
246-
// Lock both segment and part to prevent NRCS updates:
247-
partAndSegment.segment.setUserEditState(BlueprintUserOperationTypes.LOCK_SEGMENT_NRCS_UPDATES, true)
248-
partAndSegment.part.setUserEditState(BlueprintUserOperationTypes.LOCK_PART_NRCS_UPDATES, true)
249-
250-
context.logDebug(`Marked segment and part as user-edited and created unique retime state: ${pieceRetimeKey}`)
251-
}
243+
context.logDebug(`Marked segment and part as user-edited and created unique retime state: ${pieceRetimeKey}`)
252244
}
253245

254246
function processUpdateProps(
@@ -358,6 +350,7 @@ function updatePieceProps(
358350

359351
const lifespan = operation.payload.globalProperties['lifespan']
360352
context.logDebug('Update piece ' + operationTarget.pieceExternalId + ': ' + lifespan)
353+
// TODO: Do we actually update anything here? We just seem to log.
361354
}
362355

363356
function changeSource(

0 commit comments

Comments
 (0)