|
| 1 | +import React, { useState } from 'react' |
| 2 | + |
| 3 | +/** |
| 4 | + * This is a demo showing the interactions between the part and piece groups on the timeline. |
| 5 | + * The maths should be the same as in `meteor/lib/rundown/timings.ts`, but in a simplified form |
| 6 | + */ |
| 7 | + |
| 8 | +const MS_TO_PIXEL_CONSTANT = 0.1 |
| 9 | + |
| 10 | +const viewPortStyle = { |
| 11 | + width: '100%', |
| 12 | + backgroundSize: '40px 40px', |
| 13 | + backgroundImage: |
| 14 | + 'linear-gradient(to right, grey 1px, transparent 1px), linear-gradient(to bottom, grey 1px, transparent 1px)', |
| 15 | + overflowX: 'hidden', |
| 16 | + display: 'flex', |
| 17 | + flexDirection: 'column', |
| 18 | + position: 'relative', |
| 19 | +} |
| 20 | + |
| 21 | +export function PartTimingsDemo() { |
| 22 | + const [postrollA1, setPostrollA1] = useState(0) |
| 23 | + const [postrollA2, setPostrollA2] = useState(0) |
| 24 | + const [prerollB1, setPrerollB1] = useState(0) |
| 25 | + const [prerollB2, setPrerollB2] = useState(0) |
| 26 | + const [outTransitionDuration, setOutTransitionDuration] = useState(0) |
| 27 | + const [inTransitionBlockDuration, setInTransitionBlockDuration] = useState(0) |
| 28 | + const [inTransitionContentsDelay, setInTransitionContentsDelay] = useState(0) |
| 29 | + const [inTransitionKeepaliveDuration, setInTransitionKeepaliveDuration] = useState(0) |
| 30 | + |
| 31 | + // Arbitrary point in time for the take to be based around |
| 32 | + const takeTime = 2400 |
| 33 | + |
| 34 | + const outTransitionTime = outTransitionDuration - inTransitionKeepaliveDuration |
| 35 | + |
| 36 | + // The amount of time needed to preroll Part B before the 'take' point |
| 37 | + const partBPreroll = Math.max(prerollB1, prerollB2) |
| 38 | + const prerollTime = partBPreroll - inTransitionContentsDelay |
| 39 | + |
| 40 | + // The amount to delay the part 'switch' to, to ensure the outTransition has time to complete as well as any prerolls for part B |
| 41 | + const takeOffset = Math.max(0, outTransitionTime, prerollTime) |
| 42 | + const takeDelayed = takeTime + takeOffset |
| 43 | + |
| 44 | + // Calculate the part A objects |
| 45 | + const pieceA1 = { time: 0, duration: takeDelayed + inTransitionKeepaliveDuration + postrollA1 } |
| 46 | + const pieceA2 = { time: 0, duration: takeDelayed + inTransitionKeepaliveDuration + postrollA2 } |
| 47 | + const partA = { time: 0, duration: Math.max(pieceA1.duration, pieceA2.duration) } // part stretches to contain the piece |
| 48 | + |
| 49 | + // Calculate the transition objects |
| 50 | + const pieceOutTransition = { |
| 51 | + time: partA.time + partA.duration - outTransitionDuration - Math.max(postrollA1, postrollA2), |
| 52 | + duration: outTransitionDuration, |
| 53 | + } |
| 54 | + const pieceInTransition = { time: takeDelayed, duration: inTransitionBlockDuration } |
| 55 | + |
| 56 | + // Calculate the part B objects |
| 57 | + const partBBaseDuration = 2600 |
| 58 | + const partB = { time: takeTime, duration: partBBaseDuration + takeOffset } |
| 59 | + const pieceB1 = { time: takeDelayed + inTransitionContentsDelay - prerollB1, duration: partBBaseDuration + prerollB1 } |
| 60 | + const pieceB2 = { time: takeDelayed + inTransitionContentsDelay - prerollB2, duration: partBBaseDuration + prerollB2 } |
| 61 | + const pieceB3 = { time: takeDelayed + inTransitionContentsDelay + 300, duration: 200 } |
| 62 | + |
| 63 | + return ( |
| 64 | + <div> |
| 65 | + <div style={viewPortStyle}> |
| 66 | + <TimelineGroup {...pieceInTransition} name="In Transition" color="pink" /> |
| 67 | + <TimelineGroup {...pieceOutTransition} name="Out Transition" color="lightblue" /> |
| 68 | + |
| 69 | + <TimelineGroup {...partA} name="PartGroup A" color="green" /> |
| 70 | + <TimelineGroup {...pieceA1} name="Piece A1" color="orange" /> |
| 71 | + <TimelineGroup {...pieceA2} name="Piece A2" color="orange" /> |
| 72 | + |
| 73 | + <TimelineGroup {...partB} name="PartGroup B" color="green" /> |
| 74 | + <TimelineGroup {...pieceB1} name="Piece B1" color="orange" /> |
| 75 | + <TimelineGroup {...pieceB2} name="Piece B2" color="orange" /> |
| 76 | + <TimelineGroup {...pieceB3} name="Super B3" color="orange" /> |
| 77 | + |
| 78 | + <TimelineMarker time={takeTime} title="Take time" /> |
| 79 | + <TimelineMarker time={takeDelayed} title="Take Delayed" /> |
| 80 | + <TimelineMarker time={takeDelayed + inTransitionContentsDelay} title="Content Base time" /> |
| 81 | + </div> |
| 82 | + |
| 83 | + {/* Controls */} |
| 84 | + <table className="margin-top--md"> |
| 85 | + <InputRow label="Piece B1 Preroll Duration" max={1000} value={prerollB1} setValue={setPrerollB1} /> |
| 86 | + <InputRow label="Piece B2 Preroll Duration" max={1000} value={prerollB2} setValue={setPrerollB2} /> |
| 87 | + <InputRow label="Piece A1 Postroll Duration" max={1000} value={postrollA1} setValue={setPostrollA1} /> |
| 88 | + <InputRow label="Piece A2 Postroll Duration" max={1000} value={postrollA2} setValue={setPostrollA2} /> |
| 89 | + <InputRow |
| 90 | + label="Part A Out Transition Duration" |
| 91 | + max={1000} |
| 92 | + value={outTransitionDuration} |
| 93 | + setValue={setOutTransitionDuration} |
| 94 | + /> |
| 95 | + <InputRow |
| 96 | + label="Part B In Transition Block Duration" |
| 97 | + max={1000} |
| 98 | + value={inTransitionBlockDuration} |
| 99 | + setValue={setInTransitionBlockDuration} |
| 100 | + /> |
| 101 | + <InputRow |
| 102 | + label="Part B In Transition Contents Delay" |
| 103 | + max={1000} |
| 104 | + value={inTransitionContentsDelay} |
| 105 | + setValue={setInTransitionContentsDelay} |
| 106 | + /> |
| 107 | + <InputRow |
| 108 | + label="Part B In Transition Keepalive" |
| 109 | + max={1000} |
| 110 | + value={inTransitionKeepaliveDuration} |
| 111 | + setValue={setInTransitionKeepaliveDuration} |
| 112 | + /> |
| 113 | + </table> |
| 114 | + </div> |
| 115 | + ) |
| 116 | +} |
| 117 | + |
| 118 | +function TimelineGroup({ duration, time, name, color }) { |
| 119 | + return ( |
| 120 | + <div |
| 121 | + style={{ |
| 122 | + height: '25px', |
| 123 | + marginBottom: '2px', |
| 124 | + whiteSpace: 'nowrap', |
| 125 | + |
| 126 | + marginLeft: `${time * MS_TO_PIXEL_CONSTANT}px`, |
| 127 | + width: `${duration * MS_TO_PIXEL_CONSTANT}px`, |
| 128 | + background: color, |
| 129 | + }} |
| 130 | + > |
| 131 | + {name} |
| 132 | + </div> |
| 133 | + ) |
| 134 | +} |
| 135 | + |
| 136 | +function TimelineMarker({ time, title }) { |
| 137 | + return ( |
| 138 | + <div |
| 139 | + style={{ |
| 140 | + borderLeft: '2px dashed red', |
| 141 | + display: 'inline-block', |
| 142 | + width: '1px', |
| 143 | + |
| 144 | + float: 'left', |
| 145 | + position: 'absolute', |
| 146 | + top: 0, |
| 147 | + height: '100%', |
| 148 | + |
| 149 | + marginLeft: `${time * MS_TO_PIXEL_CONSTANT}px`, |
| 150 | + }} |
| 151 | + title={title} |
| 152 | + > |
| 153 | + |
| 154 | + </div> |
| 155 | + ) |
| 156 | +} |
| 157 | + |
| 158 | +function InputRow({ label, max, value, setValue }) { |
| 159 | + return ( |
| 160 | + <tr> |
| 161 | + <td>{label}</td> |
| 162 | + <td> |
| 163 | + <input |
| 164 | + type="range" |
| 165 | + min={0} |
| 166 | + max={max} |
| 167 | + value={value} |
| 168 | + onChange={(e) => setValue(parseInt(e.currentTarget.value))} |
| 169 | + /> |
| 170 | + </td> |
| 171 | + </tr> |
| 172 | + ) |
| 173 | +} |
0 commit comments