@@ -150,35 +150,55 @@ export class QuickLoopService {
150150 }
151151
152152 getSegmentsBetweenMarkers ( startMarker : QuickLoopMarker , endMarker : QuickLoopMarker ) : SegmentId [ ] {
153- const orderedParts = this . playoutModel . getAllOrderedParts ( )
154- const rundownIds = this . playoutModel . getRundownIds ( )
155-
156- const start = this . findQuickLoopMarkerPosition ( startMarker , 'start' , orderedParts , rundownIds )
157- const end = this . findQuickLoopMarkerPosition ( endMarker , 'end' , orderedParts , rundownIds )
153+ const segments = this . playoutModel . getAllOrderedSegments ( )
154+ const segmentIds : SegmentId [ ] = [ ]
158155
159- if ( this . areMarkersFlipped ( start , end ) ) return [ ]
156+ let passedStart = false
157+ let seenLastRundown = false
160158
161- const segmentIds : Set < SegmentId > = new Set ( )
159+ for ( const s of segments ) {
160+ if (
161+ ( ! passedStart &&
162+ ( ( startMarker . type === QuickLoopMarkerType . PART && s . getPart ( startMarker . id ) ) ||
163+ ( startMarker . type === QuickLoopMarkerType . SEGMENT && s . segment . _id === startMarker . id ) ||
164+ ( startMarker . type === QuickLoopMarkerType . RUNDOWN &&
165+ s . segment . rundownId === startMarker . id ) ) ) ||
166+ startMarker . type === QuickLoopMarkerType . PLAYLIST
167+ ) {
168+ // the start marker is inside this segment, is this segment, or this is the first segment that is in the loop
169+ // segments from here on are included in the loop
170+ passedStart = true
171+ }
162172
163- for ( const part of orderedParts ) {
164- const currentSegment = this . playoutModel . findSegment ( part . segmentId ) ?. segment
165- const currentRundownIndex = rundownIds . findIndex ( ( id ) => id === part . rundownId )
173+ if ( endMarker . type === QuickLoopMarkerType . RUNDOWN ) {
174+ // last rundown needs to be inclusive so we need to break once the rundownId is not equal to segment's rundownId
175+ if ( s . segment . rundownId === endMarker . id ) {
176+ if ( ! passedStart ) {
177+ // we hit the end before the start so quit now:
178+ break
179+ }
180+ seenLastRundown = true
181+ } else if ( seenLastRundown ) {
182+ // we have passed the last rundown
183+ break
184+ }
185+ }
166186
167- if ( ! currentSegment ) continue // ???
187+ if ( passedStart ) {
188+ // passed the start but we have not seen the end yet
189+ segmentIds . push ( s . segment . _id )
190+ }
168191
169192 if (
170- currentRundownIndex >= start . rundownRank &&
171- currentRundownIndex <= end . rundownRank &&
172- currentSegment . _rank >= start . segmentRank &&
173- currentSegment . _rank <= end . segmentRank &&
174- part . _rank >= start . partRank &&
175- part . _rank <= start . partRank
193+ ( endMarker . type === QuickLoopMarkerType . PART && s . getPart ( endMarker . id ) ) ||
194+ ( endMarker . type === QuickLoopMarkerType . SEGMENT && s . segment . _id === endMarker . id )
176195 ) {
177- segmentIds . add ( currentSegment . _id )
196+ // the endMarker is in this segment or this segment is the end marker
197+ break
178198 }
179199 }
180200
181- return Array . from ( segmentIds . values ( ) )
201+ return segmentIds
182202 }
183203
184204 private areMarkersFlipped ( startPosition : MarkerPosition , endPosition : MarkerPosition ) {
0 commit comments