Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add relevantBlock function #1100

Merged
merged 26 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a377e92
add relevantBlock function and test
alex-Arc Jun 23, 2024
e1c3f2a
rename to getRelevantBlock
alex-Arc Jun 23, 2024
4bc6b4c
use OntimeRundown not Normalized
alex-Arc Jun 23, 2024
b54589d
add block now to runtime state
alex-Arc Jun 23, 2024
4408690
filter in cusheet with currentBlockId
alex-Arc Jun 23, 2024
a173c27
do in only 1 iteration
alex-Arc Jun 25, 2024
9852190
fix test
alex-Arc Jun 25, 2024
6f47f33
Merge remote-tracking branch 'org/master' into relevantBlock
alex-Arc Jun 25, 2024
62cf573
0 index case
alex-Arc Jun 25, 2024
9df62dc
create block state object
alex-Arc Jun 29, 2024
e36aa4b
Merge branch 'master' into relevantBlock
alex-Arc Jul 11, 2024
83098ef
rename to currentBlock
alex-Arc Jul 17, 2024
1317e95
Merge branch 'master' into relevantBlock
alex-Arc Jul 17, 2024
92580d8
slight rename
alex-Arc Jul 17, 2024
1aaa07b
rename to CurrentBlockState
alex-Arc Jul 17, 2024
a6b6657
remove console.log
alex-Arc Jul 17, 2024
d9a139e
typo
alex-Arc Jul 17, 2024
dd5ec5f
Merge branch 'master' into relevantBlock
alex-Arc Jul 19, 2024
3cb3093
unused import
alex-Arc Jul 19, 2024
d0db8f3
lost in Merge
alex-Arc Jul 19, 2024
8c95019
filter events
alex-Arc Jul 19, 2024
75fc00d
pass full rundown to functions and use filter utils
alex-Arc Jul 19, 2024
84beba1
Merge branch 'master' into relevantBlock
alex-Arc Jul 22, 2024
0c51f2f
save to previousState to avoid constant update
alex-Arc Jul 22, 2024
b0385e4
in the same block keep the startedAt time
alex-Arc Jul 22, 2024
61a7d10
null chaining
alex-Arc Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/client/src/common/hooks/useSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const setAuxTimer = {
export const useCuesheet = () => {
const featureSelector = (state: RuntimeStore) => ({
playback: state.timer.playback,
currentBlockId: state.blockNow?.id ?? null,
selectedEventId: state.eventNow?.id ?? null,
selectedEventIndex: state.runtime.selectedEventIndex,
numEvents: state.runtime.numEvents,
Expand Down
5 changes: 5 additions & 0 deletions apps/client/src/common/utils/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ export const connectSocket = () => {
updateDevTools({ eventNow: payload });
break;
}
case 'ontime-blockNow': {
patchRuntime('blockNow', payload);
updateDevTools({ blockNow: payload });
break;
}
case 'ontime-publicEventNow': {
patchRuntime('publicEventNow', payload);
updateDevTools({ publicEventNow: payload });
Expand Down
15 changes: 9 additions & 6 deletions apps/client/src/features/cuesheet/Cuesheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ interface CuesheetProps {
columns: ColumnDef<OntimeRundownEntry>[];
handleUpdate: (rowIndex: number, accessor: keyof OntimeRundownEntry, payload: unknown) => void;
selectedId: string | null;
currentBlockId: string | null;
}

export default function Cuesheet({ data, columns, handleUpdate, selectedId }: CuesheetProps) {
export default function Cuesheet({ data, columns, handleUpdate, selectedId, currentBlockId }: CuesheetProps) {
const { followSelected, showSettings, showDelayBlock, showPrevious, showIndexColumn } = useCuesheetSettings();

const {
columnVisibility,
columnOrder,
Expand Down Expand Up @@ -91,6 +91,7 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId }: Cu

let eventIndex = 0;
let isPast = Boolean(selectedId);
console.log(currentBlockId);

return (
<>
Expand All @@ -114,11 +115,16 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId }: Cu
}

if (isOntimeBlock(row.original)) {
if (isPast && !showPrevious && key !== currentBlockId) {
return null;
}
return <BlockRow key={key} title={row.original.title} />;
}
if (isOntimeDelay(row.original)) {
if (isPast && !showPrevious) {
return null;
}
const delayVal = row.original.duration;

if (!showDelayBlock || delayVal === 0) {
return null;
}
Expand All @@ -128,9 +134,6 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId }: Cu
if (isOntimeEvent(row.original)) {
eventIndex++;
const isSelected = key === selectedId;
if (isSelected) {
isPast = false;
}

if (isPast && !showPrevious) {
return null;
Expand Down
1 change: 1 addition & 0 deletions apps/client/src/features/cuesheet/CuesheetWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function CuesheetWrapper() {
columns={columns}
handleUpdate={handleUpdate}
selectedId={featureData.selectedEventId}
currentBlockId={featureData.currentBlockId}
/>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const startServer = async (
message: messageService.getState(),
runtime: state.runtime,
eventNow: state.eventNow,
blockNow: state.blockNow,
publicEventNow: state.publicEventNow,
eventNext: state.eventNext,
publicEventNext: state.publicEventNext,
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/services/TimerService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OntimeEvent } from 'ontime-types';
import { OntimeEvent, OntimeRundown } from 'ontime-types';

import * as runtimeState from '../stores/runtimeState.js';
import type { UpdateResult } from '../stores/runtimeState.js';
Expand Down Expand Up @@ -96,8 +96,8 @@ export class TimerService {
* Loads roll information into timer service
* @param {OntimeEvent[]} rundown -- list of events to run
*/
roll(rundown: OntimeEvent[]) {
runtimeState.roll(rundown);
roll(playableEvents: OntimeEvent[], rundown: OntimeRundown) {
runtimeState.roll(playableEvents, rundown);
alex-Arc marked this conversation as resolved.
Show resolved Hide resolved
}

shutdown() {
Expand Down
24 changes: 16 additions & 8 deletions apps/server/src/services/runtime-service/RuntimeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getNextEventWithCue,
getEventWithId,
getPlayableEvents,
getRundown,
} from '../rundown-service/rundownUtils.js';
import { integrationService } from '../integration-service/IntegrationService.js';
import { getForceUpdate, getShouldClockUpdate, getShouldTimerUpdate } from './rundownService.utils.js';
Expand Down Expand Up @@ -99,8 +100,9 @@ class RuntimeService {

if (shouldCallRoll) {
// we dont call this.roll because we need to bypass the checks
const rundown = getPlayableEvents();
this.eventTimer.roll(rundown);
const playableEvents = getPlayableEvents();
const rundown = getRundown();
this.eventTimer.roll(playableEvents, rundown);
}

const timerPhaseChanged = RuntimeService.previousState.timer?.phase !== newState.timer.phase;
Expand Down Expand Up @@ -229,7 +231,8 @@ class RuntimeService {
if (onlyChangedNow) {
runtimeState.reload(eventNow);
} else {
runtimeState.reloadAll(eventNow, playableEvents);
const rundown = getRundown();
runtimeState.reloadAll(eventNow, playableEvents, rundown);
}
return;
}
Expand All @@ -253,8 +256,9 @@ class RuntimeService {
return false;
}

const timedEvents = getPlayableEvents();
const success = runtimeState.load(event, timedEvents);
const playableEvents = getPlayableEvents();
const rundown = getRundown();
const success = runtimeState.load(event, playableEvents, rundown);

if (success) {
logger.info(LogOrigin.Playback, `Loaded event with ID ${event.id}`);
Expand Down Expand Up @@ -497,7 +501,9 @@ class RuntimeService {
return;
}

this.eventTimer.roll(playableEvents);
const rundown = getRundown();

this.eventTimer.roll(playableEvents, rundown);

const state = runtimeState.getState();
const newState = state.timer.playback;
Expand Down Expand Up @@ -527,8 +533,9 @@ class RuntimeService {
return;
}

const timedEvents = getPlayableEvents();
runtimeState.resume(restorePoint, event, timedEvents);
const playableEvents = getPlayableEvents();
const rundown = getRundown();
runtimeState.resume(restorePoint, event, playableEvents, rundown);
logger.info(LogOrigin.Playback, 'Resuming playback');
}

Expand Down Expand Up @@ -586,6 +593,7 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert

// Update the events if they have changed
updateEventIfChanged('eventNow', state);
updateEventIfChanged('blockNow', state);
updateEventIfChanged('publicEventNow', state);
updateEventIfChanged('eventNext', state);
updateEventIfChanged('publicEventNext', state);
Expand Down
61 changes: 45 additions & 16 deletions apps/server/src/stores/runtimeState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { MaybeNumber, OntimeEvent, Playback, Runtime, TimerPhase, TimerState, TimerType } from 'ontime-types';
import { calculateDuration, dayInMs } from 'ontime-utils';
import {
MaybeNumber,
OntimeBlock,
OntimeEvent,
OntimeRundown,
Playback,
Runtime,
TimerPhase,
TimerState,
TimerType,
} from 'ontime-types';
import { calculateDuration, dayInMs, getRelevantBlock } from 'ontime-utils';

import { clock } from '../services/Clock.js';
import { RestorePoint } from '../services/RestoreService.js';
Expand Down Expand Up @@ -42,6 +52,7 @@
export type RuntimeState = {
clock: number; // realtime clock
eventNow: OntimeEvent | null;
blockNow: OntimeBlock | null;
publicEventNow: OntimeEvent | null;
eventNext: OntimeEvent | null;
publicEventNext: OntimeEvent | null;
Expand All @@ -59,6 +70,7 @@
const runtimeState: RuntimeState = {
clock: clock.timeNow(),
eventNow: null,
blockNow: null,
publicEventNow: null,
eventNext: null,
publicEventNext: null,
Expand All @@ -80,6 +92,7 @@
runtimeState.eventNow = null;
runtimeState.publicEventNow = null;
runtimeState.eventNext = null;
runtimeState.blockNow = null;
runtimeState.publicEventNext = null;

runtimeState.runtime.offset = null;
Expand Down Expand Up @@ -132,22 +145,24 @@
/**
* Loads a given event into state
* @param event
* @param rundown
* @param initialData
* @param {OntimeEvent[]} playableEvents list of events availebe for playback
* @param {OntimeRundown} rundown the full rundown
* @param initialData potential data from restore point
*/
export function load(
event: OntimeEvent,
rundown: OntimeEvent[],
playableEvents: OntimeEvent[],
rundown: OntimeRundown,
initialData?: Partial<TimerState & RestorePoint>,
): boolean {
clear();

const eventIndex = rundown.findIndex((eventInMemory) => eventInMemory.id === event.id);

Check failure on line 160 in apps/server/src/stores/runtimeState.ts

View workflow job for this annotation

GitHub Actions / unit-test

src/stores/__tests__/runtimeState.test.ts > mutation on runtimeState > playback operations > normal playback cycle

TypeError: Cannot read properties of undefined (reading 'findIndex') ❯ Module.load src/stores/runtimeState.ts:160:30 ❯ src/stores/__tests__/runtimeState.test.ts:84:7

Check failure on line 160 in apps/server/src/stores/runtimeState.ts

View workflow job for this annotation

GitHub Actions / unit-test

src/stores/__tests__/runtimeState.test.ts > mutation on runtimeState > playback operations > runtime offset

TypeError: Cannot read properties of undefined (reading 'findIndex') ❯ Module.load src/stores/runtimeState.ts:160:30 ❯ src/stores/__tests__/runtimeState.test.ts:153:7

runtimeState.runtime.selectedEventIndex = eventIndex;

loadNow(event, rundown);
loadNext(rundown);
loadNow(event, playableEvents, rundown);
loadNext(playableEvents);

runtimeState.clock = clock.timeNow();
runtimeState.timer.playback = Playback.Armed;
Expand All @@ -168,8 +183,9 @@
return event.id === runtimeState.eventNow?.id;
}

export function loadNow(event: OntimeEvent, playableEvents: OntimeEvent[]) {
export function loadNow(event: OntimeEvent, playableEvents: OntimeEvent[], rundown: OntimeRundown) {
runtimeState.eventNow = event;
runtimeState.blockNow = getRelevantBlock(rundown, event.id);

// check if current is also public
if (event.isPublic) {
Expand Down Expand Up @@ -227,8 +243,20 @@
}
}

export function resume(restorePoint: RestorePoint, event: OntimeEvent, rundown: OntimeEvent[]) {
load(event, rundown, restorePoint);
/**
* Resume from restore point
* @param restorePoint
* @param event
* @param playableEvents list of events availebe for playback
* @param rundown the full rundown
*/
export function resume(
restorePoint: RestorePoint,
event: OntimeEvent,
playableEvents: OntimeEvent[],
rundown: OntimeRundown,
) {
load(event, playableEvents, rundown, restorePoint);
}

/**
Expand Down Expand Up @@ -264,9 +292,10 @@
* without interrupting timer
* @param eventNow
* @param playableEvents
* @param rundown
*/
export function reloadAll(eventNow: OntimeEvent, playableEvents: OntimeEvent[]) {
loadNow(eventNow, playableEvents);
export function reloadAll(eventNow: OntimeEvent, playableEvents: OntimeEvent[], rundown: OntimeRundown) {
loadNow(eventNow, playableEvents, rundown);
loadNext(playableEvents);
reload(eventNow);
}
Expand Down Expand Up @@ -442,12 +471,12 @@
}
}

export function roll(rundown: OntimeEvent[]) {
export function roll(playableEvents: OntimeEvent[], rundown: OntimeRundown) {
const selectedEventIndex = runtimeState.runtime.selectedEventIndex;
clear();
runtimeState.runtime.numEvents = rundown.length;
runtimeState.runtime.numEvents = playableEvents.length;

const { nextEvent, currentEvent } = getRollTimers(rundown, runtimeState.clock, selectedEventIndex);
const { nextEvent, currentEvent } = getRollTimers(playableEvents, runtimeState.clock, selectedEventIndex);

if (currentEvent) {
// there is something running, load
Expand All @@ -460,7 +489,7 @@

// when we load a timer in roll, we do the same things as before
// but also pre-populate some data as to the running state
load(currentEvent, rundown, {
load(currentEvent, playableEvents, rundown, {
startedAt: currentEvent.timeStart,
expectedFinish: currentEvent.timeEnd,
current: endTime - runtimeState.clock,
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/definitions/runtime/RuntimeStore.type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OntimeEvent } from '../core/OntimeEvent.type.js';
import type { OntimeBlock, OntimeEvent } from '../core/OntimeEvent.type.js';
import type { SimpleTimerState } from './AuxTimer.type.js';
import type { MessageState } from './MessageControl.type.js';
import type { Runtime } from './Runtime.type.js';
Expand All @@ -16,6 +16,7 @@ export type RuntimeStore = {
// rundown data
runtime: Runtime;
eventNow: OntimeEvent | null;
blockNow: OntimeBlock | null;
publicEventNow: OntimeEvent | null;
eventNext: OntimeEvent | null;
publicEventNext: OntimeEvent | null;
Expand Down
1 change: 1 addition & 0 deletions packages/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {
getPreviousEventNormal,
getPreviousNormal,
swapEventData,
getRelevantBlock,
} from './src/rundown-utils/rundownUtils.js';

// time format utils
Expand Down
30 changes: 30 additions & 0 deletions packages/utils/src/rundown-utils/rundownUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getNextEvent,
getPrevious,
getPreviousEvent,
getRelevantBlock,
swapEventData,
} from './rundownUtils';

Expand Down Expand Up @@ -262,4 +263,33 @@ describe('getLastEvent', () => {
expect(lastEntry).toBe(null);
});
});

describe('relevantBlock', () => {
const testRundown = [
{ id: 'a', type: SupportedEvent.Event },
{ id: 'b', type: SupportedEvent.Event },
{ id: 'c', type: SupportedEvent.Event },
{ id: 'd', type: SupportedEvent.Delay },
{ id: 'e', type: SupportedEvent.Block },
{ id: 'f', type: SupportedEvent.Event },
{ id: 'g', type: SupportedEvent.Block },
{ id: 'h', type: SupportedEvent.Event },
];

it('returns the relevant block', () => {
const block = getRelevantBlock(testRundown as unknown as OntimeRundown, 'h');

expect(block?.id).toBe('g');
});
it('returns the relevant block', () => {
const block = getRelevantBlock(testRundown as unknown as OntimeRundown, 'f');

expect(block?.id).toBe('e');
});
it('returns the relevant block', () => {
const block = getRelevantBlock(testRundown as unknown as OntimeRundown, 'a');

expect(block).toBe(null);
});
});
});
Loading
Loading